From e016f209941db98ef58fd4e2efa12caeb4875ce6 Mon Sep 17 00:00:00 2001 From: Jeremias Maerki Date: Mon, 28 Jul 2008 15:05:14 +0000 Subject: [PATCH] Reverted revision 670341 and replaced it with a different solution as discussed: addCharacters() is now deprecated and called by the new characters() method which uses start/length instead of start/end. Fixed bugs in the AFP and PS extensions (ArrayIndexOutOfBoundsExceptions). They were not properly changed when the interface changed. Discussion: http://markmail.org/message/pdgzf6odxrnhflby git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@680378 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/org/apache/fop/fo/FONode.java | 23 +++++++++++++++++-- src/java/org/apache/fop/fo/FOText.java | 2 +- src/java/org/apache/fop/fo/FOTreeBuilder.java | 2 +- src/java/org/apache/fop/fo/FObjMixed.java | 4 ++-- src/java/org/apache/fop/fo/UnknownXMLObj.java | 16 ++++++------- src/java/org/apache/fop/fo/XMLObj.java | 23 ++++++++----------- .../pagination/bookmarks/BookmarkTitle.java | 5 ++-- .../AbstractAFPExtensionObject.java | 9 ++++---- .../AbstractPSExtensionElement.java | 16 ++++--------- .../extensions/AbstractPSExtensionObject.java | 4 ++-- 10 files changed, 55 insertions(+), 49 deletions(-) diff --git a/src/java/org/apache/fop/fo/FONode.java b/src/java/org/apache/fop/fo/FONode.java index 087bcf96c..07d8f472c 100644 --- a/src/java/org/apache/fop/fo/FONode.java +++ b/src/java/org/apache/fop/fo/FONode.java @@ -274,17 +274,36 @@ public abstract class FONode implements Cloneable { * * @param data array of characters containing text to be added * @param start starting array element to add - * @param length number of elements to add + * @param end ending array element to add * @param pList currently applicable PropertyList * @param locator location in the XSL-FO source file. * @throws FOPException if there's a problem during processing + * @deprecated Please override {@code #characters(char[], int, int, PropertyList, Locator)} + * instead! */ - protected void addCharacters(char[] data, int start, int length, + protected void addCharacters(char[] data, int start, int end, PropertyList pList, Locator locator) throws FOPException { // ignore } + /** + * Adds characters. Does nothing by default. To be overridden in subclasses + * that allow #PCDATA content. + * + * @param data array of characters containing text to be added + * @param start starting array element to add + * @param length number of elements to add + * @param pList currently applicable PropertyList + * @param locator location in the XSL-FO source file. + * @throws FOPException if there's a problem during processing + */ + protected void characters(char[] data, int start, int length, + PropertyList pList, + Locator locator) throws FOPException { + addCharacters(data, start, start + length, pList, locator); + } + /** * Called after processNode() is called. Subclasses can do additional processing. * diff --git a/src/java/org/apache/fop/fo/FOText.java b/src/java/org/apache/fop/fo/FOText.java index eb0627b4b..08ffa40a3 100644 --- a/src/java/org/apache/fop/fo/FOText.java +++ b/src/java/org/apache/fop/fo/FOText.java @@ -93,7 +93,7 @@ public class FOText extends FONode implements CharSequence { } /** {@inheritDoc} */ - protected void addCharacters(char[] data, int start, int length, + protected void characters(char[] data, int start, int length, PropertyList list, Locator locator) throws FOPException { if (this.charBuffer == null) { diff --git a/src/java/org/apache/fop/fo/FOTreeBuilder.java b/src/java/org/apache/fop/fo/FOTreeBuilder.java index 762cd0d46..7c77f0697 100644 --- a/src/java/org/apache/fop/fo/FOTreeBuilder.java +++ b/src/java/org/apache/fop/fo/FOTreeBuilder.java @@ -371,7 +371,7 @@ public class FOTreeBuilder extends DefaultHandler { public void characters(char[] data, int start, int length) throws FOPException { if (currentFObj != null) { - currentFObj.addCharacters(data, start, length, + currentFObj.characters(data, start, length, currentPropertyList, getEffectiveLocator()); } } diff --git a/src/java/org/apache/fop/fo/FObjMixed.java b/src/java/org/apache/fop/fo/FObjMixed.java index 64faa3253..5dc5dd49d 100644 --- a/src/java/org/apache/fop/fo/FObjMixed.java +++ b/src/java/org/apache/fop/fo/FObjMixed.java @@ -50,7 +50,7 @@ public abstract class FObjMixed extends FObj { } /** {@inheritDoc} */ - protected void addCharacters(char[] data, int start, int length, + protected void characters(char[] data, int start, int length, PropertyList pList, Locator locator) throws FOPException { if (ft == null) { @@ -60,7 +60,7 @@ public abstract class FObjMixed extends FObj { ft.bind(pList); } } - ft.addCharacters(data, start, length, null, null); + ft.characters(data, start, length, null, null); } /** {@inheritDoc} */ diff --git a/src/java/org/apache/fop/fo/UnknownXMLObj.java b/src/java/org/apache/fop/fo/UnknownXMLObj.java index 4db2cf0fe..ac6676427 100644 --- a/src/java/org/apache/fop/fo/UnknownXMLObj.java +++ b/src/java/org/apache/fop/fo/UnknownXMLObj.java @@ -21,6 +21,8 @@ package org.apache.fop.fo; import org.xml.sax.Locator; +import org.apache.fop.apps.FOPException; + /** * Class for handling generic XML from a namespace not recognized by FOP */ @@ -72,9 +74,7 @@ public class UnknownXMLObj extends XMLObj { return null; //We don't know that in this case. } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ protected void addChildNode(FONode child) { if (doc == null) { createBasicDocument(); @@ -82,15 +82,13 @@ public class UnknownXMLObj extends XMLObj { super.addChildNode(child); } - /** - * {@inheritDoc} - */ - protected void addCharacters(char data[], int start, int length, - PropertyList pList, Locator locator) { + /** {@inheritDoc} */ + protected void characters(char[] data, int start, int length, + PropertyList pList, Locator locator) throws FOPException { if (doc == null) { createBasicDocument(); } - super.addCharacters(data, start, length, pList, locator); + super.characters(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 97aa435e7..3330f41a5 100644 --- a/src/java/org/apache/fop/fo/XMLObj.java +++ b/src/java/org/apache/fop/fo/XMLObj.java @@ -25,14 +25,16 @@ import java.util.HashMap; import javax.xml.parsers.DocumentBuilderFactory; -import org.apache.fop.apps.FOPException; -import org.apache.fop.datatypes.Length; -import org.apache.fop.util.ContentHandlerFactory.ObjectBuiltListener; import org.w3c.dom.Document; import org.w3c.dom.Element; + import org.xml.sax.Attributes; import org.xml.sax.Locator; +import org.apache.fop.apps.FOPException; +import org.apache.fop.datatypes.Length; +import org.apache.fop.util.ContentHandlerFactory.ObjectBuiltListener; + /** * Abstract class modelling generic, non-XSL-FO XML objects. Such objects are * stored in a DOM. @@ -203,17 +205,10 @@ public abstract class XMLObj extends FONode implements ObjectBuiltListener { } } - /** - * Add parsed characters to this object - * - * @param data array of characters contaning the text to add - * @param start starting array element to add - * @param length number of characters from the array to add - * @param pList the currently applicable property list - * @param locator location in fo source file. - */ - protected void addCharacters(char[] data, int start, int length, - PropertyList pList, Locator locator) { + /** {@inheritDoc} */ + protected void characters(char[] data, int start, int length, + PropertyList pList, Locator locator) throws FOPException { + super.characters(data, start, length, pList, locator); String str = new String(data, start, length); org.w3c.dom.Text text = doc.createTextNode(str); element.appendChild(text); diff --git a/src/java/org/apache/fop/fo/pagination/bookmarks/BookmarkTitle.java b/src/java/org/apache/fop/fo/pagination/bookmarks/BookmarkTitle.java index fc508dc96..028cdc7df 100644 --- a/src/java/org/apache/fop/fo/pagination/bookmarks/BookmarkTitle.java +++ b/src/java/org/apache/fop/fo/pagination/bookmarks/BookmarkTitle.java @@ -21,8 +21,8 @@ package org.apache.fop.fo.pagination.bookmarks; import org.xml.sax.Locator; -import org.apache.fop.fo.FObj; import org.apache.fop.fo.FONode; +import org.apache.fop.fo.FObj; import org.apache.fop.fo.PropertyList; import org.apache.fop.fo.ValidationException; @@ -52,9 +52,10 @@ public class BookmarkTitle extends FObj { * @param data the character data * @param start the start position in the data array * @param length the length of the character array + * @param pList currently applicable PropertyList * @param locator location in fo source file. */ - protected void addCharacters(char[] data, int start, int length, + protected void characters(char[] data, int start, int length, PropertyList pList, Locator locator) { title += new String(data, start, length); diff --git a/src/java/org/apache/fop/render/afp/extensions/AbstractAFPExtensionObject.java b/src/java/org/apache/fop/render/afp/extensions/AbstractAFPExtensionObject.java index 364889b29..a92687aab 100644 --- a/src/java/org/apache/fop/render/afp/extensions/AbstractAFPExtensionObject.java +++ b/src/java/org/apache/fop/render/afp/extensions/AbstractAFPExtensionObject.java @@ -20,13 +20,14 @@ package org.apache.fop.render.afp.extensions; // FOP +import org.xml.sax.Attributes; +import org.xml.sax.Locator; + import org.apache.fop.apps.FOPException; import org.apache.fop.fo.FONode; import org.apache.fop.fo.PropertyList; import org.apache.fop.fo.ValidationException; import org.apache.fop.fo.extensions.ExtensionAttachment; -import org.xml.sax.Attributes; -import org.xml.sax.Locator; /** * Base class for the AFP-specific extension elements. @@ -60,9 +61,9 @@ public abstract class AbstractAFPExtensionObject extends FONode { } /** {@inheritDoc} */ - protected void addCharacters(char[] data, int start, int end, + protected void characters(char[] data, int start, int length, PropertyList pList, Locator locator) { - setupCode.setContent(new String(data, start, end - start)); + setupCode.setContent(new String(data, start, length)); } /** {@inheritDoc} */ diff --git a/src/java/org/apache/fop/render/ps/extensions/AbstractPSExtensionElement.java b/src/java/org/apache/fop/render/ps/extensions/AbstractPSExtensionElement.java index 14865a8c9..3f534af7e 100644 --- a/src/java/org/apache/fop/render/ps/extensions/AbstractPSExtensionElement.java +++ b/src/java/org/apache/fop/render/ps/extensions/AbstractPSExtensionElement.java @@ -64,24 +64,16 @@ public abstract class AbstractPSExtensionElement extends FONode { } } - /** - * Adds characters (does nothing here) - * @param data array of characters containing text to be added - * @param start starting array element to add - * @param length of data array to add - * @param pList currently applicable PropertyList - * @param locator location in fo source file. - * @see org.apache.fop.fo.FONode#addCharacters(char[], int, int, PropertyList, Locator) - */ - protected void addCharacters(char[] data, int start, int length, + /** {@inheritDoc} */ + protected void characters(char[] data, int start, int length, PropertyList pList, Locator locator) { PSExtensionAttachment a = (PSExtensionAttachment)getExtensionAttachment(); if (a.getContent() != null) { StringBuffer sb = new StringBuffer(a.getContent()); - sb.append(data, start, length - start); + sb.append(data, start, length); a.setContent(sb.toString()); } else { - a.setContent(new String(data, start, length - start)); + a.setContent(new String(data, start, length)); } } diff --git a/src/java/org/apache/fop/render/ps/extensions/AbstractPSExtensionObject.java b/src/java/org/apache/fop/render/ps/extensions/AbstractPSExtensionObject.java index 92108b551..ec90a3afd 100644 --- a/src/java/org/apache/fop/render/ps/extensions/AbstractPSExtensionObject.java +++ b/src/java/org/apache/fop/render/ps/extensions/AbstractPSExtensionObject.java @@ -54,14 +54,14 @@ public abstract class AbstractPSExtensionObject extends FONode { } /** {@inheritDoc} */ - protected void addCharacters(char[] data, int start, int length, + protected void characters(char[] data, int start, int length, PropertyList pList, Locator locator) { if (setupCode.getContent() != null) { StringBuffer sb = new StringBuffer(setupCode.getContent()); sb.append(data, start, length - start); setupCode.setContent(sb.toString()); } else { - setupCode.setContent(new String(data, start, length - start)); + setupCode.setContent(new String(data, start, length)); } } -- 2.39.5