]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Standardized error messages, brought fox:bookmarks under parent fo:root.
authorGlen Mazza <gmazza@apache.org>
Tue, 15 Jun 2004 00:30:43 +0000 (00:30 +0000)
committerGlen Mazza <gmazza@apache.org>
Tue, 15 Jun 2004 00:30:43 +0000 (00:30 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@197715 13f79535-47bb-0310-9956-ffa450edef68

13 files changed:
src/java/org/apache/fop/apps/Document.java
src/java/org/apache/fop/area/AreaTree.java
src/java/org/apache/fop/fo/FOElementMapping.java
src/java/org/apache/fop/fo/FONode.java
src/java/org/apache/fop/fo/FOTreeBuilder.java
src/java/org/apache/fop/fo/FOTreeControl.java
src/java/org/apache/fop/fo/FOTreeHandler.java
src/java/org/apache/fop/fo/FObj.java
src/java/org/apache/fop/fo/extensions/Bookmarks.java
src/java/org/apache/fop/fo/extensions/ExtensionElementMapping.java
src/java/org/apache/fop/fo/extensions/svg/BatikExtensionElementMapping.java
src/java/org/apache/fop/fo/extensions/svg/SVGElementMapping.java
src/java/org/apache/fop/fo/pagination/Root.java

index 73792076421759f6d64a55fb32f79de5b3ab51b3..cd204fcb0322c093ac41634ab4b4517760e5fccb 100644 (file)
@@ -29,7 +29,6 @@ import org.apache.fop.area.AreaTreeModel;
 
 import org.apache.fop.fo.FOInputHandler;
 import org.apache.fop.fo.FOTreeControl;
-import org.apache.fop.fo.extensions.Bookmarks;
 import org.apache.fop.fonts.FontInfo;
 
 import org.apache.commons.logging.Log;
@@ -55,8 +54,6 @@ public class Document implements FOTreeControl {
     /** The AreaTreeModel for the PageSequence being rendered. */
     public AreaTreeModel atModel;
 
-    private Bookmarks bookmarks = null;
-
     /**
      * The current set of id's in the FO tree.
      * This is used so we know if the FO tree contains duplicates.
@@ -64,8 +61,8 @@ public class Document implements FOTreeControl {
     private Set idReferences = new HashSet();
 
     /**
-     * Structure handler used to notify structure events
-     * such as start end element.
+     * Structure handler used to notify structure
+     * events such as start end element.
      */
     public FOInputHandler foInputHandler;
 
@@ -103,23 +100,6 @@ public class Document implements FOTreeControl {
         return areaTree;
     }
 
-    /**
-     * Set the Bookmarks object for this Document
-     * @param bookmarks the Bookmarks object containing the bookmarks for this
-     * Document
-     */
-    public void setBookmarks(Bookmarks bookmarks) {
-        this.bookmarks = bookmarks;
-    }
-
-    /**
-     * Public accessor for the Bookmarks for this Document
-     * @return the Bookmarks for this Document
-     */
-    public Bookmarks getBookmarks() {
-        return bookmarks;
-    }
-
     /**
      * Retuns the set of ID references.
      * @return the ID references
index 8f441f2e6d4ba2e3d40f40098a4895f53672c035..35f72fa518df2e185d1687924871d6e55ce5e578 100644 (file)
@@ -21,6 +21,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;
+import org.apache.fop.fo.extensions.Bookmarks;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -219,14 +220,15 @@ public class AreaTree {
     /**
      * Create the bookmark data in the area tree.
      */
-    public void addBookmarksToAreaTree() {
-        if (document.getBookmarks() == null) {
+    public void addBookmarksToAreaTree(Bookmarks bookmarks) {
+        if (bookmarks == null) {
             return;
         }
+
         document.getDriver().getLogger().debug("adding bookmarks to area tree");
         BookmarkData data = new BookmarkData();
-        for (int count = 0; count < document.getBookmarks().getOutlines().size(); count++) {
-            Outline out = (Outline)(document.getBookmarks().getOutlines()).get(count);
+        for (int count = 0; count < bookmarks.getOutlines().size(); count++) {
+            Outline out = (Outline)(bookmarks.getOutlines()).get(count);
             data.addSubData(createBookmarkData(out));
         }
         addTreeExtension(data);
index 7d568adae0f773a5a8f1e8d733df3789f46224f9..18b4e8830eecf954a3562253f45c259589a0ee20 100644 (file)
@@ -25,12 +25,13 @@ import java.util.HashMap;
  * Element mapping class for all XSL-FO elements.
  */
 public class FOElementMapping extends ElementMapping {
+    public static String URI = "http://www.w3.org/1999/XSL/Format";
 
     /**
      * Basic constructor; inititializes the namespace URI for the fo: namespace
      */
     public FOElementMapping() {
-        namespaceURI = "http://www.w3.org/1999/XSL/Format";
+        namespaceURI = URI;
     }
 
     /**
index 2a6b5663a83c9afa327e2620a0f8e4e2b9a700b2..a9a0f7ad06368a3599ce7f03a28183b826cb1395 100644 (file)
@@ -31,6 +31,8 @@ import org.apache.commons.logging.Log;
 import org.apache.fop.apps.FOPException;
 import org.apache.fop.util.CharUtilities;
 import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.fo.extensions.ExtensionElementMapping;
+import org.apache.fop.fo.extensions.svg.SVGElementMapping;
 
 /**
  * base class for nodes in the XML tree
@@ -198,13 +200,60 @@ public abstract class FONode {
     /**
      * Helper function to standardize the names of all namespace URI - local
      * name pairs in text messages.
+     * For readability, using fo:, fox:, svg:, for those namespaces even
+     * though that prefix may not have been chosen in the document.
      * @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
+     * @return the prefix:localname, if fo/fox/svg, or a longer representation
+     * with the unabbreviated URI otherwise.
      */
     public static String getNodeString(String namespaceURI, String localName) {
-        return "(Namespace URI: \"" + namespaceURI + "\", Local Name: \"" + localName + "\")";
+        if (namespaceURI.equals(FOElementMapping.URI)) {
+            return "fo:" + localName;
+        } else if (namespaceURI.equals(ExtensionElementMapping.URI)) {
+            return "fox:" + localName;
+        } else if (namespaceURI.equals(SVGElementMapping.URI)) {
+            return "svg:" + localName;
+        } else
+            return "(Namespace URI: \"" + namespaceURI + "\", " +
+                "Local Name: \"" + localName + "\")";
     }
+
+    /**
+     * Helper function to standardize "too many" error exceptions
+     * (e.g., two fo:declarations within fo:root)
+     * @param offendingNode incoming node that would cause a duplication.
+     */
+    protected void tooManyNodesError(String offendingNode) {
+        throw new IllegalArgumentException(
+            "Error: for " + getName() + ", only one " 
+            + offendingNode + " may be declared.");
+    }
+
+    /**
+     * Helper function to standardize "out of order" exceptions
+     * (e.g., fo:layout-master-set appearing after fo:page-sequence)
+     * @param tooLateNode string name of node that should be earlier in document
+     * @param tooEarlyNode string name of node that should be later in document
+     */
+    protected void nodesOutOfOrderError(String tooLateNode, String tooEarlyNode) {
+        throw new IllegalArgumentException(
+            "Error: for " + getName() + ", " + tooLateNode 
+            + " must be declared before " + tooEarlyNode + ".");
+    }
+    
+    /**
+     * Helper function to return "invalid child" exceptions
+     * (e.g., fo:block appearing immediately under fo:root)
+     * @param nsURI namespace URI of incoming invalid node
+     * @param lName local name (i.e., no prefix) of incoming node 
+     */
+    protected void invalidChildError(String nsURI, String lName) {
+        throw new IllegalArgumentException(
+            "Error: " + getNodeString(nsURI, lName) + 
+            " is not valid child element of " + getName() + ".");
+    }
+    
 }
 
index 3da7c857e1e622e74cce0d5771a3fe4dcdbe0a23..0e2ce5545c55d44acb1eacbd080f600654789036 100644 (file)
@@ -226,7 +226,8 @@ 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")) {
+            if (!namespaceURI.equals(FOElementMapping.URI) 
+                || !localName.equals("root")) {
                 throw new SAXException(new IllegalArgumentException(
                     "Error:  First element must be fo:root formatting object"));
             }
index 927c12a6bd0bfcb7562c815a4618ea6720fb6b68..1582d28550f2f45bbb2ef6fe5378921f37f8b515 100644 (file)
@@ -25,7 +25,6 @@ import java.util.Set;
 
 // FOP
 import org.apache.fop.apps.Driver;
-import org.apache.fop.fo.extensions.Bookmarks;
 import org.apache.fop.fonts.FontMetrics;
 import org.apache.fop.fonts.FontInfo;
 
@@ -39,19 +38,6 @@ import org.apache.fop.fonts.FontInfo;
  */
 public interface FOTreeControl {
 
-    /**
-     * Sets the Bookmark object which encapsulates the bookmarks for the FO
-     * Tree.
-     * @param bookmarks the Bookmark object encapsulating the bookmarks for this
-     * FO Tree.
-     */
-    void setBookmarks(Bookmarks bookmarks);
-
-    /**
-     * @return the Bookmark object encapsulating the bookmarks for the FO Tree.
-     */
-    Bookmarks getBookmarks();
-
     /**
      * Returns the set of ID references found in the FO Tree.
      * @return the ID references
index 9cd10fe1d1fdb799d5ca4dc9e91c396c542f4209..4dec73881a909ea41036b74f844b579743700811 100644 (file)
@@ -205,7 +205,7 @@ public class FOTreeHandler extends FOInputHandler {
             }
         }
 
-        getAreaTree().addBookmarksToAreaTree();
+        getAreaTree().addBookmarksToAreaTree(pageSequence.getRoot().getBookmarks());
         formatPageSequence(pageSequence, getAreaTree());
     }
 
index dfc87d43d18b623739316a3419b2482abac0825c..977ea6a1c004478e52a33d76de5fe86452d7d716 100644 (file)
@@ -36,8 +36,6 @@ import org.xml.sax.Locator;
  * Base class for representation of formatting objects and their processing.
  */
 public class FObj extends FONode implements Constants {
-    public static final String FO_URI = "http://www.w3.org/1999/XSL/Format";
-
     public static PropertyMaker[] propertyListTable = null;
     
     /** Formatting properties for this fo element. */
@@ -125,10 +123,10 @@ public class FObj extends FONode implements Constants {
         PropertyList parentPL = null;
 
         if (parentFO != null) {
-            parentPL = parentFO.getPropertiesForNamespace(FO_URI);
+            parentPL = parentFO.getPropertiesForNamespace(FOElementMapping.URI);
         }
 
-        propertyList = new PropertyList(this, parentPL, FO_URI, name);
+        propertyList = new PropertyList(this, parentPL, FOElementMapping.URI, name);
         propertyList.addAttributesToList(attlist);
         propMgr = new PropertyManager(propertyList);
         setWritingMode();
index fea5fc0a8a7c2f0ab1b2e5cbc78761ad0e8a64bb..8b53390127ba647b90628c6e7af9d24066e57cbe 100644 (file)
@@ -20,6 +20,7 @@ package org.apache.fop.fo.extensions;
 
 import org.apache.fop.fo.FONode;
 import org.apache.fop.fo.FOTreeVisitor;
+import org.apache.fop.fo.pagination.Root;
 
 import java.util.ArrayList;
 
@@ -58,7 +59,7 @@ public class Bookmarks extends ExtensionObj {
      * the extension to the area tree.
      */
     public void end() {
-        getFOTreeControl().setBookmarks(this);
+        ((Root) parent).setBookmarks(this);
     }
 
     public void acceptVisitor(FOTreeVisitor fotv) {
index d94fcdb1bfe16020a7fb686d2ef3a25aa9e577ba..13edff78b820304cbaab8ca161e04c743f3929c4 100644 (file)
@@ -29,12 +29,13 @@ import java.util.HashMap;
  * pdf bookmark extension.
  */
 public class ExtensionElementMapping extends ElementMapping {
+    public static String URI = "http://xml.apache.org/fop/extensions";
 
     /**
      * Constructor.
      */
     public ExtensionElementMapping() {
-        namespaceURI = "http://xml.apache.org/fop/extensions";
+        namespaceURI = URI;
     }
 
     /**
index 0928d5fafd4bf82956c1baf8540c362f68655299..c8b7d6bbdad5d1f70afab02b9dbf7c8a2d72ebea 100644 (file)
@@ -30,10 +30,11 @@ import org.apache.fop.fo.FONode;
  * of the http://xml.apache.org/batik/ext namespace.
  */
 public class BatikExtensionElementMapping extends ElementMapping {
+    public static String URI = "http://xml.apache.org/batik/ext";
     private boolean batikAvail = true;
 
     public BatikExtensionElementMapping() {
-        namespaceURI = "http://xml.apache.org/batik/ext";
+        namespaceURI = URI;
     }
 
     protected void initialize() {
index 60911adcf33111f1dcc6008325bc9f288a7b6376..42da3a693db16bab9c9888faf32ed872f518556c 100644 (file)
@@ -33,10 +33,11 @@ import org.apache.batik.dom.svg.SVGDOMImplementation;
  * that create the SVG Document.
  */
 public class SVGElementMapping extends ElementMapping {
+    public static String URI = SVGDOMImplementation.SVG_NAMESPACE_URI;
     private boolean batik = true;
 
     public SVGElementMapping() {
-        namespaceURI = SVGDOMImplementation.SVG_NAMESPACE_URI;
+        namespaceURI = URI;
     }
 
     protected void initialize() {
index 8fc8648eb3754a1d41b6d03d8adfb72a263b48d6..c5e9669a072b6827094806642bbe3b7746025d0b 100644 (file)
@@ -25,6 +25,9 @@ import java.util.List;
 import org.apache.fop.fo.FOTreeControl;
 import org.apache.fop.fo.FONode;
 import org.apache.fop.fo.FObj;
+import org.apache.fop.fo.FOElementMapping;
+import org.apache.fop.fo.extensions.ExtensionElementMapping;
+import org.apache.fop.fo.extensions.Bookmarks;
 import org.apache.fop.fo.FOTreeVisitor;
 
 /**
@@ -33,7 +36,9 @@ import org.apache.fop.fo.FOTreeVisitor;
 public class Root extends FObj {
     private LayoutMasterSet layoutMasterSet;
     private Declarations declarations;
+    private Bookmarks bookmarks = null;
     private List pageSequences;
+
     // temporary until above list populated
     private boolean pageSequenceFound = false;
 
@@ -58,39 +63,46 @@ public class Root extends FObj {
 
     /**
      * @see org.apache.fop.fo.FONode#validateChildNode(String, String)
+        XSL 1.0 Spec: (layout-master-set,declarations?,page-sequence+)
+        FOP: (layout-master-set, declarations?, fox:bookmarks?, page-sequence+)
      */
-    protected void validateChildNode(String namespaceURI, String localName) {
-        if (namespaceURI == FObj.FO_URI) {
+    protected void validateChildNode(String nsURI, String localName) {
+        if (nsURI == FOElementMapping.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");
+                if (layoutMasterSet != null) {
+                    tooManyNodesError("fo:layout-master-set");
                 }
             } 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 (pageSequenceFound) { // no page-seqs yet
-                    throw new IllegalArgumentException("Error: fo:declarations" +
-                        " must be defined before fo:page-sequence declarations");
+                if (layoutMasterSet == null) {
+                    nodesOutOfOrderError("fo:layout-master-set", "fo:declarations");
+                } else if (declarations != null) {
+                    tooManyNodesError("fo:declarations");
+                } else if (bookmarks != null) {
+                    nodesOutOfOrderError("fo:declarations", "fox:bookmarks");
+                } else if (pageSequenceFound) {
+                    nodesOutOfOrderError("fo:declarations", "fo:page-sequence");
                 }
             } 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");
+                if (layoutMasterSet == null) {
+                    nodesOutOfOrderError("fo:layout-master-set", "fo:page-sequence");
                 } else {
                     pageSequenceFound = true;
                 }
-            } else
-                throw new IllegalArgumentException("Error: Invalid child" +
-                    " node \"fo:" + localName + "\" of fo:root");
+            } else {
+                invalidChildError(nsURI, localName);
+            }
+        } else if (nsURI.equals(ExtensionElementMapping.URI)) {
+            if (!localName.equals("bookmarks")) {
+                invalidChildError(nsURI, localName);
+            } else if (layoutMasterSet == null) {
+                nodesOutOfOrderError("fo:layout-master-set", "fox:bookmarks");
+            } else if (bookmarks != null) {
+                tooManyNodesError("fox:bookmarks");
+            } else if (pageSequenceFound) {
+                nodesOutOfOrderError("fox:bookmarks", "fo:page-sequence");
+            }
         } else {
-            throw new IllegalArgumentException("Error: Invalid child node " +
-                FONode.getNodeString(namespaceURI, localName) + " of fo:root");
+            invalidChildError(nsURI, localName);
         }
     }
 
@@ -168,6 +180,22 @@ public class Root extends FObj {
         this.declarations = declarations;
     }
 
+    /**
+     * Set the Bookmarks object for this FO
+     * @param bookmarks the Bookmarks object
+     */
+    public void setBookmarks(Bookmarks bookmarks) {
+        this.bookmarks = bookmarks;
+    }
+
+    /**
+     * Public accessor for the Bookmarks for this FO
+     * @return the Bookmarks object
+     */
+    public Bookmarks getBookmarks() {
+        return bookmarks;
+    }
+
     /**
      * Sets the FOTreeControl that this Root is attached to
      * @param foTreeControl the FOTreeControl implementation to which this Root