@@ -22,11 +22,15 @@ This file is part of the iText (R) project.
22
22
*/
23
23
package com .itextpdf .commons .actions .producer ;
24
24
25
+ import com .itextpdf .commons .actions .AbstractITextConfigurationEvent ;
26
+ import com .itextpdf .commons .actions .AbstractProductProcessITextEvent ;
25
27
import com .itextpdf .commons .actions .confirmations .ConfirmedEventWrapper ;
28
+ import com .itextpdf .commons .actions .processors .ITextProductEventProcessor ;
26
29
import com .itextpdf .commons .exceptions .CommonsExceptionMessageConstant ;
27
30
import com .itextpdf .commons .logs .CommonsLogMessageConstant ;
28
31
import com .itextpdf .commons .utils .MessageFormatUtil ;
29
32
33
+ import java .util .ArrayList ;
30
34
import java .util .Collections ;
31
35
import java .util .HashMap ;
32
36
import java .util .List ;
@@ -39,9 +43,11 @@ This file is part of the iText (R) project.
39
43
/**
40
44
* Class is used for producer line building.
41
45
*/
42
- public final class ProducerBuilder {
46
+ public final class ProducerBuilder extends AbstractITextConfigurationEvent {
43
47
private static final Logger LOGGER = LoggerFactory .getLogger (ProducerBuilder .class );
44
48
49
+ private static final ProducerBuilder INSTANCE = new ProducerBuilder ();
50
+
45
51
private static final String CURRENT_DATE = "currentDate" ;
46
52
private static final String USED_PRODUCTS = "usedProducts" ;
47
53
private static final String COPYRIGHT_SINCE = "copyrightSince" ;
@@ -75,27 +81,49 @@ public final class ProducerBuilder {
75
81
private ProducerBuilder () { }
76
82
77
83
/**
78
- * Modifies an old producer line according to events registered for the document. Format of the
79
- * new producer line will be defined by the first event in the list. Placeholder will be
80
- * replaced and merged all together
84
+ * Modifies an old producer line according to events registered for the document.
85
+ * Events can be either wrapped with {@link ConfirmedEventWrapper} or not.
86
+ * Format of the new producer line will be defined by the first event in the list.
87
+ * Placeholder will be replaced and merged all together
81
88
*
82
- * @param events list of events wrapped with {@link ConfirmedEventWrapper} registered for
83
- * the document
84
- * @param oldProducer is an old producer line. If <code>null</code> or empty, will be replaced
89
+ * @param events list of events registered for the document
90
+ * @param oldProducer old producer line. If <code>null</code> or empty, will be replaced
85
91
* with a new one. Otherwise new line will be attached with
86
92
* <code>modified using</code> prefix. If old producer line already contains
87
93
* <code>modified using</code> substring, it will be overriden with a new one
88
94
* @return modified producer line
89
95
*/
90
- public static String modifyProducer (List <ConfirmedEventWrapper > events , String oldProducer ) {
91
- final String newProducer = buildProducer (events );
96
+ public static String modifyProducer (List <? extends AbstractProductProcessITextEvent > events , String oldProducer ) {
97
+ List <ConfirmedEventWrapper > confirmedEvents = new ArrayList <>();
98
+ if (events != null ) {
99
+ for (AbstractProductProcessITextEvent event : events ) {
100
+ if (event instanceof ConfirmedEventWrapper ) {
101
+ confirmedEvents .add ((ConfirmedEventWrapper ) event );
102
+ } else {
103
+ ITextProductEventProcessor processor = INSTANCE .getActiveProcessor (event .getProductName ());
104
+ confirmedEvents .add (new ConfirmedEventWrapper (event , processor .getUsageType (), processor .getProducer ()));
105
+ }
106
+ }
107
+ }
108
+
109
+ final String newProducer = buildProducer (confirmedEvents );
92
110
if (oldProducer == null || oldProducer .isEmpty ()) {
93
111
return newProducer ;
94
112
} else {
95
113
return oldProducer + MODIFIED_USING + newProducer ;
96
114
}
97
115
}
98
116
117
+ /**
118
+ * Configuration events for util internal purposes are not expected to be sent.
119
+ *
120
+ * @throws IllegalStateException on every method call
121
+ */
122
+ @ Override
123
+ protected void doAction () {
124
+ throw new IllegalStateException ("Configuration events for util internal purposes are not expected to be sent" );
125
+ }
126
+
99
127
private static String buildProducer (List <ConfirmedEventWrapper > events ) {
100
128
if (events == null || events .isEmpty ()) {
101
129
throw new IllegalArgumentException (CommonsExceptionMessageConstant .NO_EVENTS_WERE_REGISTERED_FOR_THE_DOCUMENT );
0 commit comments