From 7e4a5bba40e1ffb155d6192ec3e5edbd966716e6 Mon Sep 17 00:00:00 2001 From: Glen Mazza Date: Sun, 1 Aug 2004 16:46:46 +0000 Subject: [PATCH] PR: Obtained from: Submitted by: Reviewed by: Child element validation added to fo:instream-foreign-object. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@197849 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/org/apache/fop/fo/FONode.java | 14 +++ .../fop/fo/flow/InstreamForeignObject.java | 108 ++++++------------ 2 files changed, 49 insertions(+), 73 deletions(-) diff --git a/src/java/org/apache/fop/fo/FONode.java b/src/java/org/apache/fop/fo/FONode.java index acea124dc..c7b125e76 100644 --- a/src/java/org/apache/fop/fo/FONode.java +++ b/src/java/org/apache/fop/fo/FONode.java @@ -245,6 +245,20 @@ public abstract class FONode { * Helper function to standardize "too many" error exceptions * (e.g., two fo:declarations within fo:root) * @param loc org.xml.sax.Locator object of the error (*not* parent node) + * @param nsURI namespace URI of incoming invalid node + * @param lName local name (i.e., no prefix) of incoming node + */ + protected void tooManyNodesError(Locator loc, String nsURI, String lName) + throws SAXParseException { + throw new SAXParseException (errorText(loc) + getName() + ", only one " + + getNodeString(nsURI, lName) + " may be declared.", loc); + } + + /** + * Helper function to standardize "too many" error exceptions + * (e.g., two fo:declarations within fo:root) + * This overrloaded method helps make the caller code better self-documenting + * @param loc org.xml.sax.Locator object of the error (*not* parent node) * @param offendingNode incoming node that would cause a duplication. */ protected void tooManyNodesError(Locator loc, String offendingNode) diff --git a/src/java/org/apache/fop/fo/flow/InstreamForeignObject.java b/src/java/org/apache/fop/fo/flow/InstreamForeignObject.java index f2677268c..afbeff95e 100644 --- a/src/java/org/apache/fop/fo/flow/InstreamForeignObject.java +++ b/src/java/org/apache/fop/fo/flow/InstreamForeignObject.java @@ -18,7 +18,14 @@ package org.apache.fop.fo.flow; +// XML +import org.xml.sax.Attributes; +import org.xml.sax.Locator; +import org.xml.sax.SAXParseException; + +// FOP import org.apache.fop.fo.FONode; +import org.apache.fop.fo.FOElementMapping; import org.apache.fop.layoutmgr.AddLMVisitor; import org.apache.fop.fo.FObj; @@ -29,6 +36,8 @@ import org.apache.fop.fo.FObj; */ public class InstreamForeignObject extends FObj { + boolean hasNonXSLNamespaceElement = false; + /** * constructs an instream-foreign-object object (called by Maker). * @@ -38,6 +47,32 @@ public class InstreamForeignObject extends FObj { super(parent); } + /** + * @see org.apache.fop.fo.FONode#validateChildNode(Locator, String, String) + * XSL Content Model: one (1) non-XSL namespace child + */ + protected void validateChildNode(Locator loc, String nsURI, String localName) + throws SAXParseException { + if (nsURI == FOElementMapping.URI) { + invalidChildError(loc, nsURI, localName); + } else if (hasNonXSLNamespaceElement) { + tooManyNodesError(loc, "child element"); + } else { + hasNonXSLNamespaceElement = true; + } + } + + /** + * Make sure content model satisfied, if so then tell the + * StructureRenderer that we are at the end of the flow. + * @see org.apache.fop.fo.FONode#end + */ + protected void endOfNode() throws SAXParseException { + if (!hasNonXSLNamespaceElement) { + missingChildElementError("one (1) non-XSL namespace child"); + } + } + public int computeXOffset (int ipd, int cwidth) { int xoffset = 0; int ta = propertyList.get(PR_TEXT_ALIGN).getEnum(); @@ -85,79 +120,6 @@ public class InstreamForeignObject extends FObj { return true; } - /* - - // Common Accessibility Properties - AccessibilityProps mAccProps = propMgr.getAccessibilityProps(); - - // Common Aural Properties - AuralProps mAurProps = propMgr.getAuralProps(); - - // Common Border, Padding, and Background Properties - BorderAndPadding bap = propMgr.getBorderAndPadding(); - BackgroundProps bProps = propMgr.getBackgroundProps(); - - // Common Margin Properties-Inline - MarginInlineProps mProps = propMgr.getMarginInlineProps(); - - // Common Relative Position Properties - RelativePositionProps mRelProps = propMgr.getRelativePositionProps(); - - // this.propertyList.get("alignment-adjust"); - // this.propertyList.get("alignment-baseline"); - // this.propertyList.get("baseline-shift"); - // this.propertyList.get("block-progression-dimension"); - // this.propertyList.get("content-height"); - // this.propertyList.get("content-type"); - // this.propertyList.get("content-width"); - // this.propertyList.get("display-align"); - // this.propertyList.get("dominant-baseline"); - // this.propertyList.get("height"); - setupID(); - // this.propertyList.get("inline-progression-dimension"); - // this.propertyList.get("keep-with-next"); - // this.propertyList.get("keep-with-previous"); - // this.propertyList.get("line-height"); - // this.propertyList.get("line-height-shift-adjustment"); - // this.propertyList.get("overflow"); - // this.propertyList.get("scaling"); - // this.propertyList.get("scaling-method"); - // this.propertyList.get("text-align"); - // this.propertyList.get("width"); - - /* retrieve properties * - int align = this.propertyList.get("text-align").getEnum(); - int valign = this.propertyList.get("vertical-align").getEnum(); - int overflow = this.propertyList.get("overflow").getEnum(); - - this.breakBefore = this.propertyList.get("break-before").getEnum(); - this.breakAfter = this.propertyList.get("break-after").getEnum(); - this.width = this.propertyList.get("width").getLength().mvalue(); - this.height = this.propertyList.get("height").getLength().mvalue(); - this.contwidth = - this.propertyList.get("content-width").getLength().mvalue(); - this.contheight = - this.propertyList.get("content-height").getLength().mvalue(); - this.wauto = this.propertyList.get("width").getLength().isAuto(); - this.hauto = this.propertyList.get("height").getLength().isAuto(); - this.cwauto = - this.propertyList.get("content-width").getLength().isAuto(); - this.chauto = - this.propertyList.get("content-height").getLength().isAuto(); - - this.startIndent = - this.propertyList.get("start-indent").getLength().mvalue(); - this.endIndent = - this.propertyList.get("end-indent").getLength().mvalue(); - this.spaceBefore = - this.propertyList.get("space-before.optimum").getLength().mvalue(); - this.spaceAfter = - this.propertyList.get("space-after.optimum").getLength().mvalue(); - - this.scaling = this.propertyList.get("scaling").getEnum(); - -*/ - /** * This is a hook for the AddLMVisitor class to be able to access * this object. -- 2.39.5