]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Made the locator variable on FONode protected.
authorJeremias Maerki <jeremias@apache.org>
Fri, 9 Dec 2005 09:34:49 +0000 (09:34 +0000)
committerJeremias Maerki <jeremias@apache.org>
Fri, 9 Dec 2005 09:34:49 +0000 (09:34 +0000)
Locator information is duplicated using SAX's LocatorImpl. Otherwise, the info returned by the Locator information is only valid during FO tree building and validation.
If desired code could be added to disable storing locator information even if it is available to use less memory (one LocatorImpl instance per FO tree node) in FOTreeBuilder.

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

src/java/org/apache/fop/fo/FONode.java
src/java/org/apache/fop/fo/FOTreeBuilder.java
src/java/org/apache/fop/fo/expr/PropertyException.java
src/java/org/apache/fop/fo/pagination/LayoutMasterSet.java
src/java/org/apache/fop/fo/pagination/PageSequence.java
src/java/org/apache/fop/fo/properties/PropertyMaker.java

index caab92318e3978434fe741335a3dffd10b71adcd..5832abe47326e9ef8e8e83c413859e24f042c7d2 100644 (file)
@@ -23,6 +23,7 @@ import java.util.ListIterator;
 
 import org.xml.sax.Attributes;
 import org.xml.sax.Locator;
+import org.xml.sax.helpers.LocatorImpl;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -46,13 +47,13 @@ public abstract class FONode implements Cloneable {
     /** Parent FO node */
     protected FONode parent;
 
-    /**  Marks location of this object from the input FO
+    /** 
+     * Marks location of this object from the input FO
      *   Call locator.getSystemId(), getLineNumber(),
      *   getColumnNumber() for file, line, column
      *   information
      */
-    public Locator locator;
-    //TODO Make private or protected and access via getLocator()
+    protected Locator locator;
 
     /** Logger for fo-tree related messages **/
     protected static Log log = LogFactory.getLog(FONode.class);
@@ -102,7 +103,9 @@ public abstract class FONode implements Cloneable {
      */
     public void setLocator(Locator locator) {
         if (locator != null) {
-            this.locator = locator;
+            //Create a copy of the locator so the info is preserved when we need to
+            //give pointers during layout.
+            this.locator = new LocatorImpl(locator);
         }
     }
 
index bd8017e76c41bbaabbae189a038d327a17483a4a..cc87fcca91c036952c56125386dc6eb1f7a3ac34 100644 (file)
@@ -184,6 +184,18 @@ public class FOTreeBuilder extends DefaultHandler {
         this.namespaces.add(mapping.getNamespaceURI().intern());
     }
 
+    /**
+     * This method enables to reduce memory consumption of the FO tree slightly. When it returns
+     * true no Locator is passed to the FO tree nodes which would copy the information into
+     * a SAX LocatorImpl instance.
+     * @return true if no context information should be stored on each node in the FO tree.
+     */
+    protected boolean isLocatorDisabled() {
+        //TODO make this configurable through the FOUserAgent so people can optimize memory
+        //consumption.
+        return false;
+    }
+    
     /**
      * SAX Handler for locator
      * @see org.xml.sax.ContentHandler#setDocumentLocator(Locator)
@@ -192,6 +204,11 @@ public class FOTreeBuilder extends DefaultHandler {
         this.locator = locator;
     }
     
+    /** @return a Locator instance if it is available and not disabled */
+    protected Locator getEffectiveLocator() {
+        return (isLocatorDisabled() ? null : this.locator);
+    }
+    
     /**
      * SAX Handler for characters
      * @see org.xml.sax.ContentHandler#characters(char[], int, int)
@@ -200,7 +217,7 @@ public class FOTreeBuilder extends DefaultHandler {
         throws FOPException {
             if (currentFObj != null) {
                 currentFObj.addCharacters(data, start, start + length, 
-                        currentPropertyList, locator);
+                        currentPropertyList, getEffectiveLocator());
             }
     }
 
@@ -270,7 +287,7 @@ public class FOTreeBuilder extends DefaultHandler {
         try {
             foNode = fobjMaker.make(currentFObj);
             propertyList = foNode.createPropertyList(currentPropertyList, foEventHandler);
-            foNode.processNode(localName, locator, attlist, propertyList);
+            foNode.processNode(localName, getEffectiveLocator(), attlist, propertyList);
             foNode.startOfNode();
         } catch (IllegalArgumentException e) {
             throw new SAXException(e);
index 9ce3224b8f4b8e52a4555e96fcacbbe558d53046..696412c88a8b265d4e1cd0c05aa40f2296df01b7 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 1999-2004 The Apache Software Foundation.
+ * Copyright 1999-2005 The Apache Software Foundation.
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -35,18 +35,23 @@ public class PropertyException extends FOPException {
     }
 
     /**
+     * Sets the property context information.
+     * @param propInfo the property info instance
      */
     public void setPropertyInfo(PropertyInfo propInfo) {
-        setLocator(propInfo.getFO().locator);
+        setLocator(propInfo.getFO().getLocator());
         propertyName = propInfo.getPropertyMaker().getName();
     }
 
     /**
+     * Sets the name of the property.
+     * @param propertyName the property name
      */
     public void setPropertyName(String propertyName) {
         this.propertyName = propertyName;
     }
 
+    /** @see java.lang.Throwable#getMessage()*/
     public String getMessage() {
         if (propertyName != null) {
             return super.getMessage() + "; property:'" + propertyName + "'";
index 76b9ffd96d214916529241f9f4a2554494014d48..a98f3a0fff476e1b7f618f26ff49dffbd337ea95 100644 (file)
@@ -143,7 +143,7 @@ public class LayoutMasterSet extends FObj {
             throw new ValidationException("'master-name' ("
                + masterName
                + ") must be unique "
-               + "across page-masters and page-sequence-masters", sPM.locator);
+               + "across page-masters and page-sequence-masters", sPM.getLocator());
         }
         this.simplePageMasters.put(masterName, sPM);
     }
@@ -183,7 +183,7 @@ public class LayoutMasterSet extends FObj {
             throw new ValidationException("'master-name' ("
                + masterName
                + ") must be unique "
-               + "across page-masters and page-sequence-masters", pSM.locator);
+               + "across page-masters and page-sequence-masters", pSM.getLocator());
         }
         this.pageSequenceMasters.put(masterName, pSM);
     }
