gmazza      2004/06/14 17:30:43

  Modified:    src/java/org/apache/fop/apps Document.java
               src/java/org/apache/fop/area AreaTree.java
               src/java/org/apache/fop/fo FOElementMapping.java FONode.java
                        FOTreeBuilder.java FOTreeControl.java
                        FOTreeHandler.java FObj.java
               src/java/org/apache/fop/fo/extensions Bookmarks.java
                        ExtensionElementMapping.java
               src/java/org/apache/fop/fo/extensions/svg
                        BatikExtensionElementMapping.java
                        SVGElementMapping.java
               src/java/org/apache/fop/fo/pagination Root.java
  Log:
  Standardized error messages, brought fox:bookmarks under parent fo:root.
  
  Revision  Changes    Path
  1.19      +3 -23     xml-fop/src/java/org/apache/fop/apps/Document.java
  
  Index: Document.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/apps/Document.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- Document.java     13 Jun 2004 19:58:58 -0000      1.18
  +++ Document.java     15 Jun 2004 00:30:43 -0000      1.19
  @@ -29,7 +29,6 @@
   
   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 @@
       /** 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 @@
       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;
   
  @@ -101,23 +98,6 @@
        */
       public AreaTree getAreaTree() {
           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;
       }
   
       /**
  
  
  
  1.11      +6 -4      xml-fop/src/java/org/apache/fop/area/AreaTree.java
  
  Index: AreaTree.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/area/AreaTree.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- AreaTree.java     13 Jun 2004 19:58:58 -0000      1.10
  +++ AreaTree.java     15 Jun 2004 00:30:43 -0000      1.11
  @@ -21,6 +21,7 @@
   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 @@
       /**
        * 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);
  
  
  
  1.8       +2 -1      xml-fop/src/java/org/apache/fop/fo/FOElementMapping.java
  
  Index: FOElementMapping.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/fo/FOElementMapping.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- FOElementMapping.java     19 May 2004 22:37:53 -0000      1.7
  +++ FOElementMapping.java     15 Jun 2004 00:30:43 -0000      1.8
  @@ -25,12 +25,13 @@
    * 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;
       }
   
       /**
  
  
  
  1.21      +51 -2     xml-fop/src/java/org/apache/fop/fo/FONode.java
  
  Index: FONode.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/fo/FONode.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- FONode.java       13 Jun 2004 19:58:58 -0000      1.20
  +++ FONode.java       15 Jun 2004 00:30:43 -0000      1.21
  @@ -31,6 +31,8 @@
   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 @@
       /**
        * 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() + ".");
  +    }
  +    
   }
   
  
  
  
  1.30      +2 -1      xml-fop/src/java/org/apache/fop/fo/FOTreeBuilder.java
  
  Index: FOTreeBuilder.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/fo/FOTreeBuilder.java,v
  retrieving revision 1.29
  retrieving revision 1.30
  diff -u -r1.29 -r1.30
  --- FOTreeBuilder.java        12 Jun 2004 23:18:52 -0000      1.29
  +++ FOTreeBuilder.java        15 Jun 2004 00:30:43 -0000      1.30
  @@ -226,7 +226,8 @@
   
           // 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"));
               }
  
  
  
  1.13      +1 -15     xml-fop/src/java/org/apache/fop/fo/FOTreeControl.java
  
  Index: FOTreeControl.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/fo/FOTreeControl.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- FOTreeControl.java        11 Jun 2004 17:18:51 -0000      1.12
  +++ FOTreeControl.java        15 Jun 2004 00:30:43 -0000      1.13
  @@ -25,7 +25,6 @@
   
   // 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;
   
  @@ -38,19 +37,6 @@
    * information.
    */
   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.
  
  
  
  1.19      +2 -2      xml-fop/src/java/org/apache/fop/fo/FOTreeHandler.java
  
  Index: FOTreeHandler.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/fo/FOTreeHandler.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- FOTreeHandler.java        13 Jun 2004 19:58:58 -0000      1.18
  +++ FOTreeHandler.java        15 Jun 2004 00:30:43 -0000      1.19
  @@ -205,7 +205,7 @@
               }
           }
   
  -        getAreaTree().addBookmarksToAreaTree();
  +        getAreaTree().addBookmarksToAreaTree(pageSequence.getRoot().getBookmarks());
           formatPageSequence(pageSequence, getAreaTree());
       }
   
  
  
  
  1.43      +2 -4      xml-fop/src/java/org/apache/fop/fo/FObj.java
  
  Index: FObj.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/fo/FObj.java,v
  retrieving revision 1.42
  retrieving revision 1.43
  diff -u -r1.42 -r1.43
  --- FObj.java 12 Jun 2004 23:18:52 -0000      1.42
  +++ FObj.java 15 Jun 2004 00:30:43 -0000      1.43
  @@ -36,8 +36,6 @@
    * 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 @@
           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();
  
  
  
  1.5       +3 -2      xml-fop/src/java/org/apache/fop/fo/extensions/Bookmarks.java
  
  Index: Bookmarks.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/fo/extensions/Bookmarks.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Bookmarks.java    27 Feb 2004 17:43:50 -0000      1.4
  +++ Bookmarks.java    15 Jun 2004 00:30:43 -0000      1.5
  @@ -20,6 +20,7 @@
   
   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 @@
        * the extension to the area tree.
        */
       public void end() {
  -        getFOTreeControl().setBookmarks(this);
  +        ((Root) parent).setBookmarks(this);
       }
   
       public void acceptVisitor(FOTreeVisitor fotv) {
  
  
  
  1.4       +3 -2      
xml-fop/src/java/org/apache/fop/fo/extensions/ExtensionElementMapping.java
  
  Index: ExtensionElementMapping.java
  ===================================================================
  RCS file: 
/home/cvs/xml-fop/src/java/org/apache/fop/fo/extensions/ExtensionElementMapping.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ExtensionElementMapping.java      27 Feb 2004 17:43:50 -0000      1.3
  +++ ExtensionElementMapping.java      15 Jun 2004 00:30:43 -0000      1.4
  @@ -29,12 +29,13 @@
    * 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;
       }
   
       /**
  
  
  
  1.4       +3 -2      
xml-fop/src/java/org/apache/fop/fo/extensions/svg/BatikExtensionElementMapping.java
  
  Index: BatikExtensionElementMapping.java
  ===================================================================
  RCS file: 
/home/cvs/xml-fop/src/java/org/apache/fop/fo/extensions/svg/BatikExtensionElementMapping.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- BatikExtensionElementMapping.java 27 Feb 2004 17:43:22 -0000      1.3
  +++ BatikExtensionElementMapping.java 15 Jun 2004 00:30:43 -0000      1.4
  @@ -30,10 +30,11 @@
    * 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() {
  
  
  
  1.4       +3 -2      
xml-fop/src/java/org/apache/fop/fo/extensions/svg/SVGElementMapping.java
  
  Index: SVGElementMapping.java
  ===================================================================
  RCS file: 
/home/cvs/xml-fop/src/java/org/apache/fop/fo/extensions/svg/SVGElementMapping.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- SVGElementMapping.java    27 Feb 2004 17:43:22 -0000      1.3
  +++ SVGElementMapping.java    15 Jun 2004 00:30:43 -0000      1.4
  @@ -33,10 +33,11 @@
    * 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() {
  
  
  
  1.14      +51 -23    xml-fop/src/java/org/apache/fop/fo/pagination/Root.java
  
  Index: Root.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/fo/pagination/Root.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- Root.java 13 Jun 2004 19:58:58 -0000      1.13
  +++ Root.java 15 Jun 2004 00:30:43 -0000      1.14
  @@ -25,6 +25,9 @@
   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 @@
   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 @@
   
       /**
        * @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);
           }
       }
   
  @@ -166,6 +178,22 @@
        */
       public void setDeclarations(Declarations declarations) {
           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;
       }
   
       /**
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to