gmazza 2004/08/02 22:22:43 Modified: src/java/org/apache/fop/fo AbstractCharIterator.java FObj.java src/java/org/apache/fop/fo/flow BidiOverride.java Inline.java Log: Implemented validity checking for fo:bidi-override. Revision Changes Path 1.3 +1 -1 xml-fop/src/java/org/apache/fop/fo/AbstractCharIterator.java Index: AbstractCharIterator.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/fo/AbstractCharIterator.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- AbstractCharIterator.java 27 Feb 2004 17:57:40 -0000 1.2 +++ AbstractCharIterator.java 3 Aug 2004 05:22:43 -0000 1.3 @@ -33,7 +33,7 @@ /** * @see org.apache.fop.fo.CharIterator#nextChar() */ - public abstract char nextChar() throws NoSuchElementException ; + public abstract char nextChar() throws NoSuchElementException; /** * @see java.util.Iterator#next() 1.59 +21 -1 xml-fop/src/java/org/apache/fop/fo/FObj.java Index: FObj.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/fo/FObj.java,v retrieving revision 1.58 retrieving revision 1.59 diff -u -r1.58 -r1.59 --- FObj.java 1 Aug 2004 04:20:48 -0000 1.58 +++ FObj.java 3 Aug 2004 05:22:43 -0000 1.59 @@ -366,7 +366,7 @@ /** * Return an iterator over the object's childNodes starting - * at the pased node. + * at the passed-in node. * @param childNode First node in the iterator * @return A ListIterator or null if childNode isn't a child of * this FObj. @@ -528,6 +528,26 @@ || lName.equals("wrapper") || (!isOutOfLineFODescendant && lName.equals("float")) || lName.equals("retrieve-marker"))); + } + + /** + * Convenience method for validity checking. Checks if the + * current node has an ancestor of a given name. + * @param ancestorName -- node name to check for (e.g., "fo:root") + * @return number of levels above FO where ancestor exists, + * -1 if not found + */ + protected int findAncestor(String ancestorName) { + int found = 1; + FONode temp = getParent(); + while (temp != null) { + if (temp.getName().equals(ancestorName)) { + return found; + } + found += 1; + temp = temp.getParent(); + } + return -1; } } 1.11 +63 -25 xml-fop/src/java/org/apache/fop/fo/flow/BidiOverride.java Index: BidiOverride.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/fo/flow/BidiOverride.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- BidiOverride.java 27 Jul 2004 23:57:12 -0000 1.10 +++ BidiOverride.java 3 Aug 2004 05:22:43 -0000 1.11 @@ -18,7 +18,13 @@ 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.FOElementMapping; import org.apache.fop.fo.FONode; import org.apache.fop.fo.FObjMixed; import org.apache.fop.layoutmgr.AddLMVisitor; @@ -30,36 +36,72 @@ */ public class BidiOverride extends FObjMixed { + // used for FO validation + private boolean blockOrInlineItemFound = false; + private boolean canHaveBlockLevelChildren = true; + /** * @param parent FONode that is the parent of this object */ public BidiOverride(FONode parent) { super(parent); - } - - private void setup() { - - // Common Aural Properties - CommonAural mAurProps = propMgr.getAuralProps(); + + /* Check to see if this node can have block-level children. + * See validateChildNode() below. + */ + int lvlLeader = findAncestor("fo:leader"); + int lvlInCntr = findAncestor("fo:inline-container"); + int lvlInline = findAncestor("fo:inline"); + int lvlFootnote = findAncestor("fo:footnote"); + + if (lvlLeader > 0) { + if (lvlInCntr < 0 || + (lvlInCntr > 0 && lvlInCntr > lvlLeader)) { + canHaveBlockLevelChildren = false; + } + } else if (lvlInline > 0 && lvlFootnote == (lvlInline + 1)) { + if (lvlInCntr < 0 || + (lvlInCntr > 0 && lvlInCntr > lvlInline)) { + canHaveBlockLevelChildren = false; + } + } - // Common Font Properties - //this.fontState = propMgr.getFontState(area.getFontInfo()); - - // Common Margin Properties-Inline - CommonRelativePosition mProps = propMgr.getRelativePositionProps(); + } - // this.propertyList.get("color"); - // this.propertyList.get("direction"); + /** + * @see org.apache.fop.fo.FObj#addProperties + */ + protected void addProperties(Attributes attlist) throws SAXParseException { + super.addProperties(attlist); setupID(); - // this.propertyList.get("letter-spacing"); - // this.propertyList.get("line-height"); - // this.propertyList.get("line-height-shift-adjustment"); - // this.propertyList.get("score-spaces"); - // this.propertyList.get("text-shadow"); - // this.propertyList.get("text-transform"); - // this.propertyList.get("unicode-bidi"); - // this.propertyList.get("word-spacing"); + } + /** + * @see org.apache.fop.fo.FONode#validateChildNode(Locator, String, String) + * XSL Content Model: marker* (#PCDATA|%inline;|%block;)* + * Additionally: "An fo:bidi-override that is a descendant of an fo:leader + * or of the fo:inline child of an fo:footnote may not have block-level + * children, unless it has a nearer ancestor that is an + * fo:inline-container." + */ + protected void validateChildNode(Locator loc, String nsURI, String localName) + throws SAXParseException { + if (nsURI == FOElementMapping.URI && localName.equals("marker")) { + if (blockOrInlineItemFound) { + nodesOutOfOrderError(loc, "fo:marker", + "(#PCDATA|%inline;|%block;)"); + } + } else if (!isBlockOrInlineItem(nsURI, localName)) { + invalidChildError(loc, nsURI, localName); + } else if (!canHaveBlockLevelChildren && isBlockItem(nsURI, localName)) { + invalidChildError(loc, nsURI, localName); + } else { + blockOrInlineItemFound = true; + } + } + + public String getName() { + return "fo:bidi-override"; } /** @@ -76,9 +118,5 @@ */ public void acceptVisitor(AddLMVisitor aLMV) { aLMV.serveBidiOverride(this); - } - - public String getName() { - return "fo:bidi-override"; } } 1.20 +7 -39 xml-fop/src/java/org/apache/fop/fo/flow/Inline.java Index: Inline.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/fo/flow/Inline.java,v retrieving revision 1.19 retrieving revision 1.20 diff -u -r1.19 -r1.20 --- Inline.java 1 Aug 2004 04:20:48 -0000 1.19 +++ Inline.java 3 Aug 2004 05:22:43 -0000 1.20 @@ -67,39 +67,7 @@ + " be directly under flow", locator); } - // Common Accessibility Properties - CommonAccessibility mAccProps = propMgr.getAccessibilityProps(); - - // Common Aural Properties - CommonAural mAurProps = propMgr.getAuralProps(); - - // Common Border, Padding, and Background Properties - CommonBorderAndPadding bap = propMgr.getBorderAndPadding(); - CommonBackground bProps = propMgr.getBackgroundProps(); - - // Common Font Properties - //this.fontState = propMgr.getFontState(area.getFontInfo()); - - // Common Margin Properties-Inline - CommonMarginInline mProps = propMgr.getMarginInlineProps(); - - // Common Relative Position Properties - CommonRelativePosition mRelProps = propMgr.getRelativePositionProps(); - - // this.propertyList.get("alignment-adjust"); - // this.propertyList.get("alignment-baseline"); - // this.propertyList.get("baseline-shift"); - // this.propertyList.get("color"); - // this.propertyList.get("dominant-baseline"); setupID(); - // this.propertyList.get("keep-together"); - // 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("text-devoration"); - // this.propertyList.get("visibility"); - // this.propertyList.get("z-index"); int textDecoration = this.propertyList.get(PR_TEXT_DECORATION).getEnum(); @@ -119,6 +87,13 @@ } /** + * @see org.apache.fop.fo.FONode#end + */ + protected void endOfNode() throws SAXParseException { + getFOInputHandler().endInline(this); + } + + /** * @return true (Inline can contain Markers) */ protected boolean containsMarkers() { @@ -134,13 +109,6 @@ public void acceptVisitor(AddLMVisitor aLMV) { aLMV.serveInline(this); - } - - /** - * @see org.apache.fop.fo.FONode#end - */ - protected void endOfNode() throws SAXParseException { - getFOInputHandler().endInline(this); } public String getName() {
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]