]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Changed XMLEvent to FoXMLEvent throughout.
authorPeter Bernard West <pbwest@apache.org>
Thu, 24 Oct 2002 14:58:14 +0000 (14:58 +0000)
committerPeter Bernard West <pbwest@apache.org>
Thu, 24 Oct 2002 14:58:14 +0000 (14:58 +0000)
Account for the fact that 'expect' methods returning FoXMLEvents return null on failure.

git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/FOP_0-20-0_Alt-Design@195357 13f79535-47bb-0310-9956-ffa450edef68

src/org/apache/fop/fo/FoRoot.java
src/org/apache/fop/fo/pagination/FoLayoutMasterSet.java
src/org/apache/fop/fo/pagination/FoPageSequenceMaster.java
src/org/apache/fop/fo/pagination/FoSimplePageMaster.java

index ebd5f5dc50a26f847e3e824fffd7638ae7fba824..b51e5cd280bed1670128bbca78e788824c21d691 100644 (file)
@@ -18,9 +18,10 @@ import org.apache.fop.fo.FOTree;
 import org.apache.fop.fo.FONode;
 import org.apache.fop.fo.expr.PropertyException;
 import org.apache.fop.fo.pagination.FoLayoutMasterSet;
+import org.apache.fop.xml.FoXMLEvent;
 import org.apache.fop.xml.XMLEvent;
 import org.apache.fop.xml.XMLNamespaces;
-import org.apache.fop.xml.SyncedXmlEventsBuffer;
+import org.apache.fop.xml.SyncedFoXmlEventsBuffer;
 
 import org.xml.sax.Attributes;
 
