Browse Source

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.

git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@355428 13f79535-47bb-0310-9956-ffa450edef68
tags/fop-0_91-beta
Jeremias Maerki 18 years ago
parent
commit
1c6a45bc0c

+ 7
- 4
src/java/org/apache/fop/fo/FONode.java View 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);
}
}


+ 19
- 2
src/java/org/apache/fop/fo/FOTreeBuilder.java View 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);

+ 7
- 2
src/java/org/apache/fop/fo/expr/PropertyException.java View 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 + "'";

+ 2
- 2
src/java/org/apache/fop/fo/pagination/LayoutMasterSet.java View 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);
}

+ 2
- 2
src/java/org/apache/fop/fo/pagination/PageSequence.java View 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());
}
}


+ 1
- 1
src/java/org/apache/fop/fo/properties/PropertyMaker.java View 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;
}

Loading…
Cancel
Save