index e06eeb278e733ae13f647ac04240cfa99958fecb..1066b67e104bccc8e4db0e5a10e9d3c18a1cfb08 100644 (file)
@@ -219,7 +219,7 @@ public class PageSequence extends FObj {
         if (hasFlowName(flowName)) {
             throw new ValidationException("duplicate flow-name \""
                 + flowName
-                + "\" found within fo:page-sequence", flow.locator);
+                + "\" found within fo:page-sequence", flow.getLocator());
         }
 
         if (!root.getLayoutMasterSet().regionNameExists(flowName) 
@@ -228,7 +228,7 @@ public class PageSequence extends FObj {
                 throw new ValidationException("flow-name \""
                     + flowName
                     + "\" could not be mapped to a region-name in the"
-                    + " layout-master-set", flow.locator);
+                    + " layout-master-set", flow.getLocator());
         }
     }
 
index cd36323ab61e28d24278d70605d74dd01238d3ee..40e9b7b98c1574a695e5367c55556c4b54547664 100644 (file)
@@ -431,7 +431,7 @@ public class PropertyMaker implements Cloneable {
             }
             return newProp;
         } catch (PropertyException propEx) {
-            propEx.setLocator(fo.locator);
+            propEx.setLocator(fo.getLocator());
             propEx.setPropertyName(getName());
             throw propEx;
         }