diff options
author | Finn Bock <bckfnn@apache.org> | 2004-10-19 12:52:09 +0000 |
---|---|---|
committer | Finn Bock <bckfnn@apache.org> | 2004-10-19 12:52:09 +0000 |
commit | 62c8d560657a1f79cb7bae7fcda7b801f0930249 (patch) | |
tree | 4bbe80b59bbfe6665a20ed62936b2cd1958f3bf3 /src/java/org/apache | |
parent | 2b474e12edfb521006d9c095f936c805067adbe7 (diff) | |
download | xmlgraphics-fop-62c8d560657a1f79cb7bae7fcda7b801f0930249.tar.gz xmlgraphics-fop-62c8d560657a1f79cb7bae7fcda7b801f0930249.zip |
Second phase of performance improvement. Pass the propertyList into
processNode(..) and addCharacters(..).
PR: 31699
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@198056 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache')
-rw-r--r-- | src/java/org/apache/fop/fo/FONode.java | 4 | ||||
-rw-r--r-- | src/java/org/apache/fop/fo/FOTreeBuilder.java | 19 | ||||
-rw-r--r-- | src/java/org/apache/fop/fo/FObj.java | 119 | ||||
-rw-r--r-- | src/java/org/apache/fop/fo/UnknownXMLObj.java | 4 | ||||
-rw-r--r-- | src/java/org/apache/fop/fo/XMLObj.java | 4 | ||||
-rw-r--r-- | src/java/org/apache/fop/fo/extensions/svg/SVGElement.java | 5 |
6 files changed, 33 insertions, 122 deletions
diff --git a/src/java/org/apache/fop/fo/FONode.java b/src/java/org/apache/fop/fo/FONode.java index 7f1d376a7..22a966f48 100644 --- a/src/java/org/apache/fop/fo/FONode.java +++ b/src/java/org/apache/fop/fo/FONode.java @@ -107,7 +107,8 @@ public abstract class FONode { * @param attlist Collection of attributes passed to us from the parser. * @throws SAXParseException for errors or inconsistencies in the attributes */ - public void processNode(String elementName, Locator locator, Attributes attlist) throws SAXParseException { + public void processNode(String elementName, Locator locator, + Attributes attlist, PropertyList parent) throws SAXParseException { System.out.println("name = " + elementName); } @@ -143,6 +144,7 @@ public abstract class FONode { * @param locator location in fo source file. */ protected void addCharacters(char data[], int start, int length, + PropertyList pList, Locator locator) throws SAXParseException { // ignore } diff --git a/src/java/org/apache/fop/fo/FOTreeBuilder.java b/src/java/org/apache/fop/fo/FOTreeBuilder.java index 9bfc31358..54282799e 100644 --- a/src/java/org/apache/fop/fo/FOTreeBuilder.java +++ b/src/java/org/apache/fop/fo/FOTreeBuilder.java @@ -80,6 +80,11 @@ public class FOTreeBuilder extends DefaultHandler { protected FONode currentFObj = null; /** + * Current propertyList for the node being handled. + */ + protected PropertyList currentPropertyList; + + /** * The class that handles formatting and rendering to a stream * (mark-fop@inomial.com) */ @@ -188,7 +193,7 @@ public class FOTreeBuilder extends DefaultHandler { public void characters(char[] data, int start, int length) throws SAXParseException { if (currentFObj != null) { - currentFObj.addCharacters(data, start, start + length, locator); + currentFObj.addCharacters(data, start, start + length, currentPropertyList, locator); } } @@ -226,6 +231,7 @@ public class FOTreeBuilder extends DefaultHandler { /* the node found in the FO document */ FONode foNode; + PropertyList propertyList; // Check to ensure first node encountered is an fo:root if (rootFObj == null) { @@ -250,7 +256,9 @@ public class FOTreeBuilder extends DefaultHandler { try { foNode = fobjMaker.make(currentFObj); - foNode.processNode(localName, locator, attlist); + propertyList = foNode.createPropertyList(currentPropertyList, foEventHandler); + foNode.processNode(localName, locator, attlist, propertyList); + foNode.startOfNode(); } catch (IllegalArgumentException e) { throw new SAXException(e); } @@ -263,6 +271,9 @@ public class FOTreeBuilder extends DefaultHandler { } currentFObj = foNode; + if (propertyList != null) { + currentPropertyList = propertyList; + } } /** @@ -277,6 +288,9 @@ public class FOTreeBuilder extends DefaultHandler { throw e; } + if (currentPropertyList.getFObj() == currentFObj) { + currentPropertyList = currentPropertyList.getParentPropertyList(); + } currentFObj = currentFObj.getParent(); } @@ -341,7 +355,6 @@ public class FOTreeBuilder extends DefaultHandler { rootFObj = null; foEventHandler = null; } - } // code stolen from org.apache.batik.util and modified slightly diff --git a/src/java/org/apache/fop/fo/FObj.java b/src/java/org/apache/fop/fo/FObj.java index 682b4480f..d2dafc6b3 100644 --- a/src/java/org/apache/fop/fo/FObj.java +++ b/src/java/org/apache/fop/fo/FObj.java @@ -97,9 +97,12 @@ public class FObj extends FONode implements Constants { * @see org.apache.fop.fo.FONode#processNode */ public void processNode(String elementName, Locator locator, - Attributes attlist) throws SAXParseException { + Attributes attlist, PropertyList pList) throws SAXParseException { setLocator(locator); - addProperties(attlist); + propertyList.addAttributesToList(attlist); + propertyList.setWritingMode(); + bind(propertyList); + propMgr = new PropertyManager(propertyList); } /** @@ -107,7 +110,8 @@ public class FObj extends FONode implements Constants { */ protected PropertyList createPropertyList(PropertyList parent, FOEventHandler foEventHandler) throws SAXParseException { //return foEventHandler.getPropertyListMaker().make(this, parent); - return null; + propertyList = new StaticPropertyList(this, parent); + return propertyList; } /** @@ -140,49 +144,6 @@ public class FObj extends FONode implements Constants { } /** - * Set properties for this FO based on node attributes - * @param attlist Collection of attributes passed to us from the parser. - */ - protected void addProperties(Attributes attlist) throws SAXParseException { - FObj parentFO = findNearestAncestorFObj(); - PropertyList parentPL = null; - - if (parentFO != null) { - parentPL = parentFO.getPropertiesForNamespace(FO_URI); - } - - propertyList = new PropertyList(this, parentPL, FO_URI); - propertyList.addAttributesToList(attlist); - propMgr = new PropertyManager(propertyList); - setWritingMode(); - - // if this FO can have a PR_ID, make sure it is unique - if (PropertySets.canHaveId(getNameId())) { - setupID(); - } - } - - /** - * Setup the id for this formatting object. - * Most formatting objects can have an id that can be referenced. - * This methods checks that the id isn't already used by another - * fo and sets the id attribute of this object. - */ - private void setupID() throws SAXParseException { - String str = getPropString(PR_ID); - if (str != null && !str.equals("")) { - Set idrefs = getFOEventHandler().getIDReferences(); - if (!idrefs.contains(str)) { - idrefs.add(str); - } else { - throw new SAXParseException("Property id \"" + str + - "\" previously used; id values must be unique" + - " in document.", locator); - } - } - } - - /** * Returns Out Of Line FO Descendant indicator. * @return true if Out of Line FO or Out Of Line descendant, false otherwise */ @@ -280,61 +241,6 @@ public class FObj extends FONode implements Constants { return (FObj) par; } - /** - * Find nearest ancestor which generates Reference Areas. - * - * @param includeSelf Set to true to consider the current FObj as an - * "ancestor". Set to false to only return a true ancestor. - * @param returnRoot Supposing a condition where no appropriate ancestor - * FObj is found, setting returnRoot to true will return the FObj with no - * parent (presumably the root FO). Otherwise, null will be returned. - * Note that this will override a false setting for includeSelf, and return - * the current node if it is the root FO. Setting returnRoot to true should - * always return a valid FObj. - * @return FObj of the nearest ancestor that generates Reference Areas - * and fits the parameters. - */ - private FObj findNearestAncestorGeneratingRAs(boolean includeSelf, - boolean returnRoot) { - FObj p = this; - if (includeSelf && p.generatesReferenceAreas()) { - return p; - } - FObj parent = p.findNearestAncestorFObj(); - if (parent == null && returnRoot) { - return p; - } - do { - p = parent; - parent = p.findNearestAncestorFObj(); - } while (parent != null && !p.generatesReferenceAreas()); - if (p.generatesReferenceAreas()) { - return p; - } - // if we got here, it is because parent is null - if (returnRoot) { - return p; - } else { - return null; - } - } - - /** - * For a given namespace, determine whether the properties of this object - * match that namespace. - * @param nameSpaceURI the namespace URI to be tested against - * @return this.propertyList, if the namespaces match; otherwise, null - */ - public PropertyList getPropertiesForNamespace(String nameSpaceURI) { - if (this.propertyList == null) { - return null; - } - if (!nameSpaceURI.equals(this.propertyList.getNameSpace())) { - return null; - } - return this.propertyList; - } - /* This section is the implemenation of the property context. */ /** @@ -389,17 +295,6 @@ public class FObj extends FONode implements Constants { } /** - * Set writing mode for this FO. - * Use that from the nearest ancestor, including self, which generates - * reference areas, or from root FO if no ancestor found. - */ - protected void setWritingMode() { - FObj p = findNearestAncestorGeneratingRAs(true, true); - this.propertyList.setWritingMode( - p.getPropEnum(PR_WRITING_MODE)); - } - - /** * @see org.apache.fop.fo.FONode#getChildNodes() */ public ListIterator getChildNodes() { diff --git a/src/java/org/apache/fop/fo/UnknownXMLObj.java b/src/java/org/apache/fop/fo/UnknownXMLObj.java index cc289bf22..c46d311dd 100644 --- a/src/java/org/apache/fop/fo/UnknownXMLObj.java +++ b/src/java/org/apache/fop/fo/UnknownXMLObj.java @@ -82,11 +82,11 @@ public class UnknownXMLObj extends XMLObj { * @see XMLObj#addCharacters */ protected void addCharacters(char data[], int start, int length, - Locator locator) { + PropertyList pList, Locator locator) { if (doc == null) { createBasicDocument(); } - super.addCharacters(data, start, length, locator); + super.addCharacters(data, start, length, pList, locator); } } diff --git a/src/java/org/apache/fop/fo/XMLObj.java b/src/java/org/apache/fop/fo/XMLObj.java index 24e260f4e..3ff83ee68 100644 --- a/src/java/org/apache/fop/fo/XMLObj.java +++ b/src/java/org/apache/fop/fo/XMLObj.java @@ -69,7 +69,7 @@ public abstract class XMLObj extends FONode { * @see org.apache.fop.fo.FONode#processNode */ public void processNode(String elementName, Locator locator, - Attributes attlist) throws SAXParseException { + Attributes attlist, PropertyList propertyList) throws SAXParseException { setLocator(locator); name = elementName; attr = attlist; @@ -211,7 +211,7 @@ public abstract class XMLObj extends FONode { * @param locator location in fo source file. */ protected void addCharacters(char data[], int start, int length, - Locator locator) { + PropertyList pList, Locator locator) { String str = new String(data, start, length - start); org.w3c.dom.Text text = doc.createTextNode(str); element.appendChild(text); diff --git a/src/java/org/apache/fop/fo/extensions/svg/SVGElement.java b/src/java/org/apache/fop/fo/extensions/svg/SVGElement.java index 67923a7af..cd523da58 100644 --- a/src/java/org/apache/fop/fo/extensions/svg/SVGElement.java +++ b/src/java/org/apache/fop/fo/extensions/svg/SVGElement.java @@ -20,6 +20,7 @@ package org.apache.fop.fo.extensions.svg; // FOP import org.apache.fop.fo.FONode; +import org.apache.fop.fo.PropertyList; import org.apache.batik.dom.svg.SVGOMDocument; import org.apache.batik.dom.svg.SVGOMElement; @@ -61,8 +62,8 @@ public class SVGElement extends SVGObj { * @see org.apache.fop.fo.FONode#processNode */ public void processNode(String elementName, Locator locator, - Attributes attlist) throws SAXParseException { - super.processNode(elementName, locator, attlist); + Attributes attlist, PropertyList propertyList) throws SAXParseException { + super.processNode(elementName, locator, attlist, propertyList); init(); } |