From 5fee7bd957ac85640ed4851bece1216eb6c6d5a5 Mon Sep 17 00:00:00 2001 From: Glen Mazza Date: Mon, 13 Sep 2004 03:46:04 +0000 Subject: [PATCH] 1.) Returned to recursion for FOEventHandler. 2.) InstreamForeignObject validation changed to accomodate Finn's validation changes. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@197945 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/org/apache/fop/fo/FONode.java | 16 +----------- src/java/org/apache/fop/fo/FOTreeBuilder.java | 2 +- .../fop/fo/flow/InstreamForeignObject.java | 8 ++---- .../org/apache/fop/fo/pagination/Root.java | 25 +++++++++++++++++++ 4 files changed, 29 insertions(+), 22 deletions(-) diff --git a/src/java/org/apache/fop/fo/FONode.java b/src/java/org/apache/fop/fo/FONode.java index 0b422bc8b..24e345a00 100644 --- a/src/java/org/apache/fop/fo/FONode.java +++ b/src/java/org/apache/fop/fo/FONode.java @@ -41,12 +41,6 @@ public abstract class FONode { protected static String FO_URI = FOElementMapping.URI; - /** - * FOEventHandler that handles FO events occurring - * during FO Tree processing. - */ - protected static FOEventHandler foEventHandler = null; - /** Parent FO node */ protected FONode parent; @@ -78,21 +72,13 @@ public abstract class FONode { } } - /** - * Sets the FOEventHandler that the FOTree processing fires events to - * @param eventHandler the FOEventHandler subclass to send FO events to - */ - public static void setFOEventHandler(FOEventHandler eventHandler) { - FONode.foEventHandler = eventHandler; - } - /** * Recursively goes up the FOTree hierarchy until the fo:root is found, * which returns the parent FOEventHandler. * @return the FOEventHandler object that is the parent of the FO Tree */ public FOEventHandler getFOEventHandler() { - return FONode.foEventHandler; + return parent.getFOEventHandler(); } /** diff --git a/src/java/org/apache/fop/fo/FOTreeBuilder.java b/src/java/org/apache/fop/fo/FOTreeBuilder.java index 38bd0ef18..cda21f8e0 100644 --- a/src/java/org/apache/fop/fo/FOTreeBuilder.java +++ b/src/java/org/apache/fop/fo/FOTreeBuilder.java @@ -218,7 +218,6 @@ public class FOTreeBuilder extends DefaultHandler { */ public void startDocument() throws SAXException { rootFObj = null; // allows FOTreeBuilder to be reused - FONode.setFOEventHandler(foEventHandler); if (log.isDebugEnabled()) { log.debug("Building formatting object tree"); } @@ -278,6 +277,7 @@ public class FOTreeBuilder extends DefaultHandler { if (rootFObj == null) { rootFObj = (Root) foNode; + rootFObj.setFOEventHandler(foEventHandler); } else { currentFObj.addChildNode(foNode); } diff --git a/src/java/org/apache/fop/fo/flow/InstreamForeignObject.java b/src/java/org/apache/fop/fo/flow/InstreamForeignObject.java index bbb92af80..6505db5f7 100644 --- a/src/java/org/apache/fop/fo/flow/InstreamForeignObject.java +++ b/src/java/org/apache/fop/fo/flow/InstreamForeignObject.java @@ -37,8 +37,6 @@ import org.apache.fop.fo.FObj; */ public class InstreamForeignObject extends FObj { - boolean hasNonXSLNamespaceElement = false; - /** * constructs an instream-foreign-object object (called by Maker). * @@ -56,10 +54,8 @@ public class InstreamForeignObject extends FObj { throws SAXParseException { if (nsURI == FO_URI) { invalidChildError(loc, nsURI, localName); - } else if (hasNonXSLNamespaceElement) { + } else if (childNodes != null) { tooManyNodesError(loc, "child element"); - } else { - hasNonXSLNamespaceElement = true; } } @@ -69,7 +65,7 @@ public class InstreamForeignObject extends FObj { * @see org.apache.fop.fo.FONode#end */ protected void endOfNode() throws SAXParseException { - if (!hasNonXSLNamespaceElement) { + if (childNodes == null) { missingChildElementError("one (1) non-XSL namespace child"); } } diff --git a/src/java/org/apache/fop/fo/pagination/Root.java b/src/java/org/apache/fop/fo/pagination/Root.java index 4ef17ddec..da3f642bf 100644 --- a/src/java/org/apache/fop/fo/pagination/Root.java +++ b/src/java/org/apache/fop/fo/pagination/Root.java @@ -28,6 +28,7 @@ import org.xml.sax.SAXParseException; // FOP import org.apache.fop.fo.FONode; import org.apache.fop.fo.FObj; +import org.apache.fop.fo.FOEventHandler; import org.apache.fop.fo.extensions.ExtensionElementMapping; import org.apache.fop.fo.extensions.Bookmarks; @@ -49,6 +50,11 @@ public class Root extends FObj { private int runningPageNumberCounter = 0; /** + * FOEventHandler object for this FO Tree + */ + private FOEventHandler foEventHandler = null; + + /** * @see org.apache.fop.fo.FONode#FONode(FONode) */ public Root(FONode parent) { @@ -107,6 +113,25 @@ public class Root extends FObj { } /** + * Sets the FOEventHandler object that this Root is attached to + * @param foEventHandler the FOEventHandler object + */ + public void setFOEventHandler(FOEventHandler foEventHandler) { + this.foEventHandler = foEventHandler; + } + + /** + * This method overrides the FONode version. The FONode version calls the + * method by the same name for the parent object. Since Root is at the top + * of the tree, it returns the actual FOEventHandler object. Thus, any FONode + * can use this chain to find which FOEventHandler it is being built for. + * @return the FOEventHandler implementation that this Root is attached to + */ + public FOEventHandler getFOEventHandler() { + return foEventHandler; + } + + /** * Returns the number of pages generated (over all PageSequence instances). * @return the number of pages */ -- 2.39.5