From 33505a76647852984b0259e613bcfecd61bf2a16 Mon Sep 17 00:00:00 2001 From: Glen Mazza Date: Thu, 10 Mar 2005 23:32:45 +0000 Subject: [PATCH] Validation added for master-name and master-reference properties. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@198475 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/org/apache/fop/fo/FONode.java | 9 +++++ .../ConditionalPageMasterReference.java | 34 +++++-------------- .../fop/fo/pagination/LayoutMasterSet.java | 6 ++-- .../fop/fo/pagination/PageSequence.java | 10 ++++-- .../fop/fo/pagination/PageSequenceMaster.java | 21 ++++-------- .../RepeatablePageMasterReference.java | 6 +++- .../org/apache/fop/fo/pagination/Root.java | 10 ++++-- .../fop/fo/pagination/SimplePageMaster.java | 6 +++- .../pagination/SinglePageMasterReference.java | 12 +++---- 9 files changed, 57 insertions(+), 57 deletions(-) diff --git a/src/java/org/apache/fop/fo/FONode.java b/src/java/org/apache/fop/fo/FONode.java index 37e2b8222..0347b73d5 100644 --- a/src/java/org/apache/fop/fo/FONode.java +++ b/src/java/org/apache/fop/fo/FONode.java @@ -31,6 +31,7 @@ import org.apache.fop.apps.FOPException; import org.apache.fop.apps.FOUserAgent; import org.apache.fop.fo.extensions.ExtensionElementMapping; import org.apache.fop.fo.extensions.svg.SVGElementMapping; +import org.apache.fop.fo.pagination.Root; import org.apache.fop.util.CharUtilities; /** @@ -406,6 +407,14 @@ public abstract class FONode implements Cloneable { } } + /** + * Returns the root node of this tree + * @return the root node + */ + public Root getRoot() { + return parent.getRoot(); + } + /** * Returns the name of the node * @return the name of this node diff --git a/src/java/org/apache/fop/fo/pagination/ConditionalPageMasterReference.java b/src/java/org/apache/fop/fo/pagination/ConditionalPageMasterReference.java index f05ac271d..3d737065a 100644 --- a/src/java/org/apache/fop/fo/pagination/ConditionalPageMasterReference.java +++ b/src/java/org/apache/fop/fo/pagination/ConditionalPageMasterReference.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2004 The Apache Software Foundation. + * Copyright 1999-2005 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -60,13 +60,19 @@ public class ConditionalPageMasterReference extends FObj { pagePosition = pList.get(PR_PAGE_POSITION).getEnum(); oddOrEven = pList.get(PR_ODD_OR_EVEN).getEnum(); blankOrNotBlank = pList.get(PR_BLANK_OR_NOT_BLANK).getEnum(); + + if (masterReference == null || masterReference.equals("")) { + missingPropertyError("master-reference"); + } } /** * @see org.apache.fop.fo.FONode#startOfNode */ protected void startOfNode() throws FOPException { - validateParent(parent); + this.repeatablePageMasterAlternatives = + (RepeatablePageMasterAlternatives) parent; + this.repeatablePageMasterAlternatives.addConditionalPageMasterReference(this); } /** @@ -133,30 +139,6 @@ public class ConditionalPageMasterReference extends FObj { return true; } - /** - * Check that the parent is the right type of formatting object - * repeatable-page-master-alternatives. - * @param parent parent node - * @throws ValidationException If the parent is invalid - */ - protected void validateParent(FONode parent) throws ValidationException { - if (parent.getName().equals("fo:repeatable-page-master-alternatives")) { - this.repeatablePageMasterAlternatives = - (RepeatablePageMasterAlternatives)parent; - - if (getMasterReference() == null) { - getLogger().warn("single-page-master-reference" - + "does not have a master-name and so is being ignored"); - } else { - this.repeatablePageMasterAlternatives.addConditionalPageMasterReference(this); - } - } else { - throw new ValidationException("fo:conditional-page-master-reference must be child " - + "of fo:repeatable-page-master-alternatives, not " - + parent.getName(), locator); - } - } - /** * Returns the "master-reference" property. */ diff --git a/src/java/org/apache/fop/fo/pagination/LayoutMasterSet.java b/src/java/org/apache/fop/fo/pagination/LayoutMasterSet.java index eb571b7d5..c3e399f26 100644 --- a/src/java/org/apache/fop/fo/pagination/LayoutMasterSet.java +++ b/src/java/org/apache/fop/fo/pagination/LayoutMasterSet.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2004 The Apache Software Foundation. + * Copyright 1999-2005 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -65,10 +65,8 @@ public class LayoutMasterSet extends FObj { if (parent.getName().equals("fo:root")) { Root root = (Root)parent; root.setLayoutMasterSet(this); - } else { - throw new ValidationException("fo:layout-master-set must be child of fo:root, not " - + parent.getName(), locator); } + simplePageMasters = new java.util.HashMap(); pageSequenceMasters = new java.util.HashMap(); } diff --git a/src/java/org/apache/fop/fo/pagination/PageSequence.java b/src/java/org/apache/fop/fo/pagination/PageSequence.java index d5b87ff3f..399bcd43f 100644 --- a/src/java/org/apache/fop/fo/pagination/PageSequence.java +++ b/src/java/org/apache/fop/fo/pagination/PageSequence.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2004 The Apache Software Foundation. + * Copyright 1999-2005 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -108,6 +108,10 @@ public class PageSequence extends FObj { initialPageNumber = pList.get(PR_INITIAL_PAGE_NUMBER).getNumeric(); forcePageCount = pList.get(PR_FORCE_PAGE_COUNT).getEnum(); masterReference = pList.get(PR_MASTER_REFERENCE).getString(); + + if (masterReference == null || masterReference.equals("")) { + missingPropertyError("master-reference"); + } } /** @@ -124,8 +128,8 @@ public class PageSequence extends FObj { root.getLayoutMasterSet().getPageSequenceMaster(masterReference); if (this.pageSequenceMaster == null) { throw new ValidationException("master-reference '" + masterReference - + "' for fo:page-sequence matches no" - + " simple-page-master or page-sequence-master", locator); + + "' for fo:page-sequence matches no" + + " simple-page-master or page-sequence-master", locator); } else { pageSequenceMaster.reset(); } diff --git a/src/java/org/apache/fop/fo/pagination/PageSequenceMaster.java b/src/java/org/apache/fop/fo/pagination/PageSequenceMaster.java index bda91aa1d..2aad43894 100644 --- a/src/java/org/apache/fop/fo/pagination/PageSequenceMaster.java +++ b/src/java/org/apache/fop/fo/pagination/PageSequenceMaster.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2004 The Apache Software Foundation. + * Copyright 1999-2005 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -63,6 +63,10 @@ public class PageSequenceMaster extends FObj { */ public void bind(PropertyList pList) throws FOPException { masterName = pList.get(PR_MASTER_NAME).getString(); + + if (masterName == null || masterName.equals("")) { + missingPropertyError("master-name"); + } } /** @@ -70,19 +74,8 @@ public class PageSequenceMaster extends FObj { */ protected void startOfNode() throws FOPException { subSequenceSpecifiers = new java.util.ArrayList(); - if (parent.getName().equals("fo:layout-master-set")) { - this.layoutMasterSet = (LayoutMasterSet)parent; - if (masterName == null) { - getLogger().warn("page-sequence-master does not have " - + "a master-name and so is being ignored"); - } else { - this.layoutMasterSet.addPageSequenceMaster(masterName, this); - } - } else { - throw new ValidationException("fo:page-sequence-master must be child " - + "of fo:layout-master-set, not " - + parent.getName(), locator); - } + layoutMasterSet = parent.getRoot().getLayoutMasterSet(); + layoutMasterSet.addPageSequenceMaster(masterName, this); } /** diff --git a/src/java/org/apache/fop/fo/pagination/RepeatablePageMasterReference.java b/src/java/org/apache/fop/fo/pagination/RepeatablePageMasterReference.java index 200536321..efe3b16e1 100644 --- a/src/java/org/apache/fop/fo/pagination/RepeatablePageMasterReference.java +++ b/src/java/org/apache/fop/fo/pagination/RepeatablePageMasterReference.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2004 The Apache Software Foundation. + * Copyright 1999-2005 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -59,6 +59,10 @@ public class RepeatablePageMasterReference extends FObj public void bind(PropertyList pList) throws FOPException { masterReference = pList.get(PR_MASTER_REFERENCE).getString(); maximumRepeats = pList.get(PR_MAXIMUM_REPEATS); + + if (masterReference == null || masterReference.equals("")) { + missingPropertyError("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 ffe6ea971..f6494c0b3 100644 --- a/src/java/org/apache/fop/fo/pagination/Root.java +++ b/src/java/org/apache/fop/fo/pagination/Root.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2004 The Apache Software Foundation. + * Copyright 1999-2005 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,7 +30,6 @@ import org.apache.fop.fo.FObj; import org.apache.fop.fo.PropertyList; import org.apache.fop.fo.ValidationException; import org.apache.fop.fo.pagination.bookmarks.BookmarkTree; -import org.apache.fop.fo.extensions.ExtensionElementMapping; /** * The fo:root formatting object. Contains page masters, page-sequences. @@ -259,6 +258,13 @@ public class Root extends FObj { return bookmarkTree; } + /** + * @see org.apache.fop.fo.FONode#getRoot() + */ + public Root getRoot() { + return this; + } + /** * @see org.apache.fop.fo.FObj#getName() */ diff --git a/src/java/org/apache/fop/fo/pagination/SimplePageMaster.java b/src/java/org/apache/fop/fo/pagination/SimplePageMaster.java index 8a8ef1c5d..b704a79d2 100644 --- a/src/java/org/apache/fop/fo/pagination/SimplePageMaster.java +++ b/src/java/org/apache/fop/fo/pagination/SimplePageMaster.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2004 The Apache Software Foundation. + * Copyright 1999-2005 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -78,6 +78,10 @@ public class SimplePageMaster extends FObj { pageWidth = pList.get(PR_PAGE_WIDTH).getLength(); referenceOrientation = pList.get(PR_REFERENCE_ORIENTATION).getNumeric(); writingMode = pList.getWritingMode(); + + if (masterName == null || masterName.equals("")) { + missingPropertyError("master-name"); + } } /** diff --git a/src/java/org/apache/fop/fo/pagination/SinglePageMasterReference.java b/src/java/org/apache/fop/fo/pagination/SinglePageMasterReference.java index be5444801..68a08259a 100644 --- a/src/java/org/apache/fop/fo/pagination/SinglePageMasterReference.java +++ b/src/java/org/apache/fop/fo/pagination/SinglePageMasterReference.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2004 The Apache Software Foundation. + * Copyright 1999-2005 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -57,6 +57,10 @@ public class SinglePageMasterReference extends FObj */ public void bind(PropertyList pList) throws FOPException { masterReference = pList.get(PR_MASTER_REFERENCE).getString(); + + if (masterReference == null || masterReference.equals("")) { + missingPropertyError("master-reference"); + } } /** @@ -64,11 +68,7 @@ public class SinglePageMasterReference extends FObj */ protected void startOfNode() throws FOPException { PageSequenceMaster pageSequenceMaster = (PageSequenceMaster) parent; - if (masterReference == null) { - missingPropertyError("master-reference"); - } else { - pageSequenceMaster.addSubsequenceSpecifier(this); - } + pageSequenceMaster.addSubsequenceSpecifier(this); } /** -- 2.39.5