jeremias 2004/02/03 14:09:47 Modified: src/java/org/apache/fop/apps Driver.java Log: Move FOTreeListener registration and removal into getContentHandler() to fix SAX use case as demonstrated in ExampleXML2PDF. Revision Changes Path 1.50 +23 -12 xml-fop/src/java/org/apache/fop/apps/Driver.java Index: Driver.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/apps/Driver.java,v retrieving revision 1.49 retrieving revision 1.50 diff -u -r1.49 -r1.50 --- Driver.java 19 Nov 2003 18:32:33 -0000 1.49 +++ Driver.java 3 Feb 2004 22:09:47 -0000 1.50 @@ -65,6 +65,7 @@ import org.apache.fop.render.rtf.RTFHandler; import org.apache.fop.tools.DocumentInputSource; import org.apache.fop.tools.DocumentReader; +import org.apache.fop.tools.ProxyContentHandler; import org.apache.fop.layoutmgr.LayoutManagerLS; // Avalon @@ -467,8 +468,7 @@ public void setRenderer(String rendererClassName) throws IllegalArgumentException { try { - renderer = - (Renderer)Class.forName(rendererClassName).newInstance(); + renderer = (Renderer)Class.forName(rendererClassName).newInstance(); if (renderer instanceof LogEnabled) { ((LogEnabled)renderer).enableLogging(getLogger()); } @@ -574,7 +574,26 @@ treeBuilder.setFOInputHandler(foInputHandler); treeBuilder.foTreeControl = currentDocument; - return treeBuilder; + + return new ProxyContentHandler(treeBuilder) { + + public void startDocument() throws SAXException { + if (foInputHandler instanceof FOTreeHandler) { + FOTreeHandler foTreeHandler = (FOTreeHandler)foInputHandler; + foTreeHandler.addFOTreeListener(currentDocument); + } + super.startDocument(); + } + + public void endDocument() throws SAXException { + super.endDocument(); + if (foInputHandler instanceof FOTreeHandler) { + FOTreeHandler foTreeHandler = (FOTreeHandler)foInputHandler; + foTreeHandler.removeFOTreeListener(currentDocument); + } + } + + }; } /** @@ -608,7 +627,7 @@ * system. */ if (currentDocument.getLayoutStrategy() != null) { - if (currentDocument.getLayoutStrategy().foTreeNeeded() != true) { + if (!currentDocument.getLayoutStrategy().foTreeNeeded()) { currentDocument.getLayoutStrategy().format(null, null); return; } @@ -618,10 +637,6 @@ * For all other cases, we wish to parse normally. */ try { - if (foInputHandler instanceof FOTreeHandler) { - FOTreeHandler foTreeHandler = (FOTreeHandler)foInputHandler; - foTreeHandler.addFOTreeListener(currentDocument); - } /** The following statement triggers virtually all of the processing for this document. The SAX parser fires events that are handled by @@ -636,10 +651,6 @@ where this level of control is implemented. */ parser.parse(source); - if (foInputHandler instanceof FOTreeHandler) { - FOTreeHandler foTreeHandler = (FOTreeHandler)foInputHandler; - foTreeHandler.removeFOTreeListener(currentDocument); - } } catch (SAXException e) { if (e.getException() instanceof FOPException) { // Undo exception tunneling.
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]