From 40610cdc9d203ac61e6d80a18b68adc0f95a4ce5 Mon Sep 17 00:00:00 2001 From: Glen Mazza Date: Sat, 12 Jun 2004 23:18:53 +0000 Subject: [PATCH] Created a validateChildNode() in FONode for better syntax checking in the fo document: e.g., preventing two fo:layout-master-set's from occurring within an fo:root, requiring fo:page-sequence to follow the fo:l-m-s (and fo:declarations, if present). Currently just validates fo:root's children--validateChildNode() needs to be overridden in other FObj subclasses to do the same for other formatting objects. Comments most welcome. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@197703 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/org/apache/fop/fo/FONode.java | 11 +++++ src/java/org/apache/fop/fo/FOTreeBuilder.java | 15 +++++-- src/java/org/apache/fop/fo/FObj.java | 1 - .../org/apache/fop/fo/extensions/Label.java | 4 ++ .../org/apache/fop/fo/extensions/Outline.java | 3 ++ .../org/apache/fop/fo/flow/BasicLink.java | 4 ++ .../org/apache/fop/fo/flow/BidiOverride.java | 3 ++ src/java/org/apache/fop/fo/flow/Block.java | 4 ++ .../apache/fop/fo/flow/BlockContainer.java | 3 ++ .../org/apache/fop/fo/flow/Character.java | 3 ++ .../apache/fop/fo/flow/ExternalGraphic.java | 4 ++ src/java/org/apache/fop/fo/flow/Float.java | 3 ++ src/java/org/apache/fop/fo/flow/Footnote.java | 4 ++ .../org/apache/fop/fo/flow/FootnoteBody.java | 4 ++ .../fop/fo/flow/InitialPropertySet.java | 3 ++ src/java/org/apache/fop/fo/flow/Inline.java | 3 ++ .../apache/fop/fo/flow/InlineContainer.java | 3 ++ .../fop/fo/flow/InstreamForeignObject.java | 3 ++ src/java/org/apache/fop/fo/flow/Leader.java | 3 ++ .../org/apache/fop/fo/flow/ListBlock.java | 4 ++ src/java/org/apache/fop/fo/flow/ListItem.java | 4 ++ .../org/apache/fop/fo/flow/ListItemBody.java | 3 ++ .../org/apache/fop/fo/flow/ListItemLabel.java | 4 ++ src/java/org/apache/fop/fo/flow/Marker.java | 3 ++ .../org/apache/fop/fo/flow/MultiCase.java | 3 ++ .../apache/fop/fo/flow/MultiProperties.java | 3 ++ .../apache/fop/fo/flow/MultiPropertySet.java | 3 ++ .../org/apache/fop/fo/flow/MultiSwitch.java | 3 ++ .../org/apache/fop/fo/flow/MultiToggle.java | 3 ++ .../org/apache/fop/fo/flow/PageNumber.java | 4 ++ .../fop/fo/flow/PageNumberCitation.java | 3 ++ .../apache/fop/fo/flow/RetrieveMarker.java | 3 ++ src/java/org/apache/fop/fo/flow/Table.java | 3 ++ .../apache/fop/fo/flow/TableAndCaption.java | 4 ++ .../org/apache/fop/fo/flow/TableBody.java | 3 ++ .../org/apache/fop/fo/flow/TableCaption.java | 3 ++ .../org/apache/fop/fo/flow/TableCell.java | 5 +++ .../org/apache/fop/fo/flow/TableColumn.java | 4 ++ .../org/apache/fop/fo/flow/TableFooter.java | 3 ++ .../org/apache/fop/fo/flow/TableHeader.java | 3 ++ src/java/org/apache/fop/fo/flow/TableRow.java | 4 ++ src/java/org/apache/fop/fo/flow/Wrapper.java | 4 ++ .../fop/fo/pagination/ColorProfile.java | 3 ++ .../ConditionalPageMasterReference.java | 3 ++ .../fop/fo/pagination/Declarations.java | 3 ++ .../org/apache/fop/fo/pagination/Flow.java | 4 ++ .../fop/fo/pagination/LayoutMasterSet.java | 7 ++-- .../fo/pagination/PageMasterReference.java | 3 ++ .../fo/pagination/PageNumberGenerator.java | 4 ++ .../fop/fo/pagination/PageSequence.java | 17 +++----- .../fop/fo/pagination/PageSequenceMaster.java | 3 ++ .../apache/fop/fo/pagination/RegionAfter.java | 3 ++ .../fop/fo/pagination/RegionBefore.java | 3 ++ .../apache/fop/fo/pagination/RegionBody.java | 3 ++ .../apache/fop/fo/pagination/RegionEnd.java | 3 ++ .../apache/fop/fo/pagination/RegionStart.java | 3 ++ .../RepeatablePageMasterAlternatives.java | 3 ++ .../RepeatablePageMasterReference.java | 3 ++ .../org/apache/fop/fo/pagination/Root.java | 40 +++++++++++++++++++ .../fop/fo/pagination/SimplePageMaster.java | 3 ++ .../pagination/SinglePageMasterReference.java | 3 ++ .../fop/fo/pagination/StaticContent.java | 3 ++ .../org/apache/fop/fo/pagination/Title.java | 3 ++ 63 files changed, 259 insertions(+), 21 deletions(-) diff --git a/src/java/org/apache/fop/fo/FONode.java b/src/java/org/apache/fop/fo/FONode.java index 7d293ad77..cf74fbde1 100644 --- a/src/java/org/apache/fop/fo/FONode.java +++ b/src/java/org/apache/fop/fo/FONode.java @@ -89,6 +89,17 @@ public abstract class FONode { return this.name; } + /** + * Checks to make sure, during SAX processing of input document, that the + * incoming node is valid for the this (parent) node (e.g., checking to + * see that fo:table is not an immediate child of fo:root) + * called within FObj constructor + * @param namespaceURI namespace of incoming node + * @param localName (e.g. "table" for "fo:table") + * @throws IllegalArgumentException if incoming node not valid for parent + */ + protected void validateChildNode(String namespaceURI, String localName) {} + /** * Adds characters (does nothing here) * @param data text diff --git a/src/java/org/apache/fop/fo/FOTreeBuilder.java b/src/java/org/apache/fop/fo/FOTreeBuilder.java index f49439a41..3da7c857e 100644 --- a/src/java/org/apache/fop/fo/FOTreeBuilder.java +++ b/src/java/org/apache/fop/fo/FOTreeBuilder.java @@ -227,18 +227,25 @@ public class FOTreeBuilder extends DefaultHandler { // Check to ensure first node encountered is an fo:root if (rootFObj == null) { if (!namespaceURI.equals(FObj.FO_URI) || !localName.equals("root")) { - throw new SAXException(new FOPException("Error: Root element" + - " must be fo:root formatting object")); + throw new SAXException(new IllegalArgumentException( + "Error: First element must be fo:root formatting object")); + } + } else { // check that incoming node is valid for currentFObj + try { + currentFObj.validateChildNode(namespaceURI, localName); + } catch (IllegalArgumentException e) { + throw new SAXException(e); } } ElementMapping.Maker fobjMaker = findFOMaker(namespaceURI, localName); - // System.out.println("found a " + fobjMaker.toString()); try { foNode = fobjMaker.make(currentFObj); foNode.processNode(localName, locator, attlist); + } catch (IllegalArgumentException e) { + throw new SAXException(e); } catch (FOPException e) { throw new SAXException(e); } @@ -269,7 +276,7 @@ public class FOTreeBuilder extends DefaultHandler { * @param localName name of the Element * @return the ElementMapping.Maker that can create an FO object for this element */ - public Maker findFOMaker(String namespaceURI, String localName) { + private Maker findFOMaker(String namespaceURI, String localName) { Map table = (Map)fobjTable.get(namespaceURI); Maker fobjMaker = null; if (table != null) { diff --git a/src/java/org/apache/fop/fo/FObj.java b/src/java/org/apache/fop/fo/FObj.java index 1ecfc1aa7..dfc87d43d 100644 --- a/src/java/org/apache/fop/fo/FObj.java +++ b/src/java/org/apache/fop/fo/FObj.java @@ -91,7 +91,6 @@ public class FObj extends FONode implements Constants { */ public void processNode(String elementName, Locator locator, Attributes attlist) throws FOPException { - setName(elementName); setLocation(locator); addProperties(attlist); } diff --git a/src/java/org/apache/fop/fo/extensions/Label.java b/src/java/org/apache/fop/fo/extensions/Label.java index 2efe8f75d..a60226cb2 100644 --- a/src/java/org/apache/fop/fo/extensions/Label.java +++ b/src/java/org/apache/fop/fo/extensions/Label.java @@ -66,5 +66,9 @@ public class Label extends ExtensionObj { public void acceptVisitor(FOTreeVisitor fotv) { fotv.serveLabel(this); } + + public String getName() { + return "(http://xml.apache.org/fop/extensions) label"; + } } diff --git a/src/java/org/apache/fop/fo/extensions/Outline.java b/src/java/org/apache/fop/fo/extensions/Outline.java index 548ee0c05..c6f6194f8 100644 --- a/src/java/org/apache/fop/fo/extensions/Outline.java +++ b/src/java/org/apache/fop/fo/extensions/Outline.java @@ -108,4 +108,7 @@ public class Outline extends ExtensionObj { return outlines; } + public String getName() { + return "(http://xml.apache.org/fop/extensions) outline"; + } } diff --git a/src/java/org/apache/fop/fo/flow/BasicLink.java b/src/java/org/apache/fop/fo/flow/BasicLink.java index a541ac27f..002650c67 100644 --- a/src/java/org/apache/fop/fo/flow/BasicLink.java +++ b/src/java/org/apache/fop/fo/flow/BasicLink.java @@ -145,4 +145,8 @@ public class BasicLink extends Inline { getFOTreeControl().getFOInputHandler().endLink(); } + + public String getName() { + return "fo:basic-link"; + } } diff --git a/src/java/org/apache/fop/fo/flow/BidiOverride.java b/src/java/org/apache/fop/fo/flow/BidiOverride.java index 040bbb8a4..ffb022206 100644 --- a/src/java/org/apache/fop/fo/flow/BidiOverride.java +++ b/src/java/org/apache/fop/fo/flow/BidiOverride.java @@ -79,4 +79,7 @@ public class BidiOverride extends FObjMixed { fotv.serveBidiOverride(this); } + public String getName() { + return "fo:bidi-override"; + } } diff --git a/src/java/org/apache/fop/fo/flow/Block.java b/src/java/org/apache/fop/fo/flow/Block.java index bd99ced06..e1f90ea9a 100644 --- a/src/java/org/apache/fop/fo/flow/Block.java +++ b/src/java/org/apache/fop/fo/flow/Block.java @@ -401,4 +401,8 @@ public class Block extends FObjMixed { fotv.serveBlock(this); } + public String getName() { + return "fo:block"; + } + } diff --git a/src/java/org/apache/fop/fo/flow/BlockContainer.java b/src/java/org/apache/fop/fo/flow/BlockContainer.java index 1d8e8e90f..d3d243db9 100644 --- a/src/java/org/apache/fop/fo/flow/BlockContainer.java +++ b/src/java/org/apache/fop/fo/flow/BlockContainer.java @@ -140,5 +140,8 @@ public class BlockContainer extends FObj { fotv.serveBlockContainer(this); } + public String getName() { + return "fo:block-container"; + } } diff --git a/src/java/org/apache/fop/fo/flow/Character.java b/src/java/org/apache/fop/fo/flow/Character.java index 7aefd25fc..8bc70f0c2 100644 --- a/src/java/org/apache/fop/fo/flow/Character.java +++ b/src/java/org/apache/fop/fo/flow/Character.java @@ -126,4 +126,7 @@ public class Character extends FObj { fotv.serveCharacter(this); } + public String getName() { + return "fo:character"; + } } diff --git a/src/java/org/apache/fop/fo/flow/ExternalGraphic.java b/src/java/org/apache/fop/fo/flow/ExternalGraphic.java index 842be7641..adcac83ca 100644 --- a/src/java/org/apache/fop/fo/flow/ExternalGraphic.java +++ b/src/java/org/apache/fop/fo/flow/ExternalGraphic.java @@ -242,4 +242,8 @@ public class ExternalGraphic extends FObj { return placement; } + public String getName() { + return "fo:external-graphic"; + } + } diff --git a/src/java/org/apache/fop/fo/flow/Float.java b/src/java/org/apache/fop/fo/flow/Float.java index 3ca56f3e0..28f255ba7 100644 --- a/src/java/org/apache/fop/fo/flow/Float.java +++ b/src/java/org/apache/fop/fo/flow/Float.java @@ -47,4 +47,7 @@ public class Float extends ToBeImplementedElement { fotv.serveFloat(this); } + public String getName() { + return "fo:float"; + } } diff --git a/src/java/org/apache/fop/fo/flow/Footnote.java b/src/java/org/apache/fop/fo/flow/Footnote.java index 136e15363..4f74945a5 100644 --- a/src/java/org/apache/fop/fo/flow/Footnote.java +++ b/src/java/org/apache/fop/fo/flow/Footnote.java @@ -81,5 +81,9 @@ public class Footnote extends FObj { super.end(); getFOTreeControl().getFOInputHandler().endFootnote(this); } + + public String getName() { + return "fo:footnote"; + } } diff --git a/src/java/org/apache/fop/fo/flow/FootnoteBody.java b/src/java/org/apache/fop/fo/flow/FootnoteBody.java index 162a1bcec..5b9a2c3a6 100644 --- a/src/java/org/apache/fop/fo/flow/FootnoteBody.java +++ b/src/java/org/apache/fop/fo/flow/FootnoteBody.java @@ -64,4 +64,8 @@ public class FootnoteBody extends FObj { getFOTreeControl().getFOInputHandler().endFootnoteBody(this); } + + public String getName() { + return "fo:footnote-body"; + } } diff --git a/src/java/org/apache/fop/fo/flow/InitialPropertySet.java b/src/java/org/apache/fop/fo/flow/InitialPropertySet.java index d065c7414..0c9a7867d 100644 --- a/src/java/org/apache/fop/fo/flow/InitialPropertySet.java +++ b/src/java/org/apache/fop/fo/flow/InitialPropertySet.java @@ -76,4 +76,7 @@ public class InitialPropertySet extends ToBeImplementedElement { fotv.serveInitialPropertySet(this); } + public String getName() { + return "fo:initial-property-set"; + } } diff --git a/src/java/org/apache/fop/fo/flow/Inline.java b/src/java/org/apache/fop/fo/flow/Inline.java index 1441e0396..ebe49bd49 100644 --- a/src/java/org/apache/fop/fo/flow/Inline.java +++ b/src/java/org/apache/fop/fo/flow/Inline.java @@ -142,4 +142,7 @@ public class Inline extends FObjMixed { getFOTreeControl().getFOInputHandler().endInline(this); } + public String getName() { + return "fo:inline"; + } } diff --git a/src/java/org/apache/fop/fo/flow/InlineContainer.java b/src/java/org/apache/fop/fo/flow/InlineContainer.java index 2889034d0..bd9607a05 100644 --- a/src/java/org/apache/fop/fo/flow/InlineContainer.java +++ b/src/java/org/apache/fop/fo/flow/InlineContainer.java @@ -98,4 +98,7 @@ public class InlineContainer extends FObj { fotv.serveInlineContainer(this); } + public String getName() { + return "fo:inline-container"; + } } diff --git a/src/java/org/apache/fop/fo/flow/InstreamForeignObject.java b/src/java/org/apache/fop/fo/flow/InstreamForeignObject.java index 53ba21d88..5e27d6983 100644 --- a/src/java/org/apache/fop/fo/flow/InstreamForeignObject.java +++ b/src/java/org/apache/fop/fo/flow/InstreamForeignObject.java @@ -168,4 +168,7 @@ public class InstreamForeignObject extends FObj { fotv.serveInstreamForeignObject(this); } + public String getName() { + return "fo:instream-foreign-object"; + } } diff --git a/src/java/org/apache/fop/fo/flow/Leader.java b/src/java/org/apache/fop/fo/flow/Leader.java index 5e1fdd0cc..f9c3ac8c4 100644 --- a/src/java/org/apache/fop/fo/flow/Leader.java +++ b/src/java/org/apache/fop/fo/flow/Leader.java @@ -172,4 +172,7 @@ public class Leader extends FObjMixed { fotv.serveLeader(this); } + public String getName() { + return "fo:leader"; + } } diff --git a/src/java/org/apache/fop/fo/flow/ListBlock.java b/src/java/org/apache/fop/fo/flow/ListBlock.java index b0fd8c4b6..23d4da5ef 100644 --- a/src/java/org/apache/fop/fo/flow/ListBlock.java +++ b/src/java/org/apache/fop/fo/flow/ListBlock.java @@ -141,5 +141,9 @@ public class ListBlock extends FObj { getFOTreeControl().getFOInputHandler().endList(this); } + + public String getName() { + return "fo:list-block"; + } } diff --git a/src/java/org/apache/fop/fo/flow/ListItem.java b/src/java/org/apache/fop/fo/flow/ListItem.java index 69f2a9c29..6c5ed254b 100644 --- a/src/java/org/apache/fop/fo/flow/ListItem.java +++ b/src/java/org/apache/fop/fo/flow/ListItem.java @@ -150,5 +150,9 @@ public class ListItem extends FObj { super.end(); getFOTreeControl().getFOInputHandler().endListItem(this); } + + public String getName() { + return "fo:list-item"; + } } diff --git a/src/java/org/apache/fop/fo/flow/ListItemBody.java b/src/java/org/apache/fop/fo/flow/ListItemBody.java index 59f2e15b6..c5fec56dd 100644 --- a/src/java/org/apache/fop/fo/flow/ListItemBody.java +++ b/src/java/org/apache/fop/fo/flow/ListItemBody.java @@ -71,5 +71,8 @@ public class ListItemBody extends FObj { fotv.serveListItemBody(this); } + public String getName() { + return "fo:list-item-body"; + } } diff --git a/src/java/org/apache/fop/fo/flow/ListItemLabel.java b/src/java/org/apache/fop/fo/flow/ListItemLabel.java index c04dece44..cead94f88 100644 --- a/src/java/org/apache/fop/fo/flow/ListItemLabel.java +++ b/src/java/org/apache/fop/fo/flow/ListItemLabel.java @@ -88,5 +88,9 @@ public class ListItemLabel extends FObj { getFOTreeControl().getFOInputHandler().endListLabel(); } + + public String getName() { + return "fo:list-item-label"; + } } diff --git a/src/java/org/apache/fop/fo/flow/Marker.java b/src/java/org/apache/fop/fo/flow/Marker.java index 81e681650..215557bfc 100644 --- a/src/java/org/apache/fop/fo/flow/Marker.java +++ b/src/java/org/apache/fop/fo/flow/Marker.java @@ -74,4 +74,7 @@ public class Marker extends FObjMixed { fotv.serveMarker(this); } + public String getName() { + return "fo:marker"; + } } diff --git a/src/java/org/apache/fop/fo/flow/MultiCase.java b/src/java/org/apache/fop/fo/flow/MultiCase.java index 4b599f624..c4945ff15 100644 --- a/src/java/org/apache/fop/fo/flow/MultiCase.java +++ b/src/java/org/apache/fop/fo/flow/MultiCase.java @@ -53,4 +53,7 @@ public class MultiCase extends ToBeImplementedElement { fotv.serveMultiCase(this); } + public String getName() { + return "fo:multi-case"; + } } diff --git a/src/java/org/apache/fop/fo/flow/MultiProperties.java b/src/java/org/apache/fop/fo/flow/MultiProperties.java index 2c5c8b03e..d35f747d5 100644 --- a/src/java/org/apache/fop/fo/flow/MultiProperties.java +++ b/src/java/org/apache/fop/fo/flow/MultiProperties.java @@ -50,4 +50,7 @@ public class MultiProperties extends ToBeImplementedElement { fotv.serveMultiProperties(this); } + public String getName() { + return "fo:multi-properties"; + } } diff --git a/src/java/org/apache/fop/fo/flow/MultiPropertySet.java b/src/java/org/apache/fop/fo/flow/MultiPropertySet.java index fabd2e7f6..8472962fa 100644 --- a/src/java/org/apache/fop/fo/flow/MultiPropertySet.java +++ b/src/java/org/apache/fop/fo/flow/MultiPropertySet.java @@ -47,4 +47,7 @@ public class MultiPropertySet extends ToBeImplementedElement { fotv.serveMultiPropertySet(this); } + public String getName() { + return "fo:multi-property-set"; + } } diff --git a/src/java/org/apache/fop/fo/flow/MultiSwitch.java b/src/java/org/apache/fop/fo/flow/MultiSwitch.java index 6c350836b..5535327c7 100644 --- a/src/java/org/apache/fop/fo/flow/MultiSwitch.java +++ b/src/java/org/apache/fop/fo/flow/MultiSwitch.java @@ -51,4 +51,7 @@ public class MultiSwitch extends ToBeImplementedElement { fotv.serveMultiSwitch(this); } + public String getName() { + return "fo:multi-switch"; + } } diff --git a/src/java/org/apache/fop/fo/flow/MultiToggle.java b/src/java/org/apache/fop/fo/flow/MultiToggle.java index 60f8a4848..da77e7da8 100644 --- a/src/java/org/apache/fop/fo/flow/MultiToggle.java +++ b/src/java/org/apache/fop/fo/flow/MultiToggle.java @@ -51,4 +51,7 @@ public class MultiToggle extends ToBeImplementedElement { fotv.serveMultiToggle(this); } + public String getName() { + return "fo:multi-toggle"; + } } diff --git a/src/java/org/apache/fop/fo/flow/PageNumber.java b/src/java/org/apache/fop/fo/flow/PageNumber.java index b092cf75c..1871e8133 100644 --- a/src/java/org/apache/fop/fo/flow/PageNumber.java +++ b/src/java/org/apache/fop/fo/flow/PageNumber.java @@ -131,4 +131,8 @@ public class PageNumber extends FObj { protected void end() { getFOTreeControl().getFOInputHandler().endPageNumber(this); } + + public String getName() { + return "fo:page-number"; + } } diff --git a/src/java/org/apache/fop/fo/flow/PageNumberCitation.java b/src/java/org/apache/fop/fo/flow/PageNumberCitation.java index 865de762c..b1907b05b 100644 --- a/src/java/org/apache/fop/fo/flow/PageNumberCitation.java +++ b/src/java/org/apache/fop/fo/flow/PageNumberCitation.java @@ -142,4 +142,7 @@ public class PageNumberCitation extends FObj { return fontState; } + public String getName() { + return "fo:page-number-citation"; + } } diff --git a/src/java/org/apache/fop/fo/flow/RetrieveMarker.java b/src/java/org/apache/fop/fo/flow/RetrieveMarker.java index 826a6faf9..dee50c989 100644 --- a/src/java/org/apache/fop/fo/flow/RetrieveMarker.java +++ b/src/java/org/apache/fop/fo/flow/RetrieveMarker.java @@ -80,4 +80,7 @@ public class RetrieveMarker extends FObjMixed { fotv.serveRetrieveMarker(this); } + public String getName() { + return "fo:retrieve-marker"; + } } diff --git a/src/java/org/apache/fop/fo/flow/Table.java b/src/java/org/apache/fop/fo/flow/Table.java index 8c81cf796..94fada6c1 100644 --- a/src/java/org/apache/fop/fo/flow/Table.java +++ b/src/java/org/apache/fop/fo/flow/Table.java @@ -206,4 +206,7 @@ public class Table extends FObj { getFOTreeControl().getFOInputHandler().endTable(this); } + public String getName() { + return "fo:table"; + } } diff --git a/src/java/org/apache/fop/fo/flow/TableAndCaption.java b/src/java/org/apache/fop/fo/flow/TableAndCaption.java index 5b98a4e80..8585fb59b 100644 --- a/src/java/org/apache/fop/fo/flow/TableAndCaption.java +++ b/src/java/org/apache/fop/fo/flow/TableAndCaption.java @@ -86,5 +86,9 @@ public class TableAndCaption extends ToBeImplementedElement { fotv.serveTableAndCaption(this); } + public String getName() { + return "fo:table-and-caption"; + } + } diff --git a/src/java/org/apache/fop/fo/flow/TableBody.java b/src/java/org/apache/fop/fo/flow/TableBody.java index 23b02e2ec..ce5048a67 100644 --- a/src/java/org/apache/fop/fo/flow/TableBody.java +++ b/src/java/org/apache/fop/fo/flow/TableBody.java @@ -107,5 +107,8 @@ public class TableBody extends FObj { getFOTreeControl().getFOInputHandler().endBody(this); } + public String getName() { + return "fo:table-body"; + } } diff --git a/src/java/org/apache/fop/fo/flow/TableCaption.java b/src/java/org/apache/fop/fo/flow/TableCaption.java index 001ce2387..c167dabe2 100644 --- a/src/java/org/apache/fop/fo/flow/TableCaption.java +++ b/src/java/org/apache/fop/fo/flow/TableCaption.java @@ -79,5 +79,8 @@ public class TableCaption extends ToBeImplementedElement { fotv.serveTableCaption(this); } + public String getName() { + return "fo:table-caption"; + } } diff --git a/src/java/org/apache/fop/fo/flow/TableCell.java b/src/java/org/apache/fop/fo/flow/TableCell.java index a63eedd79..b9d4e2b6a 100644 --- a/src/java/org/apache/fop/fo/flow/TableCell.java +++ b/src/java/org/apache/fop/fo/flow/TableCell.java @@ -350,4 +350,9 @@ public class TableCell extends FObj { protected void end() { getFOTreeControl().getFOInputHandler().endCell(this); } + + public String getName() { + return "fo:table-cell"; + } + } diff --git a/src/java/org/apache/fop/fo/flow/TableColumn.java b/src/java/org/apache/fop/fo/flow/TableColumn.java index 067aec266..232d6b0ea 100644 --- a/src/java/org/apache/fop/fo/flow/TableColumn.java +++ b/src/java/org/apache/fop/fo/flow/TableColumn.java @@ -126,5 +126,9 @@ public class TableColumn extends FObj { protected void end() { getFOTreeControl().getFOInputHandler().endColumn(this); } + + public String getName() { + return "fo:table-column"; + } } diff --git a/src/java/org/apache/fop/fo/flow/TableFooter.java b/src/java/org/apache/fop/fo/flow/TableFooter.java index ced2e68c2..e1681f787 100644 --- a/src/java/org/apache/fop/fo/flow/TableFooter.java +++ b/src/java/org/apache/fop/fo/flow/TableFooter.java @@ -39,4 +39,7 @@ public class TableFooter extends TableBody { fotv.serveTableFooter(this); } + public String getName() { + return "fo:table-footer"; + } } diff --git a/src/java/org/apache/fop/fo/flow/TableHeader.java b/src/java/org/apache/fop/fo/flow/TableHeader.java index 0232bfeb0..0e6b809fc 100644 --- a/src/java/org/apache/fop/fo/flow/TableHeader.java +++ b/src/java/org/apache/fop/fo/flow/TableHeader.java @@ -39,4 +39,7 @@ public class TableHeader extends TableBody { fotv.serveTableHeader(this); } + public String getName() { + return "fo:table-header"; + } } diff --git a/src/java/org/apache/fop/fo/flow/TableRow.java b/src/java/org/apache/fop/fo/flow/TableRow.java index fabde75a0..9ecc3ec12 100644 --- a/src/java/org/apache/fop/fo/flow/TableRow.java +++ b/src/java/org/apache/fop/fo/flow/TableRow.java @@ -147,5 +147,9 @@ public class TableRow extends FObj { protected void end() { getFOTreeControl().getFOInputHandler().endRow(this); } + + public String getName() { + return "fo:table-row"; + } } diff --git a/src/java/org/apache/fop/fo/flow/Wrapper.java b/src/java/org/apache/fop/fo/flow/Wrapper.java index 6a073be37..90e35a593 100644 --- a/src/java/org/apache/fop/fo/flow/Wrapper.java +++ b/src/java/org/apache/fop/fo/flow/Wrapper.java @@ -50,6 +50,10 @@ public class Wrapper extends FObjMixed { public void acceptVisitor(FOTreeVisitor fotv) { fotv.serveWrapper(this); } + + public String getName() { + return "fo:wrapper"; + } } diff --git a/src/java/org/apache/fop/fo/pagination/ColorProfile.java b/src/java/org/apache/fop/fo/pagination/ColorProfile.java index 78a38a133..a35ac9311 100644 --- a/src/java/org/apache/fop/fo/pagination/ColorProfile.java +++ b/src/java/org/apache/fop/fo/pagination/ColorProfile.java @@ -103,4 +103,7 @@ public class ColorProfile extends FObj { fotv.serveColorProfile(this); } + public String getName() { + return "fo:color-profile"; + } } diff --git a/src/java/org/apache/fop/fo/pagination/ConditionalPageMasterReference.java b/src/java/org/apache/fop/fo/pagination/ConditionalPageMasterReference.java index b98276462..a2a931a91 100644 --- a/src/java/org/apache/fop/fo/pagination/ConditionalPageMasterReference.java +++ b/src/java/org/apache/fop/fo/pagination/ConditionalPageMasterReference.java @@ -167,4 +167,7 @@ public class ConditionalPageMasterReference extends FObj { fotv.serveConditionalPageMasterReference(this); } + public String getName() { + return "fo:conditional-page-master-reference"; + } } diff --git a/src/java/org/apache/fop/fo/pagination/Declarations.java b/src/java/org/apache/fop/fo/pagination/Declarations.java index c9aeda8fb..d48af48a8 100644 --- a/src/java/org/apache/fop/fo/pagination/Declarations.java +++ b/src/java/org/apache/fop/fo/pagination/Declarations.java @@ -87,4 +87,7 @@ public class Declarations extends FObj { fotv.serveDeclarations(this); } + public String getName() { + return "fo:declarations"; + } } diff --git a/src/java/org/apache/fop/fo/pagination/Flow.java b/src/java/org/apache/fop/fo/pagination/Flow.java index e46eb8201..8ceba8956 100644 --- a/src/java/org/apache/fop/fo/pagination/Flow.java +++ b/src/java/org/apache/fop/fo/pagination/Flow.java @@ -152,4 +152,8 @@ public class Flow extends FObj { public void acceptVisitor(FOTreeVisitor fotv) { fotv.serveFlow(this); } + + public String getName() { + return "fo:flow"; + } } diff --git a/src/java/org/apache/fop/fo/pagination/LayoutMasterSet.java b/src/java/org/apache/fop/fo/pagination/LayoutMasterSet.java index 44d033b81..8ad7f982b 100644 --- a/src/java/org/apache/fop/fo/pagination/LayoutMasterSet.java +++ b/src/java/org/apache/fop/fo/pagination/LayoutMasterSet.java @@ -60,10 +60,6 @@ public class LayoutMasterSet extends FObj { if (parent.getName().equals("fo:root")) { Root root = (Root)parent; - if (root.getLayoutMasterSet() != null) { - throw new FOPException("Multiple fo:layout-master-sets " + - "found; only one allowed per document"); - } root.setLayoutMasterSet(this); } else { throw new FOPException("fo:layout-master-set must be child of fo:root, not " @@ -197,5 +193,8 @@ public class LayoutMasterSet extends FObj { fotv.serveLayoutMasterSet(this); } + 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 409bb92c2..910c31ce7 100644 --- a/src/java/org/apache/fop/fo/pagination/PageMasterReference.java +++ b/src/java/org/apache/fop/fo/pagination/PageMasterReference.java @@ -90,4 +90,7 @@ public abstract class PageMasterReference extends FObj fotv.servePageMasterReference(this); } + public String getName() { + return "fo:page-master-reference"; + } } diff --git a/src/java/org/apache/fop/fo/pagination/PageNumberGenerator.java b/src/java/org/apache/fop/fo/pagination/PageNumberGenerator.java index 47a84dab5..85ef7b63f 100644 --- a/src/java/org/apache/fop/fo/pagination/PageNumberGenerator.java +++ b/src/java/org/apache/fop/fo/pagination/PageNumberGenerator.java @@ -193,5 +193,9 @@ public class PageNumberGenerator { return alphaNumber.reverse().toString(); } + public String getName() { + return "fo:page-number-generator"; + } + } diff --git a/src/java/org/apache/fop/fo/pagination/PageSequence.java b/src/java/org/apache/fop/fo/pagination/PageSequence.java index 92a389aa2..91755ce13 100644 --- a/src/java/org/apache/fop/fo/pagination/PageSequence.java +++ b/src/java/org/apache/fop/fo/pagination/PageSequence.java @@ -134,20 +134,11 @@ public class PageSequence extends FObj { */ protected void addProperties(Attributes attlist) throws FOPException { super.addProperties(attlist); - if (parent.getName().equals("fo:root")) { - this.root = (Root)parent; - // this.root.addPageSequence(this); - } else { - throw new FOPException("Error: page-sequence must be child of root, not " - + parent.getName()); - } + this.root = (Root) parent; +// this.root.addPageSequence(this); layoutMasterSet = root.getLayoutMasterSet(); - if (layoutMasterSet == null) { - throw new FOPException("Error: fo:layout-master-set undefined for this document"); - } - // best time to run some checks on LayoutMasterSet layoutMasterSet.checkRegionNames(); @@ -174,7 +165,6 @@ public class PageSequence extends FObj { } } - String masterName = this.propertyList.get(PR_MASTER_REFERENCE).getString(); this.simplePageMaster = this.layoutMasterSet.getSimplePageMaster(masterName); @@ -745,4 +735,7 @@ public class PageSequence extends FObj { return root; } + public String getName() { + return "fo:page-sequence"; + } } diff --git a/src/java/org/apache/fop/fo/pagination/PageSequenceMaster.java b/src/java/org/apache/fop/fo/pagination/PageSequenceMaster.java index 199ff0fb3..f5b53214f 100644 --- a/src/java/org/apache/fop/fo/pagination/PageSequenceMaster.java +++ b/src/java/org/apache/fop/fo/pagination/PageSequenceMaster.java @@ -168,5 +168,8 @@ public class PageSequenceMaster extends FObj { fotv.servePageSequenceMaster(this); } + public String getName() { + return "fo:page-sequence-master"; + } } diff --git a/src/java/org/apache/fop/fo/pagination/RegionAfter.java b/src/java/org/apache/fop/fo/pagination/RegionAfter.java index 38049c3e6..c95024629 100644 --- a/src/java/org/apache/fop/fo/pagination/RegionAfter.java +++ b/src/java/org/apache/fop/fo/pagination/RegionAfter.java @@ -79,5 +79,8 @@ public class RegionAfter extends RegionBA { fotv.serveRegionAfter(this); } + public String getName() { + return "fo:region-after"; + } } diff --git a/src/java/org/apache/fop/fo/pagination/RegionBefore.java b/src/java/org/apache/fop/fo/pagination/RegionBefore.java index f9d3ec66f..0257d2510 100644 --- a/src/java/org/apache/fop/fo/pagination/RegionBefore.java +++ b/src/java/org/apache/fop/fo/pagination/RegionBefore.java @@ -84,5 +84,8 @@ public class RegionBefore extends RegionBA { fotv.serveRegionBefore(this); } + public String getName() { + return "fo:region-before"; + } } diff --git a/src/java/org/apache/fop/fo/pagination/RegionBody.java b/src/java/org/apache/fop/fo/pagination/RegionBody.java index 797889271..427ed33b6 100644 --- a/src/java/org/apache/fop/fo/pagination/RegionBody.java +++ b/src/java/org/apache/fop/fo/pagination/RegionBody.java @@ -112,4 +112,7 @@ public class RegionBody extends Region { fotv.serveRegionBody(this); } + public String getName() { + return "fo:region-body"; + } } diff --git a/src/java/org/apache/fop/fo/pagination/RegionEnd.java b/src/java/org/apache/fop/fo/pagination/RegionEnd.java index 597517c5d..5d32912de 100644 --- a/src/java/org/apache/fop/fo/pagination/RegionEnd.java +++ b/src/java/org/apache/fop/fo/pagination/RegionEnd.java @@ -80,5 +80,8 @@ public class RegionEnd extends RegionSE { fotv.serveRegionEnd(this); } + public String getName() { + return "fo:region-end"; + } } diff --git a/src/java/org/apache/fop/fo/pagination/RegionStart.java b/src/java/org/apache/fop/fo/pagination/RegionStart.java index 9fb29b1b5..71919edcf 100644 --- a/src/java/org/apache/fop/fo/pagination/RegionStart.java +++ b/src/java/org/apache/fop/fo/pagination/RegionStart.java @@ -79,5 +79,8 @@ public class RegionStart extends RegionSE { fotv.serveRegionStart(this); } + public String getName() { + return "fo:region-start"; + } } diff --git a/src/java/org/apache/fop/fo/pagination/RepeatablePageMasterAlternatives.java b/src/java/org/apache/fop/fo/pagination/RepeatablePageMasterAlternatives.java index 2d1f54819..93b688734 100644 --- a/src/java/org/apache/fop/fo/pagination/RepeatablePageMasterAlternatives.java +++ b/src/java/org/apache/fop/fo/pagination/RepeatablePageMasterAlternatives.java @@ -137,4 +137,7 @@ public class RepeatablePageMasterAlternatives extends FObj fotv.serveRepeatablePageMasterAlternatives(this); } + public String getName() { + return "fo:repeatable-page-master-alternatives"; + } } diff --git a/src/java/org/apache/fop/fo/pagination/RepeatablePageMasterReference.java b/src/java/org/apache/fop/fo/pagination/RepeatablePageMasterReference.java index c75be5b16..bf954cddd 100644 --- a/src/java/org/apache/fop/fo/pagination/RepeatablePageMasterReference.java +++ b/src/java/org/apache/fop/fo/pagination/RepeatablePageMasterReference.java @@ -98,4 +98,7 @@ public class RepeatablePageMasterReference extends PageMasterReference fotv.serveRepeatablePageMasterReference(this); } + public String getName() { + return "fo:repeatable-page-master-reference"; + } } diff --git a/src/java/org/apache/fop/fo/pagination/Root.java b/src/java/org/apache/fop/fo/pagination/Root.java index 61a805f3b..db4da1247 100644 --- a/src/java/org/apache/fop/fo/pagination/Root.java +++ b/src/java/org/apache/fop/fo/pagination/Root.java @@ -32,6 +32,7 @@ import org.apache.fop.fo.FOTreeVisitor; */ public class Root extends FObj { private LayoutMasterSet layoutMasterSet; + private Declarations declarations; private List pageSequences; /** @@ -53,6 +54,42 @@ public class Root extends FObj { } } + /** + * @see org.apache.fop.fo.FONode#validateChildNode(String, String) + */ + protected void validateChildNode(String namespaceURI, String localName) { + if (namespaceURI == FObj.FO_URI) { + if (localName.equals("layout-master-set")) { + if (layoutMasterSet != null) { // only one fo:declarations + throw new IllegalArgumentException("Error: Only one" + + " fo:layout-master-set may be defined per fo:root"); + } + } else if (localName.equals("declarations")) { + if (layoutMasterSet == null) { // must already have a l-m-s + throw new IllegalArgumentException("Error:" + + " fo:layout-master-set must be first child of" + + " fo:root"); + } else if (declarations != null) { // only one fo:declarations + throw new IllegalArgumentException("Error: Only one" + + " fo:declarations may be defined per fo:root"); + } else if (!pageSequences.isEmpty()) { // no page-seqs yet + throw new IllegalArgumentException("Error: fo:declarations" + + " must be defined before fo:page-sequence declarations"); + } + } else if (localName.equals("page-sequence")) { + if (layoutMasterSet == null) { // must already have a l-m-s + throw new IllegalArgumentException("Error:" + + " fo:layout-master-set must be first child of fo:root"); + } + } else + throw new IllegalArgumentException("Error: Invalid child" + + " node \"fo:" + localName + "\" of fo:root"); + } else { + throw new IllegalArgumentException("Error: Invalid child node (" + + namespaceURI + ") \"" + localName + "\" of fo:root"); + } + } + /** * Returns the number of pages generated (over all PageSequence instances). * @return the number of pages @@ -139,4 +176,7 @@ public class Root extends FObj { fotv.serveRoot(this); } + public String getName() { + return "fo:root"; + } } diff --git a/src/java/org/apache/fop/fo/pagination/SimplePageMaster.java b/src/java/org/apache/fop/fo/pagination/SimplePageMaster.java index 73b484652..1fbdb0620 100644 --- a/src/java/org/apache/fop/fo/pagination/SimplePageMaster.java +++ b/src/java/org/apache/fop/fo/pagination/SimplePageMaster.java @@ -162,4 +162,7 @@ public class SimplePageMaster extends FObj { fotv.serveSimplePageMaster(this); } + 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 04d4e020e..905f08dba 100644 --- a/src/java/org/apache/fop/fo/pagination/SinglePageMasterReference.java +++ b/src/java/org/apache/fop/fo/pagination/SinglePageMasterReference.java @@ -67,5 +67,8 @@ public class SinglePageMasterReference extends PageMasterReference fotv.serveSinglePageMasterReference(this); } + public String getName() { + return "fo:single-page-master-reference"; + } } diff --git a/src/java/org/apache/fop/fo/pagination/StaticContent.java b/src/java/org/apache/fop/fo/pagination/StaticContent.java index 9de77ec3f..6fe6a67f1 100644 --- a/src/java/org/apache/fop/fo/pagination/StaticContent.java +++ b/src/java/org/apache/fop/fo/pagination/StaticContent.java @@ -64,4 +64,7 @@ public class StaticContent extends Flow { fotv.serveStaticContent(this); } + public String getName() { + return "fo:static-content"; + } } diff --git a/src/java/org/apache/fop/fo/pagination/Title.java b/src/java/org/apache/fop/fo/pagination/Title.java index 9d3d3b0e2..f90ed6d00 100644 --- a/src/java/org/apache/fop/fo/pagination/Title.java +++ b/src/java/org/apache/fop/fo/pagination/Title.java @@ -90,5 +90,8 @@ public class Title extends FObjMixed { fotv.serveTitle(this); } + public String getName() { + return "fo:title"; + } } -- 2.39.5