]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
PR:
authorGlen Mazza <gmazza@apache.org>
Sat, 27 Nov 2004 19:58:35 +0000 (19:58 +0000)
committerGlen Mazza <gmazza@apache.org>
Sat, 27 Nov 2004 19:58:35 +0000 (19:58 +0000)
Obtained from:
Submitted by:
Reviewed by:
Removed unused logger from FOEventHandler and commented the AreaTreeHandler
to make it more understandable (particularily idref resolving code.)

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

src/java/org/apache/fop/area/AreaTreeHandler.java
src/java/org/apache/fop/area/PageViewport.java
src/java/org/apache/fop/area/Resolvable.java
src/java/org/apache/fop/fo/FOEventHandler.java
src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java
src/java/org/apache/fop/render/rtf/RTFHandler.java

index 911def5bed4a46878c44283910f87fde11f30e13..abd9f529a00bf2204148ea9c515cb2cf8cb1c2e2 100644 (file)
@@ -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);
                 }
index c26104ae83b7c06f1baccba0b1241817c9c52dba..a0bbe6a5878852fd2fafe4d1e757746c6b97c564 100644 (file)
@@ -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();
         }
index 972aee99aa02488e1ce4a74b4f9a99e04f7936c8..61de613a084961c0ff5912ec0e8d17d353994ed8 100644 (file)
@@ -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
index 24123c223264b850895d30fe089489f358eb9072..8d38503c4c37ed120d275bcb858cc4ad06ff6d50 100644 (file)
@@ -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.
@@ -104,14 +99,6 @@ public abstract class FOEventHandler {
         return idReferences;
     }
 
-    /**
-     * 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
index c2c24efb01fb471abb7137ea3418dc007537a250..a7ff35a26b3aafb94cd7d844876e4d00f75d897e 100644 (file)
@@ -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);
     }
 
     /**
index 21e2ad33bf1dcc47f45f36e0128f3343e84321e5..3a2dc9fd97c4f6afda0ef4d0dd510527b74588db 100644 (file)
@@ -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;