You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by ad...@apache.org on 2008/06/22 22:57:44 UTC

svn commit: r670412 - in /xmlgraphics/fop/trunk/src/java/org/apache/fop/fo: ./ flow/ flow/table/

Author: adelmelle
Date: Sun Jun 22 13:57:43 2008
New Revision: 670412

URL: http://svn.apache.org/viewvc?rev=670412&view=rev
Log:
Partial fix of FOEventHandler call sequence (see also Bugzilla #45237):
call startOfNode() after addChildNode()
moved initialization for tableFOs to processNode()
moved finishing code to a finalizeNode() method (which is now also used by AbstractRetrieveMarker)
restored protected status of startOfNode()/endOfNode() in fo.flow.table package

Modified:
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/FONode.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/FOTreeBuilder.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/AbstractRetrieveMarker.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/table/Table.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/table/TableBody.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/table/TableCell.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/table/TableFObj.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/table/TableFooter.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/table/TableHeader.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/table/TablePart.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/table/TableRow.java

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/FONode.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/FONode.java?rev=670412&r1=670411&r2=670412&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/FONode.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/FONode.java Sun Jun 22 13:57:43 2008
@@ -298,11 +298,16 @@
      * Primarily used for making final content model validation checks
      * and/or informing the {@link FOEventHandler} that the end of this FO
      * has been reached.
+     * The default implementation simply calls {@link #finalizeNode()}, without
+     * sending any event to the {@link FOEventHandler}.
+     * <br/><i>Note: the recommended way to override this method in subclasses is</i>
+     * <br/><br/><code>super.endOfNode(); // invoke finalizeNode()
+     * <br/>getFOEventHandler().endXXX(); // send endOfNode() notification</code>
      *
      * @throws FOPException if there's a problem during processing
      */
     protected void endOfNode() throws FOPException {
-        // do nothing by default
+        this.finalizeNode();
     }
 
     /**
@@ -327,6 +332,20 @@
     }
 
     /**
+     * Finalize this node.
+     * This method can be overridden by subclasses to perform finishing
+     * tasks (cleanup, validation checks, ...) without triggering
+     * endXXX() events in the {@link FOEventHandler}.
+     * The method is called by the default {@link #endOfNode()}
+     * implementation.
+     * 
+     * @throws FOPException in case there was an error
+     */
+    public void finalizeNode() throws FOPException {
+        // do nothing by default
+    }
+
+    /**
      * Return the parent node of this node
      *
      * @return the parent node of this node

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/FOTreeBuilder.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/FOTreeBuilder.java?rev=670412&r1=670411&r2=670412&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/FOTreeBuilder.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/FOTreeBuilder.java Sun Jun 22 13:57:43 2008
@@ -288,7 +288,6 @@
                         builderContext.switchMarkerContext(true);
                     }
                 }
-                foNode.startOfNode();
             } catch (IllegalArgumentException e) {
                 throw new SAXException(e);
             }
@@ -317,6 +316,7 @@
             if (propertyList != null && !builderContext.inMarker()) {
                 currentPropertyList = propertyList;
             }
+            currentFObj.startOfNode();
         }
 
         /** {@inheritDoc} */

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/AbstractRetrieveMarker.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/AbstractRetrieveMarker.java?rev=670412&r1=670411&r2=670412&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/AbstractRetrieveMarker.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/AbstractRetrieveMarker.java Sun Jun 22 13:57:43 2008
@@ -102,12 +102,6 @@
                         getLocator(),
                         pList,
                         newPropertyList);
-                if (newChild instanceof TableFObj) {
-                    // TODO calling startOfNode (and endOfNode, below) on other fobjs may
-                    // have undesirable side-effects. This is really ugly and will need to
-                    // be addressed sooner or later
-                    ((TableFObj) newChild).startOfNode();
-                }
                 addChildTo(newChild, (FObj) newParent);
                 if (newChild.getNameId() == FO_TABLE) {
                     Table t = (Table) child;
@@ -120,15 +114,13 @@
                 }
                 cloneSubtree(child.getChildNodes(), newChild,
                         marker, newPropertyList);
-                if (newChild instanceof TableFObj) {
-                    // TODO this is ugly
-                    ((TableFObj) newChild).endOfNode();
-                }
             } else if (child instanceof FOText) {
                 FOText ft = (FOText) newChild;
                 ft.bind(parentPropertyList);
                 addChildTo(newChild, (FObj) newParent);
             }
+            
+            newChild.finalizeNode();
             // trigger 'end-of-node' white-space handling
             if (newChild instanceof FObjMixed) {
                 handleWhiteSpaceFor((FObjMixed) newChild, null);

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/table/Table.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/table/Table.java?rev=670412&r1=670411&r2=670412&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/table/Table.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/table/Table.java Sun Jun 22 13:57:43 2008
@@ -157,10 +157,8 @@
         this.propList = pList;
     }
 
