Hi Michael Creating a new EventBroadcaster is obviously wrong. The idea is that the user can get events for each FOP rendering run separately (unlike logging where concurrent runs get mixed up). So you have to get hold of that EventBroadcaster applicable to the current rendering run. Obviously, you don't have access to the FOUserAgent in the PDF library. That is intentional because the PDF library should remain reasonably independent of as much FOP code as possible for the case that we ever factor it out into a separate component/module or move it to XML Graphics Commons.
My suggestion is to follow a similar path as done in org.apache.fop.fonts: Create an interface for the events coming out of the PDF library (see FontEventListener). Let's call it PDFEventListener or something like that and put it in the org.apache.fop.pdf package. Then move your PDFEventProducer (corresponds to FontEventProducer) into org.apache.fop.render.pdf as this package makes the glue between FOP and PDF output. Then create a PDFLibraryEventAdapter (implements PDFEventListener) in the org.apache.fop.render.pdf package (corresponds to FontEventAdapter). The PDFLibraryEventAdapter will get the EventBroadcaster from the PDFDocumentHandler which is responsible for instantiating the PDFDocument and PDFLibraryEventAdapter. The adapter is then added as listener to a List<PDFEventListener> that you can add to PDFDocument. From PDFEncryptionJCE you should have access to the PDFDocument via the getDocumentSafely() method. That nicely decouples FOP's event subsystem from the PDF library. HTH On 11.05.2011 15:47:49 Michael Rubin wrote: > ?Hello there. I have been busy implementing 128 bit PDF encryption for FOP. I > have already got it working successfully but one issue remains that I have a > question about. > > In the org.apache.fop.pdf.PDFEncriptionJCE.init() method there is one place > where I want to broadcast an event message. I looked > athttp://xmlgraphics.apache.org/fop/trunk/events.html to learn about events. > However it just shows "EventBroadcaster broadcaster = [get it from > somewhere];" and doesn't show how I should be getting the broadcaster. After > looking in the code in the AFP package for existing examples I put together > the following which seems to work on testing: > > FopFactory fopFactory = FopFactory.newInstance(); > FOUserAgent agent = fopFactory.newFOUserAgent(); > EventBroadcaster eventBroadcaster = agent.getEventBroadcaster(); > PDFEventProducer eventProducer = > PDFEventProducer.Provider.get(eventBroadcaster); > eventProducer.warnRevision3PermissionsIgnored(this); > > This creates a new FopFactory, from which I create a new FOUserAgent, from > which I can get the event broadcaster to supply to my event producer. (I had > to create a PDFEventProducer which extends EventProducer. Plus > PDFEventProducer.xml which contains the message mapping.) > > In this case the EventBroadcaster will be created new every time so I am not > sure existing listeners will pick up. So is there a recommended way that I > can get an existing event broadcaster to use? Or is the above way the correct > way to do it after all? > > Version of FOP is v1.0. Platform is Ubuntu Linux, running from within the > Eclipse IDE. > > Thanks! > > -Mike > > > > > > Michael Rubin > Developer > > T: +44 20 8238 7400 > F: +44 20 8238 7401 > > mru...@thunderhead.com > > The contents of this e-mail are intended for the named addressee only. It > contains information that may be confidential. Unless you are the named > addressee or an authorized designee, you may not copy or use it, or disclose > it to anyone else. If you received it in error please notify us > immediately and then destroy it. > > > > Jeremias Maerki