xmlgraphics-fop-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeremias Maerki <...@jeremias-maerki.ch>
Subject Re: Event broadcasting and listening question
Date Thu, 12 May 2011 20:29:02 GMT
On 12.05.2011 10:44:41 Michael Rubin wrote:
> Thanks a lot for your response Jeremias. I have now done the following:
> 
> - Added 'void warnRevision3PermissionsIgnored(Object source);' (and its javadoc) to PDFEventProducer
in the org.apache.fop.render.pdf package and added a corresponding entry to the xml. Removed
the org.apache.fop.pdf.PDFEventProducer class and xml.
> - Created org.apache.fop.pdf.PDFEventListener interface containing just 'void warnRevision3PermissionsIgnored(Object
source);'.
> - Created PDFLibraryEventAdaptor in the org.apache.fop.render.pdf package that extends
the PDFEventListener. (Currently just contains my new event. Should I also add the existing
2 render.pdf events to this class?)
Or do it the other way around: add your new event to PDFEventProcuder.
Doesn't make sense to have two.
> 
>   I can also see how to obtain the PDFDocument object from the
> PDFEncryptionJCE class via the getDocumentSafely() method. But I am not sure how to get
the event broadcaster from that object. How is this done?

public class PDFDocument {

[..]

    private PDFEventListener listener;

[..]

    public void setListener(PDFEventListener listener) {
        this.listener = listener;
    }

    PDFEventListener getListener() {
        return this.listener;
    }
[..]

That's the simples way and should probably be sufficient. If we wanted
to get fancy, we could handle a List<PDFEventListener>.

In PDFDocumentHandler.startDocument():
this.pdfDoc.setEventListener(new PDFLibraryEventAdapter(getUserAgent().getEventBroadcaster());

So, the PDFDocument doesn't actually get an EventBroadcaster.
PDFDocument calls the PDFLibraryEventAdapter and that one in turn calls
the EventBroadcaster. Nicely decoupled.


> Thanks!
> 
> -Mike
> 
> 
> On 11/05/11 19:46, Jeremias Maerki wrote:
> > 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
> >>
> >> mrubin@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
> >




Jeremias Maerki


Mime
View raw message