@@ -26,17 +26,22 @@ You should have received a copy of the GNU Affero General Public License
2626using System . Text . RegularExpressions ;
2727using Microsoft . Extensions . Logging ;
2828using iText . Commons ;
29+ using iText . Commons . Actions ;
2930using iText . Commons . Actions . Confirmations ;
31+ using iText . Commons . Actions . Processors ;
3032using iText . Commons . Exceptions ;
3133using iText . Commons . Logs ;
3234using iText . Commons . Utils ;
3335
3436namespace iText . Commons . Actions . Producer {
3537 /// <summary>Class is used for producer line building.</summary>
36- public sealed class ProducerBuilder {
38+ public sealed class ProducerBuilder : AbstractITextConfigurationEvent {
3739 private static readonly ILogger LOGGER = ITextLogManager . GetLogger ( typeof ( iText . Commons . Actions . Producer . ProducerBuilder
3840 ) ) ;
3941
42+ private static readonly iText . Commons . Actions . Producer . ProducerBuilder INSTANCE = new iText . Commons . Actions . Producer . ProducerBuilder
43+ ( ) ;
44+
4045 private const String CURRENT_DATE = "currentDate" ;
4146
4247 private const String USED_PRODUCTS = "usedProducts" ;
@@ -76,25 +81,36 @@ private ProducerBuilder() {
7681
7782 /// <summary>Modifies an old producer line according to events registered for the document.</summary>
7883 /// <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
8586 /// <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>
8992 /// <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
9194 /// with a new one. Otherwise new line will be attached with
9295 /// <c>modified using</c> prefix. If old producer line already contains
9396 /// <c>modified using</c> substring, it will be overriden with a new one
9497 /// </param>
9598 /// <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 ) ;
98114 if ( oldProducer == null || String . IsNullOrEmpty ( oldProducer ) ) {
99115 return newProducer ;
100116 }
@@ -103,6 +119,12 @@ public static String ModifyProducer(IList<ConfirmedEventWrapper> events, String
103119 }
104120 }
105121
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+
106128 private static String BuildProducer ( IList < ConfirmedEventWrapper > events ) {
107129 if ( events == null || events . IsEmpty ( ) ) {
108130 throw new ArgumentException ( CommonsExceptionMessageConstant . NO_EVENTS_WERE_REGISTERED_FOR_THE_DOCUMENT ) ;
0 commit comments