]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Validation for fo:table and fo:table-header added, some minor simplifications in...
authorGlen Mazza <gmazza@apache.org>
Sat, 5 Mar 2005 00:32:25 +0000 (00:32 +0000)
committerGlen Mazza <gmazza@apache.org>
Sat, 5 Mar 2005 00:32:25 +0000 (00:32 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@198466 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/fop/area/MainReference.java
src/java/org/apache/fop/fo/FONode.java
src/java/org/apache/fop/fo/flow/Table.java
src/java/org/apache/fop/fo/flow/TableBody.java
src/java/org/apache/fop/fo/flow/TableFooter.java
src/java/org/apache/fop/fo/flow/TableHeader.java
src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java

index c9b50fd68da5a2a083b924713d0a87b274d81144..8dac9777fd68716c184a5bb6dc856832bd7fd16f 100644 (file)
@@ -31,6 +31,13 @@ public class MainReference extends Area {
     private int width;
     private boolean isEmpty = true;
 
+    /**
+     * Constructor
+     */
+    public MainReference() {
+        addTrait(Trait.IS_REFERENCE_AREA, Boolean.TRUE);
+    }
+      
     /**
      * Add a span area to this area.
      *
index ba7832858090f2bda06291e223e487925b5ef3ac..c0f3a2c92b02bc9d0d2724ed58a005396c7bd837 100644 (file)
@@ -292,8 +292,9 @@ public abstract class FONode implements Cloneable {
      */
     protected void tooManyNodesError(Locator loc, String nsURI, String lName) 
         throws ValidationException {
-        throw new ValidationException(errorText(loc) + getName() + ", only one " 
-            + getNodeString(nsURI, lName) + " may be declared.", loc);
+        throw new ValidationException(errorText(loc) + "For " + getName() + 
+            ", only one " + getNodeString(nsURI, lName) + " may be declared.", 
+            loc);
     }
 
     /**
@@ -305,8 +306,8 @@ public abstract class FONode implements Cloneable {
      */
     protected void tooManyNodesError(Locator loc, String offendingNode) 
         throws ValidationException {
-        throw new ValidationException(errorText(loc) + getName() + ", only one " 
-            + offendingNode + " may be declared.", loc);
+        throw new ValidationException(errorText(loc) + "For " + getName() + 
+            ", only one " + offendingNode + " may be declared.", loc);
     }
 
     /**
index 78272973e2a7902e854906fadde95adb74709d33..df5249648a533f44d7625bdc8b7e4ca275c07bc9 100644 (file)
@@ -18,6 +18,8 @@
 
 package org.apache.fop.fo.flow;
 
+import org.xml.sax.Locator;
+
 import java.util.List;
 
 import org.apache.fop.apps.FOPException;
@@ -25,6 +27,7 @@ import org.apache.fop.fo.FONode;
 import org.apache.fop.fo.FObj;
 import org.apache.fop.fo.PropertyList;
 import org.apache.fop.fo.StaticPropertyList;
+import org.apache.fop.fo.ValidationException;
 import org.apache.fop.fo.properties.CommonAccessibility;
 import org.apache.fop.fo.properties.CommonAural;
 import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
@@ -73,7 +76,13 @@ public class Table extends FObj {
     protected List columns = null;
     private TableBody tableHeader = null;
     private TableBody tableFooter = null;
-
+  
+    /** used for validation */
+    private boolean tableColumnFound = false;
+    private boolean tableHeaderFound = false;   
+    private boolean tableFooterFound = false;   
+    private boolean tableBodyFound = false; 
+   
     /** 
      * Default table-column used when no columns are specified. It is used
      * to handle inheritance (especially visibility) and defaults properly. */
@@ -136,6 +145,55 @@ public class Table extends FObj {
         checkId(id);
         getFOEventHandler().startTable(this);
     }
+   
+    /**
+     * @see org.apache.fop.fo.FONode#validateChildNode(Locator, String, String)
+     * XSL Content Model: (marker*,table-column*,table-header?,table-footer?,table-body+)
+     */
+    protected void validateChildNode(Locator loc, String nsURI, String localName) 
+        throws ValidationException {
+        if (nsURI == FO_URI) {
+            if (localName.equals("marker")) {
+                if (tableColumnFound || tableHeaderFound || tableFooterFound 
+                        || tableBodyFound) {
+                   nodesOutOfOrderError(loc, "fo:marker", 
+                       "(table-column*,table-header?,table-footer?,table-body+)");
+                }
+            } else if (localName.equals("table-column")) {
+                tableColumnFound = true;
+                if (tableHeaderFound || tableFooterFound || tableBodyFound) {
+                    nodesOutOfOrderError(loc, "fo:table-column", 
+                        "(table-header?,table-footer?,table-body+)");
+                }
+            } else if (localName.equals("table-header")) {
+                if (tableHeaderFound) {
+                    tooManyNodesError(loc, "table-header");
+                } else {
+                    tableHeaderFound = true;
+                    if (tableFooterFound || tableBodyFound) {
+                        nodesOutOfOrderError(loc, "fo:table-header", 
+                            "(table-footer?,table-body+)"); 
+                    }
+                }
+            } else if (localName.equals("table-footer")) {
+                if (tableFooterFound) {
+                    tooManyNodesError(loc, "table-footer");
+                } else {
+                    tableFooterFound = true;
+                    if (tableBodyFound) {
+                        nodesOutOfOrderError(loc, "fo:table-footer", 
+                            "(table-body+)");
+                    }
+                }
+            } else if (localName.equals("table-body")) {
+                tableBodyFound = true;
+            } else {
+                invalidChildError(loc, nsURI, localName);
+            }
+        } else {
+            invalidChildError(loc, nsURI, localName);
+        }
+    }
 
     /**
      * @see org.apache.fop.fo.FONode#endOfNode
index bf9aac8350ea04bead1dae345252e34a38fcee88..da1dc92f9b64f718e60d36614f536c97d75305d7 100644 (file)
@@ -102,7 +102,10 @@ public class TableBody extends FObj {
                 getParent().removeChild(this);
             }
         }
-        convertCellsToRows();
+        if (tableCellsFound) {
+            convertCellsToRows();
+        }
+        savedPropertyList = null; //Release reference
     }
 
     /**
@@ -140,44 +143,35 @@ public class TableBody extends FObj {
 
     /**
      * If table-cells are used as direct children of a table-body|header|footer
-     * they are replace in this method by proper table-rows.
+     * they are replaced in this method by proper table-rows.
      * @throws FOPException if there's a problem binding the TableRows properties.
      */
     private void convertCellsToRows() throws FOPException {
-        try {
-            if (childNodes == null 
-                    || childNodes.size() == 0 
-                    || childNodes.get(0) instanceof TableRow) {
-                return;
+        //getLogger().debug("Converting cells to rows...");
+        List cells = (List)childNodes.clone();
+        childNodes.clear();
+        Iterator i = cells.iterator();
+        TableRow row = null;
+        while (i.hasNext()) {
+            TableCell cell = (TableCell)i.next();
+            if (cell.startsRow() && (row != null)) {
+                childNodes.add(row);
+                row = null;
             }
-            //getLogger().debug("Converting cells to rows...");
-            List cells = (List)childNodes.clone();
-            childNodes.clear();
-            Iterator i = cells.iterator();
-            TableRow row = null;
-            while (i.hasNext()) {
-                TableCell cell = (TableCell)i.next();
-                if (cell.startsRow() && (row != null)) {
-                    childNodes.add(row);
-                    row = null;
-                }
-                if (row == null) {
-                    row = new TableRow(this);
-                    PropertyList pList = new StaticPropertyList(row, savedPropertyList);
-                    pList.setWritingMode();
-                    row.bind(pList);
-                }
-                row.addReplacedCell(cell);
-                if (cell.endsRow()) {
-                    childNodes.add(row);
-                    row = null;
-                }
+            if (row == null) {
+                row = new TableRow(this);
+                PropertyList pList = new StaticPropertyList(row, savedPropertyList);
+                pList.setWritingMode();
+                row.bind(pList);
             }
-            if (row != null) {
+            row.addReplacedCell(cell);
+            if (cell.endsRow()) {
                 childNodes.add(row);
+                row = null;
             }
-        } finally {
-            savedPropertyList = null; //Release reference
+        }
+        if (row != null) {
+            childNodes.add(row);
         }
     }
     
index 6db9242e8c26fe7bbad5eb8284e2fe382674592b..09cba1cc342e1f3947e8e56c9338603bf1e069e6 100644 (file)
 package org.apache.fop.fo.flow;
 
 // FOP
+import org.apache.fop.apps.FOPException;
 import org.apache.fop.fo.FONode;
 
-import org.xml.sax.Locator;
-import org.apache.fop.apps.FOPException;
-import org.apache.fop.fo.ValidationException;
 
 /**
  * Class modelling the fo:table-footer object.
index 0b61b524d4c5b81e5b94cb1a30e666b118efdbc9..8aa222ec6790f4d18c27e9e1449e0698c959fa7b 100644 (file)
 package org.apache.fop.fo.flow;
 
 // FOP
+import org.apache.fop.apps.FOPException;
 import org.apache.fop.fo.FONode;
 
+
 /**
  * Class modelling the fo:table-header object.
  * @todo implement validateChildNode()
@@ -34,6 +36,24 @@ public class TableHeader extends TableBody {
         super(parent);
     }
 
+    /**
+     * @see org.apache.fop.fo.FONode#startOfNode
+     */
+    protected void startOfNode() throws FOPException {
+//      getFOEventHandler().startHeader(this);
+    }
+
+    /**
+     * @see org.apache.fop.fo.FONode#endOfNode
+     */
+    protected void endOfNode() throws FOPException {
+//      getFOEventHandler().endHeader(this);
+        if (!(tableRowsFound || tableCellsFound)) {
+            missingChildElementError("marker* (table-row+|table-cell+)");
+        }
+//      convertCellsToRows();
+    }
+
     /**
      * @see org.apache.fop.fo.FObj#getName()
      */
index d7cb07fa3ae4f0f5b33d6208920a2c316c134e29..890f09aff073d61278b7e81fd82f684fca73d613 100644 (file)
@@ -704,9 +704,7 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager {
     }
 
     private void createBodyMainReferenceArea() {
-        MainReference mainRef = new MainReference();
-        mainRef.addTrait(Trait.IS_REFERENCE_AREA, Boolean.TRUE);
-        curBody.setMainReference(mainRef);
+        curBody.setMainReference(new MainReference());
     }
 
     private Flow createFlow() {