@@ -26,17 +26,22 @@ You should have received a copy of the GNU Affero General Public License
26
26
using System . Text . RegularExpressions ;
27
27
using Microsoft . Extensions . Logging ;
28
28
using iText . Commons ;
29
+ using iText . Commons . Actions ;
29
30
using iText . Commons . Actions . Confirmations ;
31
+ using iText . Commons . Actions . Processors ;
30
32
using iText . Commons . Exceptions ;
31
33
using iText . Commons . Logs ;
32
34
using iText . Commons . Utils ;
33
35
34
36
namespace iText . Commons . Actions . Producer {
35
37
/// <summary>Class is used for producer line building.</summary>
36
- public sealed class ProducerBuilder {
38
+ public sealed class ProducerBuilder : AbstractITextConfigurationEvent {
37
39
private static readonly ILogger LOGGER = ITextLogManager . GetLogger ( typeof ( iText . Commons . Actions . Producer . ProducerBuilder
38
40
) ) ;
39
41
42
+ private static readonly iText . Commons . Actions . Producer . ProducerBuilder INSTANCE = new iText . Commons . Actions . Producer . ProducerBuilder
43
+ ( ) ;
44
+
40
45
private const String CURRENT_DATE = "currentDate" ;
41
46
42
47
private const String USED_PRODUCTS = "usedProducts" ;
@@ -76,25 +81,36 @@ private ProducerBuilder() {
76
81
77
82
/// <summary>Modifies an old producer line according to events registered for the document.</summary>
78
83
/// <remarks>
79
- /// Modifies an old producer line according to events registered for the document. Format of the
80
- /// new producer line will be defined by the first event in the list. Placeholder will be
81
- /// replaced and merged all together
82
- /// </remarks>
83
- /// <param name="events">
84
- /// list of events wrapped with
84
+ /// Modifies an old producer line according to events registered for the document.
85
+ /// Events can be either wrapped with
85
86
/// <see cref="iText.Commons.Actions.Confirmations.ConfirmedEventWrapper"/>
86
- /// registered for
87
- /// the document
88
- /// </param>
87
+ /// or not.
88
+ /// Format of the new producer line will be defined by the first event in the list.
89
+ /// Placeholder will be replaced and merged all together
90
+ /// </remarks>
91
+ /// <param name="events">list of events registered for the document</param>
89
92
/// <param name="oldProducer">
90
- /// is an old producer line. If <c>null</c> or empty, will be replaced
93
+ /// old producer line. If <c>null</c> or empty, will be replaced
91
94
/// with a new one. Otherwise new line will be attached with
92
95
/// <c>modified using</c> prefix. If old producer line already contains
93
96
/// <c>modified using</c> substring, it will be overriden with a new one
94
97
/// </param>
95
98
/// <returns>modified producer line</returns>
96
- public static String ModifyProducer ( IList < ConfirmedEventWrapper > events , String oldProducer ) {
97
- String newProducer = BuildProducer ( events ) ;
99
+ public static String ModifyProducer < _T0 > ( IList < _T0 > events , String oldProducer )
100
+ where _T0 : AbstractProductProcessITextEvent {
101
+ IList < ConfirmedEventWrapper > confirmedEvents = new List < ConfirmedEventWrapper > ( ) ;
102
+ if ( events != null ) {
103
+ foreach ( AbstractProductProcessITextEvent @event in events ) {
104
+ if ( @event is ConfirmedEventWrapper ) {
105
+ confirmedEvents . Add ( ( ConfirmedEventWrapper ) @event ) ;
106
+ }
107
+ else {
108
+ ITextProductEventProcessor processor = INSTANCE . GetActiveProcessor ( @event . GetProductName ( ) ) ;
109
+ confirmedEvents . Add ( new ConfirmedEventWrapper ( @event , processor . GetUsageType ( ) , processor . GetProducer ( ) ) ) ;
110
+ }
111
+ }
112
+ }
113
+ String newProducer = BuildProducer ( confirmedEvents ) ;
98
114
if ( oldProducer == null || String . IsNullOrEmpty ( oldProducer ) ) {
99
115
return newProducer ;
100
116
}
@@ -103,6 +119,12 @@ public static String ModifyProducer(IList<ConfirmedEventWrapper> events, String
103
119
}
104
120
}
105
121
122
+ /// <summary>Configuration events for util internal purposes are not expected to be sent.</summary>
123
+ protected internal override void DoAction ( ) {
124
+ throw new InvalidOperationException ( "Configuration events for util internal purposes are not expected to be sent"
125
+ ) ;
126
+ }
127
+
106
128
private static String BuildProducer ( IList < ConfirmedEventWrapper > events ) {
107
129
if ( events == null || events . IsEmpty ( ) ) {
108
130
throw new ArgumentException ( CommonsExceptionMessageConstant . NO_EVENTS_WERE_REGISTERED_FOR_THE_DOCUMENT ) ;
0 commit comments