diff options
author | Adrian Cumiskey <acumiskey@apache.org> | 2008-04-14 13:05:52 +0000 |
---|---|---|
committer | Adrian Cumiskey <acumiskey@apache.org> | 2008-04-14 13:05:52 +0000 |
commit | 309f4e2998c676913e64070adda8dca5e3768fad (patch) | |
tree | 4e84f80a026d6f52e57a7a4701ae2dc14f8d5a08 /src/documentation/content | |
parent | 7045f7e0124c6a6f00736b0d1d81f89824fd1271 (diff) | |
download | xmlgraphics-fop-309f4e2998c676913e64070adda8dca5e3768fad.tar.gz xmlgraphics-fop-309f4e2998c676913e64070adda8dca5e3768fad.zip |
Merged revisions 647692,647742,647745 via svnmerge from
https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk
................
r647692 | jeremias | 2008-04-14 09:25:22 +0100 (Mon, 14 Apr 2008) | 3 lines
Initialized merge tracking via "svnmerge" with revisions "1-615152" from
https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_ProcessingFeedback
................
r647742 | jeremias | 2008-04-14 12:53:29 +0100 (Mon, 14 Apr 2008) | 298 lines
Merged branch
https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_ProcessingFeedback
into Trunk.
Changes on branch:
........
r615153 | jeremias | 2008-01-25 10:07:21 +0100 (Fr, 25 Jan 2008) | 1 line
Created temporary branch for processing feedback.
........
r615155 | jeremias | 2008-01-25 10:11:59 +0100 (Fr, 25 Jan 2008) | 1 line
Initial commit of what I've built already for those who prefer code to minimalistic design docs.
........
r615278 | jeremias | 2008-01-25 18:25:00 +0100 (Fr, 25 Jan 2008) | 1 line
EventProducer interfaces now operational.
........
r615773 | jeremias | 2008-01-28 10:06:16 +0100 (Mo, 28 Jan 2008) | 1 line
No casting in client code when creating EventProducer instances.
........
r616242 | vhennebert | 2008-01-29 11:34:45 +0100 (Di, 29 Jan 2008) | 3 lines
Trick to avoid hard-coding the class name of EventProducer in the source file.
Feel free to revert if it's not ok.
........
r616900 | jeremias | 2008-01-30 21:59:31 +0100 (Mi, 30 Jan 2008) | 1 line
Generate event model XMLs in to the build directory: build/gensrc and build/test-gensrc (the latter is new and needs to be setup as source folder in your IDE!)
........
r616907 | jeremias | 2008-01-30 22:12:59 +0100 (Mi, 30 Jan 2008) | 1 line
Added an XMLResourceBundle that uses an XML file instead of a properties file to load the translations. The XML format is the same as for Cocoon's XMLResourceBundle.
........
r617097 | vhennebert | 2008-01-31 11:53:21 +0100 (Do, 31 Jan 2008) | 2 lines
Minor typo + slight improvement of Javadoc
........
r617176 | jeremias | 2008-01-31 19:14:19 +0100 (Do, 31 Jan 2008) | 5 lines
Renamed FopEvent to Event as suggested by Simon.
EventProducerCollectorTask.java now reads the EventSeverity from a doclet tag.
Added generation of EventProducer translations (including simple merging, no validation, yet)
EventFormatter introduced (only basic functionality, yet).
Added a simple EventListener implementation that uses EventFormatter to convert the events to human-readable, localized messages that are sent to the log via Commons Logging.
........
r617362 | jeremias | 2008-02-01 08:18:07 +0100 (Fr, 01 Feb 2008) | 1 line
Some remaining rename operations based on an earlier discussion.
........
r617413 | jeremias | 2008-02-01 10:46:26 +0100 (Fr, 01 Feb 2008) | 2 lines
Extracted formatting functionality into utility class AdvancedMessageFormat.java.
AdvancedMessageFormat.java now supports conditional sub-groups (delimited by []).
........
r618682 | jeremias | 2008-02-05 17:07:08 +0100 (Di, 05 Feb 2008) | 1 line
Add support for special object formatters (where toString() isn't good enough). ATM, it's hard-coded but could later be hooked into dynamic discovery if we have multiple such formatters. The SAX Locator is the only example for now.
........
r618686 | jeremias | 2008-02-05 17:12:56 +0100 (Di, 05 Feb 2008) | 3 lines
Hooked most of FONode into the new event mechanism. The FOUserAgent provides a DefaultEventBroadcaster instance.
If a producer method declares throwing an exception, the event is automatically marked FATAL and the dynamic proxy throws an exception right after notifying the listeners.
The exceptions are created through the EventExceptionManager. It currently contains only one exception factory for ValidationException. If we need more such factories it's better to register them dynamically. Right now, they're hard-coded.
........
r619313 | jeremias | 2008-02-07 10:14:15 +0100 (Do, 07 Feb 2008) | 1 line
Make sure no events are now just silently swallowed because after upgrading a user doesn't know about the event system.
........
r619314 | jeremias | 2008-02-07 10:14:46 +0100 (Do, 07 Feb 2008) | 1 line
Log what translation file is being written.
........
r619320 | jeremias | 2008-02-07 10:31:00 +0100 (Do, 07 Feb 2008) | 2 lines
FObj hooked into the event system.
Code reduction using a protected method on FONode to acquire a FOValidationEventProducer.
........
r619359 | jeremias | 2008-02-07 11:59:19 +0100 (Do, 07 Feb 2008) | 2 lines
Fop's QName now extends XGCommons' QName to initiate a transition.
Hooked PropertyList into the event mechanism.
........
r631252 | jeremias | 2008-02-26 16:24:33 +0100 (Di, 26 Feb 2008) | 1 line
Removed superfluous warning.
........
r631268 | jeremias | 2008-02-26 17:08:11 +0100 (Di, 26 Feb 2008) | 1 line
Deprecated two methods which are a problem for localization. Also helps finding additional spots to switch over to the event mechanism.
........
r633852 | jeremias | 2008-03-05 15:20:24 +0100 (Mi, 05 Mrz 2008) | 1 line
Add severity to formatting parameters.
........
r633855 | jeremias | 2008-03-05 15:21:57 +0100 (Mi, 05 Mrz 2008) | 4 lines
Added support for additional field styles:
{<fieldname>,if,<true-text>,<false-text>}
{<fieldname>,equals,<test-string>,<true-text>,<false-text>}
........
r633856 | jeremias | 2008-03-05 15:24:04 +0100 (Mi, 05 Mrz 2008) | 2 lines
Javadocs and TODOs.
EventListeners can change the event severity.
........
r633857 | jeremias | 2008-03-05 15:27:08 +0100 (Mi, 05 Mrz 2008) | 4 lines
Javadocs.
Moved out event listener registration into a CompositeEventListener.
Event broadcaster uses the events effective severity, not the initial value (for the case where listeners override the initial value).
Set up a special EventBroadCaster in the FOUserAgent that filters events through a class (FOValidationEventListenerProxy) that adjusts the event severity for relaxed validation.
........
r633858 | jeremias | 2008-03-05 15:32:07 +0100 (Mi, 05 Mrz 2008) | 2 lines
Instead of always decentrally checking whether strict validation is enabled or not, this is now done in a special event listener. The event producer method caller simply indicates whether it can recover from the error condition and continue.
Started switching to event production in table FOs.
........
r634027 | jeremias | 2008-03-05 21:58:35 +0100 (Mi, 05 Mrz 2008) | 7 lines
Moved AdvancedMessageFormat into its own package.
AdvancedMessageFormat got the following added functionality:
- Alternative conditional regions [ bla {field}] -> [ bla {field1}| even more bla {field2}]
- Functions: functions get access to the parameters and they can produce an object that is then formatted ({#gatherContextInfo})
- "if" and "equals" format moved to top-level classes and added by dynamic registration.
EventFormatter now supports includes in the form {{includeName}} so you can include other entries from the resource bundle for better reuse.
Some more events in table code.
........
r634031 | jeremias | 2008-03-05 22:05:22 +0100 (Mi, 05 Mrz 2008) | 1 line
SVN Props
........
r634208 | jeremias | 2008-03-06 11:26:52 +0100 (Do, 06 Mrz 2008) | 2 lines
Improved context gathering.
Moved GatherContextInfoFunction to an inner class of FONode to reduce visibilities.
........
r634209 | jeremias | 2008-03-06 11:28:14 +0100 (Do, 06 Mrz 2008) | 1 line
Made FOPException localizable.
........
r634280 | jeremias | 2008-03-06 15:38:30 +0100 (Do, 06 Mrz 2008) | 2 lines
ExceptionFactory is now dynamically registered.
More table warnings and errors switch to events.
........
r634326 | jeremias | 2008-03-06 17:08:16 +0100 (Do, 06 Mrz 2008) | 1 line
Remaining table FOs switched to events.
........
r634328 | jeremias | 2008-03-06 17:09:21 +0100 (Do, 06 Mrz 2008) | 1 line
Deprecated FOP's QName. Mixing with Commons' variant only produces problems.
........
r634381 | jeremias | 2008-03-06 20:12:57 +0100 (Do, 06 Mrz 2008) | 2 lines
Made the "invalidChild" event fully localizable by adding a "lookup" field for the optional rule to be displayed.
And a few switches to the event system.
........
r634692 | jeremias | 2008-03-07 15:31:43 +0100 (Fr, 07 Mrz 2008) | 1 line
More FO tree stuff switched to events.
........
r634712 | jeremias | 2008-03-07 16:19:21 +0100 (Fr, 07 Mrz 2008) | 1 line
Avoid an NPE that says nothing (ex. could happen if the message template is wrong).
........
r634738 | jeremias | 2008-03-07 17:38:21 +0100 (Fr, 07 Mrz 2008) | 2 lines
Non-FO children were not properly run through validation by FOTreeBuilder.
Unified the way that non-FO elements are validated. Some FOs were already fixed. I now fixed the rest, so foreign elements can occur everywhere.
........
r637833 | jeremias | 2008-03-17 12:01:41 +0100 (Mo, 17 Mrz 2008) | 1 line
Exception while cloning for RetrieveMarker to be handled by user as suggested by Andreas.
........
r637835 | jeremias | 2008-03-17 12:03:31 +0100 (Mo, 17 Mrz 2008) | 1 line
Throw a RuntimeException of no other Exception class is specified for an event as a fallback if someone just sets the event severity to FATAL.
........
r637838 | jeremias | 2008-03-17 12:06:10 +0100 (Mo, 17 Mrz 2008) | 1 line
Throw a meaningful exception when the property name is wrong. Otherwise, there will be an ArrayIndexOutOfBoundsException.
........
r637859 | jeremias | 2008-03-17 13:35:26 +0100 (Mo, 17 Mrz 2008) | 1 line
Throw a meaningful exception when the property name is wrong. Otherwise, there will be an ArrayIndexOutOfBoundsException.
........
r637938 | jeremias | 2008-03-17 16:19:51 +0100 (Mo, 17 Mrz 2008) | 1 line
Switched pagination package to events.
........
r637947 | jeremias | 2008-03-17 16:45:16 +0100 (Mo, 17 Mrz 2008) | 1 line
Removed unlocalizable validation helper methods.
........
r637952 | jeremias | 2008-03-17 16:59:02 +0100 (Mo, 17 Mrz 2008) | 1 line
Events on FOTreeBuilder.
........
r638299 | jeremias | 2008-03-18 11:09:30 +0100 (Di, 18 Mrz 2008) | 2 lines
Added support for java.util.text's ChoiceFormat to AdvancedMessageFormat.
Reuse the regexes as constants.
........
r638302 | jeremias | 2008-03-18 11:17:06 +0100 (Di, 18 Mrz 2008) | 1 line
Events for inline-level layout managers.
........
r638774 | jeremias | 2008-03-19 11:17:36 +0100 (Mi, 19 Mrz 2008) | 1 line
Added DEBUG level.
........
r638777 | jeremias | 2008-03-19 11:23:40 +0100 (Mi, 19 Mrz 2008) | 3 lines
Generalized FOValidationEventListenerProxy into FOPEventListenerProxy, the main proxy for FOP's own event manipulation proxy. Done because of support for overflow="hidden" vs. overflow="error-if-overflow".
Switched block-level layout managers to events.
Some cleanup along the way.
........
r639222 | jeremias | 2008-03-20 10:27:34 +0100 (Do, 20 Mrz 2008) | 2 lines
Some initial work for event forwarding from Batik.
Missing errors/exceptions converted to events in PageSequenceMaster.
........
r639270 | jeremias | 2008-03-20 13:50:35 +0100 (Do, 20 Mrz 2008) | 1 line
Removed DEBUG event severity again. Promoted constrained geometry adjustment event to INFO level as per discussion.
........
r640395 | jeremias | 2008-03-24 13:39:13 +0100 (Mo, 24 Mrz 2008) | 3 lines
Moved the creation of the fallback LoggingEventListener to FOUserAgent so event before the startDocument() SAX event arrive in the log.
Dynamic discovery of event models. Renderers and extensions can register renderer-specific event models.
Switched the most important parts of the renderers to events (maybe not everything is converted).
........
r640397 | jeremias | 2008-03-24 13:43:04 +0100 (Mo, 24 Mrz 2008) | 1 line
Remaining fixcrlfs. Xalan likes to mix CRLF and LF on Windows.
........
r640398 | jeremias | 2008-03-24 13:43:54 +0100 (Mo, 24 Mrz 2008) | 1 line
Ignore namespace declarations for property handling.
........
r640463 | jeremias | 2008-03-24 17:59:52 +0100 (Mo, 24 Mrz 2008) | 2 lines
Event in area package.
Exposed getUserAgent() in Renderer interface (was already public in AbstractRenderer).
........
r642972 | jeremias | 2008-03-31 14:18:39 +0200 (Mo, 31 Mrz 2008) | 1 line
Code restructured a bit.
........
r642975 | jeremias | 2008-03-31 14:24:07 +0200 (Mo, 31 Mrz 2008) | 2 lines
Plugged fonts package into the event subsystem. Note: I did not follow the same pattern as for the rest as the font package is to be considered FOP-external, so I just added a manual adapter for the FontEventListener. This demonstrates how an external library can be integrated with the event system.
Missing warning for unknown formatting objects added. Warning is not issued by the ElementMappingRegistry anymore but by FOTreeBuilder which has access to more context information.
........
r642997 | jeremias | 2008-03-31 16:10:08 +0200 (Mo, 31 Mrz 2008) | 1 line
Added an example to demonstrate how to write your own event listener and how to deal with the exceptions thrown in the process.
........
r642998 | jeremias | 2008-03-31 16:13:40 +0200 (Mo, 31 Mrz 2008) | 1 line
Removed unused method. Event formatting should not be part of the Event class. Use EventFormatter.format(Event) instead.
........
r643066 | jeremias | 2008-03-31 19:18:54 +0200 (Mo, 31 Mrz 2008) | 1 line
First part of the event subsystem documentation (DRAFT).
........
r643784 | jeremias | 2008-04-02 10:05:33 +0200 (Mi, 02 Apr 2008) | 1 line
More documentation.
........
r643785 | jeremias | 2008-04-02 10:06:38 +0200 (Mi, 02 Apr 2008) | 1 line
Some nits.
........
r643787 | jeremias | 2008-04-02 10:24:41 +0200 (Mi, 02 Apr 2008) | 1 line
Completed javadocs
........
r643824 | jeremias | 2008-04-02 12:00:30 +0200 (Mi, 02 Apr 2008) | 1 line
Javadocs.
........
r645847 | vhennebert | 2008-04-08 12:54:16 +0200 (Di, 08 Apr 2008) | 2 lines
Minor typo fixes
........
r645848 | vhennebert | 2008-04-08 12:58:30 +0200 (Di, 08 Apr 2008) | 2 lines
Another small typo fix
........
r647678 | jeremias | 2008-04-14 09:20:26 +0200 (Mo, 14 Apr 2008) | 1 line
Renamed *EventProducer.Factory.create() to *EventProducer.Provider.get() to better reflect what the method does (instances may be cached and reused).
........
................
r647745 | jeremias | 2008-04-14 13:01:06 +0100 (Mon, 14 Apr 2008) | 1 line
svnmerge didn't work for me in this case. Remove svn merge info.
................
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_AFPGOCAResources@647787 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/documentation/content')
-rw-r--r-- | src/documentation/content/xdocs/site.xml | 1 | ||||
-rw-r--r-- | src/documentation/content/xdocs/trunk/events.xml | 422 |
2 files changed, 423 insertions, 0 deletions
diff --git a/src/documentation/content/xdocs/site.xml b/src/documentation/content/xdocs/site.xml index 18716903c..b0a3214e7 100644 --- a/src/documentation/content/xdocs/site.xml +++ b/src/documentation/content/xdocs/site.xml @@ -155,6 +155,7 @@ <fonts label="Fonts" href="fonts.html"/> <hyphenation label="Hyphenation" href="hyphenation.html"/> <extensions label="Extensions" href="extensions.html"/> + <events label="Events" href="events.html"/> </features> </trunk> diff --git a/src/documentation/content/xdocs/trunk/events.xml b/src/documentation/content/xdocs/trunk/events.xml new file mode 100644 index 000000000..d2fe5318c --- /dev/null +++ b/src/documentation/content/xdocs/trunk/events.xml @@ -0,0 +1,422 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<!-- $Id$ --> +<!DOCTYPE document PUBLIC "-//APACHE//DTD Documentation V2.0//EN" "http://forrest.apache.org/dtd/document-v20.dtd"> +<document> + <header> + <title>Events/Processing Feedback</title> + <version>$Revision: 634267 $</version> + </header> + <body> + <section id="introduction"> + <title>Introduction</title> + <p> + In versions until 0.20.5, FOP used + <a href="http://excalibur.apache.org/framework/index.html">Avalon-style Logging</a> where + it was possible to supply a logger per processing run. During the redesign + the logging infrastructure was switched over to + <a href="http://commons.apache.org/logging/">Commons Logging</a> which is (like Log4J or + java.util.logging) a "static" logging framework (the logger is accessed through static + variables). This made it very difficult in a multi-threaded system to retrieve information + for a single processing run. + </p> + <p> + With FOP's event subsystem, we'd like to close this gap again and even go further. The + first point is to realize that we have two kinds of "logging". Firstly, we have the logging + infrastructure for the (FOP) developer who needs to be able to enable finer log messages + for certain parts of FOP to track down a certain problem. Secondly, we have the user who + would like to be informed about missing images, overflowing lines or substituted fonts. + These messages (or events) are targeted at less technical people and may ideally be + localized (translated). Furthermore, tool and solution builders would like to integrate + FOP into their own solutions. For example, an FO editor should be able to point the user + to the right place where a particular problem occurred while developing a document template. + Finally, some integrators would like to abort processing if a resource (an image or a font) + has not been found, while others would simply continue. The event system allows to + react on these events. + </p> + <p> + On this page, we won't discuss logging as such. We will show how the event subsystem can + be used for various tasks. We'll first look at the event subsystem from the consumer side. + Finally, the production of events inside FOP will be discussed (this is mostly interesting + for FOP developers only). + </p> + </section> + <section id="consumer"> + <title>The consumer side</title> + <p> + The event subsystem is located in the <code>org.apache.fop.events</code> package and its + base is the <code>Event</code> class. An instance is created for each event and is sent + to a set of <code>EventListener</code> instances by the <code>EventBroadcaster</code>. + An <code>Event</code> contains: + </p> + <ul> + <li>an event ID,</li> + <li>a source object (which generated the event),</li> + <li>a severity level (Info, Warning, Error and Fatal Error) and</li> + <li>a map of named parameters.</li> + </ul> + <p> + The <code>EventFormatter</code> class can be used to translate the events into + human-readable, localized messages. + </p> + <p> + A full example of what is shown here can be found in the + <code>examples/embedding/java/embedding/events</code> directory in the FOP distribution. + The example can also be accessed + <a href="http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/examples/embedding/java/embedding/events/">via the web</a>. + </p> + <section id="write-listener"> + <title>Writing an EventListener</title> + <p> + The following code sample shows a very simple EventListener. It basically just sends + all events to System.out (stdout) or System.err (stderr) depending on the event severity. + </p> + <source><![CDATA[import org.apache.fop.events.Event; +import org.apache.fop.events.EventFormatter; +import org.apache.fop.events.EventListener; +import org.apache.fop.events.model.EventSeverity; + +/** A simple event listener that writes the events to stdout and stderr. */ +public class SysOutEventListener implements EventListener { + + /** {@inheritDoc} */ + public void processEvent(Event event) { + String msg = EventFormatter.format(event); + EventSeverity severity = event.getSeverity(); + if (severity == EventSeverity.INFO) { + System.out.println("[INFO ] " + msg); + } else if (severity == EventSeverity.WARN) { + System.out.println("[WARN ] " + msg); + } else if (severity == EventSeverity.ERROR) { + System.err.println("[ERROR] " + msg); + } else if (severity == EventSeverity.FATAL) { + System.err.println("[FATAL] " + msg); + } else { + assert false; + } + } +}]]></source> + <p> + You can see that for every event the method <code>processEvent</code> of the + <code>EventListener</code> will be called. Inside this method you can do whatever + processing you would like including throwing a <code>RuntimeException</code>, if you want + to abort the current processing run. + </p> + <p> + The code above also shows how you can turn an event into a human-readable, localized + message that can be presented to a user. The <code>EventFormatter</code> class does + this for you. It provides additional methods if you'd like to explicitly specify + the locale. + </p> + <p> + It is possible to gather all events for a whole processing run so they can be + evaluated afterwards. However, care should be taken about memory consumption since + the events provide references to objects inside FOP which may themselves have + references to other objects. So holding on to these objects may mean that whole + object trees cannot be released! + </p> + </section> + <section id="add-listener"> + <title>Adding an EventListener</title> + <p> + To register the event listener with FOP, get the <code>EventBroadcaster</code> which + is associated with the user agent (<code>FOUserAgent</code>) and add it there: + </p> + <source><![CDATA[FOUserAgent foUserAgent = fopFactory.newFOUserAgent(); +foUserAgent.getEventBroadcaster().addEventListener(new SysOutEventListener());]]></source> + <p> + Please note that this is done separately for each processing run, i.e. for each + new user agent. + </p> + </section> + <section id="listener-example1"> + <title>An additional listener example</title> + <p> + Here's an additional example of an event listener: + </p> + <p> + By default, FOP continues processing even if an image wasn't found. If you have + more strict requirements and want FOP to stop if an image is not available, you can + do something like the following: + </p> + <source><![CDATA[public class MyEventListener implements EventListener { + + public void processEvent(Event event) { + if ("org.apache.fop.events.ResourceEventProducer.imageNotFound" + .equals(event.getEventID())) { + + //Get the FileNotFoundException that's part of the event's parameters + FileNotFoundException fnfe = (FileNotFoundException)event.getParam("fnfe"); + + throw new RuntimeException(EventFormatter.format(event), fnfe); + } else { + //ignore all other events (or do something of your choice) + } + } + +}]]></source> + <p> + This throws a <code>RuntimeException</code> with the <code>FileNotFoundException</code> + as the cause. Further processing effectively stops in FOP. You can catch the exception + in your code and react as you see necessary. + </p> + </section> + </section> + <section id="producer"> + <title>The producer side (for FOP developers)</title> + <p> + This section is primarily for FOP and FOP plug-in developers. It describes how to use + the event subsystem for producing events. + </p> + <note> + The event package has been designed in order to be theoretically useful for use cases + outside FOP. If you think this is interesting independently from FOP, please talk to + <a href="mailto:fop-dev@xmlgraphics.apache.org">us</a>. + </note> + <section id="basic-event-production"> + <title>Producing and sending an event</title> + <p> + The basics are very simple. Just instantiate an <code>Event</code> object and fill + it with the necessary parameters. Then pass it to the <code>EventBroadcaster</code> + which distributes the events to the interested listeneners. Here's a code example: + </p> + <source><![CDATA[Event ev = new Event(this, "complain", EventSeverity.WARN, + Event.paramsBuilder() + .param("reason", "I'm tired") + .param("blah", new Integer(23)) + .build()); +EventBroadcaster broadcaster = [get it from somewhere]; +broadcaster.broadcastEvent(ev); +]]></source> + <p> + The <code>Event.paramsBuilder()</code> is a + <a href="http://en.wikipedia.org/wiki/Fluent_interface">fluent interface</a> + to help with the build-up of the parameters. You could just as well instantiate a + <code>Map</code> (<code>Map<String, Object></code>) and fill it with values. + </p> + </section> + <section id="event-producer"> + <title>The EventProducer interface</title> + <p> + To simplify event production, the event subsystem provides the <code>EventProducer</code> + interface. You can create interfaces which extend <code>EventProducer</code>. These + interfaces will contain one method per event to be generated. By contract, each event + method must have as its first parameter a parameter named "source" (Type Object) which + indicates the object that generated the event. After that come an arbitrary number of + parameters of any type as needed by the event. + </p> + <p> + The event producer interface does not need to have any implementation. The implementation + is produced at runtime by a dynamic proxy created by <code>DefaultEventBroadcaster</code>. + The dynamic proxy creates <code>Event</code> instances for each method call against + the event producer interface. Each parameter (except "source") is added to the event's + parameter map. + </p> + <p> + To simplify the code needed to get an instance of the event producer interface it is + suggested to create a public inner provider class inside the interface. + </p> + <p> + Here's an example of such an event producer interface: + </p> + <source><![CDATA[public interface MyEventProducer extends EventProducer { + + public class Provider { + + public static MyEventProducer get(EventBroadcaster broadcaster) { + return (MyEventProducer)broadcaster.getEventProducerFor(MyEventProducer.class); + } + } + + /** + * Complain about something. + * @param source the event source + * @param reason the reason for the complaint + * @param blah the complaint + * @event.severity WARN + */ + void complain(Object source, String reason, int blah); + +}]]></source> + <p> + To produce the same event as in the first example above, you'd use the following code: + </p> + <source><![CDATA[EventBroadcaster broadcaster = [get it from somewhere]; +TestEventProducer producer = TestEventProducer.Provider.get(broadcaster); +producer.complain(this, "I'm tired", 23);]]></source> + </section> + <section id="event-model"> + <title>The event model</title> + <p> + Inside an invocation handler for a dynamic proxy, there's no information about + the names of each parameter. The JVM doesn't provide it. The only thing you know is + the interface and method name. In order to properly fill the <code>Event</code>'s + parameter map we need to know the parameter names. These are retrieved from an + event object model. This is found in the <code>org.apache.fop.events.model</code> + package. The data for the object model is retrieved from an XML representation of the + event model that is loaded as a resource. The XML representation is generated using an + Ant task at build time (<code>ant resourcegen</code>). The Ant task (found in + <code>src/codegen/java/org/apache/fop/tools/EventProducerCollectorTask.java</code>) + scans FOP's sources for descendants of the <code>EventProducer</code> interface and + uses <a href="http://qdox.codehaus.org/">QDox</a> to parse these interfaces. + </p> + <p> + Primarily, the QDox-based collector task records the parameters' names and types. + Furthermore, it extracts additional attributes embedded as Javadoc comments from + the methods. At the moment, the only such attribute is "@event.severity" which indicates + the default event severity (which can be changed by event listeners). The example event + producer above shows the Javadocs for an event method. + </p> + <p> + There's one more information that is extracted from the event producer information for + the event model: an optional primary exception. The first exception in the "throws" + declaration of an event method is noted. It is used to throw an exception from + the invocation handler if the event has an event severity of "FATAL" when all + listeners have been called (listeners can update the event severity). Please note + that an implementation of + <code>org.apache.fop.events.EventExceptionManager$ExceptionFactory</code> has to be + registered for the <code>EventExceptionManager</code> to be able to construct the + exception from an event. + </p> + <p> + For a given application, there can be multiple event models active at the same time. + In FOP, each renderer is considered to be a plug-in and provides its own specific + event model. The individual event models are provided through an + <code>EventModelFactory</code>. This interface is implemented for each event model + and registered through the service provider mechanism + (see the <a href="#plug-ins">plug-ins section</a> for details). + </p> + </section> + <section id="event-severity"> + <title>Event severity</title> + <p> + Four different levels of severity for events has been defined: + </p> + <ol> + <li>INFO: informational only</li> + <li>WARN: a Warning</li> + <li>ERROR: an error condition from which FOP can recover. FOP will continue processing.</li> + <li>FATAL: a fatal error which causes an exception in the end and FOP will stop processing.</li> + </ol> + <p> + Event listeners can choose to ignore certain events based on their event severity. + Please note that you may recieve an event "twice" in a specific case: if there is + a fatal error an event is generated and sent to the listeners. After that an exception + is thrown with the same information and processing stops. If the fatal event is + shown to the user and the following exception is equally presented to the user it + may appear that the event is duplicated. Of course, the same information is just + published through two different channels. + </p> + </section> + <section id="plug-ins"> + <title>Plug-ins to the event subsystem</title> + <p> + The event subsystem is extensible. There are a number of extension points: + </p> + <ul> + <li> + <strong><code>org.apache.fop.events.model.EventModelFactory</code>:</strong> Provides + an event model to the event subsystem. + </li> + <li> + <strong><code>org.apache.fop.events.EventExceptionManager$ExceptionFactory</code>:</strong> + Creates exceptions for events, i.e. turns an event into a specific exception. + </li> + </ul> + <p> + The names in bold above are used as filenames for the service provider files that + are placed in the <code>META-INF/services</code> directory. That way, they are + automatically detected. This is a mechanism defined by the + <a href="http://java.sun.com/j2se/1.4.2/docs/guide/jar/jar.html#Service%20Provider">JAR file specification</a>. + </p> + </section> + <section id="l10n"> + <title>Localization (L10n)</title> + <p> + One goal of the event subsystem was to have localized (translated) event messages. + The <code>EventFormatter</code> class can be used to convert an event to a + human-readable message. Each <code>EventProducer</code> can provide its own XML-based + translation file. If there is none, a central translation file is used, called + "EventFormatter.xml" (found in the same directory as the <code>EventFormatter</code> + class). + </p> + <p> + The XML format used by the <code>EventFormatter</code> is the same as + <a href="ext:cocoon">Apache Cocoon's</a> catalog format. Here's an example: + </p> + <source><![CDATA[<?xml version="1.0" encoding="UTF-8"?> +<catalogue xml:lang="en"> + <message key="locator"> + [ (See position {loc})| (See {#gatherContextInfo})| (No context info available)] + </message> + <message key="org.apache.fop.render.rtf.RTFEventProducer.explicitTableColumnsRequired"> + RTF output requires that all table-columns for a table are defined. Output will be incorrect.{{locator}} + </message> + <message key="org.apache.fop.render.rtf.RTFEventProducer.ignoredDeferredEvent"> + Ignored deferred event for {node} ({start,if,start,end}).{{locator}} + </message> +</catalogue> +]]></source> + <p> + The example (extracted from the RTF handler's event producer) has message templates for + two event methods. The class used to do variable replacement in the templates is + <code>org.apache.fop.util.text.AdvancedMessageFormat</code> which is more powerful + than the <code>MessageFormat</code> classes provided by the Java class library + (<code>java.util.text</code> package). + </p> + <p> + "locator" is a template that is reused by the other message templates + by referencing it through "{{locator}}". This is some kind of include command. + </p> + <p> + Normal event parameters are accessed by name inside single curly braces, for example: + "{node}". For objects, this format just uses the <code>toString()</code> method to turn + the object into a string, unless there is an <code>ObjectFormatter</code> registered + for that type (there's an example for <code>org.xml.sax.Locator</code>). + </p> + <p> + The single curly braces pattern supports additional features. For example, it is possible + to do this: "{start,if,start,end}". "if" here is a special field modifier that evaluates + "start" as a boolean and if that is true returns the text right after the second comma + ("start"). Otherwise it returns the text after the third comma ("end"). The "equals" + modifier is similar to "if" but it takes as an additional (comma-separated) parameter + right after the "equals" modifier, a string that is compared to the value of the variable. + An example: {severity,equals,EventSeverity:FATAL,,some text} (this adds "some text" if + the severity is not FATAL). + </p> + <p> + Additional such modifiers can be added by implementing the + <code>AdvancedMessageFormat$Part</code> and <code>AdvancedMessageFormat$PartFactory</code> + interfaces. + </p> + <p> + Square braces can be used to specify optional template sections. The whole section will + be omitted if any of the variables used within are unavailable. Pipe (|) characters can + be used to specify alternative sub-templates (see "locator" above for an example). + </p> + <p> + Developers can also register a function (in the above example: + <code>{#gatherContextInfo})</code> + to do more complex information rendering. These functions are implementations of the + <code>AdvancedMessageFormat$Function</code> interface. Please take care that this is + done in a locale-independent way as there is no locale information available, yet. + </p> + </section> + </section> + </body> +</document> |