From: Glen Mazza Date: Wed, 25 Aug 2004 05:03:08 +0000 (+0000) Subject: 1. Implemented validateChildNode() for fo:simple-page-master. This may cause some... X-Git-Tag: Root_Temp_KnuthStylePageBreaking~602 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=bca058d18435025bf06fe5c828be82854f1f57b9;p=xmlgraphics-fop.git 1. Implemented validateChildNode() for fo:simple-page-master. This may cause some stress with the user community--as any declared fo:region-xxxx children must follow a specific ordering. 2. Modified several of our sample and test FO files to be compliant with the XSL spec with respect to the change above. 3. @todo's added to FO's still missing validateChildNode() 4. New FONode missingPropertyError() method created, for the major cases where missing properties should halt processing. 5. Various cleanup in our layout-master-set and region classes, including the removal of error checks that are no longer needed due to validateChildNode() being implemented. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@197889 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/examples/fo/svg/embedding.fo b/examples/fo/svg/embedding.fo index 4cd7b2bf7..4ecae2ae9 100644 --- a/examples/fo/svg/embedding.fo +++ b/examples/fo/svg/embedding.fo @@ -9,8 +9,8 @@ page-width="21cm" page-height="29.7cm" master-name="first"> - + diff --git a/examples/fo/svg/external.fo b/examples/fo/svg/external.fo index bd21cdddb..eaa76788c 100644 --- a/examples/fo/svg/external.fo +++ b/examples/fo/svg/external.fo @@ -8,8 +8,8 @@ margin-top="1cm" page-width="21cm" page-height="29.7cm"> - + diff --git a/src/java/org/apache/fop/fo/FONode.java b/src/java/org/apache/fop/fo/FONode.java index 000539700..64c1f199d 100644 --- a/src/java/org/apache/fop/fo/FONode.java +++ b/src/java/org/apache/fop/fo/FONode.java @@ -36,7 +36,6 @@ import org.apache.fop.fo.extensions.svg.SVGElementMapping; /** * base class for nodes in the XML tree - * */ public abstract class FONode { @@ -320,6 +319,18 @@ public abstract class FONode { + contentModel, locator); } + /** + * Helper function to return missing child element errors + * (e.g., fo:layout-master-set not having any page-master child element) + * @param contentModel The XSL Content Model for the fo: object. + * or a similar description indicating child elements needed. + */ + protected void missingPropertyError(String propertyName) + throws SAXParseException { + throw new SAXParseException(errorText(locator) + getName() + + " is missing required \"" + propertyName + "\" property.", locator); + } + /** * Helper function to return "Error (line#/column#)" string for * above exception messages diff --git a/src/java/org/apache/fop/fo/flow/Block.java b/src/java/org/apache/fop/fo/flow/Block.java index 254864f6f..d46651e8b 100644 --- a/src/java/org/apache/fop/fo/flow/Block.java +++ b/src/java/org/apache/fop/fo/flow/Block.java @@ -53,7 +53,7 @@ import org.apache.fop.util.CharUtilities; "this." from blockArea since BlockArea is now local. */ /** - * Class modelling the fo:block object. See Sec. 6.5.2 of the XSL-FO Standard. + * Class modelling the fo:block object. */ public class Block extends FObjMixed { diff --git a/src/java/org/apache/fop/fo/flow/BlockContainer.java b/src/java/org/apache/fop/fo/flow/BlockContainer.java index 91214ad1b..a27a0f24f 100644 --- a/src/java/org/apache/fop/fo/flow/BlockContainer.java +++ b/src/java/org/apache/fop/fo/flow/BlockContainer.java @@ -31,8 +31,8 @@ import org.xml.sax.Attributes; import org.xml.sax.SAXParseException; /** - * Class modelling the fo:block-container object. See Sec. 6.5.3 of the XSL-FO - * Standard. + * Class modelling the fo:block-container object. + * @todo implement validateChildNode() */ public class BlockContainer extends FObj { diff --git a/src/java/org/apache/fop/fo/flow/Footnote.java b/src/java/org/apache/fop/fo/flow/Footnote.java index 252f31d93..8dc407708 100644 --- a/src/java/org/apache/fop/fo/flow/Footnote.java +++ b/src/java/org/apache/fop/fo/flow/Footnote.java @@ -31,8 +31,7 @@ import org.apache.fop.fo.FONode; import org.apache.fop.fo.FObj; /** - * Class modelling the fo:footnote object. See Sec. 6.10.3 of the XSL-FO - * Standard. + * Class modelling the fo:footnote object. */ public class Footnote extends FObj { diff --git a/src/java/org/apache/fop/fo/flow/InlineContainer.java b/src/java/org/apache/fop/fo/flow/InlineContainer.java index c5251f63b..4e50556cd 100644 --- a/src/java/org/apache/fop/fo/flow/InlineContainer.java +++ b/src/java/org/apache/fop/fo/flow/InlineContainer.java @@ -33,8 +33,8 @@ import org.apache.fop.fo.FONode; import org.apache.fop.fo.FObj; /** - * Class modelling the fo:inline-container object. See Sec. 6.6.8 of the XSL-FO - * Standard. + * Class modelling the fo:inline-container object. + * @todo implement validateChildNode() */ public class InlineContainer extends FObj { diff --git a/src/java/org/apache/fop/fo/flow/Leader.java b/src/java/org/apache/fop/fo/flow/Leader.java index 1aa240c6b..a417777b4 100644 --- a/src/java/org/apache/fop/fo/flow/Leader.java +++ b/src/java/org/apache/fop/fo/flow/Leader.java @@ -34,6 +34,7 @@ import org.apache.fop.layoutmgr.LeaderLayoutManager; * Class modelling fo:leader object. * The main property of fo:leader is leader-pattern. * The following patterns are treated: rule, space, dots and use-content. + * @todo implement validateChildNode() */ public class Leader extends FObjMixed { diff --git a/src/java/org/apache/fop/fo/flow/ListBlock.java b/src/java/org/apache/fop/fo/flow/ListBlock.java index 244095c25..58e0a024b 100644 --- a/src/java/org/apache/fop/fo/flow/ListBlock.java +++ b/src/java/org/apache/fop/fo/flow/ListBlock.java @@ -33,8 +33,7 @@ import org.apache.fop.fo.FObj; import org.apache.fop.layoutmgr.list.ListBlockLayoutManager; /** - * Class modelling the fo:list-block object. See Sec. 6.8.2 of the XSL-FO - * Standard. + * Class modelling the fo:list-block object. */ public class ListBlock extends FObj { diff --git a/src/java/org/apache/fop/fo/flow/ListItemBody.java b/src/java/org/apache/fop/fo/flow/ListItemBody.java index 0c68947cb..73a7f47a3 100644 --- a/src/java/org/apache/fop/fo/flow/ListItemBody.java +++ b/src/java/org/apache/fop/fo/flow/ListItemBody.java @@ -23,8 +23,8 @@ import org.apache.fop.fo.FONode; import org.apache.fop.fo.FObj; /** - * Class modelling the fo:list-item-body object. See Sec. 6.8.4 of the XSL-FO - * Standard. + * Class modelling the fo:list-item-body object. + * @todo implement validateChildNode() */ public class ListItemBody extends FObj { diff --git a/src/java/org/apache/fop/fo/flow/ListItemLabel.java b/src/java/org/apache/fop/fo/flow/ListItemLabel.java index 5b313f305..b117bcb87 100644 --- a/src/java/org/apache/fop/fo/flow/ListItemLabel.java +++ b/src/java/org/apache/fop/fo/flow/ListItemLabel.java @@ -27,8 +27,8 @@ import org.apache.fop.fo.FONode; import org.apache.fop.fo.FObj; /** - * Class modelling the fo:list-item-label object. See Sec. 6.8.5 of the XSL-FO - * Standard. + * Class modelling the fo:list-item-label object. + * @todo implement validateChildNode() */ public class ListItemLabel extends FObj { diff --git a/src/java/org/apache/fop/fo/flow/MultiCase.java b/src/java/org/apache/fop/fo/flow/MultiCase.java index 32b6803df..4ec5ea6c1 100644 --- a/src/java/org/apache/fop/fo/flow/MultiCase.java +++ b/src/java/org/apache/fop/fo/flow/MultiCase.java @@ -24,6 +24,7 @@ import org.apache.fop.fo.FObj; /** * Class modelling the fo:multi-case object. + * @todo implement validateChildNode() */ public class MultiCase extends FObj { diff --git a/src/java/org/apache/fop/fo/flow/MultiSwitch.java b/src/java/org/apache/fop/fo/flow/MultiSwitch.java index 99c392f27..9c653172c 100644 --- a/src/java/org/apache/fop/fo/flow/MultiSwitch.java +++ b/src/java/org/apache/fop/fo/flow/MultiSwitch.java @@ -24,6 +24,7 @@ import org.apache.fop.fo.FObj; /** * Class modelling the fo:multi-switch object. + * @todo implement validateChildNode() */ public class MultiSwitch extends FObj { diff --git a/src/java/org/apache/fop/fo/flow/MultiToggle.java b/src/java/org/apache/fop/fo/flow/MultiToggle.java index a4a58e018..3d78a7476 100644 --- a/src/java/org/apache/fop/fo/flow/MultiToggle.java +++ b/src/java/org/apache/fop/fo/flow/MultiToggle.java @@ -24,6 +24,7 @@ import org.apache.fop.fo.FObj; /** * Class modelling the fo:multi-toggle property. + * @todo implement validateChildNode() */ public class MultiToggle extends FObj { diff --git a/src/java/org/apache/fop/fo/flow/PageNumber.java b/src/java/org/apache/fop/fo/flow/PageNumber.java index dd69e26d7..d4585cdb2 100644 --- a/src/java/org/apache/fop/fo/flow/PageNumber.java +++ b/src/java/org/apache/fop/fo/flow/PageNumber.java @@ -34,8 +34,7 @@ import org.apache.fop.fonts.Font; import org.apache.fop.layoutmgr.PageNumberLayoutManager; /** - * Class modelling the fo:page-number object. See Sec. 6.6.10 of the XSL-FO - * Standard. + * Class modelling the fo:page-number object. */ public class PageNumber extends FObj { /** FontState for this object */ diff --git a/src/java/org/apache/fop/fo/flow/PageNumberCitation.java b/src/java/org/apache/fop/fo/flow/PageNumberCitation.java index ff06b1b02..73257626d 100644 --- a/src/java/org/apache/fop/fo/flow/PageNumberCitation.java +++ b/src/java/org/apache/fop/fo/flow/PageNumberCitation.java @@ -34,8 +34,7 @@ import org.apache.fop.fonts.Font; import org.apache.fop.layoutmgr.PageNumberCitationLayoutManager; /** - * Class modelling the fo:page-number-citation object. See Sec. 6.6.11 of the - * XSL-FO Standard. + * Class modelling the fo:page-number-citation object. * This inline fo is replaced with the text for a page number. * The page number used is the page that contains the start of the * block referenced with the ref-id attribute. diff --git a/src/java/org/apache/fop/fo/flow/Table.java b/src/java/org/apache/fop/fo/flow/Table.java index 8146045a1..570372944 100644 --- a/src/java/org/apache/fop/fo/flow/Table.java +++ b/src/java/org/apache/fop/fo/flow/Table.java @@ -43,7 +43,7 @@ import org.apache.fop.fo.properties.CommonRelativePosition; import org.apache.fop.fo.properties.LengthRangeProperty; /** - * Class modelling the fo:table object. See Sec. 6.7.3 of the XSL-FO Standard. + * Class modelling the fo:table object. */ public class Table extends FObj { private static final int MINCOLWIDTH = 10000; // 10pt diff --git a/src/java/org/apache/fop/fo/flow/TableAndCaption.java b/src/java/org/apache/fop/fo/flow/TableAndCaption.java index df01c19c0..8538cc4f1 100644 --- a/src/java/org/apache/fop/fo/flow/TableAndCaption.java +++ b/src/java/org/apache/fop/fo/flow/TableAndCaption.java @@ -24,6 +24,7 @@ import org.apache.fop.fo.FObj; /** * Class modelling the fo:table-and-caption property. + * @todo implement validateChildNode() */ public class TableAndCaption extends FObj { diff --git a/src/java/org/apache/fop/fo/flow/TableBody.java b/src/java/org/apache/fop/fo/flow/TableBody.java index 392961826..2b0ad8dfc 100644 --- a/src/java/org/apache/fop/fo/flow/TableBody.java +++ b/src/java/org/apache/fop/fo/flow/TableBody.java @@ -33,8 +33,8 @@ import org.apache.fop.fo.FObj; import org.apache.fop.layoutmgr.table.Body; /** - * Class modelling the fo:table-body object. See Sec. 6.7.8 of the XSL-FO - * Standard. + * Class modelling the fo:table-body object. + * @todo implement validateChildNode() */ public class TableBody extends FObj { diff --git a/src/java/org/apache/fop/fo/flow/TableCaption.java b/src/java/org/apache/fop/fo/flow/TableCaption.java index 8fcbb776d..cbe53a4d0 100644 --- a/src/java/org/apache/fop/fo/flow/TableCaption.java +++ b/src/java/org/apache/fop/fo/flow/TableCaption.java @@ -24,6 +24,7 @@ import org.apache.fop.fo.FObj; /** * Class modelling the fo:table-caption object. + * @todo implement validateChildNode() */ public class TableCaption extends FObj { diff --git a/src/java/org/apache/fop/fo/flow/TableCell.java b/src/java/org/apache/fop/fo/flow/TableCell.java index 8907f5957..cb6928d87 100644 --- a/src/java/org/apache/fop/fo/flow/TableCell.java +++ b/src/java/org/apache/fop/fo/flow/TableCell.java @@ -34,8 +34,8 @@ import org.apache.fop.layoutmgr.table.Cell; import org.apache.fop.fo.properties.CommonBorderAndPadding; /** - * Class modelling the fo:table-cell object. See Sec. 6.7.10 of the XSL-FO - * Standard. + * Class modelling the fo:table-cell object. + * @todo implement validateChildNode() */ public class TableCell extends FObj { diff --git a/src/java/org/apache/fop/fo/flow/TableColumn.java b/src/java/org/apache/fop/fo/flow/TableColumn.java index 7cf6e813c..0ab7a4215 100644 --- a/src/java/org/apache/fop/fo/flow/TableColumn.java +++ b/src/java/org/apache/fop/fo/flow/TableColumn.java @@ -30,8 +30,7 @@ import org.apache.fop.fo.FONode; import org.apache.fop.fo.FObj; /** - * Class modelling the fo:table-column object. See Sec. 6.7.4 of the XSL-FO - * Standard. + * Class modelling the fo:table-column object. */ public class TableColumn extends FObj { diff --git a/src/java/org/apache/fop/fo/flow/TableFooter.java b/src/java/org/apache/fop/fo/flow/TableFooter.java index 61c1d239c..c64f0590a 100644 --- a/src/java/org/apache/fop/fo/flow/TableFooter.java +++ b/src/java/org/apache/fop/fo/flow/TableFooter.java @@ -22,8 +22,8 @@ package org.apache.fop.fo.flow; import org.apache.fop.fo.FONode; /** - * Class modelling the fo:table-footer object. See Sec. 6.7.7 of the XSL-FO - * Standard. + * Class modelling the fo:table-footer object. + * @todo implement validateChildNode() */ public class TableFooter extends TableBody { diff --git a/src/java/org/apache/fop/fo/flow/TableHeader.java b/src/java/org/apache/fop/fo/flow/TableHeader.java index 102b84d45..0b61b524d 100644 --- a/src/java/org/apache/fop/fo/flow/TableHeader.java +++ b/src/java/org/apache/fop/fo/flow/TableHeader.java @@ -22,8 +22,8 @@ package org.apache.fop.fo.flow; import org.apache.fop.fo.FONode; /** - * Class modelling the fo:table-header object. See Sec. 6.7.6 of the XSL-FO - * Standard. + * Class modelling the fo:table-header object. + * @todo implement validateChildNode() */ public class TableHeader extends TableBody { diff --git a/src/java/org/apache/fop/fo/flow/TableRow.java b/src/java/org/apache/fop/fo/flow/TableRow.java index 31d262651..21d5057d7 100644 --- a/src/java/org/apache/fop/fo/flow/TableRow.java +++ b/src/java/org/apache/fop/fo/flow/TableRow.java @@ -36,8 +36,8 @@ import org.apache.fop.fo.properties.Property; /** - * Class modelling the fo:table-row object. See Sec. 6.7.9 of the XSL-FO - * Standard. + * Class modelling the fo:table-row object. + * @todo implement validateChildNode() */ public class TableRow extends FObj { diff --git a/src/java/org/apache/fop/fo/flow/Wrapper.java b/src/java/org/apache/fop/fo/flow/Wrapper.java index fe294f9e9..5f01c7fa9 100644 --- a/src/java/org/apache/fop/fo/flow/Wrapper.java +++ b/src/java/org/apache/fop/fo/flow/Wrapper.java @@ -34,6 +34,7 @@ import org.apache.fop.fo.FObjMixed; * * Content: (#PCDATA|%inline;|%block;)* * Properties: id + * @todo implement validateChildNode() */ public class Wrapper extends FObjMixed { diff --git a/src/java/org/apache/fop/fo/pagination/Flow.java b/src/java/org/apache/fop/fo/pagination/Flow.java index 37233ca14..c756749ca 100644 --- a/src/java/org/apache/fop/fo/pagination/Flow.java +++ b/src/java/org/apache/fop/fo/pagination/Flow.java @@ -33,7 +33,7 @@ import org.apache.fop.fo.FObj; import org.apache.fop.layoutmgr.FlowLayoutManager; /** - * Class modelling the fo:flow object. See Sec. 6.4.18 in the XSL-FO Standard. + * Class modelling the fo:flow object. */ public class Flow extends FObj { diff --git a/src/java/org/apache/fop/fo/pagination/LayoutMasterSet.java b/src/java/org/apache/fop/fo/pagination/LayoutMasterSet.java index 2d143e421..a0ad061c3 100644 --- a/src/java/org/apache/fop/fo/pagination/LayoutMasterSet.java +++ b/src/java/org/apache/fop/fo/pagination/LayoutMasterSet.java @@ -30,7 +30,6 @@ import org.xml.sax.SAXParseException; // FOP import org.apache.fop.fo.FONode; import org.apache.fop.fo.FObj; -import org.apache.fop.apps.FOPException; /** * The layout-master-set formatting object. @@ -53,6 +52,24 @@ public class LayoutMasterSet extends FObj { super(parent); } + /** + * @see org.apache.fop.fo.FObj#addProperties + */ + protected void addProperties(Attributes attlist) throws SAXParseException { + super.addProperties(attlist); + + if (parent.getName().equals("fo:root")) { + Root root = (Root)parent; + root.setLayoutMasterSet(this); + } else { + throw new SAXParseException("fo:layout-master-set must be child of fo:root, not " + + parent.getName(), locator); + } + + this.simplePageMasters = new java.util.HashMap(); + this.pageSequenceMasters = new java.util.HashMap(); + } + /** * @see org.apache.fop.fo.FONode#validateChildNode(Locator, String, String) XSL/FOP: (simple-page-master|page-sequence-master)+ @@ -79,40 +96,32 @@ public class LayoutMasterSet extends FObj { } /** - * @see org.apache.fop.fo.FObj#addProperties + * Add a simple page master. + * The name is checked to throw an error if already added. + * @param sPM simple-page-master to add + * @throws SAXParseException if there's a problem with name uniqueness */ - protected void addProperties(Attributes attlist) throws SAXParseException { - super.addProperties(attlist); + protected void addSimplePageMaster(SimplePageMaster sPM) + throws SAXParseException { - if (parent.getName().equals("fo:root")) { - Root root = (Root)parent; - root.setLayoutMasterSet(this); - } else { - throw new SAXParseException("fo:layout-master-set must be child of fo:root, not " - + parent.getName(), locator); + // check for duplication of master-name + String masterName = sPM.getPropString(PR_MASTER_NAME); + if (existsName(masterName)) { + throw new SAXParseException("'master-name' (" + + masterName + + ") must be unique " + + "across page-masters and page-sequence-masters", sPM.locator); } - - this.simplePageMasters = new java.util.HashMap(); - this.pageSequenceMasters = new java.util.HashMap(); + this.simplePageMasters.put(masterName, sPM); } - /** - * Add a simple page master. - * The name is checked to throw an error if already added. - * @param simplePageMaster simple-page-master to add - * @throws FOPException if there's a problem with name uniqueness - */ - protected void addSimplePageMaster(SimplePageMaster simplePageMaster) - throws FOPException { - // check against duplication of master-name - if (existsName(simplePageMaster.getMasterName())) { - throw new FOPException("'master-name' (" - + simplePageMaster.getMasterName() - + ") must be unique " - + "across page-masters and page-sequence-masters"); + private boolean existsName(String masterName) { + if (simplePageMasters.containsKey(masterName) + || pageSequenceMasters.containsKey(masterName)) { + return true; + } else { + return false; } - this.simplePageMasters.put(simplePageMaster.getMasterName(), - simplePageMaster); } /** @@ -130,19 +139,20 @@ public class LayoutMasterSet extends FObj { * Add a page sequence master. * The name is checked to throw an error if already added. * @param masterName name for the master - * @param pageSequenceMaster PageSequenceMaster instance - * @throws FOPException if there's a problem with name uniqueness + * @param pSM PageSequenceMaster instance + * @throws SAXParseException if there's a problem with name uniqueness */ protected void addPageSequenceMaster(String masterName, - PageSequenceMaster pageSequenceMaster) - throws FOPException { + PageSequenceMaster pSM) + throws SAXParseException { // check against duplication of master-name if (existsName(masterName)) { - throw new FOPException("'master-name' (" + masterName - + ") must be unique " - + "across page-masters and page-sequence-masters"); + throw new SAXParseException("'master-name' (" + + masterName + + ") must be unique " + + "across page-masters and page-sequence-masters", pSM.locator); } - this.pageSequenceMasters.put(masterName, pageSequenceMaster); + this.pageSequenceMasters.put(masterName, pSM); } /** @@ -156,15 +166,6 @@ public class LayoutMasterSet extends FObj { return (PageSequenceMaster)this.pageSequenceMasters.get(masterName); } - private boolean existsName(String masterName) { - if (simplePageMasters.containsKey(masterName) - || pageSequenceMasters.containsKey(masterName)) { - return true; - } else { - return false; - } - } - /** * Section 7.25.7: check to see that if a region-name is a * duplicate, that it maps to the same fo region-class. @@ -215,6 +216,9 @@ public class LayoutMasterSet extends FObj { return false; } + /** + * @see org.apache.fop.fo.FObj#getName() + */ public String getName() { return "fo:layout-master-set"; } diff --git a/src/java/org/apache/fop/fo/pagination/PageMasterReference.java b/src/java/org/apache/fop/fo/pagination/PageMasterReference.java index 390477043..7a586cd60 100644 --- a/src/java/org/apache/fop/fo/pagination/PageMasterReference.java +++ b/src/java/org/apache/fop/fo/pagination/PageMasterReference.java @@ -66,11 +66,11 @@ public abstract class PageMasterReference extends FObj * Checks that the parent is the right element. The default implementation * checks for fo:page-sequence-master. * @param parent parent node - * @throws FOPException If the parent is invalid. + * @throws SAXParseException If the parent is invalid. */ protected void validateParent(FONode parent) throws SAXParseException { if (parent.getName().equals("fo:page-sequence-master")) { - PageSequenceMaster pageSequenceMaster = (PageSequenceMaster)parent; + PageSequenceMaster pageSequenceMaster = (PageSequenceMaster) parent; if (getMasterName() == null) { getLogger().warn(getName() diff --git a/src/java/org/apache/fop/fo/pagination/PageSequenceMaster.java b/src/java/org/apache/fop/fo/pagination/PageSequenceMaster.java index 31629edf8..173e0be84 100644 --- a/src/java/org/apache/fop/fo/pagination/PageSequenceMaster.java +++ b/src/java/org/apache/fop/fo/pagination/PageSequenceMaster.java @@ -100,12 +100,7 @@ public class PageSequenceMaster extends FObj { getLogger().warn("page-sequence-master does not have " + "a master-name and so is being ignored"); } else { - try { - this.layoutMasterSet.addPageSequenceMaster(masterName, this); - } catch (Exception e) { - throw new SAXParseException("Error with adding Page Sequence Master: " - + e.getMessage(), locator); - } + this.layoutMasterSet.addPageSequenceMaster(masterName, this); } } else { throw new SAXParseException("fo:page-sequence-master must be child " diff --git a/src/java/org/apache/fop/fo/pagination/Region.java b/src/java/org/apache/fop/fo/pagination/Region.java index ffc16940f..20837c65d 100644 --- a/src/java/org/apache/fop/fo/pagination/Region.java +++ b/src/java/org/apache/fop/fo/pagination/Region.java @@ -66,15 +66,6 @@ public abstract class Region extends FObj { regionId = id; } - /** - * @see org.apache.fop.fo.FONode#validateChildNode(Locator, String, String) - * XSL Content Model: empty - */ - protected void validateChildNode(Locator loc, String nsURI, String localName) - throws SAXParseException { - invalidChildError(loc, nsURI, localName); - } - /** * @see org.apache.fop.fo.FObj#addProperties */ @@ -111,6 +102,15 @@ public abstract class Region extends FObj { this.overflow = this.propertyList.get(PR_OVERFLOW).getEnum(); } + /** + * @see org.apache.fop.fo.FONode#validateChildNode(Locator, String, String) + * XSL Content Model: empty + */ + protected void validateChildNode(Locator loc, String nsURI, String localName) + throws SAXParseException { + invalidChildError(loc, nsURI, localName); + } + public abstract Rectangle getViewportRectangle(FODimension pageRefRect); /** diff --git a/src/java/org/apache/fop/fo/pagination/RepeatablePageMasterReference.java b/src/java/org/apache/fop/fo/pagination/RepeatablePageMasterReference.java index 0e6223e54..99d9f71e6 100644 --- a/src/java/org/apache/fop/fo/pagination/RepeatablePageMasterReference.java +++ b/src/java/org/apache/fop/fo/pagination/RepeatablePageMasterReference.java @@ -31,8 +31,7 @@ import org.apache.fop.fo.FONode; * This handles a reference with a specified number of repeating * instances of the referenced page master (may have no limit). */ -public class RepeatablePageMasterReference extends PageMasterReference - implements SubSequenceSpecifier { +public class RepeatablePageMasterReference extends PageMasterReference { private static final int INFINITE = -1; diff --git a/src/java/org/apache/fop/fo/pagination/SimplePageMaster.java b/src/java/org/apache/fop/fo/pagination/SimplePageMaster.java index e334988b2..7a4debebf 100644 --- a/src/java/org/apache/fop/fo/pagination/SimplePageMaster.java +++ b/src/java/org/apache/fop/fo/pagination/SimplePageMaster.java @@ -25,6 +25,7 @@ import java.util.Map; // XML import org.xml.sax.Attributes; +import org.xml.sax.Locator; import org.xml.sax.SAXParseException; // FOP @@ -44,6 +45,13 @@ public class SimplePageMaster extends FObj { private String masterName; + // used for node validation + private boolean hasRegionBody = false; + private boolean hasRegionBefore = false; + private boolean hasRegionAfter = false; + private boolean hasRegionStart = false; + private boolean hasRegionEnd = false; + /** * @see org.apache.fop.fo.FONode#FONode(FONode) */ @@ -57,29 +65,90 @@ public class SimplePageMaster extends FObj { protected void addProperties(Attributes attlist) throws SAXParseException { super.addProperties(attlist); - if (parent.getName().equals("fo:layout-master-set")) { - LayoutMasterSet layoutMasterSet = (LayoutMasterSet)parent; - masterName = this.propertyList.get(PR_MASTER_NAME).getString(); - if (masterName == null) { - getLogger().warn("simple-page-master does not have " - + "a master-name and so is being ignored"); - } else { - try { - layoutMasterSet.addSimplePageMaster(this); - } catch (Exception e) { - throw new SAXParseException("Error with adding Page Sequence Master: " - + e.getMessage(), locator); - } - } + LayoutMasterSet layoutMasterSet = (LayoutMasterSet) parent; + + if (getPropString(PR_MASTER_NAME) == null) { + missingPropertyError("master-name"); } else { - throw new SAXParseException("fo:simple-page-master must be child " - + "of fo:layout-master-set, not " - + parent.getName(), locator); + layoutMasterSet.addSimplePageMaster(this); } + //Well, there are only 5 regions so we can save a bit of memory here regions = new HashMap(5); } + /** + * @see org.apache.fop.fo.FONode#validateChildNode(Locator, String, String) + * XSL Content Model: (region-body,region-before?,region-after?,region-start?,region-end?) + */ + protected void validateChildNode(Locator loc, String nsURI, String localName) + throws SAXParseException { + if (nsURI == FO_URI && localName.equals("region-body")) { + if (hasRegionBody) { + tooManyNodesError(loc, "fo:region-body"); + } else { + hasRegionBody = true; + } + } else if (nsURI == FO_URI && localName.equals("region-before")) { + if (!hasRegionBody) { + nodesOutOfOrderError(loc, "fo:region-body", "fo:region-before"); + } else if (hasRegionBefore) { + tooManyNodesError(loc, "fo:region-before"); + } else if (hasRegionAfter) { + nodesOutOfOrderError(loc, "fo:region-before", "fo:region-after"); + } else if (hasRegionStart) { + nodesOutOfOrderError(loc, "fo:region-before", "fo:region-start"); + } else if (hasRegionEnd) { + nodesOutOfOrderError(loc, "fo:region-before", "fo:region-end"); + } else { + hasRegionBody = true; + } + } else if (nsURI == FO_URI && localName.equals("region-after")) { + if (!hasRegionBody) { + nodesOutOfOrderError(loc, "fo:region-body", "fo:region-after"); + } else if (hasRegionAfter) { + tooManyNodesError(loc, "fo:region-after"); + } else if (hasRegionStart) { + nodesOutOfOrderError(loc, "fo:region-after", "fo:region-start"); + } else if (hasRegionEnd) { + nodesOutOfOrderError(loc, "fo:region-after", "fo:region-end"); + } else { + hasRegionAfter = true; + } + } else if (nsURI == FO_URI && localName.equals("region-start")) { + if (!hasRegionBody) { + nodesOutOfOrderError(loc, "fo:region-body", "fo:region-start"); + } else if (hasRegionStart) { + tooManyNodesError(loc, "fo:region-start"); + } else if (hasRegionEnd) { + nodesOutOfOrderError(loc, "fo:region-start", "fo:region-end"); + } else { + hasRegionStart = true; + } + } else if (nsURI == FO_URI && localName.equals("region-end")) { + if (!hasRegionBody) { + nodesOutOfOrderError(loc, "fo:region-body", "fo:region-end"); + } else if (hasRegionEnd) { + tooManyNodesError(loc, "fo:region-end"); + } else { + hasRegionEnd = true; + } + } else { + invalidChildError(loc, nsURI, localName); + } + } + + /** + * Make sure content model satisfied. + * @see org.apache.fop.fo.FONode#end + */ + protected void endOfNode() throws SAXParseException { + if (!hasRegionBody) { + missingChildElementError("(region-body, region-before?," + + " region-after?, region-start?, region-end?)"); + } + } + /** * @see org.apache.fop.fo.FObj#generatesReferenceAreas() */ @@ -92,19 +161,14 @@ public class SimplePageMaster extends FObj { * @return the page master name */ public String getMasterName() { - return masterName; + return getPropString(PR_MASTER_NAME); } /** * @see org.apache.fop.fo.FONode#addChildNode(FONode) */ protected void addChildNode(FONode child) { - if (child instanceof Region) { - addRegion((Region)child); - } else { - getLogger().error("SimplePageMaster cannot have child of type " - + child.getName()); - } + addRegion((Region)child); } /** @@ -113,13 +177,7 @@ public class SimplePageMaster extends FObj { */ protected void addRegion(Region region) { String key = String.valueOf(region.getRegionClassCode()); - if (regions.containsKey(key)) { - getLogger().error("Only one region of class " + region.getRegionName() - + " allowed within a simple-page-master. The duplicate" - + " region (" + region.getName() + ") is ignored."); - } else { - regions.put(key, region); - } + regions.put(key, region); } /** @@ -148,7 +206,7 @@ public class SimplePageMaster extends FObj { protected boolean regionNameExists(String regionName) { for (Iterator regenum = regions.values().iterator(); regenum.hasNext();) { - Region r = (Region)regenum.next(); + Region r = (Region) regenum.next(); if (r.getRegionName().equals(regionName)) { return true; } @@ -156,6 +214,9 @@ public class SimplePageMaster extends FObj { return false; } + /** + * @see org.apache.fop.fo.FObj#getName() + */ public String getName() { return "fo:simple-page-master"; } diff --git a/src/java/org/apache/fop/fo/pagination/SinglePageMasterReference.java b/src/java/org/apache/fop/fo/pagination/SinglePageMasterReference.java index f90e5c584..94642714f 100644 --- a/src/java/org/apache/fop/fo/pagination/SinglePageMasterReference.java +++ b/src/java/org/apache/fop/fo/pagination/SinglePageMasterReference.java @@ -31,8 +31,7 @@ import org.apache.fop.fo.FONode; * This is a reference for a single page. It returns the * master name only once until reset. */ -public class SinglePageMasterReference extends PageMasterReference - implements SubSequenceSpecifier { +public class SinglePageMasterReference extends PageMasterReference { private static final int FIRST = 0; private static final int DONE = 1; diff --git a/src/java/org/apache/fop/fo/pagination/StaticContent.java b/src/java/org/apache/fop/fo/pagination/StaticContent.java index 02f725676..81b8e67af 100644 --- a/src/java/org/apache/fop/fo/pagination/StaticContent.java +++ b/src/java/org/apache/fop/fo/pagination/StaticContent.java @@ -27,8 +27,7 @@ import org.xml.sax.SAXParseException; import org.apache.fop.fo.FONode; /** - * Class modelling the fo:static-content object. See Sec. 6.4.19 of the XSL-FO - * Standard. + * Class modelling the fo:static-content object. */ public class StaticContent extends Flow { diff --git a/src/java/org/apache/fop/fo/pagination/Title.java b/src/java/org/apache/fop/fo/pagination/Title.java index f887db91b..8f1d1158a 100644 --- a/src/java/org/apache/fop/fo/pagination/Title.java +++ b/src/java/org/apache/fop/fo/pagination/Title.java @@ -39,7 +39,7 @@ import org.apache.fop.fonts.Font; import org.apache.fop.fo.properties.CommonMarginInline; /** - * Class modelling the fo:title object. See Sec. 6.4.20 in the XSL-FO Standard. + * Class modelling the fo:title object. */ public class Title extends FObjMixed { diff --git a/test/xml/bugtests/background_color.fo b/test/xml/bugtests/background_color.fo index c18109794..6f393b054 100644 --- a/test/xml/bugtests/background_color.fo +++ b/test/xml/bugtests/background_color.fo @@ -8,8 +8,8 @@ margin-bottom="1cm" margin-left="1.5cm" margin-right="1.5cm"> - + diff --git a/test/xml/bugtests/background_transparent.fo b/test/xml/bugtests/background_transparent.fo index e8aca5b02..013a8db8a 100644 --- a/test/xml/bugtests/background_transparent.fo +++ b/test/xml/bugtests/background_transparent.fo @@ -8,8 +8,8 @@ margin-bottom="1cm" margin-left="1.5cm" margin-right="1.5cm"> - + diff --git a/test/xml/bugtests/block-container.fo b/test/xml/bugtests/block-container.fo index 8ed2485ea..8757f763b 100644 --- a/test/xml/bugtests/block-container.fo +++ b/test/xml/bugtests/block-container.fo @@ -8,8 +8,8 @@ margin-bottom="1cm" margin-left="1.5cm" margin-right="1.5cm"> - + diff --git a/test/xml/bugtests/block.fo b/test/xml/bugtests/block.fo index a3443bf8a..b729e9ab6 100644 --- a/test/xml/bugtests/block.fo +++ b/test/xml/bugtests/block.fo @@ -8,8 +8,8 @@ margin-bottom="1cm" margin-left="1.5cm" margin-right="1.5cm"> - + diff --git a/test/xml/bugtests/border.fo b/test/xml/bugtests/border.fo index b4a800577..01ea34c24 100644 --- a/test/xml/bugtests/border.fo +++ b/test/xml/bugtests/border.fo @@ -8,8 +8,8 @@ margin-bottom="1cm" margin-left="1.5cm" margin-right="1.5cm"> - + diff --git a/test/xml/bugtests/break-before.fo b/test/xml/bugtests/break-before.fo index 901468f40..37701285b 100644 --- a/test/xml/bugtests/break-before.fo +++ b/test/xml/bugtests/break-before.fo @@ -8,8 +8,8 @@ margin-bottom="1cm" margin-left="1.5cm" margin-right="1.5cm"> - + diff --git a/test/xml/bugtests/color.fo b/test/xml/bugtests/color.fo index 2e3eb6112..a4b252ac4 100644 --- a/test/xml/bugtests/color.fo +++ b/test/xml/bugtests/color.fo @@ -8,8 +8,8 @@ margin-bottom="1cm" margin-left="1.5cm" margin-right="1.5cm"> - + diff --git a/test/xml/bugtests/font-family.fo b/test/xml/bugtests/font-family.fo index 5269c7a29..998458d38 100644 --- a/test/xml/bugtests/font-family.fo +++ b/test/xml/bugtests/font-family.fo @@ -8,8 +8,8 @@ margin-bottom="1cm" margin-left="1.5cm" margin-right="1.5cm"> - + diff --git a/test/xml/bugtests/font-size.fo b/test/xml/bugtests/font-size.fo index b0516a4bc..a9c920b7b 100644 --- a/test/xml/bugtests/font-size.fo +++ b/test/xml/bugtests/font-size.fo @@ -8,8 +8,8 @@ margin-bottom="1cm" margin-left="1.5cm" margin-right="1.5cm"> - + diff --git a/test/xml/bugtests/font.fo b/test/xml/bugtests/font.fo index 5a29b22d3..8740f4429 100644 --- a/test/xml/bugtests/font.fo +++ b/test/xml/bugtests/font.fo @@ -8,8 +8,8 @@ margin-bottom="1cm" margin-left="1.5cm" margin-right="1.5cm"> - + diff --git a/test/xml/bugtests/header_footer.fo b/test/xml/bugtests/header_footer.fo index df3d030b3..d278e818a 100644 --- a/test/xml/bugtests/header_footer.fo +++ b/test/xml/bugtests/header_footer.fo @@ -8,8 +8,8 @@ margin-bottom="1cm" margin-left="1.5cm" margin-right="1.5cm"> - + diff --git a/test/xml/bugtests/indent.fo b/test/xml/bugtests/indent.fo index 31f6eb251..ab3d91be0 100644 --- a/test/xml/bugtests/indent.fo +++ b/test/xml/bugtests/indent.fo @@ -8,8 +8,8 @@ margin-bottom="1cm" margin-left="1.5cm" margin-right="1.5cm"> - + diff --git a/test/xml/bugtests/inline.fo b/test/xml/bugtests/inline.fo index 6e2f48e5e..8ae7aeee8 100644 --- a/test/xml/bugtests/inline.fo +++ b/test/xml/bugtests/inline.fo @@ -8,8 +8,8 @@ margin-bottom="1cm" margin-left="1.5cm" margin-right="1.5cm"> - + diff --git a/test/xml/bugtests/keep-with-next.fo b/test/xml/bugtests/keep-with-next.fo index d6f43d432..ba808219b 100644 --- a/test/xml/bugtests/keep-with-next.fo +++ b/test/xml/bugtests/keep-with-next.fo @@ -8,8 +8,8 @@ margin-bottom="1cm" margin-left="1in" margin-right="0.75in"> - + diff --git a/test/xml/bugtests/leader.fo b/test/xml/bugtests/leader.fo index b7cce9e2b..384ecf21f 100644 --- a/test/xml/bugtests/leader.fo +++ b/test/xml/bugtests/leader.fo @@ -8,8 +8,8 @@ margin-bottom="1cm" margin-left="1.5cm" margin-right="1.5cm"> - + diff --git a/test/xml/bugtests/letter-spacing.fo b/test/xml/bugtests/letter-spacing.fo index 31ddf5bc9..abd022c93 100644 --- a/test/xml/bugtests/letter-spacing.fo +++ b/test/xml/bugtests/letter-spacing.fo @@ -8,8 +8,8 @@ margin-bottom="1cm" margin-left="1.5cm" margin-right="1.5cm"> - + diff --git a/test/xml/bugtests/line-height.fo b/test/xml/bugtests/line-height.fo index 267bec7c1..640fe462c 100644 --- a/test/xml/bugtests/line-height.fo +++ b/test/xml/bugtests/line-height.fo @@ -8,8 +8,8 @@ margin-bottom="1cm" margin-left="1.5cm" margin-right="1.5cm"> - + diff --git a/test/xml/bugtests/list-mountjoy.fo b/test/xml/bugtests/list-mountjoy.fo index c2b8a6eb9..9c47fd93c 100644 --- a/test/xml/bugtests/list-mountjoy.fo +++ b/test/xml/bugtests/list-mountjoy.fo @@ -9,7 +9,7 @@ margin-bottom="2cm" margin-left="2.5cm" margin-right="2.5cm"> - + diff --git a/test/xml/bugtests/padding.fo b/test/xml/bugtests/padding.fo index 2052f4579..74028f13f 100644 --- a/test/xml/bugtests/padding.fo +++ b/test/xml/bugtests/padding.fo @@ -8,8 +8,8 @@ margin-bottom="1cm" margin-left="1.5cm" margin-right="1.5cm"> - + diff --git a/test/xml/bugtests/page-number.fo b/test/xml/bugtests/page-number.fo index b352970be..cd3b37bb1 100644 --- a/test/xml/bugtests/page-number.fo +++ b/test/xml/bugtests/page-number.fo @@ -8,8 +8,8 @@ margin-bottom="1cm" margin-left="1.5cm" margin-right="1.5cm"> - + diff --git a/test/xml/bugtests/rule.fo b/test/xml/bugtests/rule.fo index 4e4dcf7ed..f3b23fdb8 100644 --- a/test/xml/bugtests/rule.fo +++ b/test/xml/bugtests/rule.fo @@ -8,8 +8,8 @@ margin-bottom="1cm" margin-left="1.5cm" margin-right="1.5cm"> - + diff --git a/test/xml/bugtests/simple-link.fo b/test/xml/bugtests/simple-link.fo index 2e3d7ce5b..f18adaba8 100644 --- a/test/xml/bugtests/simple-link.fo +++ b/test/xml/bugtests/simple-link.fo @@ -8,8 +8,8 @@ margin-bottom="1cm" margin-left="1.5cm" margin-right="1.5cm"> - + diff --git a/test/xml/bugtests/space-treatment.fo b/test/xml/bugtests/space-treatment.fo index c29e18734..0df02dd34 100644 --- a/test/xml/bugtests/space-treatment.fo +++ b/test/xml/bugtests/space-treatment.fo @@ -8,8 +8,8 @@ margin-bottom="1cm" margin-left="1in" margin-right="0.75in"> - + diff --git a/test/xml/bugtests/space.fo b/test/xml/bugtests/space.fo index 12ac01113..ad572503a 100644 --- a/test/xml/bugtests/space.fo +++ b/test/xml/bugtests/space.fo @@ -8,8 +8,8 @@ margin-bottom="1cm" margin-left="1.5cm" margin-right="1.5cm"> - + diff --git a/test/xml/bugtests/text-align.fo b/test/xml/bugtests/text-align.fo index d5505ca0f..a0a001880 100644 --- a/test/xml/bugtests/text-align.fo +++ b/test/xml/bugtests/text-align.fo @@ -8,8 +8,8 @@ margin-bottom="1cm" margin-left="1.5cm" margin-right="1.5cm"> - + diff --git a/test/xml/bugtests/text-decoration.fo b/test/xml/bugtests/text-decoration.fo index 4f4b57d60..cefb2f56c 100644 --- a/test/xml/bugtests/text-decoration.fo +++ b/test/xml/bugtests/text-decoration.fo @@ -8,8 +8,8 @@ margin-bottom="1cm" margin-left="1.5cm" margin-right="1.5cm"> - + diff --git a/test/xml/bugtests/text-indent.fo b/test/xml/bugtests/text-indent.fo index 98889e444..745eec8e9 100644 --- a/test/xml/bugtests/text-indent.fo +++ b/test/xml/bugtests/text-indent.fo @@ -8,8 +8,8 @@ margin-bottom="1cm" margin-left="1.5cm" margin-right="1.5cm"> - + diff --git a/test/xml/bugtests/word-spacing.fo b/test/xml/bugtests/word-spacing.fo index d02bceeea..b318775bb 100644 --- a/test/xml/bugtests/word-spacing.fo +++ b/test/xml/bugtests/word-spacing.fo @@ -8,8 +8,8 @@ margin-bottom="1cm" margin-left="1.5cm" margin-right="1.5cm"> - + diff --git a/test/xml/bugtests/wrap.fo b/test/xml/bugtests/wrap.fo index 79a421925..8f89fd06d 100644 --- a/test/xml/bugtests/wrap.fo +++ b/test/xml/bugtests/wrap.fo @@ -8,8 +8,8 @@ margin-bottom="1cm" margin-left="1.5cm" margin-right="1.5cm"> - + - +