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;
/** 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);
*/
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);
}
}
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)
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)
throws FOPException {
if (currentFObj != null) {
currentFObj.addCharacters(data, start, start + length,
- currentPropertyList, locator);
+ currentPropertyList, getEffectiveLocator());
}
}
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);
/*
- * 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.
}
/**
+ * 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 + "'";
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);
}
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);
}
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)
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());
}
}
}
return newProp;
} catch (PropertyException propEx) {
- propEx.setLocator(fo.locator);
+ propEx.setLocator(fo.getLocator());
propEx.setPropertyName(getName());
throw propEx;
}