]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
PR:
authorGlen Mazza <gmazza@apache.org>
Mon, 6 Dec 2004 05:37:17 +0000 (05:37 +0000)
committerGlen Mazza <gmazza@apache.org>
Mon, 6 Dec 2004 05:37:17 +0000 (05:37 +0000)
Obtained from:
Submitted by:
Reviewed by:
Removed pretend "resolution" of still-unresolved idrefs at ATH.endDocument().  This was apparently done to force page rendering of remaining unresolved pages at RenderPagesModel.checkPreparedPages() (which requires a page to be completely resolved before rendering).  Replacement code keeps unresolved idrefs unresolved, but explicitly forces page rendering for calls to checkPreparedPages() that originate from ATH.endDocument().  Comments welcome.

git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@198187 13f79535-47bb-0310-9956-ffa450edef68

fop.bat
src/java/org/apache/fop/area/AreaTreeHandler.java
src/java/org/apache/fop/area/CachedRenderPagesModel.java
src/java/org/apache/fop/area/Page.java
src/java/org/apache/fop/area/PageViewport.java
src/java/org/apache/fop/area/RenderPagesModel.java
src/java/org/apache/fop/area/StorePagesModel.java

diff --git a/fop.bat b/fop.bat
index 459d3d164dfb922de24c7dc43faa55e994e67676..b06d590461933cc8a68e6f156ce5a879e2e7940d 100644 (file)
--- a/fop.bat
+++ b/fop.bat
@@ -25,7 +25,7 @@ set LOGCHOICE=
 rem The default commons logger for JDK1.4 is JDK1.4Logger.
 rem To use a different logger, uncomment the one desired below
 rem set LOGCHOICE=-Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.NoOpLog
-rem set LOGCHOICE=-Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.SimpleLog
+set LOGCHOICE=-Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.SimpleLog
 rem set LOGCHOICE=-Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JLogger
 
 set LOGLEVEL=
index 36f7fe8a1a202ac9019dd3e68f3f5355fa3614ff..572793e9bff6d81ba8b830362fe325146ec10e85 100644 (file)
@@ -31,6 +31,8 @@ import java.util.Iterator;
 import org.xml.sax.SAXException;
 
 // Apache
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.fop.apps.FOPException;
 import org.apache.fop.apps.FOUserAgent;
 import org.apache.fop.fo.FOEventHandler;
