gmazza      2005/03/01 17:59:40

  Modified:    src/java/org/apache/fop/fo/flow TableBody.java
                        TableFooter.java
               src/java/org/apache/fop/apps FOUserAgent.java
  Log:
  Flag added in FOUserAgent for strict/unstrict validation (see TableBody to 
see how used.)
  Validation added (only strict version) for TableFooter.
  
  Revision  Changes    Path
  1.39      +47 -5     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.38
  retrieving revision 1.39
  diff -u -r1.38 -r1.39
  --- TableBody.java    23 Feb 2005 22:04:01 -0000      1.38
  +++ TableBody.java    2 Mar 2005 01:59:40 -0000       1.39
  @@ -22,11 +22,14 @@
   import java.util.Iterator;
   import java.util.List;
   
  +import org.xml.sax.Locator;
  +
   import org.apache.fop.apps.FOPException;
   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;
  @@ -34,7 +37,6 @@
   
   /**
    * Class modelling the fo:table-body object.
  - * @todo implement validateChildNode()
    */
   public class TableBody extends FObj {
       // The value of properties relevant for fo:table-body.
  @@ -50,6 +52,9 @@
       // End of property values
       
       private PropertyList savedPropertyList;
  +
  +    private boolean tableRowsFound = false;
  +    private boolean tableColumnsFound = false;   
       
       /**
        * @param parent FONode that is the parent of the object
  @@ -88,15 +93,52 @@
        */
       protected void endOfNode() throws FOPException {
           getFOEventHandler().endBody(this);
  -        if (childNodes == null || childNodes.size() == 0) {
  -            getLogger().error("fo:table-body must not be empty. "
  -                    + "Expected: (table-row+|table-cell+)");
  -            getParent().removeChild(this);
  +        if (!(tableRowsFound || tableColumnsFound)) {
  +            if (getUserAgent().validateStrictly()) {
  +                missingChildElementError("marker* (table-row+|table-cell+)");
  +            } else {
  +                getLogger().error("fo:table-body must not be empty. "
  +                        + "Expected: marker* (table-row+|table-cell+)");
  +                getParent().removeChild(this);
  +            }
           }
           convertCellsToRows();
       }
   
       /**
  +     * @see org.apache.fop.fo.FONode#validateChildNode(Locator, String, 
String)
  +     * XSL Content Model: marker* (table-row+|table-cell+)
  +     */
  +    protected void validateChildNode(Locator loc, String nsURI, String 
localName) 
  +        throws ValidationException {
  +        if (nsURI == FO_URI) {
  +            if (localName.equals("marker")) {
  +                if (tableRowsFound || tableColumnsFound) {
  +                   nodesOutOfOrderError(loc, "fo:marker", 
"(table-row+|table-cell+)");
  +                }
  +            } else if (localName.equals("table-row")) {
  +                tableRowsFound = true;
  +                if (tableColumnsFound) {
  +                    invalidChildError(loc, nsURI, localName, "Either 
fo:table-rows" +
  +                      " or fo:table-columns may be children of an 
fo:table-body" +
  +                      " but not both");
  +                }
  +            } else if (localName.equals("table-column")) {
  +                tableColumnsFound = true;
  +                if (tableRowsFound) {
  +                    invalidChildError(loc, nsURI, localName, "Either 
fo:table-rows" +
  +                      " or fo:table-columns may be children of an 
fo:table-body" +
  +                      " but not both");
  +                }  
  +            } else {
  +                invalidChildError(loc, nsURI, localName);
  +            }
  +        } else {
  +            invalidChildError(loc, nsURI, localName);
  +        }
  +    }
  +
  +    /**
        * If table-cells are used as direct children of a 
table-body|header|footer
        * they are replace in this method by proper table-rows.
        * @throws FOPException if there's a problem binding the TableRows 
properties.
  
  
  
  1.12      +58 -1     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.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- TableFooter.java  25 Aug 2004 05:03:06 -0000      1.11
  +++ TableFooter.java  2 Mar 2005 01:59:40 -0000       1.12
  @@ -21,9 +21,12 @@
   // FOP
   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.
  - * @todo implement validateChildNode()
    */
   public class TableFooter extends TableBody {
   
  @@ -34,6 +37,60 @@
           super(parent);
       }
   
  +    private boolean tableRowsFound = false;
  +    private boolean tableColumnsFound = false;
  +
  +    /**
  +     * @see org.apache.fop.fo.FONode#startOfNode
  +     */
  +    protected void startOfNode() throws FOPException {
  +//      getFOEventHandler().startBody(this);
  +    }
  +
  +    /**
  +     * @see org.apache.fop.fo.FONode#validateChildNode(Locator, String, 
String)
  +     * XSL Content Model: marker* (table-row+|table-cell+)
  +     */
  +    protected void validateChildNode(Locator loc, String nsURI, String 
localName) 
  +        throws ValidationException {
  +        if (nsURI == FO_URI) {
  +            if (localName.equals("marker")) {
  +                if (tableRowsFound || tableColumnsFound) {
  +                   nodesOutOfOrderError(loc, "fo:marker", 
"(table-row+|table-cell+)");
  +                }
  +            } else if (localName.equals("table-row")) {
  +                tableRowsFound = true;
  +                if (tableColumnsFound) {
  +                    invalidChildError(loc, nsURI, localName, "Either 
fo:table-rows" +
  +                      " or fo:table-columns may be children of an 
fo:table-footer" +
  +                      " but not both");
  +                }
  +            } else if (localName.equals("table-column")) {
  +                tableColumnsFound = true;
  +                if (tableRowsFound) {
  +                    invalidChildError(loc, nsURI, localName, "Either 
fo:table-rows" +
  +                      " or fo:table-columns may be children of an 
fo:table-footer" +
  +                      " but not both");
  +                }  
  +            } else {
  +                invalidChildError(loc, nsURI, localName);
  +            }
  +        } else {
  +            invalidChildError(loc, nsURI, localName);
  +        }
  +    }
  +
  +    /**
  +     * @see org.apache.fop.fo.FONode#endOfNode
  +     */
  +    protected void endOfNode() throws FOPException {
  +//      getFOEventHandler().endFooter(this);
  +        if (!(tableRowsFound || tableColumnsFound)) {
  +            missingChildElementError("marker* (table-row+|table-cell+)");
  +        }
  +//      convertCellsToRows();
  +    }
  +
       /**
        * @see org.apache.fop.fo.FObj#getName()
        */
  
  
  
  1.22      +25 -1     xml-fop/src/java/org/apache/fop/apps/FOUserAgent.java
  
  Index: FOUserAgent.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/apps/FOUserAgent.java,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- FOUserAgent.java  12 Feb 2005 15:33:07 -0000      1.21
  +++ FOUserAgent.java  2 Mar 2005 01:59:40 -0000       1.22
  @@ -79,6 +79,13 @@
       /* user configuration */
       private Configuration userConfig = null;
       private Log log = LogFactory.getLog("FOP");
  +    
  +    /* FOP has the ability, for some FO's, to continue processing even if the
  +     * input XSL violates that FO's content model.  This is the default  
  +     * behavior for FOP.  However, this flag, if set, provides the user the
  +     * ability for FOP to halt on all content model violations if desired.   
  +     */ 
  +    private boolean strictValidation = false;
   
       /* Additional fo.ElementMapping subclasses set by user */
       private ArrayList additionalElementMappings = null;
  @@ -176,6 +183,23 @@
       }
   
       /**
  +     * Activates strict XSL content model validation for FOP
  +     * Default is false (FOP will continue processing where it can)
  +     * @param validateStrictly true to turn on strict validation
  +     */
  +    public void setStrictValidation(boolean validateStrictly) {
  +        this.strictValidation = validateStrictly;
  +    }
  +
  +    /**
  +     * Returns whether FOP is strictly validating input XSL
  +     * @return true of strict validation turned on, false otherwise
  +     */
  +    public boolean validateStrictly() {
  +        return strictValidation;
  +    }
  +
  +    /**
        * Sets an explicit LayoutManagerMaker instance which overrides the one
        * defined by the AreaTreeHandler.
        * @param lmMaker the LayoutManagerMaker instance
  
  
  

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

Reply via email to