From 239320b99c8ba834d186fd4fa0c59ada5e66a633 Mon Sep 17 00:00:00 2001 From: Glen Mazza Date: Sun, 13 Jun 2004 19:58:58 +0000 Subject: [PATCH] 1.) App now returns an error if no page-sequence declared within fo:root. 2.) Standardized node names via a new static FONode.getNodeName() method 3.) Declarations object now tied to Root object, will no longer return NPE if empty (bug fixed). 4.) AreaTreeControl removed in favor of direct connection between Document and the Area Tree. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@197708 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/org/apache/fop/apps/Document.java | 3 +- src/java/org/apache/fop/area/AreaTree.java | 21 ++++---- .../org/apache/fop/area/AreaTreeControl.java | 54 ------------------- src/java/org/apache/fop/fo/FONode.java | 11 ++++ src/java/org/apache/fop/fo/FOTreeHandler.java | 8 ++- .../fop/fo/pagination/Declarations.java | 45 ++++++++-------- .../org/apache/fop/fo/pagination/Root.java | 26 +++++++-- 7 files changed, 77 insertions(+), 91 deletions(-) delete mode 100644 src/java/org/apache/fop/area/AreaTreeControl.java diff --git a/src/java/org/apache/fop/apps/Document.java b/src/java/org/apache/fop/apps/Document.java index 68118a576..737920764 100644 --- a/src/java/org/apache/fop/apps/Document.java +++ b/src/java/org/apache/fop/apps/Document.java @@ -25,7 +25,6 @@ import java.util.HashSet; // FOP import org.apache.fop.area.AreaTree; -import org.apache.fop.area.AreaTreeControl; import org.apache.fop.area.AreaTreeModel; import org.apache.fop.fo.FOInputHandler; @@ -42,7 +41,7 @@ import org.xml.sax.SAXException; * Class storing information for the FOP Document being processed, and managing * the processing of it. */ -public class Document implements FOTreeControl, AreaTreeControl { +public class Document implements FOTreeControl { /** The parent Driver object */ private Driver driver; diff --git a/src/java/org/apache/fop/area/AreaTree.java b/src/java/org/apache/fop/area/AreaTree.java index ce0c2f6ca..8f441f2e6 100644 --- a/src/java/org/apache/fop/area/AreaTree.java +++ b/src/java/org/apache/fop/area/AreaTree.java @@ -18,6 +18,7 @@ package org.apache.fop.area; +import org.apache.fop.apps.Document; import org.apache.fop.area.extensions.BookmarkData; import org.apache.fop.fo.extensions.Outline; @@ -50,7 +51,7 @@ public class AreaTree { // allows for different models to deal with adding/rendering // in different situations private AreaTreeModel model; - private AreaTreeControl atControl; + private Document document; // hashmap of arraylists containing pages with id area private Map idLocations = new HashMap(); @@ -60,10 +61,10 @@ public class AreaTree { /** * Constructor. - * @param atControl the AreaTreeControl object controlling this AreaTree + * @param document the apps.Document object controlling this AreaTree */ - public AreaTree (AreaTreeControl atControl) { - this.atControl = atControl; + public AreaTree (Document document) { + this.document = document; } @@ -219,13 +220,13 @@ public class AreaTree { * Create the bookmark data in the area tree. */ public void addBookmarksToAreaTree() { - if (atControl.getBookmarks() == null) { + if (document.getBookmarks() == null) { return; } - atControl.getDriver().getLogger().debug("adding bookmarks to area tree"); + document.getDriver().getLogger().debug("adding bookmarks to area tree"); BookmarkData data = new BookmarkData(); - for (int count = 0; count < atControl.getBookmarks().getOutlines().size(); count++) { - Outline out = (Outline)(atControl.getBookmarks().getOutlines()).get(count); + for (int count = 0; count < document.getBookmarks().getOutlines().size(); count++) { + Outline out = (Outline)(document.getBookmarks().getOutlines()).get(count); data.addSubData(createBookmarkData(out)); } addTreeExtension(data); @@ -251,8 +252,8 @@ public class AreaTree { return data; } - public AreaTreeControl getAreaTreeControl() { - return atControl; + public Document getDocument() { + return document; } } diff --git a/src/java/org/apache/fop/area/AreaTreeControl.java b/src/java/org/apache/fop/area/AreaTreeControl.java deleted file mode 100644 index 13ad510ba..000000000 --- a/src/java/org/apache/fop/area/AreaTreeControl.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright 1999-2004 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* $Id$ */ - - -package org.apache.fop.area; - -// FOP -import org.apache.fop.fo.extensions.Bookmarks; -import org.apache.fop.apps.Driver; - -// Java -import java.util.Set; - -/** - * An interface for classes that are conceptually the parent class of the - * area.AreaTree object. The purpose of the interface is to keep the AreaTree - * isolated from apps, but to acknowledge that a higher-level object is needed - * to control the Area Tree, to provide it with information about the - * environment, and to keep track of meta information. - */ -public interface AreaTreeControl { - - /** - * @return the Bookmark object encapsulating the bookmarks for the FO Tree. - */ - Bookmarks getBookmarks(); - - /** - * @return the Driver instance being used with this FO Tree - */ - Driver getDriver(); - - /** - * The current set of IDs in the document. - * @return the Set of IDReferences in the document. - */ - Set getIDReferences(); - -} diff --git a/src/java/org/apache/fop/fo/FONode.java b/src/java/org/apache/fop/fo/FONode.java index cf74fbde1..2a6b5663a 100644 --- a/src/java/org/apache/fop/fo/FONode.java +++ b/src/java/org/apache/fop/fo/FONode.java @@ -195,5 +195,16 @@ public abstract class FONode { fotv.serveFONode(this); } + /** + * Helper function to standardize the names of all namespace URI - local + * name pairs in text messages. + * @param namespaceURI URI of node found + * (e.g., "http://www.w3.org/1999/XSL/Format") + * @param localName local name of node, (e.g., "root" for "fo:root") + * @return a string combining the two values + */ + public static String getNodeString(String namespaceURI, String localName) { + return "(Namespace URI: \"" + namespaceURI + "\", Local Name: \"" + localName + "\")"; + } } diff --git a/src/java/org/apache/fop/fo/FOTreeHandler.java b/src/java/org/apache/fop/fo/FOTreeHandler.java index 7cf13d324..9cd10fe1d 100644 --- a/src/java/org/apache/fop/fo/FOTreeHandler.java +++ b/src/java/org/apache/fop/fo/FOTreeHandler.java @@ -69,7 +69,8 @@ public class FOTreeHandler extends FOInputHandler { // TODO: Collecting of statistics should be configurable private final boolean collectStatistics = true; private static final boolean MEM_PROFILE_WITH_GC = false; - + private boolean pageSequenceFound = false; + /** * Somewhere to get our stats from. */ @@ -135,6 +136,10 @@ public class FOTreeHandler extends FOInputHandler { */ public void endDocument() throws SAXException { try { + if (pageSequenceFound == false) { + throw new SAXException("Error: No fo:page-sequence child " + + "found within fo:root element."); + } getAreaTree().endDocument(); getDriver().getRenderer().stopRenderer(); } catch (IOException ex) { @@ -174,6 +179,7 @@ public class FOTreeHandler extends FOInputHandler { * @param pageSeq the page sequence starting */ public void startPageSequence(PageSequence pageSeq) { + pageSequenceFound = true; } /** diff --git a/src/java/org/apache/fop/fo/pagination/Declarations.java b/src/java/org/apache/fop/fo/pagination/Declarations.java index d48af48a8..21cca9935 100644 --- a/src/java/org/apache/fop/fo/pagination/Declarations.java +++ b/src/java/org/apache/fop/fo/pagination/Declarations.java @@ -47,37 +47,40 @@ public class Declarations extends FObj { */ public Declarations(FONode parent) { super(parent); + ((Root) parent).setDeclarations(this); } /** - * At then end of this element sort out the child into + * At the end of this element sort out the child into * a hashmap of color profiles and a list of external xml. */ public void end() { - for (Iterator iter = children.iterator(); iter.hasNext();) { - FONode node = (FONode)iter.next(); - if (node.getName().equals("fo:color-profile")) { - ColorProfile cp = (ColorProfile)node; - if (!"".equals(cp.getProfileName())) { - if (colorProfiles == null) { - colorProfiles = new java.util.HashMap(); + if (children != null) { + for (Iterator iter = children.iterator(); iter.hasNext();) { + FONode node = (FONode)iter.next(); + if (node.getName().equals("fo:color-profile")) { + ColorProfile cp = (ColorProfile)node; + if (!"".equals(cp.getProfileName())) { + if (colorProfiles == null) { + colorProfiles = new java.util.HashMap(); + } + if (colorProfiles.get(cp.getProfileName()) != null) { + // duplicate names + getLogger().warn("Duplicate fo:color-profile profile name : " + + cp.getProfileName()); + } + colorProfiles.put(cp.getProfileName(), cp); + } else { + getLogger().warn("color-profile-name required for color profile"); } - if (colorProfiles.get(cp.getProfileName()) != null) { - // duplicate names - getLogger().warn("Duplicate fo:color-profile profile name : " - + cp.getProfileName()); + } else if (node instanceof XMLObj) { + if (external == null) { + external = new java.util.ArrayList(); } - colorProfiles.put(cp.getProfileName(), cp); + external.add(node); } else { - getLogger().warn("color-profile-name required for color profile"); + getLogger().warn("invalid element " + node.getName() + "inside declarations"); } - } else if (node instanceof XMLObj) { - if (external == null) { - external = new java.util.ArrayList(); - } - external.add(node); - } else { - getLogger().warn("invalid element " + node.getName() + "inside declarations"); } } children = null; diff --git a/src/java/org/apache/fop/fo/pagination/Root.java b/src/java/org/apache/fop/fo/pagination/Root.java index db4da1247..8fc8648eb 100644 --- a/src/java/org/apache/fop/fo/pagination/Root.java +++ b/src/java/org/apache/fop/fo/pagination/Root.java @@ -34,6 +34,8 @@ public class Root extends FObj { private LayoutMasterSet layoutMasterSet; private Declarations declarations; private List pageSequences; + // temporary until above list populated + private boolean pageSequenceFound = false; /** * Keeps count of page number from over PageSequence instances @@ -72,7 +74,7 @@ public class Root extends FObj { } 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 + } else if (pageSequenceFound) { // no page-seqs yet throw new IllegalArgumentException("Error: fo:declarations" + " must be defined before fo:page-sequence declarations"); } @@ -80,13 +82,15 @@ public class Root extends FObj { 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 { + pageSequenceFound = true; } } 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"); + throw new IllegalArgumentException("Error: Invalid child node " + + FONode.getNodeString(namespaceURI, localName) + " of fo:root"); } } @@ -148,6 +152,22 @@ public class Root extends FObj { this.layoutMasterSet = layoutMasterSet; } + /** + * Returns the associated Declarations. + * @return the Declarations instance + */ + public Declarations getDeclarations() { + return this.declarations; + } + + /** + * Sets the associated Declarations. + * @param Declarations the Declarations to use + */ + public void setDeclarations(Declarations declarations) { + this.declarations = declarations; + } + /** * Sets the FOTreeControl that this Root is attached to * @param foTreeControl the FOTreeControl implementation to which this Root -- 2.39.5