gmazza      2005/03/04 16:32:25

  Modified:    src/java/org/apache/fop/fo/flow TableBody.java Table.java
                        TableFooter.java TableHeader.java
               src/java/org/apache/fop/layoutmgr
                        PageSequenceLayoutManager.java
               src/java/org/apache/fop/area MainReference.java
               src/java/org/apache/fop/fo FONode.java
  Log:
  Validation for fo:table and fo:table-header added, some minor simplifications 
in other places.
  
  Revision  Changes    Path
  1.41      +26 -32    xml-fop/src/java/org/apache/fop/fo/flow/TableBody.java
  
  Index: TableBody.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/fo/flow/TableBody.java,v
  retrieving revision 1.40
  retrieving revision 1.41
  diff -u -r1.40 -r1.41
  --- TableBody.java    2 Mar 2005 21:03:25 -0000       1.40
  +++ TableBody.java    5 Mar 2005 00:32:25 -0000       1.41
  @@ -102,7 +102,10 @@
                   getParent().removeChild(this);
               }
           }
  -        convertCellsToRows();
  +        if (tableCellsFound) {
  +            convertCellsToRows();
  +        }
  +        savedPropertyList = null; //Release reference
       }
   
       /**
  @@ -140,44 +143,35 @@
   
       /**
        * 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);
           }
       }
       
  
  
  
  1.50      +59 -1     xml-fop/src/java/org/apache/fop/fo/flow/Table.java
  
  Index: Table.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/fo/flow/Table.java,v
  retrieving revision 1.49
  retrieving revision 1.50
  diff -u -r1.49 -r1.50
  --- Table.java        15 Feb 2005 19:30:51 -0000      1.49
  +++ Table.java        5 Mar 2005 00:32:25 -0000       1.50
  @@ -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.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 @@
       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 @@
           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
  
  
  
  1.14      +1 -3      xml-fop/src/java/org/apache/fop/fo/flow/TableFooter.java
  
  Index: TableFooter.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/fo/flow/TableFooter.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- TableFooter.java  2 Mar 2005 21:03:25 -0000       1.13
  +++ TableFooter.java  5 Mar 2005 00:32:25 -0000       1.14
  @@ -19,11 +19,9 @@
   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.
  
  
  
  1.12      +20 -0     xml-fop/src/java/org/apache/fop/fo/flow/TableHeader.java
  
  Index: TableHeader.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/fo/flow/TableHeader.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- TableHeader.java  25 Aug 2004 05:03:06 -0000      1.11
  +++ TableHeader.java  5 Mar 2005 00:32:25 -0000       1.12
  @@ -19,8 +19,10 @@
   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()
  @@ -35,6 +37,24 @@
       }
   
       /**
  +     * @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()
        */
       public String getName() {
  
  
  
  1.39      +2 -4      
xml-fop/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java
  
  Index: PageSequenceLayoutManager.java
  ===================================================================
  RCS file: 
/home/cvs/xml-fop/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java,v
  retrieving revision 1.38
  retrieving revision 1.39
  diff -u -r1.38 -r1.39
  --- PageSequenceLayoutManager.java    1 Mar 2005 00:11:03 -0000       1.38
  +++ PageSequenceLayoutManager.java    5 Mar 2005 00:32:25 -0000       1.39
  @@ -704,9 +704,7 @@
       }
   
       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() {
  
  
  
  1.4       +7 -0      xml-fop/src/java/org/apache/fop/area/MainReference.java
  
  Index: MainReference.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/area/MainReference.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- MainReference.java        27 May 2004 10:52:33 -0000      1.3
  +++ MainReference.java        5 Mar 2005 00:32:25 -0000       1.4
  @@ -32,6 +32,13 @@
       private boolean isEmpty = true;
   
       /**
  +     * Constructor
  +     */
  +    public MainReference() {
  +        addTrait(Trait.IS_REFERENCE_AREA, Boolean.TRUE);
  +    }
  +      
  +    /**
        * Add a span area to this area.
        *
        * @param span the span area to add
  
  
  
  1.55      +5 -4      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.54
  retrieving revision 1.55
  diff -u -r1.54 -r1.55
  --- FONode.java       23 Feb 2005 22:04:01 -0000      1.54
  +++ FONode.java       5 Mar 2005 00:32:25 -0000       1.55
  @@ -292,8 +292,9 @@
        */
       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 @@
        */
       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);
       }
   
       /**
  
  
  

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

Reply via email to