// 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;
* 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;
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;
// 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();
/**
* 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;
}
* 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);
return data;
}
- public AreaTreeControl getAreaTreeControl() {
- return atControl;
+ public Document getDocument() {
+ return document;
}
}
+++ /dev/null
-/*
- * 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();
-
-}
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 + "\")";
+ }
}
// 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.
*/
*/
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) {
* @param pageSeq the page sequence starting
*/
public void startPageSequence(PageSequence pageSeq) {
+ pageSequenceFound = true;
}
/**
*/
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;
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
} 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");
}
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");
}
}
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