diff --git a/itext.tests/itext.kernel.tests/itext/kernel/pdf/PdfStampingTest.cs b/itext.tests/itext.kernel.tests/itext/kernel/pdf/PdfStampingTest.cs index 4f5a911683..390c9ab661 100644 --- a/itext.tests/itext.kernel.tests/itext/kernel/pdf/PdfStampingTest.cs +++ b/itext.tests/itext.kernel.tests/itext/kernel/pdf/PdfStampingTest.cs @@ -24,12 +24,12 @@ You should have received a copy of the GNU Affero General Public License using System.IO; using iText.Commons.Utils; using iText.IO.Source; -using iText.Kernel.Events; using iText.Kernel.Font; using iText.Kernel.Logs; using iText.Kernel.Pdf.Canvas; using iText.Kernel.Pdf.Canvas.Parser; using iText.Kernel.Pdf.Canvas.Parser.Listener; +using iText.Kernel.Pdf.Event; using iText.Kernel.Utils; using iText.Test; using iText.Test.Attributes; @@ -1239,8 +1239,8 @@ internal static void VerifyPdfPagesCount(PdfObject root) { //\endcond //\cond DO_NOT_DOCUMENT - internal class WatermarkEventHandler : iText.Kernel.Events.IEventHandler { - public virtual void HandleEvent(Event @event) { + internal class WatermarkEventHandler : AbstractPdfDocumentEventHandler { + protected internal override void OnAcceptedEvent(AbstractPdfDocumentEvent @event) { PdfDocumentEvent pdfEvent = (PdfDocumentEvent)@event; PdfPage page = pdfEvent.GetPage(); PdfCanvas pdfCanvas = new PdfCanvas(page); diff --git a/itext.tests/itext.kernel.tests/itext/kernel/pdf/event/PdfDocumentEventHandlingTest.cs b/itext.tests/itext.kernel.tests/itext/kernel/pdf/event/PdfDocumentEventHandlingTest.cs new file mode 100644 index 0000000000..07e8de34fd --- /dev/null +++ b/itext.tests/itext.kernel.tests/itext/kernel/pdf/event/PdfDocumentEventHandlingTest.cs @@ -0,0 +1,101 @@ +/* +This file is part of the iText (R) project. +Copyright (c) 1998-2024 Apryse Group NV +Authors: Apryse Software. + +This program is offered under a commercial and under the AGPL license. +For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below. + +AGPL licensing: +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ +using System.IO; +using iText.Commons.Actions; +using iText.Kernel.Pdf; +using iText.Test; + +namespace iText.Kernel.Pdf.Event { + [NUnit.Framework.Category("UnitTest")] + public class PdfDocumentEventHandlingTest : ExtendedITextTest { + [NUnit.Framework.Test] + public virtual void SimplePdfDocumentEventTest() { + using (PdfDocument document = new PdfDocument(new PdfWriter(new MemoryStream()))) { + PdfDocumentEventHandlingTest.InsertPageHandler insertPageHandler = new PdfDocumentEventHandlingTest.InsertPageHandler + (); + document.AddEventHandler(PdfDocumentEvent.INSERT_PAGE, insertPageHandler); + document.AddNewPage(); + document.AddNewPage(); + NUnit.Framework.Assert.AreEqual(2, insertPageHandler.GetInsertedPagesCounter()); + } + } + + [NUnit.Framework.Test] + public virtual void GloballyRegisteredAbstractPdfDocumentEventHandlerTest() { + PdfDocumentEventHandlingTest.InsertPageHandler insertPageHandler = new PdfDocumentEventHandlingTest.InsertPageHandler + (); + insertPageHandler.AddType(PdfDocumentEvent.INSERT_PAGE); + EventManager.GetInstance().Register(insertPageHandler); + using (PdfDocument document = new PdfDocument(new PdfWriter(new MemoryStream()))) { + document.AddNewPage(); + } + // Events with specified PDF document are ignored. + NUnit.Framework.Assert.AreEqual(0, insertPageHandler.GetInsertedPagesCounter()); + EventManager.GetInstance().Unregister(insertPageHandler); + } + + [NUnit.Framework.Test] + public virtual void EventHandlerPerSeveralDocumentsTest() { + using (PdfDocument document1 = new PdfDocument(new PdfWriter(new MemoryStream()))) { + using (PdfDocument document2 = new PdfDocument(new PdfWriter(new MemoryStream()))) { + using (PdfDocument document3 = new PdfDocument(new PdfWriter(new MemoryStream()))) { + PdfDocumentEventHandlingTest.InsertPageHandler insertPageHandler = new PdfDocumentEventHandlingTest.InsertPageHandler + (); + document1.AddEventHandler(PdfDocumentEvent.INSERT_PAGE, insertPageHandler); + document2.AddEventHandler(PdfDocumentEvent.INSERT_PAGE, insertPageHandler); + document1.AddNewPage(); + document2.AddNewPage(); + document3.AddNewPage(); + NUnit.Framework.Assert.AreEqual(2, insertPageHandler.GetInsertedPagesCounter()); + document2.RemoveEventHandler(insertPageHandler); + document2.AddNewPage(); + NUnit.Framework.Assert.AreEqual(2, insertPageHandler.GetInsertedPagesCounter()); + } + } + } + } + + [NUnit.Framework.Test] + public virtual void NoDocumentSpecifiedForEventButHandlerIsGloballyRegisteredTest() { + PdfDocumentEventHandlingTest.InsertPageHandler insertPageHandler = new PdfDocumentEventHandlingTest.InsertPageHandler + (); + insertPageHandler.AddType(PdfDocumentEvent.INSERT_PAGE); + EventManager.GetInstance().Register(insertPageHandler); + EventManager.GetInstance().OnEvent(new PdfDocumentEvent(PdfDocumentEvent.INSERT_PAGE)); + EventManager.GetInstance().Unregister(insertPageHandler); + NUnit.Framework.Assert.AreEqual(1, insertPageHandler.GetInsertedPagesCounter()); + } + + private class InsertPageHandler : AbstractPdfDocumentEventHandler { + private int insertedPagesCounter = 0; + + public virtual int GetInsertedPagesCounter() { + return insertedPagesCounter; + } + + protected internal override void OnAcceptedEvent(AbstractPdfDocumentEvent @event) { + insertedPagesCounter++; + } + } + } +} diff --git a/itext.tests/itext.layout.tests/itext/layout/DefaultLayoutTest.cs b/itext.tests/itext.layout.tests/itext/layout/DefaultLayoutTest.cs index a2d440518a..23d3c442ac 100644 --- a/itext.tests/itext.layout.tests/itext/layout/DefaultLayoutTest.cs +++ b/itext.tests/itext.layout.tests/itext/layout/DefaultLayoutTest.cs @@ -24,11 +24,11 @@ You should have received a copy of the GNU Affero General Public License using System.Collections.Generic; using System.IO; using iText.Kernel.Colors; -using iText.Kernel.Events; using iText.Kernel.Font; using iText.Kernel.Geom; using iText.Kernel.Pdf; using iText.Kernel.Pdf.Canvas; +using iText.Kernel.Pdf.Event; using iText.Kernel.Pdf.Layer; using iText.Kernel.Utils; using iText.Layout.Borders; @@ -241,8 +241,8 @@ public virtual void CloseEmptyDocumentWithRemovingPageEventOnAddingPageTest() { , "diff")); } - private class ParagraphAdderHandler : iText.Kernel.Events.IEventHandler { - public virtual void HandleEvent(Event @event) { + private class ParagraphAdderHandler : AbstractPdfDocumentEventHandler { + protected override void OnAcceptedEvent(AbstractPdfDocumentEvent @event) { PdfDocumentEvent docEvent = (PdfDocumentEvent)@event; PdfPage page = docEvent.GetPage(); PdfDocument pdfDoc = ((PdfDocumentEvent)@event).GetDocument(); @@ -257,12 +257,12 @@ public virtual void HandleEvent(Event @event) { } } - private class PageRemoverHandler : iText.Kernel.Events.IEventHandler { - public virtual void HandleEvent(Event @event) { + private class PageRemoverHandler : AbstractPdfDocumentEventHandler { + protected override void OnAcceptedEvent(AbstractPdfDocumentEvent @event) { PdfDocumentEvent docEvent = (PdfDocumentEvent)@event; PdfPage page = docEvent.GetPage(); - PdfDocument pdfDoc = ((PdfDocumentEvent)@event).GetDocument(); - pdfDoc.RemovePage(1); + PdfDocument pdfDoc = @event.GetDocument(); + pdfDoc.RemovePage(page); } } } diff --git a/itext.tests/itext.pdfa.tests/itext/pdfa/PdfAPageTest.cs b/itext.tests/itext.pdfa.tests/itext/pdfa/PdfAPageTest.cs index 484c3d62ce..8e2c77171d 100644 --- a/itext.tests/itext.pdfa.tests/itext/pdfa/PdfAPageTest.cs +++ b/itext.tests/itext.pdfa.tests/itext/pdfa/PdfAPageTest.cs @@ -22,9 +22,9 @@ You should have received a copy of the GNU Affero General Public License */ using System; using iText.Commons.Utils; -using iText.Kernel.Events; using iText.Kernel.Geom; using iText.Kernel.Pdf; +using iText.Kernel.Pdf.Event; using iText.Layout; using iText.Layout.Element; using iText.Pdfa.Logs; @@ -174,7 +174,7 @@ public virtual void CheckFlushingOfCheckedPage() { //\cond DO_NOT_DOCUMENT // Android-Conversion-Skip-Line (TODO DEVSIX-7377 introduce pdf\a validation on Android) - internal class EndPageEventHandler : iText.Kernel.Events.IEventHandler { + internal class EndPageEventHandler : AbstractPdfDocumentEventHandler { private int counter = 0; //\cond DO_NOT_DOCUMENT @@ -186,7 +186,7 @@ public virtual int GetCounter() { return counter; } - public virtual void HandleEvent(Event @event) { + protected override void OnAcceptedEvent(AbstractPdfDocumentEvent @event) { counter++; } } diff --git a/itext.tests/itext.sign.tests/resources/itext/signatures/sign/SignatureAppearanceTest/cmp_emptySignatureAppearance.pdf b/itext.tests/itext.sign.tests/resources/itext/signatures/sign/SignatureAppearanceTest/cmp_emptySignatureAppearance.pdf index e5a2cb45f3..34d21d1fd0 100644 Binary files a/itext.tests/itext.sign.tests/resources/itext/signatures/sign/SignatureAppearanceTest/cmp_emptySignatureAppearance.pdf and b/itext.tests/itext.sign.tests/resources/itext/signatures/sign/SignatureAppearanceTest/cmp_emptySignatureAppearance.pdf differ diff --git a/itext.tests/itext.sign.tests/resources/itext/signatures/sign/SignatureAppearanceTest/cmp_signatureFieldAppearanceTest.pdf b/itext.tests/itext.sign.tests/resources/itext/signatures/sign/SignatureAppearanceTest/cmp_signatureFieldAppearanceTest.pdf index 3b4b50654a..0963394d15 100644 Binary files a/itext.tests/itext.sign.tests/resources/itext/signatures/sign/SignatureAppearanceTest/cmp_signatureFieldAppearanceTest.pdf and b/itext.tests/itext.sign.tests/resources/itext/signatures/sign/SignatureAppearanceTest/cmp_signatureFieldAppearanceTest.pdf differ diff --git a/itext.tests/itext.sign.tests/resources/itext/signatures/sign/SignatureAppearanceTest/test.pem b/itext.tests/itext.sign.tests/resources/itext/signatures/sign/SignatureAppearanceTest/test.pem index a9307d180a..4cbee8fcbd 100644 --- a/itext.tests/itext.sign.tests/resources/itext/signatures/sign/SignatureAppearanceTest/test.pem +++ b/itext.tests/itext.sign.tests/resources/itext/signatures/sign/SignatureAppearanceTest/test.pem @@ -1,51 +1,74 @@ -----BEGIN ENCRYPTED PRIVATE KEY----- -MIIFNTBf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/itext/bouncycastle/cert/ocsp/ResponderIDBC.cs b/itext/itext.bouncy-castle-adapter/itext/bouncycastle/cert/ocsp/ResponderIDBC.cs index 4f458913fa..770b8cd9ce 100644 --- a/itext/itext.bouncy-castle-adapter/itext/bouncycastle/cert/ocsp/ResponderIDBC.cs +++ b/itext/itext.bouncy-castle-adapter/itext/bouncycastle/cert/ocsp/ResponderIDBC.cs @@ -26,6 +26,10 @@ You should have received a copy of the GNU Affero General Public License using iText.Commons.Bouncycastle.Cert.Ocsp; namespace iText.Bouncycastle.Cert.Ocsp { + /// + /// Wrapper class for + /// . + /// public class ResponderIDBC : IResponderID { private readonly ResponderID responderID; diff --git a/itext/itext.bouncy-castle-fips-adapter/itext/bouncycastlefips/cert/ocsp/ResponderIDBCFips.cs b/itext/itext.bouncy-castle-fips-adapter/itext/bouncycastlefips/cert/ocsp/ResponderIDBCFips.cs index 5fa28964cb..75b6bd9e6d 100644 --- a/itext/itext.bouncy-castle-fips-adapter/itext/bouncycastlefips/cert/ocsp/ResponderIDBCFips.cs +++ b/itext/itext.bouncy-castle-fips-adapter/itext/bouncycastlefips/cert/ocsp/ResponderIDBCFips.cs @@ -26,6 +26,10 @@ You should have received a copy of the GNU Affero General Public License using iText.Commons.Bouncycastle.Cert.Ocsp; namespace iText.Bouncycastlefips.Cert.Ocsp { + /// + /// Wrapper class for + /// . + /// public class ResponderIDBCFips : IResponderID { private readonly ResponderID responderID; diff --git a/itext/itext.commons/itext/commons/actions/EventManager.cs b/itext/itext.commons/itext/commons/actions/EventManager.cs index 2cd292e245..c5af788e8a 100644 --- a/itext/itext.commons/itext/commons/actions/EventManager.cs +++ b/itext/itext.commons/itext/commons/actions/EventManager.cs @@ -43,7 +43,7 @@ private EventManager() { handlers.Add(ProductEventHandler.INSTANCE); } - /// Allows an access to the instance of EventManager. + /// Allows access to the instance of EventManager. /// the instance of the class public static iText.Commons.Actions.EventManager GetInstance() { return INSTANCE; diff --git a/itext/itext.kernel/itext/kernel/events/Event.cs b/itext/itext.kernel/itext/kernel/events/Event.cs deleted file mode 100644 index 033040c93d..0000000000 --- a/itext/itext.kernel/itext/kernel/events/Event.cs +++ /dev/null @@ -1,43 +0,0 @@ -/* -This file is part of the iText (R) project. -Copyright (c) 1998-2024 Apryse Group NV -Authors: Apryse Software. - -This program is offered under a commercial and under the AGPL license. -For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below. - -AGPL licensing: -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU Affero General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Affero General Public License for more details. - -You should have received a copy of the GNU Affero General Public License -along with this program. If not, see . -*/ -using System; - -namespace iText.Kernel.Events { - /// Describes abstract event. - public class Event { - /// A type of event. - protected internal String type; - - /// Creates an event of the specified type. - /// type of event - public Event(String type) { - this.type = type; - } - - /// Returns the type of this event. - /// type of this event - public virtual String GetEventType() { - return type; - } - } -} diff --git a/itext/itext.kernel/itext/kernel/events/EventDispatcher.cs b/itext/itext.kernel/itext/kernel/events/EventDispatcher.cs deleted file mode 100644 index ebea2532ee..0000000000 --- a/itext/itext.kernel/itext/kernel/events/EventDispatcher.cs +++ /dev/null @@ -1,78 +0,0 @@ -/* -This file is part of the iText (R) project. -Copyright (c) 1998-2024 Apryse Group NV -Authors: Apryse Software. - -This program is offered under a commercial and under the AGPL license. -For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below. - -AGPL licensing: -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU Affero General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Affero General Public License for more details. - -You should have received a copy of the GNU Affero General Public License -along with this program. If not, see . -*/ -using System; -using System.Collections.Generic; - -namespace iText.Kernel.Events { - /// - /// IEventDispatcher implementation that forwards Events to registered - /// - /// implementations. - /// - public class EventDispatcher : IEventDispatcher { - protected internal IDictionary> eventHandlers = new Dictionary - >(); - - public virtual void AddEventHandler(String type, iText.Kernel.Events.IEventHandler handler) { - RemoveEventHandler(type, handler); - IList handlers = eventHandlers.Get(type); - if (handlers == null) { - handlers = new List(); - eventHandlers.Put(type, handlers); - } - handlers.Add(handler); - } - - public virtual void DispatchEvent(Event @event) { - DispatchEvent(@event, false); - } - - public virtual void DispatchEvent(Event @event, bool delayed) { - IList handlers = eventHandlers.Get(@event.GetEventType()); - if (handlers != null) { - foreach (iText.Kernel.Events.IEventHandler handler in handlers) { - handler.HandleEvent(@event); - } - } - } - - public virtual bool HasEventHandler(String type) { - return eventHandlers.ContainsKey(type); - } - - public virtual void RemoveEventHandler(String type, iText.Kernel.Events.IEventHandler handler) { - IList handlers = eventHandlers.Get(type); - if (handlers == null) { - return; - } - handlers.Remove(handler); - if (handlers.Count == 0) { - eventHandlers.JRemove(type); - } - } - - public virtual void RemoveAllHandlers() { - eventHandlers.Clear(); - } - } -} diff --git a/itext/itext.kernel/itext/kernel/events/IEventDispatcher.cs b/itext/itext.kernel/itext/kernel/events/IEventDispatcher.cs deleted file mode 100644 index bc8bc3911f..0000000000 --- a/itext/itext.kernel/itext/kernel/events/IEventDispatcher.cs +++ /dev/null @@ -1,81 +0,0 @@ -/* -This file is part of the iText (R) project. -Copyright (c) 1998-2024 Apryse Group NV -Authors: Apryse Software. - -This program is offered under a commercial and under the AGPL license. -For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below. - -AGPL licensing: -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU Affero General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Affero General Public License for more details. - -You should have received a copy of the GNU Affero General Public License -along with this program. If not, see . -*/ -using System; - -namespace iText.Kernel.Events { - /// Event dispatcher interface. - public interface IEventDispatcher { - /// Adds new event handler. - /// a type of event to be handled - /// event handler - void AddEventHandler(String type, iText.Kernel.Events.IEventHandler handler); - - /// Dispatches an event. - /// - /// the - /// - /// to be dispatched - /// - void DispatchEvent(Event @event); - - /// Dispatches a delayed event. - /// - /// Dispatches a delayed event. - /// Sometimes event cannot be handled immediately because event handler has not been set yet. - /// In this case event is placed into event ques of dispatcher and is waiting until handler is assigned. - /// - /// - /// the - /// - /// to be dispatched - /// - /// - /// flag whether - /// - /// delayed or not - /// - void DispatchEvent(Event @event, bool delayed); - - /// Checks if event dispatcher as an event handler assigned for a certain event type. - /// - /// a type of the - /// - /// - /// true if event dispatcher as an event handler assigned for a certain event type - bool HasEventHandler(String type); - - /// Removes event handler. - /// - /// a type of the - /// - /// - /// - /// event handler - /// - /// - void RemoveEventHandler(String type, iText.Kernel.Events.IEventHandler handler); - - /// Remove all event handlers. - void RemoveAllHandlers(); - } -} diff --git a/itext/itext.kernel/itext/kernel/events/IEventHandler.cs b/itext/itext.kernel/itext/kernel/events/IEventHandler.cs deleted file mode 100644 index e7b21b85fc..0000000000 --- a/itext/itext.kernel/itext/kernel/events/IEventHandler.cs +++ /dev/null @@ -1,38 +0,0 @@ -/* -This file is part of the iText (R) project. -Copyright (c) 1998-2024 Apryse Group NV -Authors: Apryse Software. - -This program is offered under a commercial and under the AGPL license. -For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below. - -AGPL licensing: -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU Affero General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Affero General Public License for more details. - -You should have received a copy of the GNU Affero General Public License -along with this program. If not, see . -*/ -namespace iText.Kernel.Events { - /// Interface for handling events. - /// - /// Interface for handling events. EventHandlers are added to the - /// . - /// - public interface IEventHandler { - /// Hook for handling events. - /// - /// Hook for handling events. Implementations can access the PdfDocument instance - /// associated to the specified Event or, if available, the PdfPage instance. - /// - /// the Event that needs to be processed - void HandleEvent(Event @event); - } -} diff --git a/itext/itext.kernel/itext/kernel/mac/StandaloneMacIntegrityProtector.cs b/itext/itext.kernel/itext/kernel/mac/StandaloneMacIntegrityProtector.cs index f2ded9ad2e..8b46685873 100644 --- a/itext/itext.kernel/itext/kernel/mac/StandaloneMacIntegrityProtector.cs +++ b/itext/itext.kernel/itext/kernel/mac/StandaloneMacIntegrityProtector.cs @@ -24,9 +24,9 @@ You should have received a copy of the GNU Affero General Public License using System.IO; using iText.Commons.Bouncycastle.Security; using iText.IO.Source; -using iText.Kernel.Events; using iText.Kernel.Exceptions; using iText.Kernel.Pdf; +using iText.Kernel.Pdf.Event; namespace iText.Kernel.Mac { //\cond DO_NOT_DOCUMENT @@ -108,8 +108,8 @@ private MemoryStream GetDocumentByteArrayOutputStream() { return ((MemoryStream)document.GetWriter().GetOutputStream()); } - private sealed class StandaloneMacPdfObjectAdder : iText.Kernel.Events.IEventHandler { - public void HandleEvent(Event @event) { + private sealed class StandaloneMacPdfObjectAdder : AbstractPdfDocumentEventHandler { + protected internal override void OnAcceptedEvent(AbstractPdfDocumentEvent @event) { this._enclosing.macPdfObject = new MacPdfObject(this._enclosing.GetContainerSizeEstimate()); this._enclosing.document.GetTrailer().Put(PdfName.AuthCode, this._enclosing.macPdfObject.GetPdfObject()); } @@ -121,8 +121,8 @@ internal StandaloneMacPdfObjectAdder(StandaloneMacIntegrityProtector _enclosing) private readonly StandaloneMacIntegrityProtector _enclosing; } - private sealed class StandaloneMacContainerEmbedder : iText.Kernel.Events.IEventHandler { - public void HandleEvent(Event @event) { + private sealed class StandaloneMacContainerEmbedder : AbstractPdfDocumentEventHandler { + protected internal override void OnAcceptedEvent(AbstractPdfDocumentEvent @event) { try { this._enclosing.EmbedMacContainerInTrailer(); } diff --git a/itext/itext.kernel/itext/kernel/pdf/OcgPropertiesCopier.cs b/itext/itext.kernel/itext/kernel/pdf/OcgPropertiesCopier.cs index 2138e88d47..7276b16dda 100644 --- a/itext/itext.kernel/itext/kernel/pdf/OcgPropertiesCopier.cs +++ b/itext/itext.kernel/itext/kernel/pdf/OcgPropertiesCopier.cs @@ -71,11 +71,12 @@ public static void CopyOCGProperties(PdfDocument sourceDocument, PdfDocument des } } +//\cond DO_NOT_DOCUMENT /// Get all OCGs from a given page annotations/xobjects/resources, including ones already stored in catalog /// /// where to search for OCGs. /// set of indirect references pointing to found OCGs. - public static ICollection GetOCGsFromPage(PdfPage page) { + internal static ICollection GetOCGsFromPage(PdfPage page) { //Using linked hash set for elements order consistency (e.g. in tests) ICollection ocgs = new LinkedHashSet(); IList annotations = page.GetAnnotations(); @@ -88,6 +89,7 @@ public static ICollection GetOCGsFromPage(PdfPage page) { new HashSet()); return ocgs; } +//\endcond private static ICollection GetAllUsedNonFlushedOCGs(IDictionary page2page , PdfDictionary toOcProperties) { diff --git a/itext/itext.kernel/itext/kernel/pdf/PageFlushingHelper.cs b/itext/itext.kernel/itext/kernel/pdf/PageFlushingHelper.cs index 5b84b48aea..2fe775a544 100644 --- a/itext/itext.kernel/itext/kernel/pdf/PageFlushingHelper.cs +++ b/itext/itext.kernel/itext/kernel/pdf/PageFlushingHelper.cs @@ -23,8 +23,8 @@ You should have received a copy of the GNU Affero General Public License using System; using System.Collections.Generic; using iText.Commons.Utils; -using iText.Kernel.Events; using iText.Kernel.Exceptions; +using iText.Kernel.Pdf.Event; using iText.Kernel.Pdf.Layer; namespace iText.Kernel.Pdf { diff --git a/itext/itext.kernel/itext/kernel/pdf/PdfDocument.cs b/itext/itext.kernel/itext/kernel/pdf/PdfDocument.cs index 8e135859e1..af293ebf9d 100644 --- a/itext/itext.kernel/itext/kernel/pdf/PdfDocument.cs +++ b/itext/itext.kernel/itext/kernel/pdf/PdfDocument.cs @@ -33,7 +33,6 @@ You should have received a copy of the GNU Affero General Public License using iText.Kernel.Actions.Data; using iText.Kernel.Actions.Events; using iText.Kernel.Colors; -using iText.Kernel.Events; using iText.Kernel.Exceptions; using iText.Kernel.Font; using iText.Kernel.Geom; @@ -41,6 +40,7 @@ You should have received a copy of the GNU Affero General Public License using iText.Kernel.Numbering; using iText.Kernel.Pdf.Annot; using iText.Kernel.Pdf.Collection; +using iText.Kernel.Pdf.Event; using iText.Kernel.Pdf.Filespec; using iText.Kernel.Pdf.Navigation; using iText.Kernel.Pdf.Statistics; @@ -53,7 +53,7 @@ You should have received a copy of the GNU Affero General Public License namespace iText.Kernel.Pdf { /// Main enter point to work with PDF document. - public class PdfDocument : IEventDispatcher, IDisposable { + public class PdfDocument : IDisposable { private static readonly PdfName[] PDF_NAMES_TO_REMOVE_FROM_ORIGINAL_TRAILER = new PdfName[] { PdfName.Encrypt , PdfName.Size, PdfName.Prev, PdfName.Root, PdfName.Info, PdfName.ID, PdfName.XRefStm, PdfName.AuthCode }; @@ -70,6 +70,8 @@ public class PdfDocument : IEventDispatcher, IDisposable { private readonly IDictionary documentFonts = new Dictionary(); + private readonly ICollection documentHandlers = new LinkedHashSet(); + private readonly SequenceId documentId; /// To be adjusted destinations. @@ -81,8 +83,6 @@ public class PdfDocument : IEventDispatcher, IDisposable { private readonly IList pendingDestinationMutations = new List(); - protected internal EventDispatcher eventDispatcher = new EventDispatcher(); - /// PdfWriter associated with the document. /// /// PdfWriter associated with the document. @@ -732,34 +732,57 @@ public virtual void SetDefaultPageSize(PageSize pageSize) { defaultPageSize = pageSize; } - /// - public virtual void AddEventHandler(String type, iText.Kernel.Events.IEventHandler handler) { - eventDispatcher.AddEventHandler(type, handler); + /// Adds new event handler. + /// a type of event to be handled + /// event handler + public virtual void AddEventHandler(String type, AbstractPdfDocumentEventHandler handler) { + handler.AddType(type); + documentHandlers.Add(handler); } - /// - public virtual void DispatchEvent(Event @event) { - eventDispatcher.DispatchEvent(@event); - } - - /// - public virtual void DispatchEvent(Event @event, bool delayed) { - eventDispatcher.DispatchEvent(@event, delayed); + /// Dispatches an event. + /// + /// the + /// + /// to be dispatched + /// + public virtual void DispatchEvent(AbstractPdfDocumentEvent @event) { + @event.SetDocument(this); + foreach (IEventHandler handler in documentHandlers) { + handler.OnEvent(@event); + } } - /// - public virtual bool HasEventHandler(String type) { - return eventDispatcher.HasEventHandler(type); + /// Checks if provided event handler assigned for this document. + /// + /// the + /// + /// to check + /// + /// + /// + /// + /// if event handler is assigned for this document, + /// + /// otherwise + /// + public virtual bool HasEventHandler(AbstractPdfDocumentEventHandler handler) { + return documentHandlers.Contains(handler); } - /// - public virtual void RemoveEventHandler(String type, iText.Kernel.Events.IEventHandler handler) { - eventDispatcher.RemoveEventHandler(type, handler); + /// Removes event handler. + /// + /// + /// + /// event handler to remove for this document + /// + public virtual void RemoveEventHandler(AbstractPdfDocumentEventHandler handler) { + documentHandlers.Remove(handler); } - /// + /// Removes all event handlers for this document. public virtual void RemoveAllHandlers() { - eventDispatcher.RemoveAllHandlers(); + documentHandlers.Clear(); } /// @@ -840,7 +863,7 @@ public virtual void Close() { .GetInstance())); // The event will prepare document for flushing, i.e. will set an appropriate producer line manager.OnEvent(new FlushPdfDocumentEvent(this)); - DispatchEvent(new PdfDocumentEvent(PdfDocumentEvent.START_DOCUMENT_CLOSING, this)); + DispatchEvent(new PdfDocumentEvent(PdfDocumentEvent.START_DOCUMENT_CLOSING)); UpdateXmpMetadata(); // In PDF 2.0, all the values except CreationDate and ModDate are deprecated. Remove them now if (pdfVersion.CompareTo(PdfVersion.PDF_2_0) >= 0) { diff --git a/itext/itext.kernel/itext/kernel/pdf/PdfPage.cs b/itext/itext.kernel/itext/kernel/pdf/PdfPage.cs index 4293bd1ed9..49a637e39c 100644 --- a/itext/itext.kernel/itext/kernel/pdf/PdfPage.cs +++ b/itext/itext.kernel/itext/kernel/pdf/PdfPage.cs @@ -25,11 +25,11 @@ You should have received a copy of the GNU Affero General Public License using Microsoft.Extensions.Logging; using iText.Commons; using iText.Commons.Utils; -using iText.Kernel.Events; using iText.Kernel.Exceptions; using iText.Kernel.Geom; using iText.Kernel.Pdf.Action; using iText.Kernel.Pdf.Annot; +using iText.Kernel.Pdf.Event; using iText.Kernel.Pdf.Filespec; using iText.Kernel.Pdf.Layer; using iText.Kernel.Pdf.Tagging; diff --git a/itext/itext.kernel/itext/kernel/pdf/PdfWriter.cs b/itext/itext.kernel/itext/kernel/pdf/PdfWriter.cs index 65c0ae5799..fe8a8261c6 100644 --- a/itext/itext.kernel/itext/kernel/pdf/PdfWriter.cs +++ b/itext/itext.kernel/itext/kernel/pdf/PdfWriter.cs @@ -27,9 +27,9 @@ You should have received a copy of the GNU Affero General Public License using iText.Commons; using iText.Commons.Utils; using iText.IO.Source; -using iText.Kernel.Events; using iText.Kernel.Exceptions; using iText.Kernel.Mac; +using iText.Kernel.Pdf.Event; using iText.Kernel.Utils; namespace iText.Kernel.Pdf { @@ -421,7 +421,7 @@ protected internal virtual void FlushModifiedWaitingObjects(ICollection. +*/ +using System; +using iText.Commons.Actions; +using iText.Kernel.Pdf; + +namespace iText.Kernel.Pdf.Event { + /// Describes abstract PDF document event of the specified type. + /// + /// Describes abstract PDF document event of the specified type. + /// + /// Use + /// + /// to fire an event + /// and + /// + /// to register + /// + /// handler for that type of event. + /// + public abstract class AbstractPdfDocumentEvent : IEvent { + /// A type of event. + protected internal String type; + + private PdfDocument document; + + /// Creates an event of the specified type. + /// the type of event + protected internal AbstractPdfDocumentEvent(String type) { + this.type = type; + } + + /// Returns the type of this event. + /// type of this event + public virtual String GetType() { + return type; + } + + /// Retrieves the document associated with this event. + /// + /// + /// + /// that triggered this event + /// + public virtual PdfDocument GetDocument() { + return document; + } + + /// Sets the document associated with this event. + /// + /// + /// + /// that triggered this event + /// + /// + /// this + /// + /// instance + /// + public virtual iText.Kernel.Pdf.Event.AbstractPdfDocumentEvent SetDocument(PdfDocument document) { + this.document = document; + return this; + } + } +} diff --git a/itext/itext.kernel/itext/kernel/pdf/event/AbstractPdfDocumentEventHandler.cs b/itext/itext.kernel/itext/kernel/pdf/event/AbstractPdfDocumentEventHandler.cs new file mode 100644 index 0000000000..25f283aa23 --- /dev/null +++ b/itext/itext.kernel/itext/kernel/pdf/event/AbstractPdfDocumentEventHandler.cs @@ -0,0 +1,102 @@ +/* +This file is part of the iText (R) project. +Copyright (c) 1998-2024 Apryse Group NV +Authors: Apryse Software. + +This program is offered under a commercial and under the AGPL license. +For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below. + +AGPL licensing: +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ +using System; +using System.Collections.Generic; +using iText.Commons.Actions; + +namespace iText.Kernel.Pdf.Event { + /// Base class for PDF document events handling based on the event type. + /// + /// Base class for PDF document events handling based on the event type. + /// + /// Handles + /// + /// event fired by + /// . + /// Use + /// + /// to register this handler for + /// specific type of event. + /// + public abstract class AbstractPdfDocumentEventHandler : IEventHandler { + private readonly ICollection types = new HashSet(); + + /// + /// Creates new + /// + /// instance. + /// + /// + /// Creates new + /// + /// instance. + /// + /// By default, this instance handles all types of the + /// + /// events. For specific types + /// handling, use + /// + /// method. + /// + protected internal AbstractPdfDocumentEventHandler() { + } + + /// + /// Adds new event type to handle by this + /// + /// instance. + /// + /// + /// the + /// + /// type to handle + /// + /// + /// this + /// + /// instance + /// + public virtual iText.Kernel.Pdf.Event.AbstractPdfDocumentEventHandler AddType(String type) { + this.types.Add(type); + return this; + } + + public virtual void OnEvent(IEvent @event) { + if (!(@event is AbstractPdfDocumentEvent)) { + return; + } + AbstractPdfDocumentEvent iTextEvent = (AbstractPdfDocumentEvent)@event; + if (types.IsEmpty() || types.Contains(iTextEvent.GetType())) { + OnAcceptedEvent(iTextEvent); + } + } + + /// Handles the accepted event. + /// + /// + /// + /// to handle + /// + protected internal abstract void OnAcceptedEvent(AbstractPdfDocumentEvent @event); + } +} diff --git a/itext/itext.kernel/itext/kernel/events/PdfDocumentEvent.cs b/itext/itext.kernel/itext/kernel/pdf/event/PdfDocumentEvent.cs similarity index 82% rename from itext/itext.kernel/itext/kernel/events/PdfDocumentEvent.cs rename to itext/itext.kernel/itext/kernel/pdf/event/PdfDocumentEvent.cs index 2b7319ec63..87e844f5a5 100644 --- a/itext/itext.kernel/itext/kernel/events/PdfDocumentEvent.cs +++ b/itext/itext.kernel/itext/kernel/pdf/event/PdfDocumentEvent.cs @@ -23,9 +23,9 @@ You should have received a copy of the GNU Affero General Public License using System; using iText.Kernel.Pdf; -namespace iText.Kernel.Events { +namespace iText.Kernel.Pdf.Event { /// Event dispatched by PdfDocument. - public class PdfDocumentEvent : Event { + public class PdfDocumentEvent : AbstractPdfDocumentEvent { /// Dispatched after page is created. public const String START_PAGE = "StartPdfPage"; @@ -52,15 +52,10 @@ public class PdfDocumentEvent : Event { /// The PdfPage associated with this event. protected internal PdfPage page; - /// The PdfDocument associated with this event. - private PdfDocument document; - /// Creates a PdfDocumentEvent. /// type of the event that fired this event - /// document that fired this event - public PdfDocumentEvent(String type, PdfDocument document) + public PdfDocumentEvent(String type) : base(type) { - this.document = document; } /// Creates a PdfDocumentEvent. @@ -69,13 +64,6 @@ public PdfDocumentEvent(String type, PdfDocument document) public PdfDocumentEvent(String type, PdfPage page) : base(type) { this.page = page; - this.document = page.GetDocument(); - } - - /// Returns the PdfDocument associated with this event. - /// the PdfDocument associated with this event - public virtual PdfDocument GetDocument() { - return document; } /// Returns the PdfPage associated with this event. diff --git a/itext/itext.sign/itext/signatures/mac/SignatureContainerGenerationEvent.cs b/itext/itext.sign/itext/signatures/mac/SignatureContainerGenerationEvent.cs index 5e13a07fff..9f6256a009 100644 --- a/itext/itext.sign/itext/signatures/mac/SignatureContainerGenerationEvent.cs +++ b/itext/itext.sign/itext/signatures/mac/SignatureContainerGenerationEvent.cs @@ -23,11 +23,11 @@ You should have received a copy of the GNU Affero General Public License using System; using System.IO; using iText.Commons.Bouncycastle.Asn1; -using iText.Kernel.Events; +using iText.Kernel.Pdf.Event; namespace iText.Signatures.Mac { /// Represents an event firing before creating signature container. - public class SignatureContainerGenerationEvent : Event { + public class SignatureContainerGenerationEvent : AbstractPdfDocumentEvent { public const String START_SIGNATURE_CONTAINER_GENERATION = "StartSignatureContainerGeneration"; private readonly IAsn1EncodableVector unsignedAttributes; diff --git a/itext/itext.sign/itext/signatures/mac/SignatureDocumentClosingEvent.cs b/itext/itext.sign/itext/signatures/mac/SignatureDocumentClosingEvent.cs index 7568325914..29148c215b 100644 --- a/itext/itext.sign/itext/signatures/mac/SignatureDocumentClosingEvent.cs +++ b/itext/itext.sign/itext/signatures/mac/SignatureDocumentClosingEvent.cs @@ -21,12 +21,12 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ using System; -using iText.Kernel.Events; using iText.Kernel.Pdf; +using iText.Kernel.Pdf.Event; namespace iText.Signatures.Mac { /// Represents an event firing before embedding the signature into the document. - public class SignatureDocumentClosingEvent : Event { + public class SignatureDocumentClosingEvent : AbstractPdfDocumentEvent { public const String START_SIGNATURE_PRE_CLOSE = "StartSignaturePreClose"; private readonly PdfIndirectReference signatureReference; diff --git a/itext/itext.sign/itext/signatures/mac/SignatureMacIntegrityProtector.cs b/itext/itext.sign/itext/signatures/mac/SignatureMacIntegrityProtector.cs index 28c00931a7..97ff710071 100644 --- a/itext/itext.sign/itext/signatures/mac/SignatureMacIntegrityProtector.cs +++ b/itext/itext.sign/itext/signatures/mac/SignatureMacIntegrityProtector.cs @@ -26,10 +26,10 @@ You should have received a copy of the GNU Affero General Public License using iText.Commons.Bouncycastle; using iText.Commons.Bouncycastle.Asn1; using iText.Commons.Bouncycastle.Security; -using iText.Kernel.Events; using iText.Kernel.Exceptions; using iText.Kernel.Mac; using iText.Kernel.Pdf; +using iText.Kernel.Pdf.Event; namespace iText.Signatures.Mac { //\cond DO_NOT_DOCUMENT @@ -77,8 +77,8 @@ private void EmbedMacContainerInUnsignedAttributes(IAsn1EncodableVector unsigned unsignedAttributes.Add(BC_FACTORY.CreateDERSequence(macAttribute)); } - private sealed class SignatureMacPdfObjectAdder : iText.Kernel.Events.IEventHandler { - public void HandleEvent(Event @event) { + private sealed class SignatureMacPdfObjectAdder : AbstractPdfDocumentEventHandler { + protected override void OnAcceptedEvent(AbstractPdfDocumentEvent @event) { if (@event is SignatureDocumentClosingEvent) { PdfDictionary signatureMacDictionary = new PdfDictionary(); signatureMacDictionary.Put(PdfName.MACLocation, PdfName.AttachedToSig); @@ -95,8 +95,8 @@ internal SignatureMacPdfObjectAdder(SignatureMacIntegrityProtector _enclosing) { private readonly SignatureMacIntegrityProtector _enclosing; } - private sealed class SignatureMacContainerEmbedder : iText.Kernel.Events.IEventHandler { - public void HandleEvent(Event @event) { + private sealed class SignatureMacContainerEmbedder : AbstractPdfDocumentEventHandler { + protected override void OnAcceptedEvent(AbstractPdfDocumentEvent @event) { if (@event is SignatureContainerGenerationEvent) { SignatureContainerGenerationEvent signatureEvent = (SignatureContainerGenerationEvent)@event; try { diff --git a/port-hash b/port-hash index 7111f8cda8..c2d50f67a1 100644 --- a/port-hash +++ b/port-hash @@ -1 +1 @@ -a0fc8b8fe2956f080130695f69f406bc43a9f980 +5d52188d21a976693e808d174a519195b62f241c