From 26b5548ee2bec051c2cc18bccbda31b86edfa560 Mon Sep 17 00:00:00 2001 From: "Andreas L. Delmelle" Date: Thu, 13 Dec 2007 14:43:08 +0000 Subject: [PATCH] Minor tweaks: * only add text to a fo:wrapper if it is not a direct flow-descendant * error if an fo:wrapper that is a direct flow-descendant contains inline-level children git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@603926 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/org/apache/fop/fo/flow/Wrapper.java | 37 ++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/java/org/apache/fop/fo/flow/Wrapper.java b/src/java/org/apache/fop/fo/flow/Wrapper.java index c7ca33a10..8b833f6b7 100644 --- a/src/java/org/apache/fop/fo/flow/Wrapper.java +++ b/src/java/org/apache/fop/fo/flow/Wrapper.java @@ -19,9 +19,12 @@ package org.apache.fop.fo.flow; +import org.apache.fop.apps.FOPException; import org.apache.fop.fo.FONode; import org.apache.fop.fo.FObjMixed; +import org.apache.fop.fo.PropertyList; import org.apache.fop.fo.ValidationException; +import org.apache.fop.fo.pagination.Flow; import org.xml.sax.Locator; /** @@ -35,12 +38,24 @@ public class Wrapper extends FObjMixed { // used for FO validation private boolean blockOrInlineItemFound = false; + private boolean isFlowChild = false; /** * @param parent FONode that is the parent of this object */ public Wrapper(FONode parent) { super(parent); + /* Check if the fo:wrapper is a child of an fo:flow or fo:static-content + * (or a descendant in nested fo:wrapper sequence, the first of which + * is a child of an fo:flow or fo:static-content */ + FONode ancestor = this.parent; + while (!(ancestor instanceof Flow) + && ancestor instanceof Wrapper) { + ancestor = ancestor.getParent(); + } + if (ancestor instanceof Flow) { + this.isFlowChild = true; + } } /** @@ -49,6 +64,7 @@ public class Wrapper extends FObjMixed { * Additionally (unimplemented): "An fo:wrapper that is a child of an * fo:multi-properties is only permitted to have children that would * be permitted in place of the fo:multi-properties." + * */ protected void validateChildNode(Locator loc, String nsURI, String localName) throws ValidationException { @@ -58,12 +74,33 @@ public class Wrapper extends FObjMixed { "(#PCDATA|%inline;|%block;)"); } } else if (isBlockOrInlineItem(nsURI, localName)) { + if (isFlowChild + && isInlineItem(nsURI, localName) + && !isNeutralItem(nsURI, localName)) { + invalidChildError(loc, nsURI, localName, + "fo:" + localName + " not allowed as child of an fo:wrapper " + + "that is a child of an fo:flow or fo:static-content"); + } blockOrInlineItemFound = true; } else { invalidChildError(loc, nsURI, localName); } } + /** {@inheritDoc} */ + protected void addCharacters( + char[] data, + int start, + int end, + PropertyList pList, + Locator locator) throws FOPException { + /* Only add text if the fo:wrapper is not a child of an fo:flow + * or fo:static-content */ + if (!this.isFlowChild) { + super.addCharacters(data, start, end, pList, locator); + } + } + /** {@inheritDoc} */ public String getLocalName() { return "wrapper"; -- 2.39.5