@@ -38,8 +40,6 @@ import org.apache.fop.fo.extensions.Outline;
 import org.apache.fop.fo.extensions.Bookmarks;
 import org.apache.fop.fo.pagination.PageSequence;
 import org.apache.fop.layoutmgr.PageSequenceLayoutManager;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 
 /**
  * Area tree handler for formatting objects.
@@ -193,22 +193,6 @@ public class AreaTreeHandler extends FOEventHandler {
      * @throws SAXException if there is some error
      */
     public void endDocument() throws SAXException {
-        /* 
-         * inform Resolveable objects that certain idrefs
-         * could not be found
-         * @todo unsure if this block is needed. 
-         */
-        for (Iterator iter = unresolvedIDRefs.keySet().iterator(); 
-                iter.hasNext();) {
-            String idref = (String) iter.next();
-            Set list = (Set) unresolvedIDRefs.get(idref);
-            for (Iterator resIter = list.iterator(); resIter.hasNext();) {
-                Resolvable res = (Resolvable) resIter.next();
-                if (!res.isResolved()) {
-                    res.resolveIDRef(idref, null);
-                }
-            }
-        }
         model.endDocument();
 
         if (outputStatistics) {
index bc89f1451c9fb78f85a23b79681b18507f1338a7..18e003cb97b5d014d2d7db4a4e5b79a7b3a2c737 100644 (file)
@@ -54,19 +54,12 @@ public class CachedRenderPagesModel extends RenderPagesModel {
     }
 
     /**
-     * Check prepared pages
-     * If a page is resolved it loads the page contents from
-     * the file.
-     *
-     * @param newpage the new page being added
-     * @return true if the current page should be rendered
-     *         false if the renderer doesn't support out of order
-     *         rendering and there are pending pages
+     * @see org.apache.fop.area.RenderPagesModel#checkPreparedPages(PageViewport, boolean)
      */
-    protected boolean checkPreparedPages(PageViewport newpage) {
+    protected boolean checkPreparedPages(PageViewport newpage, boolean renderUnresolved) {
         for (Iterator iter = prepared.iterator(); iter.hasNext();) {
             PageViewport p = (PageViewport)iter.next();
-            if (p.isResolved()) {
+            if (p.isResolved() || renderUnresolved) {
                 if (p != newpage) {
                     try {
                         // load page from cache
@@ -87,6 +80,14 @@ public class CachedRenderPagesModel extends RenderPagesModel {
 
                 try {
                     renderer.renderPage(p);
+                    if (!p.isResolved()) {
+                        String[] idrefs = p.getIDs();
+                        for (int count = 0; count < idrefs.length; count++) {
+                            log.warn("Page " + p.getPageNumber() + 
+                                ": Unresolved id reference \"" + idrefs[count] 
+                                + "\" found.");
+                        }
+                    }
                 } catch (Exception e) {
                     // use error handler to handle this FOP or IO Exception
                     e.printStackTrace();
index 4eca122e2ffcea3a13645ccd1a3f71ed0ce8ccb3..9c1a1aafd3c98ae68edfd50c606066847928a588 100644 (file)
@@ -19,7 +19,7 @@
 package org.apache.fop.area;
 
 import java.io.Serializable;
-import java.util.Map;
+import java.util.HashMap;
 
 import org.apache.fop.fo.Constants;
 
@@ -43,7 +43,7 @@ public class Page implements Serializable, Cloneable {
     private RegionViewport regionAfter = null;
 
     // temporary map of unresolved objects used when serializing the page
-    private Map unresolved = null;
+    private HashMap unresolved = null;
 
     /**
      * Set the region on this page.
@@ -132,9 +132,9 @@ public class Page implements Serializable, Cloneable {
     /**
      * Set the unresolved references on this page for serializing.
      *
-     * @param unres the map of unresolved objects
+     * @param unres the HashMap of unresolved objects
      */
-    public void setUnresolvedReferences(Map unres) {
+    public void setUnresolvedReferences(HashMap unres) {
         unresolved = unres;
     }
 
@@ -143,9 +143,9 @@ public class Page implements Serializable, Cloneable {
      * This should be called after deserializing to retrieve
      * the map of unresolved references that were serialized.
      *
-     * @return the de-serialized map of unresolved objects
+     * @return the de-serialized HashMap of unresolved objects
      */
-    public Map getUnresolvedReferences() {
+    public HashMap getUnresolvedReferences() {
         return unresolved;
     }
 }
index fdcbf26c2d4e705202a63232b9667efd8495d926..94d0b9f94dd1aedf458fc96a8f7a787204d6d013 100644 (file)
@@ -50,10 +50,8 @@ public class PageViewport implements Resolvable, Cloneable {
     // this keeps a list of currently unresolved areas or extensions
     // once an idref is resolved it is removed
     // when this is empty the page can be rendered
-    private Map unresolvedIDRefs = new HashMap();
+    private HashMap unresolvedIDRefs = new HashMap();
     
-    private Map unresolved = null;
-
     private Map pendingResolved = null;
 
     // hashmap of markers for this page
@@ -126,12 +124,14 @@ public class PageViewport implements Resolvable, Cloneable {
     }
 
     /**
-     * Add an unresolved id to this page.
-     * All unresolved ids for the contents of this page are
-     * added to this page. This is so that the resolvers can be
-     * serialized with the page to preserve the proper function.
-     * @param id the id of the reference
-     * @param res the resolver of the reference
+     * Add an idref to this page.
+     * All idrefs found for child areas of this PageViewport are added
+     * to unresolvedIDRefs, for subsequent resolution by AreaTreeHandler
+     * calls to this object's resolveIDRef().
+     *
+     * @param id the idref
+     * @param res the child element of this page that needs this
+     *      idref resolved
      */
     public void addUnresolvedIDRef(String idref, Resolvable res) {
         if (unresolvedIDRefs == null) {
@@ -154,11 +154,12 @@ public class PageViewport implements Resolvable, Cloneable {
     }
 
     /**
-     * Get the id references for this page.
-     * @return always null
+     * Get the unresolved idrefs for this page.
+     * @return String array of idref's that still have not been resolved
      */
     public String[] getIDs() {
-        return null;
+        return (unresolvedIDRefs == null) ? null :
+            (String[]) unresolvedIDRefs.keySet().toArray(new String[] {});
     }
 
     /**
@@ -181,7 +182,7 @@ public class PageViewport implements Resolvable, Cloneable {
                 }
             }
         }
-        if (unresolvedIDRefs != null) {
+        if (unresolvedIDRefs != null && pages != null) {
             unresolvedIDRefs.remove(id);
             if (unresolvedIDRefs.isEmpty()) {
                 unresolvedIDRefs = null;
@@ -315,7 +316,7 @@ public class PageViewport implements Resolvable, Cloneable {
      */
     public void savePage(ObjectOutputStream out) throws Exception {
         // set the unresolved references so they are serialized
-        page.setUnresolvedReferences(unresolved);
+        page.setUnresolvedReferences(unresolvedIDRefs);
         out.writeObject(page);
         page = null;
     }
@@ -330,8 +331,8 @@ public class PageViewport implements Resolvable, Cloneable {
      */
     public void loadPage(ObjectInputStream in) throws Exception {
         page = (Page) in.readObject();
-        unresolved = page.getUnresolvedReferences();
-        if (unresolved != null && pendingResolved != null) {
+        unresolvedIDRefs = page.getUnresolvedReferences();
+        if (unresolvedIDRefs != null && pendingResolved != null) {
             for (Iterator iter = pendingResolved.keySet().iterator();
                          iter.hasNext();) {
                 String id = (String) iter.next();
index ad8a125b6e27a42d3b3fcf8e53ff2db455816dff..8a188b99bd17a03037c5c050cf027d3def130d7e 100644 (file)
@@ -123,7 +123,7 @@ public class RenderPagesModel extends StorePagesModel {
 
 
         // check prepared pages
-        boolean cont = checkPreparedPages(page);
+        boolean cont = checkPreparedPages(page, false);
 
         if (cont) {
             processOffDocumentItems(pendingODI);
@@ -135,16 +135,27 @@ public class RenderPagesModel extends StorePagesModel {
      * Check prepared pages
      *
      * @param newpage the new page being added
+     * @param renderUnresolved render pages with unresolved idref's
+     *          (done at end-of-document processing)
      * @return true if the current page should be rendered
      *         false if the renderer doesn't support out of order
      *         rendering and there are pending pages
      */
-    protected boolean checkPreparedPages(PageViewport newpage) {
+    protected boolean checkPreparedPages(PageViewport newpage, boolean
+        renderUnresolved) {
         for (Iterator iter = prepared.iterator(); iter.hasNext();) {
             PageViewport p = (PageViewport)iter.next();
-            if (p.isResolved()) {
+            if (p.isResolved() || renderUnresolved) {
                 try {
                     renderer.renderPage(p);
+                    if (!p.isResolved()) {
+                        String[] idrefs = p.getIDs();
+                        for (int count = 0; count < idrefs.length; count++) {
+                            log.warn("Page " + p.getPageNumber() + 
+                                ": Unresolved id reference \"" + idrefs[count] 
+                                + "\" found.");
+                        }
+                    }
                 } catch (Exception e) {
                     // use error handler to handle this FOP or IO Exception
                     e.printStackTrace();
@@ -204,7 +215,7 @@ public class RenderPagesModel extends StorePagesModel {
      */
     public void endDocument() throws SAXException {
         // render any pages that had unresolved ids
-        checkPreparedPages(null);
+        checkPreparedPages(null, true);
 
         processOffDocumentItems(pendingODI);
         pendingODI.clear();
index e293d5faf4de3cdf4e127683ec16e9129795f287..922e29441d391c07e5b018782e388ed77af41448 100644 (file)
@@ -24,6 +24,9 @@ import java.util.List;
 // XML
 import org.xml.sax.SAXException;
 
+// Apache
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 /**
  * This class stores all the pages in the document
@@ -35,6 +38,8 @@ public class StorePagesModel extends AreaTreeModel {
     private List currSequence;
     private List offDocumentItems = new java.util.ArrayList();
 
+    protected static Log log = LogFactory.getLog(StorePagesModel.class);
+
     /**
      * Create a new store pages model
      */