You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by je...@apache.org on 2005/12/09 10:35:15 UTC

svn commit: r355428 - in /xmlgraphics/fop/trunk/src/java/org/apache/fop/fo: FONode.java FOTreeBuilder.java expr/PropertyException.java pagination/LayoutMasterSet.java pagination/PageSequence.java properties/PropertyMaker.java

Author: jeremias
Date: Fri Dec  9 01:34:49 2005
New Revision: 355428

URL: http://svn.apache.org/viewcvs?rev=355428&view=rev
Log:
Made the locator variable on FONode protected.
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.

Modified:
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/FONode.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/FOTreeBuilder.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/PropertyException.java   (contents, props changed)
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/pagination/LayoutMasterSet.java   (contents, props changed)
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/pagination/PageSequence.java   (contents, props changed)
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/PropertyMaker.java

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/FONode.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/FONode.java?rev=355428&r1=355427&r2=355428&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/FONode.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/FONode.java Fri Dec  9 01:34:49 2005
@@ -23,6 +23,7 @@
 
 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 @@
     /** 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 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);
         }
     }
 

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/FOTreeBuilder.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/FOTreeBuilder.java?rev=355428&r1=355427&r2=355428&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/FOTreeBuilder.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/FOTreeBuilder.java Fri Dec  9 01:34:49 2005
@@ -185,6 +185,18 @@
     }
 
     /**
+     * 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 @@
         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 @@
         throws FOPException {
             if (currentFObj != null) {
                 currentFObj.addCharacters(data, start, start + length, 
-                        currentPropertyList, locator);
+                        currentPropertyList, getEffectiveLocator());
             }
     }
 
@@ -270,7 +287,7 @@
         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);

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/PropertyException.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/PropertyException.java?rev=355428&r1=355427&r2=355428&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/PropertyException.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/PropertyException.java Fri Dec  9 01:34:49 2005
@@ -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 @@
     }
 
     /**
+     * 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 + "'";

Propchange: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/PropertyException.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/pagination/LayoutMasterSet.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/pagination/LayoutMasterSet.java?rev=355428&r1=355427&r2=355428&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/pagination/LayoutMasterSet.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/pagination/LayoutMasterSet.java Fri Dec  9 01:34:49 2005
@@ -143,7 +143,7 @@
             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 @@
             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);
     }

Propchange: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/pagination/LayoutMasterSet.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/pagination/PageSequence.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/pagination/PageSequence.java?rev=355428&r1=355427&r2=355428&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/pagination/PageSequence.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/pagination/PageSequence.java Fri Dec  9 01:34:49 2005
@@ -219,7 +219,7 @@
         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 @@
                 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());
         }
     }
 

Propchange: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/pagination/PageSequence.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/PropertyMaker.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/PropertyMaker.java?rev=355428&r1=355427&r2=355428&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/PropertyMaker.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/PropertyMaker.java Fri Dec  9 01:34:49 2005
@@ -431,7 +431,7 @@
             }
             return newProp;
         } catch (PropertyException propEx) {
-            propEx.setLocator(fo.locator);
+            propEx.setLocator(fo.getLocator());
             propEx.setPropertyName(getName());
             throw propEx;
         }



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org