From a1202a1bee4cc9b60a78696392999a522c5e8bb3 Mon Sep 17 00:00:00 2001 From: Glen Mazza Date: Mon, 6 Dec 2004 05:37:17 +0000 Subject: [PATCH] PR: 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 | 2 +- .../org/apache/fop/area/AreaTreeHandler.java | 20 ++--------- .../fop/area/CachedRenderPagesModel.java | 21 ++++++------ src/java/org/apache/fop/area/Page.java | 12 +++---- .../org/apache/fop/area/PageViewport.java | 33 ++++++++++--------- .../org/apache/fop/area/RenderPagesModel.java | 19 ++++++++--- .../org/apache/fop/area/StorePagesModel.java | 5 +++ 7 files changed, 57 insertions(+), 55 deletions(-) diff --git a/fop.bat b/fop.bat index 459d3d164..b06d59046 100644 --- 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= diff --git a/src/java/org/apache/fop/area/AreaTreeHandler.java b/src/java/org/apache/fop/area/AreaTreeHandler.java index 36f7fe8a1..572793e9b 100644 --- a/src/java/org/apache/fop/area/AreaTreeHandler.java +++ b/src/java/org/apache/fop/area/AreaTreeHandler.java @@ -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) { diff --git a/src/java/org/apache/fop/area/CachedRenderPagesModel.java b/src/java/org/apache/fop/area/CachedRenderPagesModel.java index bc89f1451..18e003cb9 100644 --- a/src/java/org/apache/fop/area/CachedRenderPagesModel.java +++ b/src/java/org/apache/fop/area/CachedRenderPagesModel.java @@ -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(); diff --git a/src/java/org/apache/fop/area/Page.java b/src/java/org/apache/fop/area/Page.java index 4eca122e2..9c1a1aafd 100644 --- a/src/java/org/apache/fop/area/Page.java +++ b/src/java/org/apache/fop/area/Page.java @@ -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; } } diff --git a/src/java/org/apache/fop/area/PageViewport.java b/src/java/org/apache/fop/area/PageViewport.java index fdcbf26c2..94d0b9f94 100644 --- a/src/java/org/apache/fop/area/PageViewport.java +++ b/src/java/org/apache/fop/area/PageViewport.java @@ -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(); diff --git a/src/java/org/apache/fop/area/RenderPagesModel.java b/src/java/org/apache/fop/area/RenderPagesModel.java index ad8a125b6..8a188b99b 100644 --- a/src/java/org/apache/fop/area/RenderPagesModel.java +++ b/src/java/org/apache/fop/area/RenderPagesModel.java @@ -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(); diff --git a/src/java/org/apache/fop/area/StorePagesModel.java b/src/java/org/apache/fop/area/StorePagesModel.java index e293d5faf..922e29441 100644 --- a/src/java/org/apache/fop/area/StorePagesModel.java +++ b/src/java/org/apache/fop/area/StorePagesModel.java @@ -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 */ -- 2.39.5