@@ -44,11 +45,11 @@ public class FoRoot extends FONode {
 
     /**
      * @param foTree the FO tree being built
-     * @param event the <tt>XMLEvent</tt> that triggered the creation of this
+     * @param event the <tt>FoXMLEvent</tt> that triggered the creation of this
      * node
      */
     public FoRoot
-        (FOTree foTree, XMLEvent event)
+        (FOTree foTree, FoXMLEvent event)
         throws Tree.TreeException, FOPException, PropertyException
     {
         // This is the root node of the tree; hence the null argument
@@ -80,7 +81,7 @@ public class FoRoot extends FONode {
      * in the page-sequence-sequence.
      */
     public void buildFoTree() throws FOPException{
-        XMLEvent ev;
+        FoXMLEvent ev;
         System.out.println("buildFoTree: " + event);
         // Look for layout-master-set
         try {
@@ -88,7 +89,7 @@ public class FoRoot extends FONode {
                     (XMLNamespaces.XSLNSpaceIndex, "layout-master-set",
                                                     XMLEvent.DISCARD_W_SPACE);
         } catch (NoSuchElementException e) {
-            throw new FOPException(e);
+            throw new FOPException("buildFoTree: Unexpected EOF in layout-master-set.");
         }
         // Process the layout-master-set
         try {
@@ -100,15 +101,18 @@ public class FoRoot extends FONode {
         }
         // Look for optional declarations
         try {
-            xmlevents.expectStartElement
+            ev = xmlevents.expectStartElement
                         (XMLNamespaces.XSLNSpaceIndex, "declarations",
                                                     XMLEvent.DISCARD_W_SPACE);
-            // process the declarations
-            xmlevents.getEndElement
-                    (XMLNamespaces.XSLNSpaceIndex, "declarations");
+            if (ev != null) {
+                // process the declarations
+                xmlevents.getEndElement
+                        (XMLNamespaces.XSLNSpaceIndex, "declarations");
+            }
         } catch (NoSuchElementException e) {
-            // Take no notice - declarations is optional
+            throw new FOPException
+                ("Unexpected EOF while processing declarations.");
         }
-        
+
     }
 }
index ebd1e828df07debd0f0b48af63ac71e76df463ae..d7c3d9931f924a5dd7fe7de4198a8b4f46dbe07d 100644 (file)
@@ -12,10 +12,11 @@ import org.apache.fop.fo.FObjectNames;
 import org.apache.fop.fo.FOTree;
 import org.apache.fop.fo.FONode;
 import org.apache.fop.fo.expr.PropertyException;
+import org.apache.fop.xml.FoXMLEvent;
 import org.apache.fop.xml.XMLEvent;
 import org.apache.fop.xml.UriLocalName;
 import org.apache.fop.xml.XMLNamespaces;
-import org.apache.fop.xml.SyncedXmlEventsBuffer;
+import org.apache.fop.xml.SyncedFoXmlEventsBuffer;
 import org.apache.fop.datastructs.Tree;
 import org.apache.fop.fo.pagination.FoPageSequenceMaster;
 import org.apache.fop.fo.pagination.PageSequenceMaster;
@@ -78,7 +79,7 @@ public class FoLayoutMasterSet extends FONode {
      * this node
      */
     public FoLayoutMasterSet
-        (FOTree foTree, FONode parent, XMLEvent event)
+        (FOTree foTree, FONode parent, FoXMLEvent event)
         throws Tree.TreeException, FOPException, PropertyException
     {
         super(foTree, FObjectNames.LAYOUT_MASTER_SET, parent, event,
@@ -93,7 +94,7 @@ public class FoLayoutMasterSet extends FONode {
      * @param event - the layout page-master-set STARTELEMENT event.
      * @throws <tt>FOPException</tt>.
      */
-    public void setupPageMasters(XMLEvent event)
+    public void setupPageMasters(FoXMLEvent event)
            throws FOPException, PropertyException
     {
        FoSimplePageMaster simple;
@@ -102,9 +103,10 @@ public class FoLayoutMasterSet extends FONode {
        FoPageSequenceMaster foPageSeq;
         try {
             do {
-                XMLEvent ev =
+                FoXMLEvent ev =
                     xmlevents.expectStartElement
                         (simpleOrSequenceMaster, XMLEvent.DISCARD_W_SPACE);
+                if (ev == null) break; // No instance of these elements found
                 localName = ev.getLocalName();
                 if (localName.equals("simple-page-master")) {
                     //System.out.println("Found simple-page-master");
@@ -145,7 +147,8 @@ public class FoLayoutMasterSet extends FONode {
                             ("Aargh! expectStartElement(events, list)");
             } while (true);
         } catch (NoSuchElementException e) {
-            // Masters exhausted
+            // Unexpected end of file
+            throw new FOPException("layout-master-set: unexpected EOF.");
         }
         catch (PropertyException e) {
             throw new FOPException(e);
@@ -153,6 +156,8 @@ public class FoLayoutMasterSet extends FONode {
         catch (Tree.TreeException e) {
             throw new FOPException(e);
         }
+        if (pageMasters.size() == 0)
+            throw new FOPException("No pageg masters defined in layout-master-set.");
        // Create the master set structures.
        // Scan the page-sequence-masters
        // N.B. Processing of the page-sequence-masters must be deferred until
index b8f80f45898f53fe2df383ceb6f307a25b913a7a..c0e1b014648676931a64c41e332892fed1fe9ac5 100644 (file)
@@ -15,6 +15,7 @@ import java.util.NoSuchElementException;
 
 // FOP
 import org.apache.fop.fo.FOAttributes;
+import org.apache.fop.xml.FoXMLEvent;
 import org.apache.fop.xml.XMLEvent;
 import org.apache.fop.xml.XMLNamespaces;
 import org.apache.fop.xml.UriLocalName;
@@ -68,7 +69,7 @@ public class FoPageSequenceMaster extends FONode {
 
     //private ArrayList subSequenceList = new ArrayList(1);
 
-    public FoPageSequenceMaster(FOTree foTree, FONode parent, XMLEvent event)
+    public FoPageSequenceMaster(FOTree foTree, FONode parent, FoXMLEvent event)
         throws Tree.TreeException, FOPException, PropertyException
     {
         super(foTree, FObjectNames.PAGE_SEQUENCE_MASTER, parent, event,
@@ -76,8 +77,9 @@ public class FoPageSequenceMaster extends FONode {
         // Process sequence members here
         try {
             do {
-                XMLEvent ev = xmlevents.expectStartElement
+                FoXMLEvent ev = xmlevents.expectStartElement
                     (singleOrRepeatableMasterRefs, XMLEvent.DISCARD_W_SPACE);
+                if (ev == null) break;  // page-sequence-masters exhausted
                 String localName = ev.getLocalName();
                 if (localName.equals("single-page-master-reference")) {
                     //System.out.println("Found single-page-master-reference");
@@ -103,8 +105,10 @@ public class FoPageSequenceMaster extends FONode {
                             ("Aargh! expectStartElement(events, list)");
             } while (true);
         } catch (NoSuchElementException e) {
-            // sub-sequence specifiers exhausted
+            throw new FOPException("Unexpected EOF in page-sequence-master.");
         }
+        if (this.numChildren() == 0)
+            throw new FOPException("No children of page-sequence-master.");
         XMLEvent ev = xmlevents.getEndElement(event);
     }
 
@@ -131,7 +135,7 @@ public class FoPageSequenceMaster extends FONode {
     public class FoSinglePageMasterReference extends FONode {
 
        public FoSinglePageMasterReference
-                           (FOTree foTree, FONode parent, XMLEvent event)
+                           (FOTree foTree, FONode parent, FoXMLEvent event)
            throws Tree.TreeException, FOPException, PropertyException
        {
            super(foTree, FObjectNames.SINGLE_PAGE_MASTER_REFERENCE, parent,
@@ -152,7 +156,7 @@ public class FoPageSequenceMaster extends FONode {
     public class FoRepeatablePageMasterReference extends FONode {
 
        public FoRepeatablePageMasterReference
-                           (FOTree foTree, FONode parent, XMLEvent event)
+                           (FOTree foTree, FONode parent, FoXMLEvent event)
            throws Tree.TreeException, FOPException, PropertyException
        {
            super(foTree, FObjectNames.REPEATABLE_PAGE_MASTER_REFERENCE,
@@ -177,7 +181,7 @@ public class FoPageSequenceMaster extends FONode {
     public class FoRepeatablePageMasterAlternatives extends FONode {
 
        public FoRepeatablePageMasterAlternatives
-                           (FOTree foTree, FONode parent, XMLEvent event)
+                           (FOTree foTree, FONode parent, FoXMLEvent event)
            throws Tree.TreeException, FOPException, PropertyException
        {
            super(foTree, FObjectNames.REPEATABLE_PAGE_MASTER_ALTERNATIVES,
@@ -186,17 +190,19 @@ public class FoPageSequenceMaster extends FONode {
            // Process conditional-page-master-references here
            try {
                do {
-                   XMLEvent ev = this.xmlevents.expectStartElement
+                   FoXMLEvent ev = this.xmlevents.expectStartElement
                        (conditionalPageMasterRef.uriIndex,
                            conditionalPageMasterRef.localName,
                                                XMLEvent.DISCARD_W_SPACE);
-                       //System.out.println
-                       //    ("Found conditional-page-master-reference");
-                       new FoConditionalPageMasterReference(foTree, this, ev);
-                       this.xmlevents.getEndElement(ev);
+                    if (ev == null) break; // Sun-sequences exhausted
+                    //System.out.println
+                    //    ("Found conditional-page-master-reference");
+                    new FoConditionalPageMasterReference(foTree, this, ev);
+                    this.xmlevents.getEndElement(ev);
                } while (true);
            } catch (NoSuchElementException e) {
-               // sub-sequence specifiers exhausted
+               // Enf of file reached
+                throw new FOPException("EOF in repeatable-page-masters.");
            }
            XMLEvent ev = this.xmlevents.getEndElement(event);
        }
@@ -208,7 +214,7 @@ public class FoPageSequenceMaster extends FONode {
        public class FoConditionalPageMasterReference extends FONode {
 
            public FoConditionalPageMasterReference
-                           (FOTree foTree, FONode parent, XMLEvent event)
+                           (FOTree foTree, FONode parent, FoXMLEvent event)
            throws Tree.TreeException, FOPException, PropertyException
            {
                super(foTree, FObjectNames.CONDITIONAL_PAGE_MASTER_REFERENCE,
index 2feef717c93535714b00b5c2f0bb3b82deb4b083..14c032892b470fb753a3dea0083920ad7ed91ebf 100644 (file)
@@ -12,7 +12,7 @@ package org.apache.fop.fo.pagination;
 // FOP
 import org.apache.fop.fo.FOAttributes;
 import org.apache.fop.fo.PropNames;
-import org.apache.fop.xml.XMLEvent;
+import org.apache.fop.xml.FoXMLEvent;
 import org.apache.fop.apps.FOPException;
 import org.apache.fop.fo.FOPropertySets;
 import org.apache.fop.fo.FObjectNames;
@@ -37,13 +37,13 @@ public class FoSimplePageMaster extends FONode {
      * @param event the <tt>XMLEvent</tt> that triggered the creation of
      * this node
      */
-    public FoSimplePageMaster(FOTree foTree, FONode parent, XMLEvent event)
+    public FoSimplePageMaster(FOTree foTree, FONode parent, FoXMLEvent event)
         throws Tree.TreeException, FOPException
     {
         super(foTree, FObjectNames.SIMPLE_PAGE_MASTER, parent, event,
               FOPropertySets.LAYOUT_SET);
         // Process regions here
-        XMLEvent ev = xmlevents.getEndElement(event);
+        FoXMLEvent ev = xmlevents.getEndElement(event);
     }
 
     /**