diff options
6 files changed, 47 insertions, 56 deletions
diff --git a/src/java/org/apache/fop/area/AreaTreeHandler.java b/src/java/org/apache/fop/area/AreaTreeHandler.java index 911def5be..abd9f529a 100644 --- a/src/java/org/apache/fop/area/AreaTreeHandler.java +++ b/src/java/org/apache/fop/area/AreaTreeHandler.java @@ -60,8 +60,9 @@ import org.apache.commons.logging.LogFactory; */ public class AreaTreeHandler extends FOEventHandler { - // TODO: Collecting of statistics should be configurable - private final boolean collectStatistics = true; + // show statistics after document complete? + private boolean outputStatistics; + private static final boolean MEM_PROFILE_WITH_GC = false; // for statistics gathering @@ -82,8 +83,9 @@ public class AreaTreeHandler extends FOEventHandler { // hashmap of arraylists containing pages with id area private Map idLocations = new HashMap(); - // list of id's yet to be resolved and arraylists of pages - private Map resolve = new HashMap(); + // idref's whose corresponding id's have yet to be found + // Each idref has a HashSet of Resolvable objects containing that idref + private Map unresolvedIDRefs = new HashMap(); private static Log log = LogFactory.getLog(AreaTreeHandler.class); @@ -98,12 +100,12 @@ public class AreaTreeHandler extends FOEventHandler { OutputStream stream) throws FOPException { super(userAgent); - // model = new CachedRenderPagesModel(userAgent, renderType, - // fontInfo, stream); model = new RenderPagesModel(userAgent, renderType, fontInfo, stream); - if (collectStatistics) { + outputStatistics = log.isDebugEnabled(); + + if (outputStatistics) { runtime = Runtime.getRuntime(); } } @@ -130,13 +132,13 @@ public class AreaTreeHandler extends FOEventHandler { } list.add(pv); - Set todo = (Set)resolve.get(id); + Set todo = (Set) unresolvedIDRefs.get(id); if (todo != null) { for (Iterator iter = todo.iterator(); iter.hasNext();) { Resolvable res = (Resolvable)iter.next(); res.resolve(id, list); } - resolve.remove(id); + unresolvedIDRefs.remove(id); } } @@ -150,16 +152,17 @@ public class AreaTreeHandler extends FOEventHandler { } /** - * Add an unresolved object with a given id. - * @param id the id reference that needs resolving - * @param res the Resolvable object to resolve + * Add an Resolvable object with an unresolved idref + * @param idref the idref whose target id has not yet been located + * @param res the Resolvable object with the unresolved idref */ - public void addUnresolvedID(String id, Resolvable res) { - Set todo = (Set)resolve.get(id); + public void addUnresolvedIDRef(String idref, Resolvable res) { + Set todo = (Set) unresolvedIDRefs.get(idref); if (todo == null) { todo = new HashSet(); - resolve.put(id, todo); + unresolvedIDRefs.put(idref, todo); } + // add Resolvable object to this HashSet todo.add(res); } @@ -171,7 +174,7 @@ public class AreaTreeHandler extends FOEventHandler { */ public void startDocument() throws SAXException { //Initialize statistics - if (collectStatistics) { + if (outputStatistics) { pageCount = 0; if (MEM_PROFILE_WITH_GC) { System.gc(); // This takes time but gives better results @@ -189,9 +192,10 @@ public class AreaTreeHandler extends FOEventHandler { */ public void endDocument() throws SAXException { // deal with unresolved references - for (Iterator iter = resolve.keySet().iterator(); iter.hasNext();) { + for (Iterator iter = unresolvedIDRefs.keySet().iterator(); + iter.hasNext();) { String id = (String)iter.next(); - Set list = (Set)resolve.get(id); + Set list = (Set) unresolvedIDRefs.get(id); for (Iterator resIter = list.iterator(); resIter.hasNext();) { Resolvable res = (Resolvable)resIter.next(); if (!res.isResolved()) { @@ -201,7 +205,7 @@ public class AreaTreeHandler extends FOEventHandler { } model.endDocument(); - if (collectStatistics) { + if (outputStatistics) { if (MEM_PROFILE_WITH_GC) { // This takes time but gives better results System.gc(); @@ -209,18 +213,18 @@ public class AreaTreeHandler extends FOEventHandler { long memoryNow = runtime.totalMemory() - runtime.freeMemory(); long memoryUsed = (memoryNow - initialMemory) / 1024L; long timeUsed = System.currentTimeMillis() - startTime; - if (logger != null && logger.isDebugEnabled()) { - logger.debug("Initial heap size: " + (initialMemory / 1024L) + "Kb"); - logger.debug("Current heap size: " + (memoryNow / 1024L) + "Kb"); - logger.debug("Total memory used: " + memoryUsed + "Kb"); + if (log != null && log.isDebugEnabled()) { + log.debug("Initial heap size: " + (initialMemory / 1024L) + "Kb"); + log.debug("Current heap size: " + (memoryNow / 1024L) + "Kb"); + log.debug("Total memory used: " + memoryUsed + "Kb"); if (!MEM_PROFILE_WITH_GC) { - logger.debug(" Memory use is indicative; no GC was performed"); - logger.debug(" These figures should not be used comparatively"); + log.debug(" Memory use is indicative; no GC was performed"); + log.debug(" These figures should not be used comparatively"); } - logger.debug("Total time used: " + timeUsed + "ms"); - logger.debug("Pages rendered: " + pageCount); + log.debug("Total time used: " + timeUsed + "ms"); + log.debug("Pages rendered: " + pageCount); if (pageCount > 0) { - logger.debug("Avg render time: " + (timeUsed / pageCount) + "ms/page"); + log.debug("Avg render time: " + (timeUsed / pageCount) + "ms/page"); } } } @@ -235,14 +239,14 @@ public class AreaTreeHandler extends FOEventHandler { */ public void endPageSequence(PageSequence pageSequence) { - if (collectStatistics) { + if (outputStatistics) { if (MEM_PROFILE_WITH_GC) { // This takes time but gives better results System.gc(); } long memoryNow = runtime.totalMemory() - runtime.freeMemory(); - if (logger != null) { - logger.debug("Current heap size: " + (memoryNow / 1024L) + "Kb"); + if (log != null) { + log.debug("Current heap size: " + (memoryNow / 1024L) + "Kb"); } } @@ -307,10 +311,10 @@ public class AreaTreeHandler extends FOEventHandler { if (idLocations.containsKey(ids[count])) { res.resolve(ids[count], (List)idLocations.get(ids[count])); } else { - Set todo = (Set)resolve.get(ids[count]); + Set todo = (Set) unresolvedIDRefs.get(ids[count]); if (todo == null) { todo = new HashSet(); - resolve.put(ids[count], todo); + unresolvedIDRefs.put(ids[count], todo); } todo.add(ext); } diff --git a/src/java/org/apache/fop/area/PageViewport.java b/src/java/org/apache/fop/area/PageViewport.java index c26104ae8..a0bbe6a58 100644 --- a/src/java/org/apache/fop/area/PageViewport.java +++ b/src/java/org/apache/fop/area/PageViewport.java @@ -131,7 +131,7 @@ public class PageViewport implements Resolvable, Cloneable { * @param id the id of the reference * @param res the resolver of the reference */ - public void addUnresolvedID(String id, Resolvable res) { + public void addUnresolvedIDRef(String id, Resolvable res) { if (unresolved == null) { unresolved = new HashMap(); } diff --git a/src/java/org/apache/fop/area/Resolvable.java b/src/java/org/apache/fop/area/Resolvable.java index 972aee99a..61de613a0 100644 --- a/src/java/org/apache/fop/area/Resolvable.java +++ b/src/java/org/apache/fop/area/Resolvable.java @@ -21,9 +21,9 @@ package org.apache.fop.area; import java.util.List; /** - * Resolvable Interface. - * Classes that implement this can be resolved when - * an id is added to the area tree. + * Resolvable Interface. Classes that implement this interface contain + * idrefs (see Section 5.11 of spec for definition of <idref> datatype) + * that are resolved when their target IDs are added to the area tree. */ public interface Resolvable { @@ -35,9 +35,9 @@ public interface Resolvable { boolean isResolved(); /** - * Get the array of id references of this resolvable object. + * Get the array of idrefs of this resolvable object. * If this object contains child resolvables that are - * resolved through this then it should return the id's of + * resolved through this then it should return the idref's of * the child also. * * @return the id references for resolving this object diff --git a/src/java/org/apache/fop/fo/FOEventHandler.java b/src/java/org/apache/fop/fo/FOEventHandler.java index 24123c223..8d38503c4 100644 --- a/src/java/org/apache/fop/fo/FOEventHandler.java +++ b/src/java/org/apache/fop/fo/FOEventHandler.java @@ -46,8 +46,6 @@ import org.apache.fop.fo.flow.TableRow; import org.apache.fop.fo.pagination.Flow; import org.apache.fop.fo.pagination.PageSequence; import org.apache.fop.fonts.FontInfo; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; /** @@ -73,9 +71,6 @@ public abstract class FOEventHandler { */ protected FontInfo fontInfo; - /** Logger for FOEventHandler-related messages **/ - protected static Log logger = LogFactory.getLog(FOEventHandler.class); - /** * The current set of id's in the FO tree. * This is used so we know if the FO tree contains duplicates. @@ -105,14 +100,6 @@ public abstract class FOEventHandler { } /** - * Returns the Commons-Logging instance for this class - * @return The Commons-Logging instance - */ - protected Log getLogger(Log logger) { - return logger; - } - - /** * Returns the User Agent object associated with this FOEventHandler. * @return the User Agent object */ diff --git a/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java b/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java index c2c24efb0..a7ff35a26 100644 --- a/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java @@ -340,8 +340,8 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager implements public void addUnresolvedArea(String id, Resolvable res) { // add unresolved to tree // adds to the page viewport so it can serialize - curPage.addUnresolvedID(id, res); - areaTreeHandler.addUnresolvedID(id, curPage); + curPage.addUnresolvedIDRef(id, res); + areaTreeHandler.addUnresolvedIDRef(id, curPage); } /** diff --git a/src/java/org/apache/fop/render/rtf/RTFHandler.java b/src/java/org/apache/fop/render/rtf/RTFHandler.java index 21e2ad33b..3a2dc9fd9 100644 --- a/src/java/org/apache/fop/render/rtf/RTFHandler.java +++ b/src/java/org/apache/fop/render/rtf/RTFHandler.java @@ -24,8 +24,8 @@ import java.io.OutputStream; import java.io.OutputStreamWriter; import java.util.Iterator; -import org.apache.commons.logging.impl.SimpleLog; 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; @@ -95,7 +95,7 @@ public class RTFHandler extends FOEventHandler { private RtfFile rtfFile; private final OutputStream os; - private final Log log = new SimpleLog("FOP/RTF"); + private static Log log = LogFactory.getLog(RTFHandler.class); private RtfSection sect; private RtfDocumentArea docArea; private int iNestCount; |