-    /**
-     * {@inheritDoc}
-     */
-    public void startOfNode() throws FOPException {
+    /** {@inheritDoc} */
+    protected void startOfNode() throws FOPException {
         super.startOfNode();
         getFOEventHandler().startTable(this);
     }
@@ -218,11 +216,15 @@
         }
     }
 
-    /**
-     * {@inheritDoc}
-     */
-    public void endOfNode() throws FOPException {
+    /** {@inheritDoc} */
+    protected void endOfNode() throws FOPException {
+        super.endOfNode();
+        getFOEventHandler().endTable(this);
+    }
 
+    /** {@inheritDoc} */
+    public void finalizeNode() throws FOPException {
+        
         if (!tableBodyFound) {
            missingChildElementError(
                    "(marker*,table-column*,table-header?,table-footer?"
@@ -244,13 +246,10 @@
             this.propList = null;
             rowGroupBuilder = null;
         }
-        getFOEventHandler().endTable(this);
-
+        
     }
-
-    /**
-     * {@inheritDoc}
-     */
+    
+    /** {@inheritDoc} */
     protected void addChildNode(FONode child) throws FOPException {
 
         int childId = child.getNameId();
@@ -523,17 +522,17 @@
         return FO_TABLE;
     }
 
-    /**
-     * {@inheritDoc}
-     */
+    /** {@inheritDoc} */
     public FONode clone(FONode parent, boolean removeChildren)
         throws FOPException {
         Table clone = (Table) super.clone(parent, removeChildren);
-        clone.columnsFinalized = false;
         if (removeChildren) {
             clone.columns = new ArrayList();
+            clone.columnsFinalized = false;
+            clone.columnNumberManager = new ColumnNumberManager();
             clone.tableHeader = null;
             clone.tableFooter = null;
+            clone.rowGroupBuilder = null;
         }
         return clone;
     }

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/table/TableBody.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/table/TableBody.java?rev=670412&r1=670411&r2=670412&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/table/TableBody.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/table/TableBody.java Sun Jun 22 13:57:43 2008
@@ -38,13 +38,13 @@
     }
 
     /** {@inheritDoc} */
-    public void startOfNode() throws FOPException {
+    protected void startOfNode() throws FOPException {
         super.startOfNode();
         getFOEventHandler().startBody(this);
     }
 
     /** {@inheritDoc} */
-    public void endOfNode() throws FOPException {
+    protected void endOfNode() throws FOPException {
         super.endOfNode();
         getFOEventHandler().endBody(this);
     }

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/table/TableCell.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/table/TableCell.java?rev=670412&r1=670411&r2=670412&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/table/TableCell.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/table/TableCell.java Sun Jun 22 13:57:43 2008
@@ -91,17 +91,24 @@
     }
 
     /** {@inheritDoc} */
-    public void startOfNode() throws FOPException {
+    protected void startOfNode() throws FOPException {
         super.startOfNode();
         getFOEventHandler().startCell(this);
     }
 
     /**
      * Make sure content model satisfied, if so then tell the
-     * FOEventHandler that we are at the end of the flow.
+     * FOEventHandler that we are at the end of the table-cell.
      * {@inheritDoc}
      */
-    public void endOfNode() throws FOPException {
+    protected void endOfNode() throws FOPException {
+        super.endOfNode();
+        getFOEventHandler().endCell(this);
+    }
+
+    /** {@inheritDoc} */
+    public void finalizeNode() throws FOPException {
+        
         if (!blockItemFound) {
             missingChildElementError("marker* (%block;)+", true);
         }
@@ -111,9 +118,9 @@
                     getUserAgent().getEventBroadcaster());
             eventProducer.startEndRowUnderTableRowWarning(this, getLocator());
         }
-        getFOEventHandler().endCell(this);
+        
     }
-
+    
     /**
      * {@inheritDoc}
      * <br>XSL Content Model: marker* (%block;)+

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/table/TableFObj.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/table/TableFObj.java?rev=670412&r1=670411&r2=670412&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/table/TableFObj.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/table/TableFObj.java Sun Jun 22 13:57:43 2008
@@ -34,6 +34,8 @@
 import org.apache.fop.fo.properties.Property;
 import org.apache.fop.fo.properties.PropertyMaker;
 import org.apache.fop.layoutmgr.table.CollapsingBorderModel;
+import org.xml.sax.Locator;
+import org.xml.sax.Attributes;
 
 /**
  * Common base class for table-related FOs
@@ -207,8 +209,8 @@
     }
 
     /** {@inheritDoc} */
-    public void startOfNode() throws FOPException {
-        super.startOfNode();
+    public void processNode(String elementName, Locator locator, Attributes attlist, PropertyList pList) throws FOPException {
+        super.processNode(elementName, locator, attlist, pList);
         Table table = getTable();
         if (!inMarker() && !table.isSeparateBorderModel()) {
             collapsingBorderModel = CollapsingBorderModel.getBorderModelFor(table
@@ -216,15 +218,7 @@
             setCollapsedBorders();
         }
     }
-
-    /*
-     * TODO made public so that RetrieveMarker can access it.
-     */
-    /** {@inheritDoc} */
-    public void endOfNode() throws FOPException {
-        super.endOfNode();
-    }
-
+    
     /**
      * Prepares the borders of this element if the collapsing-border model is in use.
      * Conflict resolution with parent elements is done where applicable.

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/table/TableFooter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/table/TableFooter.java?rev=670412&r1=670411&r2=670412&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/table/TableFooter.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/table/TableFooter.java Sun Jun 22 13:57:43 2008
@@ -41,13 +41,13 @@
     }
 
     /** {@inheritDoc} */
-    public void startOfNode() throws FOPException {
+    protected void startOfNode() throws FOPException {
         super.startOfNode();
         getFOEventHandler().startFooter(this);
     }
 
     /** {@inheritDoc} */
-    public void endOfNode() throws FOPException {
+    protected void endOfNode() throws FOPException {
         super.endOfNode();
         getFOEventHandler().endFooter(this);
     }

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/table/TableHeader.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/table/TableHeader.java?rev=670412&r1=670411&r2=670412&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/table/TableHeader.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/table/TableHeader.java Sun Jun 22 13:57:43 2008
@@ -40,13 +40,13 @@
     }
 
     /** {@inheritDoc} */
-    public void startOfNode() throws FOPException {
+    protected void startOfNode() throws FOPException {
         super.startOfNode();
         getFOEventHandler().startHeader(this);
     }
 
     /** {@inheritDoc} */
-    public void endOfNode() throws FOPException {
+    protected void endOfNode() throws FOPException {
         super.endOfNode();
         getFOEventHandler().endHeader(this);
     }

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/table/TablePart.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/table/TablePart.java?rev=670412&r1=670411&r2=670412&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/table/TablePart.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/table/TablePart.java Sun Jun 22 13:57:43 2008
@@ -79,7 +79,8 @@
     public void processNode(String elementName, Locator locator,
                             Attributes attlist, PropertyList pList)
                     throws FOPException {
-
+        
+        super.processNode(elementName, locator, attlist, pList);
         if (!inMarker()) {
             Table t = getTable();
             if (t.hasExplicitColumns()) {
@@ -93,13 +94,11 @@
             }
             columnNumberManager = new ColumnNumberManager();
         }
-        super.processNode(elementName, locator, attlist, pList);
-
+        
     }
 
     /** {@inheritDoc} */
-    public void endOfNode() throws FOPException {
-        super.endOfNode();
+    public void finalizeNode() throws FOPException {
         if (!inMarker()) {
             pendingSpans = null;
             columnNumberManager = null;

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/table/TableRow.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/table/TableRow.java?rev=670412&r1=670411&r2=670412&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/table/TableRow.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/table/TableRow.java Sun Jun 22 13:57:43 2008
@@ -78,12 +78,12 @@
     /** {@inheritDoc} */
     public void processNode(String elementName, Locator locator,
             Attributes attlist, PropertyList pList) throws FOPException {
+        super.processNode(elementName, locator, attlist, pList);
         if (!inMarker()) {
             TablePart part = (TablePart) parent;
             pendingSpans = part.pendingSpans;
             columnNumberManager = part.columnNumberManager;
         }
-        super.processNode(elementName, locator, attlist, pList);
     }
 
     /** {@inheritDoc} */
@@ -97,13 +97,19 @@
     }
 
     /** {@inheritDoc} */
-    public void startOfNode() throws FOPException {
+    protected void startOfNode() throws FOPException {
         super.startOfNode();
         getFOEventHandler().startRow(this);
     }
 
     /** {@inheritDoc} */
-    public void endOfNode() throws FOPException {
+    protected void endOfNode() throws FOPException {
+        super.endOfNode();
+        getFOEventHandler().endRow(this);
+    }
+
+    /** {@inheritDoc} */
+    public void finalizeNode() throws FOPException {
         if (firstChild == null) {
             missingChildElementError("(table-cell+)");
         }
@@ -111,9 +117,8 @@
             pendingSpans = null;
             columnNumberManager = null;
         }
-        getFOEventHandler().endRow(this);
     }
-
+    
     /**
      * {@inheritDoc} String, String)
      * <br>XSL Content Model: (table-cell+)



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org