summaryrefslogtreecommitdiff
path: root/libjava/classpath/gnu/xml
diff options
context:
space:
mode:
Diffstat (limited to 'libjava/classpath/gnu/xml')
-rw-r--r--libjava/classpath/gnu/xml/dom/DomAttr.java36
-rw-r--r--libjava/classpath/gnu/xml/dom/DomDocument.java8
-rw-r--r--libjava/classpath/gnu/xml/dom/DomElement.java26
-rw-r--r--libjava/classpath/gnu/xml/dom/DomEvent.java13
-rw-r--r--libjava/classpath/gnu/xml/dom/DomNode.java12
-rw-r--r--libjava/classpath/gnu/xml/dom/DomNsNode.java29
-rw-r--r--libjava/classpath/gnu/xml/dom/DomText.java4
-rw-r--r--libjava/classpath/gnu/xml/dom/ls/DomLSInput.java4
-rw-r--r--libjava/classpath/gnu/xml/dom/ls/DomLSParser.java2
-rw-r--r--libjava/classpath/gnu/xml/dom/ls/SAXEventSink.java7
-rw-r--r--libjava/classpath/gnu/xml/libxmlj/dom/GnomeAttr.java4
-rw-r--r--libjava/classpath/gnu/xml/libxmlj/dom/GnomeCharacterData.java4
-rw-r--r--libjava/classpath/gnu/xml/libxmlj/dom/GnomeDocument.java7
-rw-r--r--libjava/classpath/gnu/xml/libxmlj/dom/GnomeDocumentType.java4
-rw-r--r--libjava/classpath/gnu/xml/libxmlj/dom/GnomeElement.java4
-rw-r--r--libjava/classpath/gnu/xml/libxmlj/dom/GnomeEntity.java4
-rw-r--r--libjava/classpath/gnu/xml/libxmlj/dom/GnomeNode.java6
-rw-r--r--libjava/classpath/gnu/xml/libxmlj/dom/GnomeNotation.java4
-rw-r--r--libjava/classpath/gnu/xml/libxmlj/dom/GnomeProcessingInstruction.java4
-rw-r--r--libjava/classpath/gnu/xml/libxmlj/dom/GnomeText.java4
-rw-r--r--libjava/classpath/gnu/xml/libxmlj/dom/GnomeXPathResult.java4
-rw-r--r--libjava/classpath/gnu/xml/stream/XMLEventImpl.java14
-rw-r--r--libjava/classpath/gnu/xml/stream/XMLParser.java28
-rw-r--r--libjava/classpath/gnu/xml/transform/AbstractNumberNode.java12
-rw-r--r--libjava/classpath/gnu/xml/transform/ApplyTemplatesNode.java4
-rw-r--r--libjava/classpath/gnu/xml/transform/AttributeNode.java4
-rw-r--r--libjava/classpath/gnu/xml/transform/Bindings.java4
-rw-r--r--libjava/classpath/gnu/xml/transform/CallTemplateNode.java17
-rw-r--r--libjava/classpath/gnu/xml/transform/ChooseNode.java4
-rw-r--r--libjava/classpath/gnu/xml/transform/CopyNode.java4
-rw-r--r--libjava/classpath/gnu/xml/transform/CopyOfNode.java4
-rw-r--r--libjava/classpath/gnu/xml/transform/ElementNode.java4
-rw-r--r--libjava/classpath/gnu/xml/transform/ForEachNode.java58
-rw-r--r--libjava/classpath/gnu/xml/transform/IfNode.java4
-rw-r--r--libjava/classpath/gnu/xml/transform/MessageNode.java4
-rw-r--r--libjava/classpath/gnu/xml/transform/ParameterNode.java44
-rw-r--r--libjava/classpath/gnu/xml/transform/ProcessingInstructionNode.java4
-rw-r--r--libjava/classpath/gnu/xml/transform/SortKey.java62
-rw-r--r--libjava/classpath/gnu/xml/transform/StreamSerializer.java18
-rw-r--r--libjava/classpath/gnu/xml/transform/Stylesheet.java129
-rw-r--r--libjava/classpath/gnu/xml/transform/Template.java6
-rw-r--r--libjava/classpath/gnu/xml/transform/TemplateNode.java2
-rw-r--r--libjava/classpath/gnu/xml/transform/TemplatesImpl.java17
-rw-r--r--libjava/classpath/gnu/xml/transform/TextNode.java4
-rw-r--r--libjava/classpath/gnu/xml/transform/TransformerImpl.java6
-rw-r--r--libjava/classpath/gnu/xml/transform/TransformerOutputProperties.java4
-rw-r--r--libjava/classpath/gnu/xml/transform/UnparsedEntityUriFunction.java19
-rw-r--r--libjava/classpath/gnu/xml/transform/ValueOfNode.java12
-rw-r--r--libjava/classpath/gnu/xml/transform/WhenNode.java4
-rw-r--r--libjava/classpath/gnu/xml/transform/XSLComparator.java108
-rw-r--r--libjava/classpath/gnu/xml/transform/XSLURIResolver.java9
-rw-r--r--libjava/classpath/gnu/xml/util/DoParse.java4
-rw-r--r--libjava/classpath/gnu/xml/util/XCat.java6
-rw-r--r--libjava/classpath/gnu/xml/util/XMLWriter.java6
-rw-r--r--libjava/classpath/gnu/xml/validation/datatype/EntitiesType.java4
-rw-r--r--libjava/classpath/gnu/xml/validation/datatype/NMTokensType.java4
-rw-r--r--libjava/classpath/gnu/xml/xpath/ArithmeticExpr.java4
-rw-r--r--libjava/classpath/gnu/xml/xpath/BooleanFunction.java4
-rw-r--r--libjava/classpath/gnu/xml/xpath/CeilingFunction.java4
-rw-r--r--libjava/classpath/gnu/xml/xpath/ConcatFunction.java22
-rw-r--r--libjava/classpath/gnu/xml/xpath/ContainsFunction.java5
-rw-r--r--libjava/classpath/gnu/xml/xpath/CountFunction.java7
-rw-r--r--libjava/classpath/gnu/xml/xpath/DocumentOrderComparator.java12
-rw-r--r--libjava/classpath/gnu/xml/xpath/EqualityExpr.java36
-rw-r--r--libjava/classpath/gnu/xml/xpath/Expr.java75
-rw-r--r--libjava/classpath/gnu/xml/xpath/FloorFunction.java5
-rw-r--r--libjava/classpath/gnu/xml/xpath/Function.java2
-rw-r--r--libjava/classpath/gnu/xml/xpath/FunctionCall.java26
-rw-r--r--libjava/classpath/gnu/xml/xpath/IdFunction.java7
-rw-r--r--libjava/classpath/gnu/xml/xpath/LangFunction.java5
-rw-r--r--libjava/classpath/gnu/xml/xpath/LocalNameFunction.java13
-rw-r--r--libjava/classpath/gnu/xml/xpath/NameFunction.java18
-rw-r--r--libjava/classpath/gnu/xml/xpath/NamespaceUriFunction.java13
-rw-r--r--libjava/classpath/gnu/xml/xpath/NormalizeSpaceFunction.java9
-rw-r--r--libjava/classpath/gnu/xml/xpath/NotFunction.java5
-rw-r--r--libjava/classpath/gnu/xml/xpath/NumberFunction.java5
-rw-r--r--libjava/classpath/gnu/xml/xpath/ParenthesizedExpr.java7
-rw-r--r--libjava/classpath/gnu/xml/xpath/Path.java2
-rw-r--r--libjava/classpath/gnu/xml/xpath/Root.java10
-rw-r--r--libjava/classpath/gnu/xml/xpath/RoundFunction.java5
-rw-r--r--libjava/classpath/gnu/xml/xpath/Selector.java48
-rw-r--r--libjava/classpath/gnu/xml/xpath/StartsWithFunction.java4
-rw-r--r--libjava/classpath/gnu/xml/xpath/Steps.java61
-rw-r--r--libjava/classpath/gnu/xml/xpath/StringFunction.java4
-rw-r--r--libjava/classpath/gnu/xml/xpath/StringLengthFunction.java3
-rw-r--r--libjava/classpath/gnu/xml/xpath/SubstringAfterFunction.java4
-rw-r--r--libjava/classpath/gnu/xml/xpath/SubstringBeforeFunction.java4
-rw-r--r--libjava/classpath/gnu/xml/xpath/SubstringFunction.java7
-rw-r--r--libjava/classpath/gnu/xml/xpath/SumFunction.java12
-rw-r--r--libjava/classpath/gnu/xml/xpath/TranslateFunction.java10
-rw-r--r--libjava/classpath/gnu/xml/xpath/UnionExpr.java21
-rw-r--r--libjava/classpath/gnu/xml/xpath/VariableReference.java4
-rw-r--r--libjava/classpath/gnu/xml/xpath/XPathParser.java88
-rw-r--r--libjava/classpath/gnu/xml/xpath/XPathParser.y62
-rw-r--r--libjava/classpath/gnu/xml/xpath/XPathTokenizer.java10
95 files changed, 915 insertions, 555 deletions
diff --git a/libjava/classpath/gnu/xml/dom/DomAttr.java b/libjava/classpath/gnu/xml/dom/DomAttr.java
index 31d7af2d2f1..6a8da837154 100644
--- a/libjava/classpath/gnu/xml/dom/DomAttr.java
+++ b/libjava/classpath/gnu/xml/dom/DomAttr.java
@@ -37,6 +37,8 @@ exception statement from your version. */
package gnu.xml.dom;
+import gnu.java.lang.CPStringBuilder;
+
import org.w3c.dom.Attr;
import org.w3c.dom.DOMException;
import org.w3c.dom.Element;
@@ -106,7 +108,37 @@ public class DomAttr
// and character data change events and when they happen,
// report self-mutation
}
-
+
+ /**
+ * Constructs an Attr node associated with the specified document.
+ * The "specified" flag is initialized to true, since this DOM has
+ * no current "back door" mechanisms to manage default values so
+ * that every value must effectively be "specified".
+ *
+ * <p>This constructor should only be invoked by a Document as part of
+ * its createAttribute functionality, or through a subclass which is
+ * similarly used in a "Sub-DOM" style layer.
+ * <p>
+ * With this constructor, the prefix and local part are given explicitly
+ * rather than being computed. This allows them to be explicitly set to
+ * {@code null} as required by {@link Document#createAttribute(String)}.
+ * </p>
+ *
+ * @param owner The document with which this node is associated
+ * @param namespaceURI Combined with the local part of the name,
+ * this is used to uniquely identify a type of attribute
+ * @param name Name of this attribute, which may include a prefix
+ * @param prefix the namespace prefix of the name. May be {@code null}.
+ * @param localName the local part of the name. May be {@code null}.
+ */
+ protected DomAttr(DomDocument owner, String namespaceURI, String name,
+ String prefix, String localName)
+ {
+ super(ATTRIBUTE_NODE, owner, namespaceURI, name, prefix, localName);
+ specified = true;
+ length = 1;
+ }
+
/**
* <b>DOM L1</b>
* Returns the attribute name (same as getNodeName)
@@ -147,7 +179,7 @@ public class DomAttr
return (value == null) ? "" : value;
}
// Otherwise collect child node-values
- StringBuffer buf = new StringBuffer();
+ CPStringBuilder buf = new CPStringBuilder();
for (DomNode ctx = first; ctx != null; ctx = ctx.next)
{
switch (ctx.nodeType)
diff --git a/libjava/classpath/gnu/xml/dom/DomDocument.java b/libjava/classpath/gnu/xml/dom/DomDocument.java
index bcc729335d5..b32c6b82dfc 100644
--- a/libjava/classpath/gnu/xml/dom/DomDocument.java
+++ b/libjava/classpath/gnu/xml/dom/DomDocument.java
@@ -597,6 +597,8 @@ public class DomDocument
/**
* <b>DOM L1</b>
* Returns a newly created element with the specified name.
+ * The node name of the created element will be equal to {@code name}.
+ * The namespace, prefix and local name will all be {@code null}.
*/
public Element createElement(String name)
{
@@ -612,8 +614,7 @@ public class DomDocument
}
else
{
- DomElement domElement = new DomElement(this, null, name);
- domElement.localName = null;
+ DomElement domElement = new DomElement(this, null, name, null, null);
element = domElement;
}
if (defaultAttributes)
@@ -813,8 +814,7 @@ public class DomDocument
}
else
{
- DomAttr ret = new DomAttr(this, null, name);
- ret.localName = null;
+ DomAttr ret = new DomAttr(this, null, name, null, null);
return ret;
}
}
diff --git a/libjava/classpath/gnu/xml/dom/DomElement.java b/libjava/classpath/gnu/xml/dom/DomElement.java
index 9fd81e9705b..462cb9178a6 100644
--- a/libjava/classpath/gnu/xml/dom/DomElement.java
+++ b/libjava/classpath/gnu/xml/dom/DomElement.java
@@ -90,6 +90,32 @@ public class DomElement
}
/**
+ * <p>
+ * Constructs an Element node associated with the specified document.
+ * This constructor should only be invoked by a Document as part
+ * of its createElement functionality, or through a subclass which is
+ * similarly used in a "Sub-DOM" style layer.
+ * </p>
+ * <p>
+ * With this constructor, the prefix and local part are given explicitly
+ * rather than being computed. This allows them to be explicitly set to
+ * {@code null} as required by {@link Document#createElement(String)}.
+ * </p>
+ *
+ * @param owner The document with which this node is associated
+ * @param namespaceURI Combined with the local part of the name,
+ * this is used to uniquely identify a type of element
+ * @param name Name of this element, which may include a prefix
+ * @param prefix the namespace prefix of the name. May be {@code null}.
+ * @param localName the local part of the name. May be {@code null}.
+ */
+ protected DomElement(DomDocument owner, String namespaceURI, String name,
+ String prefix, String localName)
+ {
+ super(ELEMENT_NODE, owner, namespaceURI, name, prefix, localName);
+ }
+
+ /**
* <b>DOM L1</b>
* Returns the element's attributes
*/
diff --git a/libjava/classpath/gnu/xml/dom/DomEvent.java b/libjava/classpath/gnu/xml/dom/DomEvent.java
index d57eac0e445..9190ed8eb0e 100644
--- a/libjava/classpath/gnu/xml/dom/DomEvent.java
+++ b/libjava/classpath/gnu/xml/dom/DomEvent.java
@@ -37,8 +37,15 @@ exception statement from your version. */
package gnu.xml.dom;
-import org.w3c.dom.*;
-import org.w3c.dom.events.*;
+import gnu.java.lang.CPStringBuilder;
+
+import org.w3c.dom.Node;
+
+import org.w3c.dom.events.Event;
+import org.w3c.dom.events.EventTarget;
+import org.w3c.dom.events.MutationEvent;
+import org.w3c.dom.events.UIEvent;
+
import org.w3c.dom.views.AbstractView; // used by UIEvent
/**
@@ -180,7 +187,7 @@ public class DomEvent
*/
public String toString()
{
- StringBuffer buf = new StringBuffer("[Event ");
+ CPStringBuilder buf = new CPStringBuilder("[Event ");
buf.append(type);
switch (eventPhase)
{
diff --git a/libjava/classpath/gnu/xml/dom/DomNode.java b/libjava/classpath/gnu/xml/dom/DomNode.java
index 1cbdc2aecc0..78e1ab85c85 100644
--- a/libjava/classpath/gnu/xml/dom/DomNode.java
+++ b/libjava/classpath/gnu/xml/dom/DomNode.java
@@ -37,6 +37,8 @@ exception statement from your version. */
package gnu.xml.dom;
+import gnu.java.lang.CPStringBuilder;
+
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
@@ -1939,7 +1941,7 @@ public abstract class DomNode
case ENTITY_NODE:
case ENTITY_REFERENCE_NODE:
case DOCUMENT_FRAGMENT_NODE:
- StringBuffer buffer = new StringBuffer();
+ CPStringBuilder buffer = new CPStringBuilder();
for (DomNode ctx = first; ctx != null; ctx = ctx.next)
{
String textContent = ctx.getTextContent(false);
@@ -2124,7 +2126,7 @@ public abstract class DomNode
{
String nodeName = getNodeName();
String nodeValue = getNodeValue();
- StringBuffer buf = new StringBuffer(getClass().getName());
+ CPStringBuilder buf = new CPStringBuilder(getClass().getName());
buf.append('[');
if (nodeName != null)
{
@@ -2146,7 +2148,7 @@ public abstract class DomNode
String encode(String value)
{
- StringBuffer buf = null;
+ CPStringBuilder buf = null;
int len = value.length();
for (int i = 0; i < len; i++)
{
@@ -2155,7 +2157,7 @@ public abstract class DomNode
{
if (buf == null)
{
- buf = new StringBuffer(value.substring(0, i));
+ buf = new CPStringBuilder(value.substring(0, i));
}
buf.append("\\n");
}
@@ -2163,7 +2165,7 @@ public abstract class DomNode
{
if (buf == null)
{
- buf = new StringBuffer(value.substring(0, i));
+ buf = new CPStringBuilder(value.substring(0, i));
}
buf.append("\\r");
}
diff --git a/libjava/classpath/gnu/xml/dom/DomNsNode.java b/libjava/classpath/gnu/xml/dom/DomNsNode.java
index b27514ecb56..d3361515b70 100644
--- a/libjava/classpath/gnu/xml/dom/DomNsNode.java
+++ b/libjava/classpath/gnu/xml/dom/DomNsNode.java
@@ -54,7 +54,7 @@ public abstract class DomNsNode
private String name;
private String namespace;
private String prefix;
- String localName;
+ private String localName;
/**
* Constructs a node associated with the specified document, and
@@ -76,6 +76,33 @@ public abstract class DomNsNode
}
/**
+ * Constructs a node associated with the specified document, and
+ * with the specified namespace information. The prefix and local part
+ * are given explicitly rather than being computed. This allows them
+ * to be explicitly set to {@code null} as required by
+ * {@link Document#createElement(String)}.
+ *
+ * @param owner The document with which this entity is associated
+ * @param namespaceURI Combined with the local part of the name,
+ * this identifies a type of element or attribute; may be null.
+ * If this is the empty string, it is reassigned as null so that
+ * applications only need to test that case.
+ * @param name Name of this node, which may include a prefix
+ * @param prefix the namespace prefix of the name. May be {@code null}.
+ * @param localName the local part of the name. May be {@code null}.
+ */
+ // package private
+ DomNsNode(short nodeType, DomDocument owner, String namespaceURI, String name,
+ String prefix, String localName)
+ {
+ super(nodeType, owner);
+ this.name = name.intern();
+ this.prefix = prefix == null ? null : prefix.intern();
+ this.localName = localName == null ? null : localName.intern();
+ setNamespaceURI(namespaceURI);
+ }
+
+ /**
* <b>DOM L1</b>
* Returns the node's name, including any namespace prefix.
*/
diff --git a/libjava/classpath/gnu/xml/dom/DomText.java b/libjava/classpath/gnu/xml/dom/DomText.java
index 3ca17dc9b87..167eba3c1d2 100644
--- a/libjava/classpath/gnu/xml/dom/DomText.java
+++ b/libjava/classpath/gnu/xml/dom/DomText.java
@@ -37,6 +37,8 @@ exception statement from your version. */
package gnu.xml.dom;
+import gnu.java.lang.CPStringBuilder;
+
import org.w3c.dom.DOMException;
import org.w3c.dom.Text;
@@ -172,7 +174,7 @@ public class DomText
{
ref = ctx;
}
- StringBuffer buf = new StringBuffer(ref.getNodeValue());
+ CPStringBuilder buf = new CPStringBuilder(ref.getNodeValue());
for (ctx = ref.next; ctx != null &&
(ctx.nodeType == TEXT_NODE || ctx.nodeType == CDATA_SECTION_NODE);
ctx = ctx.next)
diff --git a/libjava/classpath/gnu/xml/dom/ls/DomLSInput.java b/libjava/classpath/gnu/xml/dom/ls/DomLSInput.java
index 44274ec4734..68705fdee92 100644
--- a/libjava/classpath/gnu/xml/dom/ls/DomLSInput.java
+++ b/libjava/classpath/gnu/xml/dom/ls/DomLSInput.java
@@ -37,6 +37,8 @@ exception statement from your version. */
package gnu.xml.dom.ls;
+import gnu.java.lang.CPStringBuilder;
+
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.IOException;
@@ -82,7 +84,7 @@ public class DomLSInput
public String getStringData()
{
- StringBuffer acc = new StringBuffer();
+ CPStringBuilder acc = new CPStringBuilder();
Reader reader = getCharacterStream();
try
{
diff --git a/libjava/classpath/gnu/xml/dom/ls/DomLSParser.java b/libjava/classpath/gnu/xml/dom/ls/DomLSParser.java
index 88f9bae23fe..f4f555e8c39 100644
--- a/libjava/classpath/gnu/xml/dom/ls/DomLSParser.java
+++ b/libjava/classpath/gnu/xml/dom/ls/DomLSParser.java
@@ -253,7 +253,7 @@ public class DomLSParser
eventSink = (filter == null) ? new SAXEventSink() :
new FilteredSAXEventSink(filter);
// configure sink
- eventSink.namespaceAware = namespaceAware;
+ eventSink.setNamespaceAware(namespaceAware);
eventSink.ignoreWhitespace = ignoreWhitespace;
eventSink.expandEntityReferences = expandEntityReferences;
eventSink.ignoreComments = ignoreComments;
diff --git a/libjava/classpath/gnu/xml/dom/ls/SAXEventSink.java b/libjava/classpath/gnu/xml/dom/ls/SAXEventSink.java
index 0a165aafbad..1f8de046d42 100644
--- a/libjava/classpath/gnu/xml/dom/ls/SAXEventSink.java
+++ b/libjava/classpath/gnu/xml/dom/ls/SAXEventSink.java
@@ -89,7 +89,7 @@ public class SAXEventSink
PREDEFINED_ENTITIES.add("apos");
}
- boolean namespaceAware;
+ private boolean namespaceAware;
boolean ignoreWhitespace;
boolean expandEntityReferences;
boolean ignoreComments;
@@ -128,6 +128,11 @@ public class SAXEventSink
this.locator = locator;
}
+ public void setNamespaceAware(boolean namespaceAware)
+ {
+ this.namespaceAware = namespaceAware;
+ }
+
public void startDocument()
throws SAXException
{
diff --git a/libjava/classpath/gnu/xml/libxmlj/dom/GnomeAttr.java b/libjava/classpath/gnu/xml/libxmlj/dom/GnomeAttr.java
index 24088fb8154..144aaf82862 100644
--- a/libjava/classpath/gnu/xml/libxmlj/dom/GnomeAttr.java
+++ b/libjava/classpath/gnu/xml/libxmlj/dom/GnomeAttr.java
@@ -37,6 +37,8 @@ exception statement from your version. */
package gnu.xml.libxmlj.dom;
+import gnu.java.lang.CPStringBuilder;
+
import org.w3c.dom.Attr;
import org.w3c.dom.DOMException;
import org.w3c.dom.Element;
@@ -103,7 +105,7 @@ class GnomeAttr
public String toString()
{
- StringBuffer buffer = new StringBuffer(getClass().getName());
+ CPStringBuilder buffer = new CPStringBuilder(getClass().getName());
buffer.append("[name=");
buffer.append(getName());
buffer.append(",value=");
diff --git a/libjava/classpath/gnu/xml/libxmlj/dom/GnomeCharacterData.java b/libjava/classpath/gnu/xml/libxmlj/dom/GnomeCharacterData.java
index a3200921df6..aa98652ba83 100644
--- a/libjava/classpath/gnu/xml/libxmlj/dom/GnomeCharacterData.java
+++ b/libjava/classpath/gnu/xml/libxmlj/dom/GnomeCharacterData.java
@@ -37,6 +37,8 @@ exception statement from your version. */
package gnu.xml.libxmlj.dom;
+import gnu.java.lang.CPStringBuilder;
+
import org.w3c.dom.CharacterData;
import org.w3c.dom.DOMException;
@@ -107,7 +109,7 @@ abstract class GnomeCharacterData
public String toString()
{
- StringBuffer buffer = new StringBuffer(getClass().getName());
+ CPStringBuilder buffer = new CPStringBuilder(getClass().getName());
buffer.append("[data=");
buffer.append(getData());
buffer.append("]");
diff --git a/libjava/classpath/gnu/xml/libxmlj/dom/GnomeDocument.java b/libjava/classpath/gnu/xml/libxmlj/dom/GnomeDocument.java
index 03420c463e8..a5333550e16 100644
--- a/libjava/classpath/gnu/xml/libxmlj/dom/GnomeDocument.java
+++ b/libjava/classpath/gnu/xml/libxmlj/dom/GnomeDocument.java
@@ -37,6 +37,9 @@ exception statement from your version. */
package gnu.xml.libxmlj.dom;
+import gnu.java.lang.CPStringBuilder;
+import gnu.xml.dom.DomNodeIterator;
+
import java.util.Iterator;
import org.w3c.dom.Attr;
@@ -66,8 +69,6 @@ import org.w3c.dom.xpath.XPathException;
import org.w3c.dom.xpath.XPathExpression;
import org.w3c.dom.xpath.XPathNSResolver;
-import gnu.xml.dom.DomNodeIterator;
-
/**
* A DOM document node implemented in libxml2.
*
@@ -549,7 +550,7 @@ public class GnomeDocument
public String toString()
{
- StringBuffer buffer = new StringBuffer(getClass().getName());
+ CPStringBuilder buffer = new CPStringBuilder(getClass().getName());
buffer.append("[version=");
buffer.append(getXmlVersion());
buffer.append(",standalone=");
diff --git a/libjava/classpath/gnu/xml/libxmlj/dom/GnomeDocumentType.java b/libjava/classpath/gnu/xml/libxmlj/dom/GnomeDocumentType.java
index 257fbbceb69..eb3a65f1d49 100644
--- a/libjava/classpath/gnu/xml/libxmlj/dom/GnomeDocumentType.java
+++ b/libjava/classpath/gnu/xml/libxmlj/dom/GnomeDocumentType.java
@@ -37,6 +37,8 @@ exception statement from your version. */
package gnu.xml.libxmlj.dom;
+import gnu.java.lang.CPStringBuilder;
+
import org.w3c.dom.DocumentType;
import org.w3c.dom.NamedNodeMap;
@@ -79,7 +81,7 @@ implements DocumentType
public String toString ()
{
String publicId = getPublicId ();
- StringBuffer buffer = new StringBuffer (getClass ().getName ());
+ CPStringBuilder buffer = new CPStringBuilder (getClass ().getName ());
buffer.append ("[");
if (publicId != null)
{
diff --git a/libjava/classpath/gnu/xml/libxmlj/dom/GnomeElement.java b/libjava/classpath/gnu/xml/libxmlj/dom/GnomeElement.java
index 2770cbbfd1e..e87e3adfe1c 100644
--- a/libjava/classpath/gnu/xml/libxmlj/dom/GnomeElement.java
+++ b/libjava/classpath/gnu/xml/libxmlj/dom/GnomeElement.java
@@ -37,6 +37,8 @@ exception statement from your version. */
package gnu.xml.libxmlj.dom;
+import gnu.java.lang.CPStringBuilder;
+
import java.util.HashSet;
import java.util.Set;
@@ -172,7 +174,7 @@ class GnomeElement
public String toString()
{
- StringBuffer buffer = new StringBuffer(getClass().getName());
+ CPStringBuilder buffer = new CPStringBuilder(getClass().getName());
buffer.append("[tagName=");
buffer.append(getTagName());
buffer.append("]");
diff --git a/libjava/classpath/gnu/xml/libxmlj/dom/GnomeEntity.java b/libjava/classpath/gnu/xml/libxmlj/dom/GnomeEntity.java
index 76367f8bd4f..8d61a26c1ad 100644
--- a/libjava/classpath/gnu/xml/libxmlj/dom/GnomeEntity.java
+++ b/libjava/classpath/gnu/xml/libxmlj/dom/GnomeEntity.java
@@ -37,6 +37,8 @@ exception statement from your version. */
package gnu.xml.libxmlj.dom;
+import gnu.java.lang.CPStringBuilder;
+
import org.w3c.dom.Entity;
/**
@@ -83,7 +85,7 @@ implements Entity
public String toString ()
{
String publicId = getPublicId ();
- StringBuffer buffer = new StringBuffer (getClass ().getName ());
+ CPStringBuilder buffer = new CPStringBuilder (getClass ().getName ());
buffer.append ("[");
if (publicId != null)
{
diff --git a/libjava/classpath/gnu/xml/libxmlj/dom/GnomeNode.java b/libjava/classpath/gnu/xml/libxmlj/dom/GnomeNode.java
index 4a2e9ff48d6..6f574ec29dd 100644
--- a/libjava/classpath/gnu/xml/libxmlj/dom/GnomeNode.java
+++ b/libjava/classpath/gnu/xml/libxmlj/dom/GnomeNode.java
@@ -37,6 +37,8 @@ exception statement from your version. */
package gnu.xml.libxmlj.dom;
+import gnu.java.lang.CPStringBuilder;
+
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
@@ -368,7 +370,7 @@ class GnomeNode
case ENTITY_NODE:
case ENTITY_REFERENCE_NODE:
case DOCUMENT_FRAGMENT_NODE:
- StringBuffer buffer = new StringBuffer();
+ CPStringBuilder buffer = new CPStringBuilder();
NodeList children = getChildNodes();
int len = children.getLength();
for (int i = 0; i < len; i++)
@@ -489,7 +491,7 @@ class GnomeNode
public String toString()
{
- StringBuffer buffer = new StringBuffer(getClass().getName());
+ CPStringBuilder buffer = new CPStringBuilder(getClass().getName());
buffer.append("[nodeName=");
buffer.append(getNodeName());
buffer.append("]");
diff --git a/libjava/classpath/gnu/xml/libxmlj/dom/GnomeNotation.java b/libjava/classpath/gnu/xml/libxmlj/dom/GnomeNotation.java
index ca1560e21bc..7f6fdf44896 100644
--- a/libjava/classpath/gnu/xml/libxmlj/dom/GnomeNotation.java
+++ b/libjava/classpath/gnu/xml/libxmlj/dom/GnomeNotation.java
@@ -37,6 +37,8 @@ exception statement from your version. */
package gnu.xml.libxmlj.dom;
+import gnu.java.lang.CPStringBuilder;
+
import org.w3c.dom.Notation;
/**
@@ -61,7 +63,7 @@ implements Notation
public String toString ()
{
String publicId = getPublicId ();
- StringBuffer buffer = new StringBuffer (getClass ().getName ());
+ CPStringBuilder buffer = new CPStringBuilder (getClass ().getName ());
buffer.append ("[");
if (publicId != null)
{
diff --git a/libjava/classpath/gnu/xml/libxmlj/dom/GnomeProcessingInstruction.java b/libjava/classpath/gnu/xml/libxmlj/dom/GnomeProcessingInstruction.java
index a6c47b2e1ca..d2ecd189004 100644
--- a/libjava/classpath/gnu/xml/libxmlj/dom/GnomeProcessingInstruction.java
+++ b/libjava/classpath/gnu/xml/libxmlj/dom/GnomeProcessingInstruction.java
@@ -37,6 +37,8 @@ exception statement from your version. */
package gnu.xml.libxmlj.dom;
+import gnu.java.lang.CPStringBuilder;
+
import org.w3c.dom.DOMException;
import org.w3c.dom.ProcessingInstruction;
@@ -67,7 +69,7 @@ implements ProcessingInstruction
public String toString ()
{
- StringBuffer buffer = new StringBuffer (getClass ().getName ());
+ CPStringBuilder buffer = new CPStringBuilder (getClass ().getName ());
buffer.append ("[data=");
buffer.append (getData ());
buffer.append ("]");
diff --git a/libjava/classpath/gnu/xml/libxmlj/dom/GnomeText.java b/libjava/classpath/gnu/xml/libxmlj/dom/GnomeText.java
index 77677a56223..8b8e5e0c1a4 100644
--- a/libjava/classpath/gnu/xml/libxmlj/dom/GnomeText.java
+++ b/libjava/classpath/gnu/xml/libxmlj/dom/GnomeText.java
@@ -37,6 +37,8 @@ exception statement from your version. */
package gnu.xml.libxmlj.dom;
+import gnu.java.lang.CPStringBuilder;
+
import org.w3c.dom.DOMException;
import org.w3c.dom.Node;
import org.w3c.dom.Text;
@@ -84,7 +86,7 @@ implements Text
first = node;
node = node.getPreviousSibling ();
}
- StringBuffer buf = new StringBuffer (first.getNodeValue ());
+ CPStringBuilder buf = new CPStringBuilder (first.getNodeValue ());
node = first.getNextSibling ();
while (node != null && node instanceof Text)
{
diff --git a/libjava/classpath/gnu/xml/libxmlj/dom/GnomeXPathResult.java b/libjava/classpath/gnu/xml/libxmlj/dom/GnomeXPathResult.java
index d0e1a4f20de..850b5fae08f 100644
--- a/libjava/classpath/gnu/xml/libxmlj/dom/GnomeXPathResult.java
+++ b/libjava/classpath/gnu/xml/libxmlj/dom/GnomeXPathResult.java
@@ -37,6 +37,8 @@ exception statement from your version. */
package gnu.xml.libxmlj.dom;
+import gnu.java.lang.CPStringBuilder;
+
import org.w3c.dom.DOMException;
import org.w3c.dom.Node;
import org.w3c.dom.xpath.XPathException;
@@ -112,7 +114,7 @@ implements XPathResult
case 1:
return getSingleNodeValue ().toString ();
default:
- StringBuffer buffer = new StringBuffer ();
+ CPStringBuilder buffer = new CPStringBuilder ();
for (int i = 0; i < len; i++)
{
if (i > 0)
diff --git a/libjava/classpath/gnu/xml/stream/XMLEventImpl.java b/libjava/classpath/gnu/xml/stream/XMLEventImpl.java
index de2fccb7a1e..8d73b177427 100644
--- a/libjava/classpath/gnu/xml/stream/XMLEventImpl.java
+++ b/libjava/classpath/gnu/xml/stream/XMLEventImpl.java
@@ -37,6 +37,8 @@ exception statement from your version. */
package gnu.xml.stream;
+import gnu.java.lang.CPStringBuilder;
+
import java.io.Writer;
import javax.xml.namespace.QName;
import javax.xml.stream.Location;
@@ -141,7 +143,7 @@ public abstract class XMLEventImpl
protected String encode(String text, boolean inAttr)
{
int len = text.length();
- StringBuffer buf = null;
+ CPStringBuilder buf = null;
for (int i = 0; i < len; i++)
{
char c = text.charAt(i);
@@ -149,7 +151,7 @@ public abstract class XMLEventImpl
{
if (buf == null)
{
- buf = new StringBuffer(text.substring(0, i));
+ buf = new CPStringBuilder(text.substring(0, i));
}
buf.append("&lt;");
}
@@ -157,7 +159,7 @@ public abstract class XMLEventImpl
{
if (buf == null)
{
- buf = new StringBuffer(text.substring(0, i));
+ buf = new CPStringBuilder(text.substring(0, i));
}
buf.append("&gt;");
}
@@ -165,7 +167,7 @@ public abstract class XMLEventImpl
{
if (buf == null)
{
- buf = new StringBuffer(text.substring(0, i));
+ buf = new CPStringBuilder(text.substring(0, i));
}
buf.append("&amp;");
}
@@ -173,7 +175,7 @@ public abstract class XMLEventImpl
{
if (buf == null)
{
- buf = new StringBuffer(text.substring(0, i));
+ buf = new CPStringBuilder(text.substring(0, i));
}
buf.append("&apos;");
}
@@ -181,7 +183,7 @@ public abstract class XMLEventImpl
{
if (buf == null)
{
- buf = new StringBuffer(text.substring(0, i));
+ buf = new CPStringBuilder(text.substring(0, i));
}
buf.append("&quot;");
}
diff --git a/libjava/classpath/gnu/xml/stream/XMLParser.java b/libjava/classpath/gnu/xml/stream/XMLParser.java
index 049575ac707..27aaa734dd6 100644
--- a/libjava/classpath/gnu/xml/stream/XMLParser.java
+++ b/libjava/classpath/gnu/xml/stream/XMLParser.java
@@ -53,6 +53,8 @@ Partly derived from code which carried the following notice:
package gnu.xml.stream;
+import gnu.java.lang.CPStringBuilder;
+
import java.io.BufferedInputStream;
import java.io.EOFException;
import java.io.File;
@@ -691,7 +693,7 @@ public class XMLParser
{
if (event != XMLStreamConstants.START_ELEMENT)
throw new XMLStreamException("current event must be START_ELEMENT");
- StringBuffer elementText = new StringBuffer();
+ CPStringBuilder elementText = new CPStringBuilder();
int depth = stack.size();
while (event != XMLStreamConstants.END_ELEMENT || stack.size() > depth)
{
@@ -2011,7 +2013,7 @@ public class XMLParser
else
{
ContentModel model;
- StringBuffer acc = new StringBuffer();
+ CPStringBuilder acc = new CPStringBuilder();
require('(');
acc.append('(');
skipWhitespace();
@@ -2058,7 +2060,7 @@ public class XMLParser
/**
* Parses an element content model.
*/
- private ElementContentModel readElements(StringBuffer acc)
+ private ElementContentModel readElements(CPStringBuilder acc)
throws IOException, XMLStreamException
{
int separator;
@@ -2159,7 +2161,7 @@ public class XMLParser
/**
* Parse a cp production.
*/
- private ContentParticle readContentParticle(StringBuffer acc)
+ private ContentParticle readContentParticle(CPStringBuilder acc)
throws IOException, XMLStreamException
{
ContentParticle cp = new ContentParticle();
@@ -2228,7 +2230,7 @@ public class XMLParser
{
String name = readNmtoken(true);
requireWhitespace();
- StringBuffer acc = new StringBuffer();
+ CPStringBuilder acc = new CPStringBuilder();
HashSet values = new HashSet();
String type = readAttType(acc, values);
if (validating)
@@ -2277,7 +2279,7 @@ public class XMLParser
/**
* Parse an attribute type.
*/
- private String readAttType(StringBuffer acc, HashSet values)
+ private String readAttType(CPStringBuilder acc, HashSet values)
throws IOException, XMLStreamException
{
if (tryRead('('))
@@ -2313,7 +2315,7 @@ public class XMLParser
/**
* Parse an enumeration.
*/
- private void readEnumeration(boolean isNames, StringBuffer acc,
+ private void readEnumeration(boolean isNames, CPStringBuilder acc,
HashSet values)
throws IOException, XMLStreamException
{
@@ -2344,7 +2346,7 @@ public class XMLParser
/**
* Parse a notation type for an attribute.
*/
- private void readNotationType(StringBuffer acc, HashSet values)
+ private void readNotationType(CPStringBuilder acc, HashSet values)
throws IOException, XMLStreamException
{
requireWhitespace();
@@ -3518,7 +3520,7 @@ public class XMLParser
private char[] readCharacterRef(int base)
throws IOException, XMLStreamException
{
- StringBuffer b = new StringBuffer();
+ CPStringBuilder b = new CPStringBuilder();
for (int c = readCh(); c != 0x3b && c != -1; c = readCh())
b.append(Character.toChars(c));
try
@@ -4246,7 +4248,7 @@ public class XMLParser
throws XMLStreamException
{
// Use regular expression
- StringBuffer buf = new StringBuffer();
+ CPStringBuilder buf = new CPStringBuilder();
for (Iterator i = children.iterator(); i.hasNext(); )
{
buf.append((String) i.next());
@@ -4266,7 +4268,7 @@ public class XMLParser
{
if (model.regex == null)
{
- StringBuffer buf = new StringBuffer();
+ CPStringBuilder buf = new CPStringBuilder();
buf.append('(');
for (Iterator i = model.contentParticles.iterator(); i.hasNext(); )
{
@@ -4476,7 +4478,7 @@ public class XMLParser
*/
private static String encodeText(String text)
{
- StringBuffer b = new StringBuffer();
+ CPStringBuilder b = new CPStringBuilder();
int len = text.length();
for (int i = 0; i < len; i++)
{
@@ -4584,7 +4586,7 @@ public class XMLParser
public String toString()
{
- StringBuffer buf = new StringBuffer(getClass().getName());
+ CPStringBuilder buf = new CPStringBuilder(getClass().getName());
buf.append('[');
buf.append("name=");
buf.append(name);
diff --git a/libjava/classpath/gnu/xml/transform/AbstractNumberNode.java b/libjava/classpath/gnu/xml/transform/AbstractNumberNode.java
index 6d1202e69b4..fb953e4f66b 100644
--- a/libjava/classpath/gnu/xml/transform/AbstractNumberNode.java
+++ b/libjava/classpath/gnu/xml/transform/AbstractNumberNode.java
@@ -37,6 +37,8 @@ exception statement from your version. */
package gnu.xml.transform;
+import gnu.java.lang.CPStringBuilder;
+
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -140,7 +142,7 @@ abstract class AbstractNumberNode
start = end;
}
// Process tokens
- StringBuffer buf = new StringBuffer();
+ CPStringBuilder buf = new CPStringBuilder();
len = tokens.size();
int pos = 0;
for (int i = 0; i < len; i++)
@@ -188,7 +190,7 @@ abstract class AbstractNumberNode
return l;
}*/
- void format(StringBuffer buf, int number, String formatToken)
+ void format(CPStringBuilder buf, int number, String formatToken)
{
int len = formatToken.length();
char c = formatToken.charAt(len - 1);
@@ -254,7 +256,7 @@ abstract class AbstractNumberNode
static final String alphabetic(char offset, int number)
{
- StringBuffer buf = new StringBuffer();
+ CPStringBuilder buf = new CPStringBuilder();
while (number > 0)
{
int r = number % 26;
@@ -269,7 +271,7 @@ abstract class AbstractNumberNode
static final String roman(boolean upper, int number)
{
- StringBuffer buf = new StringBuffer();
+ CPStringBuilder buf = new CPStringBuilder();
for (int pos = roman_numbers.length - 1; pos >= 0; pos -= 2)
{
int f = number / roman_numbers[pos];
@@ -317,7 +319,7 @@ abstract class AbstractNumberNode
public String toString()
{
- StringBuffer buf = new StringBuffer("number");
+ CPStringBuilder buf = new CPStringBuilder("number");
buf.append('[');
buf.append("format=");
buf.append(format);
diff --git a/libjava/classpath/gnu/xml/transform/ApplyTemplatesNode.java b/libjava/classpath/gnu/xml/transform/ApplyTemplatesNode.java
index 041809bdf1a..0daaa7aeccd 100644
--- a/libjava/classpath/gnu/xml/transform/ApplyTemplatesNode.java
+++ b/libjava/classpath/gnu/xml/transform/ApplyTemplatesNode.java
@@ -37,6 +37,8 @@ exception statement from your version. */
package gnu.xml.transform;
+import gnu.java.lang.CPStringBuilder;
+
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -192,7 +194,7 @@ final class ApplyTemplatesNode
public String toString()
{
- StringBuffer buf = new StringBuffer("apply-templates");
+ CPStringBuilder buf = new CPStringBuilder("apply-templates");
buf.append('[');
boolean o = false;
if (select != null)
diff --git a/libjava/classpath/gnu/xml/transform/AttributeNode.java b/libjava/classpath/gnu/xml/transform/AttributeNode.java
index 71e2ed0f7af..bbc4e08059e 100644
--- a/libjava/classpath/gnu/xml/transform/AttributeNode.java
+++ b/libjava/classpath/gnu/xml/transform/AttributeNode.java
@@ -37,6 +37,8 @@ exception statement from your version. */
package gnu.xml.transform;
+import gnu.java.lang.CPStringBuilder;
+
import javax.xml.XMLConstants;
import javax.xml.namespace.QName;
import javax.xml.transform.TransformerException;
@@ -231,7 +233,7 @@ final class AttributeNode
public String toString()
{
- StringBuffer buf = new StringBuffer("attribute");
+ CPStringBuilder buf = new CPStringBuilder("attribute");
buf.append('[');
buf.append("name=");
buf.append(name);
diff --git a/libjava/classpath/gnu/xml/transform/Bindings.java b/libjava/classpath/gnu/xml/transform/Bindings.java
index 4ee08322317..009321315bb 100644
--- a/libjava/classpath/gnu/xml/transform/Bindings.java
+++ b/libjava/classpath/gnu/xml/transform/Bindings.java
@@ -37,6 +37,8 @@ exception statement from your version. */
package gnu.xml.transform;
+import gnu.java.lang.CPStringBuilder;
+
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
@@ -259,7 +261,7 @@ public class Bindings
public String toString()
{
- StringBuffer buf = new StringBuffer();
+ CPStringBuilder buf = new CPStringBuilder();
boolean next = false;
Collection seen = new HashSet();
Map wctx = (Map) withParameters.getFirst();
diff --git a/libjava/classpath/gnu/xml/transform/CallTemplateNode.java b/libjava/classpath/gnu/xml/transform/CallTemplateNode.java
index 31b26cbcdb0..fe0eea74eff 100644
--- a/libjava/classpath/gnu/xml/transform/CallTemplateNode.java
+++ b/libjava/classpath/gnu/xml/transform/CallTemplateNode.java
@@ -37,6 +37,8 @@ exception statement from your version. */
package gnu.xml.transform;
+import gnu.java.lang.CPStringBuilder;
+
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
@@ -86,7 +88,7 @@ final class CallTemplateNode
TemplateNode t = stylesheet.getTemplate(mode, name);
if (t != null)
{
- if (withParams != null)
+ if (!withParams.isEmpty())
{
// compute the parameter values
LinkedList values = new LinkedList();
@@ -118,7 +120,7 @@ final class CallTemplateNode
}
t.apply(stylesheet, mode, context, pos, len,
parent, nextSibling);
- if (withParams != null)
+ if (!withParams.isEmpty())
{
// pop the variable context
stylesheet.bindings.pop(Bindings.WITH_PARAM);
@@ -133,20 +135,17 @@ final class CallTemplateNode
public boolean references(QName var)
{
- if (withParams != null)
+ for (Iterator i = withParams.iterator(); i.hasNext(); )
{
- for (Iterator i = withParams.iterator(); i.hasNext(); )
- {
- if (((WithParam) i.next()).references(var))
- return true;
- }
+ if (((WithParam) i.next()).references(var))
+ return true;
}
return super.references(var);
}
public String toString()
{
- StringBuffer buf = new StringBuffer("call-template");
+ CPStringBuilder buf = new CPStringBuilder("call-template");
buf.append('[');
buf.append("name=");
buf.append(name);
diff --git a/libjava/classpath/gnu/xml/transform/ChooseNode.java b/libjava/classpath/gnu/xml/transform/ChooseNode.java
index cf07fa54b07..fe2dc0c2f3a 100644
--- a/libjava/classpath/gnu/xml/transform/ChooseNode.java
+++ b/libjava/classpath/gnu/xml/transform/ChooseNode.java
@@ -37,6 +37,8 @@ exception statement from your version. */
package gnu.xml.transform;
+import gnu.java.lang.CPStringBuilder;
+
import javax.xml.namespace.QName;
import javax.xml.transform.TransformerException;
import org.w3c.dom.Node;
@@ -77,7 +79,7 @@ final class ChooseNode
public String toString()
{
- StringBuffer buf = new StringBuffer("choose");
+ CPStringBuilder buf = new CPStringBuilder("choose");
buf.append('[');
buf.append(']');
return buf.toString();
diff --git a/libjava/classpath/gnu/xml/transform/CopyNode.java b/libjava/classpath/gnu/xml/transform/CopyNode.java
index 64cfa519158..bae628d9632 100644
--- a/libjava/classpath/gnu/xml/transform/CopyNode.java
+++ b/libjava/classpath/gnu/xml/transform/CopyNode.java
@@ -37,6 +37,8 @@ exception statement from your version. */
package gnu.xml.transform;
+import gnu.java.lang.CPStringBuilder;
+
import java.util.Iterator;
import java.util.StringTokenizer;
import javax.xml.namespace.QName;
@@ -152,7 +154,7 @@ final class CopyNode
public String toString()
{
- StringBuffer buf = new StringBuffer("copy");
+ CPStringBuilder buf = new CPStringBuilder("copy");
if (uas != null)
{
buf.append('[');
diff --git a/libjava/classpath/gnu/xml/transform/CopyOfNode.java b/libjava/classpath/gnu/xml/transform/CopyOfNode.java
index ed4358c90b6..4ce84329fc0 100644
--- a/libjava/classpath/gnu/xml/transform/CopyOfNode.java
+++ b/libjava/classpath/gnu/xml/transform/CopyOfNode.java
@@ -37,6 +37,8 @@ exception statement from your version. */
package gnu.xml.transform;
+import gnu.java.lang.CPStringBuilder;
+
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -161,7 +163,7 @@ final class CopyOfNode
public String toString()
{
- StringBuffer buf = new StringBuffer("copy-of");
+ CPStringBuilder buf = new CPStringBuilder("copy-of");
buf.append('[');
buf.append("select=");
buf.append(select);
diff --git a/libjava/classpath/gnu/xml/transform/ElementNode.java b/libjava/classpath/gnu/xml/transform/ElementNode.java
index b6a5c365b12..c5a4dd20da4 100644
--- a/libjava/classpath/gnu/xml/transform/ElementNode.java
+++ b/libjava/classpath/gnu/xml/transform/ElementNode.java
@@ -37,6 +37,8 @@ exception statement from your version. */
package gnu.xml.transform;
+import gnu.java.lang.CPStringBuilder;
+
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
@@ -238,7 +240,7 @@ final class ElementNode
public String toString()
{
- StringBuffer buf = new StringBuffer("element");
+ CPStringBuilder buf = new CPStringBuilder("element");
buf.append('[');
buf.append("name=");
if (namespace != null)
diff --git a/libjava/classpath/gnu/xml/transform/ForEachNode.java b/libjava/classpath/gnu/xml/transform/ForEachNode.java
index 25b824534c9..8908114ccf4 100644
--- a/libjava/classpath/gnu/xml/transform/ForEachNode.java
+++ b/libjava/classpath/gnu/xml/transform/ForEachNode.java
@@ -37,6 +37,8 @@ exception statement from your version. */
package gnu.xml.transform;
+import gnu.java.lang.CPStringBuilder;
+
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -57,9 +59,9 @@ final class ForEachNode
{
final Expr select;
- final List sortKeys;
+ final List<SortKey> sortKeys;
- ForEachNode(Expr select, List sortKeys)
+ ForEachNode(Expr select, List<SortKey> sortKeys)
{
this.select = select;
this.sortKeys = sortKeys;
@@ -67,10 +69,10 @@ final class ForEachNode
TemplateNode clone(Stylesheet stylesheet)
{
- int len = sortKeys != null ? sortKeys.size() : 0;
- List sortKeys2 = new ArrayList(len);
+ int len = sortKeys.size();
+ List<SortKey> sortKeys2 = new ArrayList<SortKey>(len);
for (int i = 0; i < len; i++)
- sortKeys2.add(((Key) sortKeys.get(i)).clone(stylesheet));
+ sortKeys2.add(sortKeys.get(i).clone(stylesheet));
TemplateNode ret = new ForEachNode(select.clone(stylesheet),
sortKeys2);
if (children != null)
@@ -80,6 +82,7 @@ final class ForEachNode
return ret;
}
+ @Override
void doApply(Stylesheet stylesheet, QName mode,
Node context, int pos, int len,
Node parent, Node nextSibling)
@@ -94,26 +97,26 @@ final class ForEachNode
//System.err.println(toString() + ": " + context+" -> "+ret);
if (ret instanceof Collection)
{
- Collection ns = (Collection) ret;
- List list = new ArrayList(ns);
- if (sortKeys != null)
- {
- for (Iterator i = sortKeys.iterator(); i.hasNext(); )
- {
- SortKey sortKey = (SortKey) i.next();
- sortKey.init(stylesheet, mode, context, pos, len, parent,
- nextSibling);
- }
- Collections.sort(list, new XSLComparator(sortKeys));
- }
- else
+ /* Suppression is safe, as we know context produces Collection<Node> */
+ @SuppressWarnings("unchecked")
+ Collection<Node> ns = (Collection<Node>) ret;
+ List<Node> list = new ArrayList<Node>(ns);
+ if (!sortKeys.isEmpty())
+ {
+ for (SortKey sortKey : sortKeys)
+ {
+ sortKey.init(stylesheet, mode, context, pos, len, parent,
+ nextSibling);
+ }
+ Collections.sort(list, new XSLComparator(sortKeys));
+ }
+ else
Collections.sort(list, documentOrderComparator);
// Perform children for each node
int l = list.size();
int p = 1;
- for (Iterator i = list.iterator(); i.hasNext(); )
+ for (Node node : list)
{
- Node node = (Node) i.next();
stylesheet.current = node;
children.apply(stylesheet, mode,
node, p++, l,
@@ -129,24 +132,23 @@ final class ForEachNode
parent, nextSibling);
}
+ @Override
public boolean references(QName var)
{
if (select != null && select.references(var))
return true;
- if (sortKeys != null)
+ for (Iterator<SortKey> i = sortKeys.iterator(); i.hasNext(); )
{
- for (Iterator i = sortKeys.iterator(); i.hasNext(); )
- {
- if (((SortKey) i.next()).references(var))
- return true;
- }
+ if (i.next().references(var))
+ return true;
}
return super.references(var);
}
-
+
+ @Override
public String toString()
{
- StringBuffer buf = new StringBuffer("for-each");
+ CPStringBuilder buf = new CPStringBuilder("for-each");
buf.append('[');
buf.append("select=");
buf.append(select);
diff --git a/libjava/classpath/gnu/xml/transform/IfNode.java b/libjava/classpath/gnu/xml/transform/IfNode.java
index 2a00d64ca82..eeb294138ba 100644
--- a/libjava/classpath/gnu/xml/transform/IfNode.java
+++ b/libjava/classpath/gnu/xml/transform/IfNode.java
@@ -37,6 +37,8 @@ exception statement from your version. */
package gnu.xml.transform;
+import gnu.java.lang.CPStringBuilder;
+
import javax.xml.namespace.QName;
import javax.xml.transform.TransformerException;
import org.w3c.dom.Node;
@@ -99,7 +101,7 @@ final class IfNode
public String toString()
{
- StringBuffer buf = new StringBuffer("if");
+ CPStringBuilder buf = new CPStringBuilder("if");
buf.append('[');
buf.append("test=");
buf.append(test);
diff --git a/libjava/classpath/gnu/xml/transform/MessageNode.java b/libjava/classpath/gnu/xml/transform/MessageNode.java
index 890d76f6b1c..a7eeeeef6ee 100644
--- a/libjava/classpath/gnu/xml/transform/MessageNode.java
+++ b/libjava/classpath/gnu/xml/transform/MessageNode.java
@@ -37,6 +37,8 @@ exception statement from your version. */
package gnu.xml.transform;
+import gnu.java.lang.CPStringBuilder;
+
import java.util.logging.Logger;
import javax.xml.namespace.QName;
import javax.xml.transform.TransformerException;
@@ -95,7 +97,7 @@ final class MessageNode
public String toString()
{
- StringBuffer buf = new StringBuffer("message");
+ CPStringBuilder buf = new CPStringBuilder("message");
if (terminate)
{
buf.append('[');
diff --git a/libjava/classpath/gnu/xml/transform/ParameterNode.java b/libjava/classpath/gnu/xml/transform/ParameterNode.java
index 8cd2677cf08..431fbd3b1ea 100644
--- a/libjava/classpath/gnu/xml/transform/ParameterNode.java
+++ b/libjava/classpath/gnu/xml/transform/ParameterNode.java
@@ -37,6 +37,8 @@ exception statement from your version. */
package gnu.xml.transform;
+import gnu.java.lang.CPStringBuilder;
+
import java.util.Collections;
import javax.xml.namespace.QName;
import javax.xml.transform.TransformerException;
@@ -53,7 +55,7 @@ import gnu.xml.xpath.Expr;
*/
final class ParameterNode
extends TemplateNode
- implements Comparable
+ implements Comparable<ParameterNode>
{
final QName name;
@@ -67,11 +69,12 @@ final class ParameterNode
this.type = type;
}
- TemplateNode clone(Stylesheet stylesheet)
+ @Override
+ ParameterNode clone(Stylesheet stylesheet)
{
- TemplateNode ret = new ParameterNode(name,
- select.clone(stylesheet),
- type);
+ ParameterNode ret = new ParameterNode(name,
+ select == null ? null : select.clone(stylesheet),
+ type);
if (children != null)
ret.children = children.clone(stylesheet);
if (next != null)
@@ -129,26 +132,22 @@ final class ParameterNode
return super.references(var);
}
- public int compareTo(Object other)
+ public int compareTo(ParameterNode pn)
{
- if (other instanceof ParameterNode)
- {
- ParameterNode pn = (ParameterNode) other;
- boolean r1 = references(pn.name);
- boolean r2 = pn.references(name);
- if (r1 && r2)
- throw new IllegalArgumentException("circular definitions");
- if (r1)
- return 1;
- if (r2)
- return -1;
- }
+ boolean r1 = references(pn.name);
+ boolean r2 = pn.references(name);
+ if (r1 && r2)
+ throw new IllegalArgumentException("circular definitions");
+ if (r1)
+ return 1;
+ if (r2)
+ return -1;
return 0;
}
public String toString()
{
- StringBuffer buf = new StringBuffer();
+ CPStringBuilder buf = new CPStringBuilder();
switch (type)
{
case Bindings.VARIABLE:
@@ -164,11 +163,8 @@ final class ParameterNode
buf.append('[');
buf.append("name=");
buf.append(name);
- if (select != null)
- {
- buf.append(",select=");
- buf.append(select);
- }
+ buf.append(",select=");
+ buf.append(select);
buf.append(']');
return buf.toString();
}
diff --git a/libjava/classpath/gnu/xml/transform/ProcessingInstructionNode.java b/libjava/classpath/gnu/xml/transform/ProcessingInstructionNode.java
index bf61fc03880..655f51f0130 100644
--- a/libjava/classpath/gnu/xml/transform/ProcessingInstructionNode.java
+++ b/libjava/classpath/gnu/xml/transform/ProcessingInstructionNode.java
@@ -37,6 +37,8 @@ exception statement from your version. */
package gnu.xml.transform;
+import gnu.java.lang.CPStringBuilder;
+
import javax.xml.namespace.QName;
import javax.xml.transform.TransformerException;
import org.w3c.dom.Document;
@@ -105,7 +107,7 @@ final class ProcessingInstructionNode
public String toString()
{
- StringBuffer buf = new StringBuffer("processing-instruction");
+ CPStringBuilder buf = new CPStringBuilder("processing-instruction");
buf.append('[');
buf.append("name=");
buf.append(name);
diff --git a/libjava/classpath/gnu/xml/transform/SortKey.java b/libjava/classpath/gnu/xml/transform/SortKey.java
index d4ffb05e224..72934a5b750 100644
--- a/libjava/classpath/gnu/xml/transform/SortKey.java
+++ b/libjava/classpath/gnu/xml/transform/SortKey.java
@@ -45,7 +45,22 @@ import org.w3c.dom.Node;
import gnu.xml.xpath.Expr;
/**
- * An XSL sort key.
+ * <p>
+ * An XSL sort key, as specified by section 10 of the XSL
+ * Transformations specification. This takes the form:
+ * </p>
+ * <pre>
+ * &lt;xsl:sort
+ * select = string-expression
+ * lang = { nmtoken }
+ * data-type = { "text" | "number" | qname-but-not-ncname }
+ * order = { "ascending" | "descending" }
+ * case-order = { "upper-first" | "lower-first" } /&rt;
+ * </pre>
+ * <p>
+ * Note that all but the selection expression are optional,
+ * and so may be {@code null}.
+ * </p>
*
* @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
*/
@@ -67,6 +82,20 @@ final class SortKey
transient boolean descending;
transient int caseOrder;
+ /**
+ * Constructs a new {@link SortKey} to represent an &lt;xsl:sort&rt;
+ * tag.
+ *
+ * @param select the XPath expression which selects the nodes to be sorted.
+ * @param lang the language of the sort keys or {@code null} if unspecified.
+ * @param dataType the data type of the strings. May be "string", "number",
+ * a QName or {@code null} if unspecified.
+ * @param order the ordering of the nodes, which may be "ascending", "descending"
+ * or {@code null} if unspecified.
+ * @param caseOrder the treatment of case when the data type is a string. This
+ * may be "upper-first", "lower-first" or {@code null} if
+ * unspecified.
+ */
SortKey(Expr select, TemplateNode lang, TemplateNode dataType,
TemplateNode order, TemplateNode caseOrder)
{
@@ -176,4 +205,35 @@ final class SortKey
return false;
}
+ /**
+ * Provides a clone of this {@link SortKey}, using the given
+ * stylesheet as a context.
+ *
+ * @param stylesheet the stylesheet which provides context for the cloning.
+ * @return a clone of this instance.
+ */
+ SortKey clone(Stylesheet stylesheet)
+ {
+ return new SortKey(select.clone(stylesheet),
+ langTemplate == null ? null : cloneAttributeValueTemplate(langTemplate, stylesheet),
+ dataTypeTemplate == null ? null : cloneAttributeValueTemplate(dataTypeTemplate, stylesheet),
+ orderTemplate == null ? null : cloneAttributeValueTemplate(orderTemplate, stylesheet),
+ caseOrderTemplate == null ? null : cloneAttributeValueTemplate(caseOrderTemplate, stylesheet));
+ }
+
+ /**
+ * Clones an attribute value template as created by
+ * {@link Stylesheet#parseAttributeValueTemplate(String, Node)}.
+ * The node may either by a literal node or an xsl:value-of expression.
+ *
+ * @param node the node to clone.
+ * @param stylesheet the stylesheet which provides context for the cloning.
+ * @return the cloned node.
+ */
+ private TemplateNode cloneAttributeValueTemplate(TemplateNode node, Stylesheet stylesheet)
+ {
+ if (node instanceof ValueOfNode)
+ return ((ValueOfNode) node).clone(stylesheet);
+ return ((LiteralNode) node).clone(stylesheet);
+ }
}
diff --git a/libjava/classpath/gnu/xml/transform/StreamSerializer.java b/libjava/classpath/gnu/xml/transform/StreamSerializer.java
index 35323e7353d..28996721884 100644
--- a/libjava/classpath/gnu/xml/transform/StreamSerializer.java
+++ b/libjava/classpath/gnu/xml/transform/StreamSerializer.java
@@ -37,6 +37,8 @@ exception statement from your version. */
package gnu.xml.transform;
+import gnu.java.lang.CPStringBuilder;
+
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
@@ -595,7 +597,7 @@ public class StreamSerializer
if (!encoder.canEncode(text) || htmlNeedingEncoding)
{
// Check each character
- StringBuffer buf = new StringBuffer();
+ CPStringBuilder buf = new CPStringBuilder();
int len = text.length();
for (int i = 0; i < len; i++)
{
@@ -648,20 +650,20 @@ public class StreamSerializer
String encode(String text, boolean encodeCtl, boolean inAttr)
{
int len = text.length();
- StringBuffer buf = null;
+ CPStringBuilder buf = null;
for (int i = 0; i < len; i++)
{
char c = text.charAt(i);
if (c == '<')
{
if (buf == null)
- buf = new StringBuffer(text.substring(0, i));
+ buf = new CPStringBuilder(text.substring(0, i));
buf.append("&lt;");
}
else if (c == '>')
{
if (buf == null)
- buf = new StringBuffer(text.substring(0, i));
+ buf = new CPStringBuilder(text.substring(0, i));
buf.append("&gt;");
}
else if (c == '&')
@@ -675,14 +677,14 @@ public class StreamSerializer
else
{
if (buf == null)
- buf = new StringBuffer(text.substring(0, i));
+ buf = new CPStringBuilder(text.substring(0, i));
buf.append("&amp;");
}
}
else if (c == '\'' && inAttr)
{
if (buf == null)
- buf = new StringBuffer(text.substring(0, i));
+ buf = new CPStringBuilder(text.substring(0, i));
if (mode == Stylesheet.OUTPUT_HTML)
// HTML does not define &apos;, use character entity ref
buf.append("&#x27;");
@@ -692,7 +694,7 @@ public class StreamSerializer
else if (c == '"' && inAttr)
{
if (buf == null)
- buf = new StringBuffer(text.substring(0, i));
+ buf = new CPStringBuilder(text.substring(0, i));
buf.append("&quot;");
}
else if (encodeCtl)
@@ -700,7 +702,7 @@ public class StreamSerializer
if (c < 0x20)
{
if (buf == null)
- buf = new StringBuffer(text.substring(0, i));
+ buf = new CPStringBuilder(text.substring(0, i));
buf.append('&');
buf.append('#');
buf.append((int) c);
diff --git a/libjava/classpath/gnu/xml/transform/Stylesheet.java b/libjava/classpath/gnu/xml/transform/Stylesheet.java
index 41562c3c60a..30bd953495b 100644
--- a/libjava/classpath/gnu/xml/transform/Stylesheet.java
+++ b/libjava/classpath/gnu/xml/transform/Stylesheet.java
@@ -37,6 +37,8 @@ exception statement from your version. */
package gnu.xml.transform;
+import gnu.java.lang.CPStringBuilder;
+
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.util.ArrayList;
@@ -108,18 +110,18 @@ class Stylesheet
*/
String version;
- Collection extensionElementPrefixes;
- Collection excludeResultPrefixes;
+ Collection<String> extensionElementPrefixes;
+ Collection<String> excludeResultPrefixes;
/**
* Set of element names for which we should strip whitespace.
*/
- Set stripSpace;
+ Set<StrippingInstruction> stripSpace;
/**
* Set of element names for which we should preserve whitespace.
*/
- Set preserveSpace;
+ Set<StrippingInstruction> preserveSpace;
/**
* Output options.
@@ -132,34 +134,34 @@ class Stylesheet
boolean outputStandalone;
String outputPublicId;
String outputSystemId;
- Collection outputCdataSectionElements;
+ Collection<String> outputCdataSectionElements;
boolean outputIndent;
String outputMediaType;
/**
* Keys.
*/
- Collection keys;
+ Collection<Key> keys;
/**
* Decimal formats.
*/
- Map decimalFormats;
+ Map<String,DecimalFormat> decimalFormats;
/**
* Namespace aliases.
*/
- Map namespaceAliases;
+ Map<String,String> namespaceAliases;
/**
* Attribute-sets.
*/
- List attributeSets;
+ List<AttributeSet> attributeSets;
/**
* Variables.
*/
- List variables;
+ List<ParameterNode> variables;
/**
* Variable and parameter bindings.
@@ -169,7 +171,7 @@ class Stylesheet
/**
* Templates.
*/
- LinkedList templates;
+ LinkedList<Template> templates;
TemplateNode builtInNodeTemplate;
TemplateNode builtInTextTemplate;
@@ -203,22 +205,22 @@ class Stylesheet
this.systemId = systemId;
this.precedence = precedence;
this.parent = parent;
- extensionElementPrefixes = new HashSet();
- excludeResultPrefixes = new HashSet();
- stripSpace = new LinkedHashSet();
- preserveSpace = new LinkedHashSet();
- outputCdataSectionElements = new LinkedHashSet();
+ extensionElementPrefixes = new HashSet<String>();
+ excludeResultPrefixes = new HashSet<String>();
+ stripSpace = new LinkedHashSet<StrippingInstruction>();
+ preserveSpace = new LinkedHashSet<StrippingInstruction>();
+ outputCdataSectionElements = new LinkedHashSet<String>();
xpath = (XPathImpl) factory.xpathFactory.newXPath();
xpath.setNamespaceContext(this);
if (parent == null)
{
bindings = new Bindings(this);
- attributeSets = new LinkedList();
- variables = new LinkedList();
- namespaceAliases = new LinkedHashMap();
- templates = new LinkedList();
- keys = new LinkedList();
- decimalFormats = new LinkedHashMap();
+ attributeSets = new LinkedList<AttributeSet>();
+ variables = new LinkedList<ParameterNode>();
+ namespaceAliases = new LinkedHashMap<String,String>();
+ templates = new LinkedList<Template>();
+ keys = new LinkedList<Key>();
+ decimalFormats = new LinkedHashMap<String,DecimalFormat>();
initDefaultDecimalFormat();
xpath.setXPathFunctionResolver(this);
}
@@ -247,7 +249,7 @@ class Stylesheet
xpath.setXPathVariableResolver(bindings);
Test anyNode = new NodeTypeTest((short) 0);
- List tests = Collections.singletonList(anyNode);
+ List<Test> tests = Collections.singletonList(anyNode);
builtInNodeTemplate =
new ApplyTemplatesNode(new Selector(Selector.CHILD, tests),
null, null, null, true);
@@ -263,9 +265,8 @@ class Stylesheet
if (debug)
{
System.err.println("Stylesheet: " + doc.getDocumentURI());
- for (Iterator i = templates.iterator(); i.hasNext(); )
+ for (Template t : templates)
{
- Template t = (Template) i.next();
t.list(System.err);
System.err.println("--------------------");
}
@@ -307,34 +308,30 @@ class Stylesheet
Stylesheet clone = (Stylesheet) super.clone();
clone.bindings = (Bindings) bindings.clone();
- LinkedList templates2 = new LinkedList();
- for (Iterator i = templates.iterator(); i.hasNext(); )
+ LinkedList<Template> templates2 = new LinkedList<Template>();
+ for (Template t : templates)
{
- Template t = (Template) i.next();
templates2.add(t.clone(clone));
}
clone.templates = templates2;
- LinkedList attributeSets2 = new LinkedList();
- for (Iterator i = attributeSets.iterator(); i.hasNext(); )
+ LinkedList<AttributeSet> attributeSets2 = new LinkedList<AttributeSet>();
+ for (AttributeSet as : attributeSets)
{
- AttributeSet as = (AttributeSet) i.next();
attributeSets2.add(as.clone(clone));
}
clone.attributeSets = attributeSets2;
- LinkedList variables2 = new LinkedList();
- for (Iterator i = variables.iterator(); i.hasNext(); )
+ LinkedList<ParameterNode> variables2 = new LinkedList<ParameterNode>();
+ for (ParameterNode var : variables)
{
- ParameterNode var = (ParameterNode) i.next();
variables2.add(var.clone(clone));
}
clone.variables = variables2;
- LinkedList keys2 = new LinkedList();
- for (Iterator i = keys.iterator(); i.hasNext(); )
+ LinkedList<Key> keys2 = new LinkedList<Key>();
+ for (Key k : keys)
{
- Key k = (Key) i.next();
keys2.add(k.clone(clone));
}
clone.keys = keys2;
@@ -357,11 +354,10 @@ class Stylesheet
// See XSLT 11.4: "If the template or expression specifying the value of
// a global variable x references a global variable y, then the value
// for y must be computed before the value of x."
- List topLevel = new ArrayList(variables);
+ List<ParameterNode> topLevel = new ArrayList<ParameterNode>(variables);
Collections.sort(topLevel);
- for (Iterator i = topLevel.iterator(); i.hasNext(); )
+ for (ParameterNode var : topLevel)
{
- ParameterNode var = (ParameterNode) i.next();
bindings.set(var.name,
var.getValue(this, null, context, 1, 1),
var.type);
@@ -381,7 +377,7 @@ class Stylesheet
return (current == null) ? null : current.lookupPrefix(namespaceURI);
}
- public Iterator getPrefixes(String namespaceURI)
+ public Iterator<String> getPrefixes(String namespaceURI)
{
// TODO
return Collections.singleton(getPrefix(namespaceURI)).iterator();
@@ -408,9 +404,8 @@ class Stylesheet
if (debug)
System.err.println("getTemplate: mode="+mode+" context="+context);
Template selected = null;
- for (Iterator j = templates.iterator(); j.hasNext(); )
+ for (Template t : templates)
{
- Template t = (Template) j.next();
boolean isMatch = t.matches(mode, context);
if (applyImports)
{
@@ -472,9 +467,8 @@ class Stylesheet
throws TransformerException
{
Template selected = null;
- for (Iterator j = templates.iterator(); j.hasNext(); )
+ for (Template t : templates)
{
- Template t = (Template) j.next();
boolean isMatch = t.matches(name);
if (isMatch)
{
@@ -862,8 +856,8 @@ class Stylesheet
// Tokenize
int len = value.length();
int off = 0;
- List tokens = new ArrayList(); // text tokens
- List types = new ArrayList(); // literal or expression
+ List<String> tokens = new ArrayList<String>(); // text tokens
+ List<Boolean> types = new ArrayList<Boolean>(); // literal or expression
int depth = 0;
for (int i = 0; i < len; i++)
{
@@ -936,8 +930,8 @@ class Stylesheet
len = tokens.size();
for (int i = len - 1; i >= 0; i--)
{
- String token = (String) tokens.get(i);
- Boolean type = (Boolean) types.get(i);
+ String token = tokens.get(i);
+ Boolean type = types.get(i);
if (type == Boolean.TRUE)
{
// Expression text
@@ -989,9 +983,8 @@ class Stylesheet
{
// Conflict resolution
StrippingInstruction ssi = null, psi = null;
- for (Iterator i = stripSpace.iterator(); i.hasNext(); )
+ for (StrippingInstruction si : stripSpace)
{
- StrippingInstruction si = (StrippingInstruction) i.next();
if (si.element.matches(ctx, 1, 1))
{
if (ssi != null)
@@ -1005,9 +998,8 @@ class Stylesheet
ssi = si;
}
}
- for (Iterator i = preserveSpace.iterator(); i.hasNext(); )
+ for (StrippingInstruction si : preserveSpace)
{
- StrippingInstruction si = (StrippingInstruction) i.next();
if (si.element.matches(ctx, 1, 1))
{
if (psi != null)
@@ -1114,8 +1106,8 @@ class Stylesheet
if (s == null)
s = "child::node()";
Node children = node.getFirstChild();
- List sortKeys = parseSortKeys(children);
- List withParams = parseWithParams(children);
+ List<SortKey> sortKeys = parseSortKeys(children);
+ List<WithParam> withParams = parseWithParams(children);
Expr select = (Expr) xpath.compile(s);
return new ApplyTemplatesNode(select, mode,
sortKeys, withParams, false);
@@ -1131,7 +1123,7 @@ class Stylesheet
String n = getRequiredAttribute(attrs, "name", node);
QName name = getQName(n);
Node children = node.getFirstChild();
- List withParams = parseWithParams(children);
+ List<WithParam> withParams = parseWithParams(children);
return new CallTemplateNode(name, withParams);
}
@@ -1158,7 +1150,7 @@ class Stylesheet
NamedNodeMap attrs = node.getAttributes();
String s = getRequiredAttribute(attrs, "select", node);
Node children = node.getFirstChild();
- List sortKeys = parseSortKeys(children);
+ List<SortKey> sortKeys = parseSortKeys(children);
Expr select = (Expr) xpath.compile(s);
ForEachNode ret = new ForEachNode(select, sortKeys);
ret.children = parse(children);
@@ -1620,10 +1612,10 @@ class Stylesheet
return ret;
}
- final List parseSortKeys(Node node)
+ final List<SortKey> parseSortKeys(Node node)
throws TransformerConfigurationException, XPathExpressionException
{
- List ret = new LinkedList();
+ List<SortKey> ret = new LinkedList<SortKey>();
while (node != null)
{
String namespaceUri = node.getNamespaceURI();
@@ -1652,13 +1644,13 @@ class Stylesheet
}
node = node.getNextSibling();
}
- return ret.isEmpty() ? null : ret;
+ return ret;
}
- final List parseWithParams(Node node)
+ final List<WithParam> parseWithParams(Node node)
throws TransformerConfigurationException, XPathExpressionException
{
- List ret = new LinkedList();
+ List<WithParam> ret = new LinkedList<WithParam>();
while (node != null)
{
String namespaceUri = node.getNamespaceURI();
@@ -1688,7 +1680,7 @@ class Stylesheet
}
node = node.getNextSibling();
}
- return ret.isEmpty() ? null : ret;
+ return ret;
}
/**
@@ -1697,7 +1689,7 @@ class Stylesheet
* exclude-result-prefixes.
*/
final void addNamespaceNodes(Node source, Node target, Document doc,
- Collection elementExcludeResultPrefixes)
+ Collection<String> elementExcludeResultPrefixes)
{
NamedNodeMap attrs = source.getAttributes();
if (attrs != null)
@@ -1768,5 +1760,14 @@ class Stylesheet
dst.setUserData(key, data, this);
}
+ public String toString()
+ {
+ CPStringBuilder b = new CPStringBuilder(getClass().getName());
+ b.append("[templates=");
+ b.append(templates);
+ b.append("]");
+ return b.toString();
+ }
+
}
diff --git a/libjava/classpath/gnu/xml/transform/Template.java b/libjava/classpath/gnu/xml/transform/Template.java
index 1414dac9eb3..7ddef0ae50e 100644
--- a/libjava/classpath/gnu/xml/transform/Template.java
+++ b/libjava/classpath/gnu/xml/transform/Template.java
@@ -37,6 +37,8 @@ exception statement from your version. */
package gnu.xml.transform;
+import gnu.java.lang.CPStringBuilder;
+
import java.io.PrintStream;
import javax.xml.namespace.QName;
import javax.xml.transform.TransformerException;
@@ -226,7 +228,7 @@ class Template
public String toString()
{
- StringBuffer buf = new StringBuffer(getClass().getName());
+ CPStringBuilder buf = new CPStringBuilder(getClass().getName());
buf.append('[');
if (name != null)
{
@@ -243,6 +245,8 @@ class Template
buf.append(",mode=");
buf.append(mode);
}
+ buf.append(",node=");
+ buf.append(node);
buf.append(']');
return buf.toString();
diff --git a/libjava/classpath/gnu/xml/transform/TemplateNode.java b/libjava/classpath/gnu/xml/transform/TemplateNode.java
index 6ff727c073c..ad80c59f922 100644
--- a/libjava/classpath/gnu/xml/transform/TemplateNode.java
+++ b/libjava/classpath/gnu/xml/transform/TemplateNode.java
@@ -52,7 +52,7 @@ import gnu.xml.xpath.DocumentOrderComparator;
abstract class TemplateNode
{
- static final Comparator documentOrderComparator =
+ static final Comparator<Node> documentOrderComparator =
new DocumentOrderComparator();
TemplateNode children;
diff --git a/libjava/classpath/gnu/xml/transform/TemplatesImpl.java b/libjava/classpath/gnu/xml/transform/TemplatesImpl.java
index 527bd979db0..e5395f6fb22 100644
--- a/libjava/classpath/gnu/xml/transform/TemplatesImpl.java
+++ b/libjava/classpath/gnu/xml/transform/TemplatesImpl.java
@@ -37,6 +37,8 @@ exception statement from your version. */
package gnu.xml.transform;
+import gnu.java.lang.CPStringBuilder;
+
import java.util.Properties;
import javax.xml.transform.Templates;
import javax.xml.transform.Transformer;
@@ -76,5 +78,18 @@ class TemplatesImpl
{
return (Properties) outputProperties.clone();
}
-
+
+ public String toString()
+ {
+ CPStringBuilder b = new CPStringBuilder(getClass().getName());
+ b.append("[factory=");
+ b.append(factory);
+ b.append(",stylesheet=");
+ b.append(stylesheet);
+ b.append(",outputProperties=");
+ b.append(outputProperties);
+ b.append("]");
+ return b.toString();
+ }
+
}
diff --git a/libjava/classpath/gnu/xml/transform/TextNode.java b/libjava/classpath/gnu/xml/transform/TextNode.java
index 39423b270eb..93d1d541775 100644
--- a/libjava/classpath/gnu/xml/transform/TextNode.java
+++ b/libjava/classpath/gnu/xml/transform/TextNode.java
@@ -37,6 +37,8 @@ exception statement from your version. */
package gnu.xml.transform;
+import gnu.java.lang.CPStringBuilder;
+
import javax.xml.namespace.QName;
import javax.xml.transform.TransformerException;
import org.w3c.dom.Document;
@@ -106,7 +108,7 @@ final class TextNode
public String toString()
{
- StringBuffer buf = new StringBuffer("text");
+ CPStringBuilder buf = new CPStringBuilder("text");
if (disableOutputEscaping)
{
buf.append('[');
diff --git a/libjava/classpath/gnu/xml/transform/TransformerImpl.java b/libjava/classpath/gnu/xml/transform/TransformerImpl.java
index f43b6602f23..a975c691f29 100644
--- a/libjava/classpath/gnu/xml/transform/TransformerImpl.java
+++ b/libjava/classpath/gnu/xml/transform/TransformerImpl.java
@@ -37,6 +37,8 @@ exception statement from your version. */
package gnu.xml.transform;
+import gnu.java.lang.CPStringBuilder;
+
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
@@ -722,7 +724,7 @@ class TransformerImpl
}
else
{
- StringBuffer buf = new StringBuffer();
+ CPStringBuilder buf = new CPStringBuilder();
buf.append('\n');
for (int i = 0; i < offset + 1; i++)
buf.append(INDENT_WHITESPACE);
@@ -733,7 +735,7 @@ class TransformerImpl
node.insertBefore(doc.createTextNode(ws), ctx);
reindent(doc, ctx, offset + 1);
}
- buf = new StringBuffer();
+ buf = new CPStringBuilder();
buf.append('\n');
for (int i = 0; i < offset; i++)
buf.append(INDENT_WHITESPACE);
diff --git a/libjava/classpath/gnu/xml/transform/TransformerOutputProperties.java b/libjava/classpath/gnu/xml/transform/TransformerOutputProperties.java
index cc8593c4601..9ac5cdc0413 100644
--- a/libjava/classpath/gnu/xml/transform/TransformerOutputProperties.java
+++ b/libjava/classpath/gnu/xml/transform/TransformerOutputProperties.java
@@ -37,6 +37,8 @@ exception statement from your version. */
package gnu.xml.transform;
+import gnu.java.lang.CPStringBuilder;
+
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedHashSet;
@@ -95,7 +97,7 @@ class TransformerOutputProperties
defaultProperties.put(OutputKeys.DOCTYPE_SYSTEM,
stylesheet.outputSystemId);
}
- StringBuffer buf = new StringBuffer();
+ CPStringBuilder buf = new CPStringBuilder();
for (Iterator i = stylesheet.outputCdataSectionElements.iterator();
i.hasNext(); )
{
diff --git a/libjava/classpath/gnu/xml/transform/UnparsedEntityUriFunction.java b/libjava/classpath/gnu/xml/transform/UnparsedEntityUriFunction.java
index 92002f1f5b6..7ba0eae21a4 100644
--- a/libjava/classpath/gnu/xml/transform/UnparsedEntityUriFunction.java
+++ b/libjava/classpath/gnu/xml/transform/UnparsedEntityUriFunction.java
@@ -61,27 +61,28 @@ final class UnparsedEntityUriFunction
implements XPathFunction, Function
{
- List args;
+ List<Expr> args;
public Object evaluate(List args)
throws XPathFunctionException
{
// Useless...
- return Collections.EMPTY_SET;
+ return Collections.emptySet();
}
- public void setArguments(List args)
+ public void setArguments(List<Expr> args)
{
this.args = args;
}
+ @Override
public Object evaluate(Node context, int pos, int len)
{
int arity = args.size();
- List values = new ArrayList(arity);
+ List<Object> values = new ArrayList<Object>(arity);
for (int i = 0; i < arity; i++)
{
- Expr arg = (Expr) args.get(i);
+ Expr arg = args.get(i);
values.add(arg.evaluate(context, pos, len));
}
String name = _string(context, values.get(0));
@@ -107,10 +108,10 @@ final class UnparsedEntityUriFunction
{
UnparsedEntityUriFunction f = new UnparsedEntityUriFunction();
int len = args.size();
- List args2 = new ArrayList(len);
+ List<Expr> args2 = new ArrayList<Expr>(len);
for (int i = 0; i < len; i++)
{
- args2.add(((Expr) args.get(i)).clone(context));
+ args2.add(args.get(i).clone(context));
}
f.setArguments(args2);
return f;
@@ -118,9 +119,9 @@ final class UnparsedEntityUriFunction
public boolean references(QName var)
{
- for (Iterator i = args.iterator(); i.hasNext(); )
+ for (Iterator<Expr> i = args.iterator(); i.hasNext(); )
{
- if (((Expr) i.next()).references(var))
+ if (i.next().references(var))
{
return true;
}
diff --git a/libjava/classpath/gnu/xml/transform/ValueOfNode.java b/libjava/classpath/gnu/xml/transform/ValueOfNode.java
index 68f31e05ae3..156affa77be 100644
--- a/libjava/classpath/gnu/xml/transform/ValueOfNode.java
+++ b/libjava/classpath/gnu/xml/transform/ValueOfNode.java
@@ -37,6 +37,8 @@ exception statement from your version. */
package gnu.xml.transform;
+import gnu.java.lang.CPStringBuilder;
+
import java.util.Collection;
import java.util.Iterator;
import javax.xml.namespace.QName;
@@ -74,7 +76,8 @@ final class ValueOfNode
ret.next = next.clone(stylesheet);
return ret;
}
-
+
+ @Override
void doApply(Stylesheet stylesheet, QName mode,
Node context, int pos, int len,
Node parent, Node nextSibling)
@@ -84,10 +87,9 @@ final class ValueOfNode
String value;
if (ret instanceof Collection)
{
- StringBuffer buf = new StringBuffer();
- for (Iterator i = ((Collection) ret).iterator(); i.hasNext(); )
+ CPStringBuilder buf = new CPStringBuilder();
+ for (Node node : ((Collection<Node>) ret))
{
- Node node = (Node) i.next();
buf.append(Expr.stringValue(node));
}
value = buf.toString();
@@ -126,7 +128,7 @@ final class ValueOfNode
public String toString()
{
- StringBuffer buf = new StringBuffer("value-of");
+ CPStringBuilder buf = new CPStringBuilder("value-of");
buf.append('[');
buf.append("select=");
buf.append(select);
diff --git a/libjava/classpath/gnu/xml/transform/WhenNode.java b/libjava/classpath/gnu/xml/transform/WhenNode.java
index fe3f403ab0c..fc9d5b187ef 100644
--- a/libjava/classpath/gnu/xml/transform/WhenNode.java
+++ b/libjava/classpath/gnu/xml/transform/WhenNode.java
@@ -37,6 +37,8 @@ exception statement from your version. */
package gnu.xml.transform;
+import gnu.java.lang.CPStringBuilder;
+
import javax.xml.namespace.QName;
import javax.xml.transform.TransformerException;
import org.w3c.dom.Node;
@@ -102,7 +104,7 @@ final class WhenNode
public String toString()
{
- StringBuffer buf = new StringBuffer("when");
+ CPStringBuilder buf = new CPStringBuilder("when");
buf.append('[');
buf.append("test=");
buf.append(test);
diff --git a/libjava/classpath/gnu/xml/transform/XSLComparator.java b/libjava/classpath/gnu/xml/transform/XSLComparator.java
index 222f370c8b9..88243693d7f 100644
--- a/libjava/classpath/gnu/xml/transform/XSLComparator.java
+++ b/libjava/classpath/gnu/xml/transform/XSLComparator.java
@@ -51,72 +51,66 @@ import gnu.xml.xpath.Expr;
* @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
*/
class XSLComparator
- implements Comparator
+ implements Comparator<Node>
{
- final List sortKeys;
+ final List<SortKey> sortKeys;
- XSLComparator(List sortKeys)
+ XSLComparator(List<SortKey> sortKeys)
{
this.sortKeys = sortKeys;
}
- public int compare(Object o1, Object o2)
+ public int compare(Node n1, Node n2)
{
- if (o1 instanceof Node && o2 instanceof Node)
+ for (SortKey sortKey : sortKeys)
{
- Node n1 = (Node) o1;
- Node n2 = (Node) o2;
- for (Iterator i = sortKeys.iterator(); i.hasNext(); )
- {
- SortKey sortKey = (SortKey) i.next();
- String k1 = sortKey.key(n1);
- String k2 = sortKey.key(n2);
- if ("text".equals(sortKey.dataType))
- {
- Locale locale = (sortKey.lang == null) ? Locale.getDefault() :
- new Locale(sortKey.lang);
- Collator collator = Collator.getInstance(locale);
- int d = collator.compare(k1, k2);
- if (d != 0)
- {
- switch (sortKey.caseOrder)
- {
- case SortKey.UPPER_FIRST:
- // TODO
- break;
- case SortKey.LOWER_FIRST:
- // TODO
- break;
- }
- if (sortKey.descending)
- {
- d = -d;
- }
- return d;
- }
- }
- else if ("number".equals(sortKey.dataType))
- {
- double kn1 = Expr._number(n1, k1);
- double kn2 = Expr._number(n2, k2);
- int d;
- if (Double.isNaN(kn1) || Double.isInfinite(kn2))
- {
- d = -1;
- }
- else if (Double.isNaN(kn2) || Double.isInfinite(kn1))
- {
- d = 1;
- }
- else
- {
- // conversion to int may give 0 for small numbers
- d = (kn1 > kn2) ? 1 : (kn1 < kn2) ? -1 : 0;
- }
- return (sortKey.descending) ? -d : d;
- }
- }
+ String k1 = sortKey.key(n1);
+ String k2 = sortKey.key(n2);
+ if ("text".equals(sortKey.dataType))
+ {
+ Locale locale = (sortKey.lang == null) ? Locale.getDefault() :
+ new Locale(sortKey.lang);
+ Collator collator = Collator.getInstance(locale);
+ int d = collator.compare(k1, k2);
+ if (d != 0)
+ {
+ switch (sortKey.caseOrder)
+ {
+ case SortKey.UPPER_FIRST:
+ // TODO
+ break;
+ case SortKey.LOWER_FIRST:
+ // TODO
+ break;
+ }
+ if (sortKey.descending)
+ {
+ d = -d;
+ }
+ return d;
+ }
+ }
+ else if ("number".equals(sortKey.dataType))
+ {
+ double kn1 = Expr._number(n1, k1);
+ double kn2 = Expr._number(n2, k2);
+ int d;
+ if (Double.isNaN(kn1) || Double.isInfinite(kn2))
+ {
+ d = -1;
+ }
+ else if (Double.isNaN(kn2) || Double.isInfinite(kn1))
+ {
+ d = 1;
+ }
+ else
+ {
+ // conversion to int may give 0 for small numbers
+ d = (kn1 > kn2) ? 1 : (kn1 < kn2) ? -1 : 0;
+ }
+ return (sortKey.descending) ? -d : d;
+ }
}
return 0;
}
diff --git a/libjava/classpath/gnu/xml/transform/XSLURIResolver.java b/libjava/classpath/gnu/xml/transform/XSLURIResolver.java
index 8bb8977315e..c1379211ae5 100644
--- a/libjava/classpath/gnu/xml/transform/XSLURIResolver.java
+++ b/libjava/classpath/gnu/xml/transform/XSLURIResolver.java
@@ -75,8 +75,8 @@ class XSLURIResolver
implements URIResolver
{
- Map lastModifiedCache = new HashMap();
- Map nodeCache = new HashMap();
+ final Map<String,Long> lastModifiedCache = new HashMap<String,Long>();
+ final Map<String,Node> nodeCache = new HashMap<String,Node>();
DocumentBuilder builder;
URIResolver userResolver;
ErrorListener userListener;
@@ -157,10 +157,10 @@ class XSLURIResolver
if (url != null)
{
systemId = url.toString();
- node = (Node) nodeCache.get(systemId);
+ node = nodeCache.get(systemId);
// Is the resource up to date?
URLConnection conn = url.openConnection();
- Long llm = (Long) lastModifiedCache.get(systemId);
+ Long llm = lastModifiedCache.get(systemId);
if (llm != null)
{
lastLastModified = llm.longValue();
@@ -301,6 +301,7 @@ class XSLURIResolver
{
SAXEventSink eventSink = new SAXEventSink();
eventSink.setReader(reader);
+ eventSink.setNamespaceAware(true);
reader.setContentHandler(eventSink);
reader.setDTDHandler(eventSink);
reader.setProperty("http://xml.org/sax/properties/lexical-handler",
diff --git a/libjava/classpath/gnu/xml/util/DoParse.java b/libjava/classpath/gnu/xml/util/DoParse.java
index 5da086ed8f9..a8f50969168 100644
--- a/libjava/classpath/gnu/xml/util/DoParse.java
+++ b/libjava/classpath/gnu/xml/util/DoParse.java
@@ -37,6 +37,8 @@ exception statement from your version. */
package gnu.xml.util;
+import gnu.java.lang.CPStringBuilder;
+
import java.io.IOException;
import org.xml.sax.ErrorHandler;
@@ -271,7 +273,7 @@ final public class DoParse
String label,
SAXParseException e
) {
- StringBuffer buf = new StringBuffer ();
+ CPStringBuilder buf = new CPStringBuilder ();
int temp;
buf.append ("** ");
diff --git a/libjava/classpath/gnu/xml/util/XCat.java b/libjava/classpath/gnu/xml/util/XCat.java
index f3704cd25c7..93127f44211 100644
--- a/libjava/classpath/gnu/xml/util/XCat.java
+++ b/libjava/classpath/gnu/xml/util/XCat.java
@@ -38,6 +38,8 @@ exception statement from your version. */
package gnu.xml.util;
+import gnu.java.lang.CPStringBuilder;
+
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.net.URL;
@@ -623,7 +625,7 @@ public class XCat implements EntityResolver2
private static String normalizePublicId (boolean full, String publicId)
{
if (publicId.startsWith ("urn:publicid:")) {
- StringBuffer buf = new StringBuffer ();
+ CPStringBuilder buf = new CPStringBuilder ();
char chars [] = publicId.toCharArray ();
boolean hasbug = false;
@@ -814,7 +816,7 @@ System.err.println ("nyet unhexing public id: " + publicId);
replace = (String) rewrites.get (temp);
}
if (prefix != null) {
- StringBuffer buf = new StringBuffer (replace);
+ CPStringBuilder buf = new CPStringBuilder (replace);
buf.append (uri.substring (prefixLen));
// IF the URI is accessible ...
return new InputSource (buf.toString ());
diff --git a/libjava/classpath/gnu/xml/util/XMLWriter.java b/libjava/classpath/gnu/xml/util/XMLWriter.java
index 24b38923fa2..27459472019 100644
--- a/libjava/classpath/gnu/xml/util/XMLWriter.java
+++ b/libjava/classpath/gnu/xml/util/XMLWriter.java
@@ -37,6 +37,8 @@ exception statement from your version. */
package gnu.xml.util;
+import gnu.java.lang.CPStringBuilder;
+
import java.io.BufferedWriter;
import java.io.CharConversionException;
import java.io.IOException;
@@ -152,7 +154,7 @@ public class XMLWriter
private String eol = sysEOL;
private short dangerMask;
- private StringBuffer stringBuf;
+ private CPStringBuilder stringBuf;
private Locator locator;
private ErrorHandler errHandler;
@@ -289,7 +291,7 @@ public class XMLWriter
}
if (dangerMask != 0)
- stringBuf = new StringBuffer ();
+ stringBuf = new CPStringBuilder ();
}
this.encoding = encoding;
diff --git a/libjava/classpath/gnu/xml/validation/datatype/EntitiesType.java b/libjava/classpath/gnu/xml/validation/datatype/EntitiesType.java
index 98554e1847a..d16106e0044 100644
--- a/libjava/classpath/gnu/xml/validation/datatype/EntitiesType.java
+++ b/libjava/classpath/gnu/xml/validation/datatype/EntitiesType.java
@@ -37,6 +37,8 @@ exception statement from your version. */
package gnu.xml.validation.datatype;
+import gnu.java.lang.CPStringBuilder;
+
import javax.xml.XMLConstants;
import javax.xml.namespace.QName;
import org.relaxng.datatype.DatatypeException;
@@ -75,7 +77,7 @@ final class EntitiesType
throws DatatypeException
{
super.checkValid(value, context);
- StringBuffer buf = new StringBuffer();
+ CPStringBuilder buf = new CPStringBuilder();
int len = value.length();
for (int i = 0; i < len; i++)
{
diff --git a/libjava/classpath/gnu/xml/validation/datatype/NMTokensType.java b/libjava/classpath/gnu/xml/validation/datatype/NMTokensType.java
index 62524edf7cb..d49964561a6 100644
--- a/libjava/classpath/gnu/xml/validation/datatype/NMTokensType.java
+++ b/libjava/classpath/gnu/xml/validation/datatype/NMTokensType.java
@@ -37,6 +37,8 @@ exception statement from your version. */
package gnu.xml.validation.datatype;
+import gnu.java.lang.CPStringBuilder;
+
import java.io.IOException;
import javax.xml.XMLConstants;
import javax.xml.namespace.QName;
@@ -79,7 +81,7 @@ final class NMTokensType
{
super.checkValid(value, context);
int len = value.length();
- StringBuffer buf = new StringBuffer();
+ CPStringBuilder buf = new CPStringBuilder();
for (int i = 0; i < len; i++)
{
char c = value.charAt(i);
diff --git a/libjava/classpath/gnu/xml/xpath/ArithmeticExpr.java b/libjava/classpath/gnu/xml/xpath/ArithmeticExpr.java
index cbc1ee0648b..61098d6e4f2 100644
--- a/libjava/classpath/gnu/xml/xpath/ArithmeticExpr.java
+++ b/libjava/classpath/gnu/xml/xpath/ArithmeticExpr.java
@@ -37,6 +37,8 @@ exception statement from your version. */
package gnu.xml.xpath;
+import gnu.java.lang.CPStringBuilder;
+
import javax.xml.namespace.QName;
import org.w3c.dom.Node;
@@ -139,7 +141,7 @@ final class ArithmeticExpr
public String toString()
{
- StringBuffer buf = new StringBuffer();
+ CPStringBuilder buf = new CPStringBuilder();
buf.append(lhs);
buf.append(' ');
switch (op)
diff --git a/libjava/classpath/gnu/xml/xpath/BooleanFunction.java b/libjava/classpath/gnu/xml/xpath/BooleanFunction.java
index 256de0382a8..f661b2ac285 100644
--- a/libjava/classpath/gnu/xml/xpath/BooleanFunction.java
+++ b/libjava/classpath/gnu/xml/xpath/BooleanFunction.java
@@ -61,9 +61,9 @@ final class BooleanFunction
final Expr arg;
- BooleanFunction(List args)
+ BooleanFunction(List<Expr> args)
{
- this((Expr) args.get(0));
+ this(args.get(0));
}
BooleanFunction(Expr arg)
diff --git a/libjava/classpath/gnu/xml/xpath/CeilingFunction.java b/libjava/classpath/gnu/xml/xpath/CeilingFunction.java
index 7db08fc5d61..15398842248 100644
--- a/libjava/classpath/gnu/xml/xpath/CeilingFunction.java
+++ b/libjava/classpath/gnu/xml/xpath/CeilingFunction.java
@@ -54,9 +54,9 @@ final class CeilingFunction
final Expr arg;
- CeilingFunction(List args)
+ CeilingFunction(List<Expr> args)
{
- this((Expr) args.get(0));
+ this(args.get(0));
}
CeilingFunction(Expr arg)
diff --git a/libjava/classpath/gnu/xml/xpath/ConcatFunction.java b/libjava/classpath/gnu/xml/xpath/ConcatFunction.java
index fddd7ae2520..a61a45477b1 100644
--- a/libjava/classpath/gnu/xml/xpath/ConcatFunction.java
+++ b/libjava/classpath/gnu/xml/xpath/ConcatFunction.java
@@ -37,6 +37,8 @@ exception statement from your version. */
package gnu.xml.xpath;
+import gnu.java.lang.CPStringBuilder;
+
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@@ -52,19 +54,19 @@ final class ConcatFunction
extends Expr
{
- final List args;
+ final List<Expr> args;
- ConcatFunction(List args)
+ ConcatFunction(List<Expr> args)
{
this.args = args;
}
+ @Override
public Object evaluate(Node context, int pos, int len)
{
- StringBuffer buf = new StringBuffer();
- for (Iterator i = args.iterator(); i.hasNext(); )
+ CPStringBuilder buf = new CPStringBuilder();
+ for (Expr arg : args)
{
- Expr arg = (Expr) i.next();
Object val = arg.evaluate(context, pos, len);
buf.append(_string(context, val));
}
@@ -74,19 +76,19 @@ final class ConcatFunction
public Expr clone(Object context)
{
int len = args.size();
- List args2 = new ArrayList(len);
+ List<Expr> args2 = new ArrayList<Expr>(len);
for (int i = 0; i < len; i++)
{
- args2.add(((Expr) args.get(i)).clone(context));
+ args2.add(args.get(i).clone(context));
}
return new ConcatFunction(args2);
}
public boolean references(QName var)
{
- for (Iterator i = args.iterator(); i.hasNext(); )
+ for (Iterator<Expr> i = args.iterator(); i.hasNext(); )
{
- if (((Expr) i.next()).references(var))
+ if (i.next().references(var))
{
return true;
}
@@ -96,7 +98,7 @@ final class ConcatFunction
public String toString()
{
- StringBuffer buf = new StringBuffer("concat(");
+ CPStringBuilder buf = new CPStringBuilder("concat(");
int len = args.size();
for (int i = 0; i < len; i++)
{
diff --git a/libjava/classpath/gnu/xml/xpath/ContainsFunction.java b/libjava/classpath/gnu/xml/xpath/ContainsFunction.java
index fc2f33faf52..620606b3f20 100644
--- a/libjava/classpath/gnu/xml/xpath/ContainsFunction.java
+++ b/libjava/classpath/gnu/xml/xpath/ContainsFunction.java
@@ -54,9 +54,9 @@ final class ContainsFunction
final Expr arg1;
final Expr arg2;
- ContainsFunction(List args)
+ ContainsFunction(List<Expr> args)
{
- this((Expr) args.get(0), (Expr) args.get(1));
+ this(args.get(0), args.get(1));
}
ContainsFunction(Expr arg1, Expr arg2)
@@ -65,6 +65,7 @@ final class ContainsFunction
this.arg2 = arg2;
}
+ @Override
public Object evaluate(Node context, int pos, int len)
{
Object val1 = arg1.evaluate(context, pos, len);
diff --git a/libjava/classpath/gnu/xml/xpath/CountFunction.java b/libjava/classpath/gnu/xml/xpath/CountFunction.java
index cb534bffc9e..f29d833106d 100644
--- a/libjava/classpath/gnu/xml/xpath/CountFunction.java
+++ b/libjava/classpath/gnu/xml/xpath/CountFunction.java
@@ -54,9 +54,9 @@ final class CountFunction
final Expr arg;
- CountFunction(List args)
+ CountFunction(List<Expr> args)
{
- this((Expr) args.get(0));
+ this(args.get(0));
}
CountFunction(Expr arg)
@@ -64,10 +64,11 @@ final class CountFunction
this.arg = arg;
}
+ @Override
public Object evaluate(Node context, int pos, int len)
{
Object val = arg.evaluate(context, pos, len);
- return new Double((double) ((Collection) val).size());
+ return new Double((double) ((Collection<?>) val).size());
}
public Expr clone(Object context)
diff --git a/libjava/classpath/gnu/xml/xpath/DocumentOrderComparator.java b/libjava/classpath/gnu/xml/xpath/DocumentOrderComparator.java
index c7d7de9f7c7..605749d09d7 100644
--- a/libjava/classpath/gnu/xml/xpath/DocumentOrderComparator.java
+++ b/libjava/classpath/gnu/xml/xpath/DocumentOrderComparator.java
@@ -46,18 +46,12 @@ import org.w3c.dom.Node;
* @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
*/
public class DocumentOrderComparator
- implements Comparator
+ implements Comparator<Node>
{
- public int compare(Object o1, Object o2)
+ public int compare(Node n1, Node n2)
{
- if (o1 instanceof Node && o2 instanceof Node)
- {
- Node n1 = (Node)o1;
- Node n2 = (Node)o2;
- return (int) n1.compareDocumentPosition(n2);
- }
- return 0;
+ return (int) n1.compareDocumentPosition(n2);
}
}
diff --git a/libjava/classpath/gnu/xml/xpath/EqualityExpr.java b/libjava/classpath/gnu/xml/xpath/EqualityExpr.java
index 6d00cee89a9..3b6fd568a86 100644
--- a/libjava/classpath/gnu/xml/xpath/EqualityExpr.java
+++ b/libjava/classpath/gnu/xml/xpath/EqualityExpr.java
@@ -62,6 +62,7 @@ final class EqualityExpr
this.invert = invert;
}
+ @Override
public Object evaluate(Node context, int pos, int len)
{
boolean val = evaluateImpl(context, pos, len);
@@ -90,19 +91,20 @@ final class EqualityExpr
boolean frns = right instanceof Collection;
if (flns && frns)
{
- Collection lns = (Collection) left;
- Collection rns = (Collection) right;
+ /* Suppression is safe, as we know context produces Collection<Node> */
+ @SuppressWarnings("unchecked")
+ Collection<Node> lns = (Collection<Node>) left;
+ @SuppressWarnings("unchecked")
+ Collection<Node> rns = (Collection<Node>) right;
if (lns.isEmpty())
{
return false;
}
boolean all = true;
- for (Iterator i = lns.iterator(); i.hasNext(); )
- {
- Node ltest = (Node) i.next();
- for (Iterator j = rns.iterator(); j.hasNext(); )
- {
- Node rtest = (Node) j.next();
+ for (Node ltest : lns)
+ {
+ for (Node rtest : rns)
+ {
if (ltest == rtest || ltest.equals(rtest))
{
// much shorter
@@ -138,13 +140,14 @@ final class EqualityExpr
boolean frn = right instanceof Double;
if ((flns && frn) || (frns && fln))
{
- Collection ns = flns ? (Collection) left : (Collection) right;
+ /* Suppression is safe, as we know context produces Collection<Node> */
+ @SuppressWarnings("unchecked")
+ Collection<Node> ns = flns ? (Collection<Node>) left : (Collection<Node>) right;
double n = fln ? ((Double) left).doubleValue() :
((Double) right).doubleValue();
boolean all = true;
- for (Iterator i = ns.iterator(); i.hasNext(); )
+ for (Node test : ns)
{
- Node test = (Node) i.next();
double nn = _number(context, stringValue(test));
if (nn == n)
{
@@ -171,12 +174,13 @@ final class EqualityExpr
boolean frs = right instanceof String;
if ((flns && frs) || (frns && fls))
{
- Collection ns = flns ? (Collection) left : (Collection) right;
+ /* Suppression is safe, as we know context produces Collection<Node> */
+ @SuppressWarnings("unchecked")
+ Collection<Node> ns = flns ? (Collection<Node>) left : (Collection<Node>) right;
String s = fls ? (String) left : (String) right;
boolean all = true;
- for (Iterator i = ns.iterator(); i.hasNext(); )
+ for (Node test : ns)
{
- Node test = (Node) i.next();
if (stringValue(test).equals(s))
{
if (!invert)
@@ -202,7 +206,9 @@ final class EqualityExpr
boolean frb = right instanceof Boolean;
if ((flns && frb) || (frns && flb))
{
- Collection ns = flns ? (Collection) left : (Collection) right;
+ /* Suppression is safe, as we know context produces Collection<Node> */
+ @SuppressWarnings("unchecked")
+ Collection<Node> ns = flns ? (Collection<Node>) left : (Collection<Node>) right;
boolean b = flb ? ((Boolean) left).booleanValue() :
((Boolean) right).booleanValue();
return _boolean(context, ns) == b;
diff --git a/libjava/classpath/gnu/xml/xpath/Expr.java b/libjava/classpath/gnu/xml/xpath/Expr.java
index cafc83b0d37..87ce3dfb63c 100644
--- a/libjava/classpath/gnu/xml/xpath/Expr.java
+++ b/libjava/classpath/gnu/xml/xpath/Expr.java
@@ -37,6 +37,8 @@ exception statement from your version. */
package gnu.xml.xpath;
+import gnu.java.lang.CPStringBuilder;
+
import java.io.IOException;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
@@ -73,7 +75,7 @@ public abstract class Expr
implements XPathExpression
{
- protected static final Comparator documentOrderComparator =
+ protected static final Comparator<Node> documentOrderComparator =
new DocumentOrderComparator();
protected static final DecimalFormat decimalFormat =
@@ -84,14 +86,14 @@ public abstract class Expr
static class ExprNodeSet implements NodeList
{
- private ArrayList list;
+ private ArrayList<Node> list;
- ExprNodeSet(Collection collection)
+ ExprNodeSet(Collection<Node> collection)
{
if (collection instanceof ArrayList)
- list = (ArrayList) collection;
+ list = (ArrayList<Node>) collection;
else
- list = new ArrayList(collection);
+ list = new ArrayList<Node>(collection);
}
public int getLength()
@@ -103,7 +105,7 @@ public abstract class Expr
{
try
{
- return (Node) list.get(index);
+ return list.get(index);
}
catch (ArrayIndexOutOfBoundsException e)
{
@@ -141,14 +143,17 @@ public abstract class Expr
{
if (ret instanceof Collection)
{
- Collection ns = (Collection) ret;
+ /* Suppression is safe, as we know context
+ produces Collection<Node> */
+ @SuppressWarnings("unchecked")
+ Collection<Node> ns = (Collection<Node>) ret;
switch (ns.size())
{
case 0:
ret = null;
break;
case 1:
- ret = (Node) ns.iterator().next();
+ ret = ns.iterator().next();
break;
default:
throw new XPathExpressionException("multiple nodes in node-set");
@@ -166,7 +171,12 @@ public abstract class Expr
throw new XPathExpressionException("return value is not a node-set");
}
if (ret != null)
- ret = new ExprNodeSet((Collection) ret);
+ {
+ /* Suppression is safe, as we know context produces Collection<Node> */
+ @SuppressWarnings("unchecked")
+ Collection<Node> nodes = (Collection<Node>) ret;
+ ret = new ExprNodeSet(nodes);
+ }
}
}
return ret;
@@ -229,15 +239,17 @@ public abstract class Expr
* same document as the context node that have a unique ID equal to any of
* the tokens in the list.
*/
- public static Collection _id(Node context, Object object)
+ public static Collection<Node> _id(Node context, Object object)
{
- Set ret = new HashSet();
+ Set<Node> ret = new HashSet<Node>();
if (object instanceof Collection)
{
- Collection nodeSet = (Collection) object;
- for (Iterator i = nodeSet.iterator(); i.hasNext(); )
+ /* Suppression is safe, as the iteration will check each value is a Node */
+ @SuppressWarnings("unchecked")
+ Collection<Node> nodeSet = (Collection<Node>) object;
+ for (Iterator<Node> i = nodeSet.iterator(); i.hasNext(); )
{
- String string = stringValue((Node) i.next());
+ String string = stringValue(i.next());
ret.addAll(_id (context, string));
}
}
@@ -266,7 +278,7 @@ public abstract class Expr
* an empty string is returned. If the argument is omitted, it defaults to
* a node-set with the context node as its only member.
*/
- public static String _local_name(Node context, Collection nodeSet)
+ public static String _local_name(Node context, Collection<Node> nodeSet)
{
if (nodeSet == null || nodeSet.isEmpty())
return "";
@@ -283,7 +295,7 @@ public abstract class Expr
* empty string is returned. If the argument is omitted, it defaults to a
* node-set with the context node as its only member.
*/
- public static String _namespace_uri(Node context, Collection nodeSet)
+ public static String _namespace_uri(Node context, Collection<Node> nodeSet)
{
if (nodeSet == null || nodeSet.isEmpty())
return "";
@@ -308,7 +320,7 @@ public abstract class Expr
* string is returned. If the argument it omitted, it defaults to a
* node-set with the context node as its only member.
*/
- public static String _name(Node context, Collection nodeSet)
+ public static String _name(Node context, Collection<Node> nodeSet)
{
if (nodeSet == null || nodeSet.isEmpty())
return "";
@@ -327,11 +339,11 @@ public abstract class Expr
/**
* Returns the first node in the set in document order.
*/
- static Node firstNode(Collection nodeSet)
+ static Node firstNode(Collection<Node> nodeSet)
{
- List list = new ArrayList(nodeSet);
+ List<Node> list = new ArrayList<Node>(nodeSet);
Collections.sort(list, documentOrderComparator);
- return (Node) list.get(0);
+ return list.get(0);
}
/* -- 4.2 String Functions -- */
@@ -387,7 +399,10 @@ public abstract class Expr
}
if (object instanceof Collection)
{
- Collection nodeSet = (Collection) object;
+ /* Suppression is safe, as we fail immediately if the
+ * first element is not a Node and don't use the rest */
+ @SuppressWarnings("unchecked")
+ Collection<Node> nodeSet = (Collection<Node>) object;
if (nodeSet.isEmpty())
{
return "";
@@ -422,7 +437,7 @@ public abstract class Expr
}
if (object instanceof Collection)
{
- return ((Collection) object).size() != 0;
+ return ((Collection<?>) object).size() != 0;
}
return false; // TODO user defined types
}
@@ -448,8 +463,12 @@ public abstract class Expr
}
if (object instanceof Collection)
{
+ /* Suppression is safe, as we fail immediately if one
+ * of the elements is not a Node */
+ @SuppressWarnings("unchecked")
+ Collection<Node> nodeSet = (Collection<Node>) object;
// Convert node-set to string
- object = stringValue((Collection) object);
+ object = stringValue(nodeSet);
}
if (object instanceof String)
{
@@ -469,12 +488,12 @@ public abstract class Expr
/**
* Computes the XPath string-value of the specified node-set.
*/
- public static String stringValue(Collection nodeSet)
+ public static String stringValue(Collection<Node> nodeSet)
{
- StringBuffer buf = new StringBuffer();
- for (Iterator i = nodeSet.iterator(); i.hasNext(); )
+ CPStringBuilder buf = new CPStringBuilder();
+ for (Iterator<Node> i = nodeSet.iterator(); i.hasNext(); )
{
- buf.append(stringValue((Node) i.next()));
+ buf.append(stringValue(i.next()));
}
return buf.toString();
}
@@ -494,7 +513,7 @@ public abstract class Expr
case Node.DOCUMENT_NODE: // 5.1 Root Node
case Node.DOCUMENT_FRAGMENT_NODE:
case Node.ELEMENT_NODE: // 5.2 Element Nodes
- StringBuffer buf = new StringBuffer();
+ CPStringBuilder buf = new CPStringBuilder();
for (Node ctx = node.getFirstChild(); ctx != null;
ctx = ctx.getNextSibling())
{
diff --git a/libjava/classpath/gnu/xml/xpath/FloorFunction.java b/libjava/classpath/gnu/xml/xpath/FloorFunction.java
index c03c0e7edaf..bbf56c91178 100644
--- a/libjava/classpath/gnu/xml/xpath/FloorFunction.java
+++ b/libjava/classpath/gnu/xml/xpath/FloorFunction.java
@@ -54,9 +54,9 @@ final class FloorFunction
final Expr arg;
- FloorFunction(List args)
+ FloorFunction(List<Expr> args)
{
- this((Expr) args.get(0));
+ this(args.get(0));
}
FloorFunction(Expr arg)
@@ -64,6 +64,7 @@ final class FloorFunction
this.arg = arg;
}
+ @Override
public Object evaluate(Node context, int pos, int len)
{
Object val = arg.evaluate(context, pos, len);
diff --git a/libjava/classpath/gnu/xml/xpath/Function.java b/libjava/classpath/gnu/xml/xpath/Function.java
index aecd49d9c73..12e2e1141fd 100644
--- a/libjava/classpath/gnu/xml/xpath/Function.java
+++ b/libjava/classpath/gnu/xml/xpath/Function.java
@@ -51,7 +51,7 @@ public interface Function
/**
* Sets the list of expressions to evaluate as parameter values.
*/
- void setArguments(List args);
+ void setArguments(List<Expr> args);
}
diff --git a/libjava/classpath/gnu/xml/xpath/FunctionCall.java b/libjava/classpath/gnu/xml/xpath/FunctionCall.java
index 669efbf1866..e811f53a2ab 100644
--- a/libjava/classpath/gnu/xml/xpath/FunctionCall.java
+++ b/libjava/classpath/gnu/xml/xpath/FunctionCall.java
@@ -37,6 +37,8 @@ exception statement from your version. */
package gnu.xml.xpath;
+import gnu.java.lang.CPStringBuilder;
+
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
@@ -58,20 +60,24 @@ public final class FunctionCall
final XPathFunctionResolver resolver;
final String name;
- final List args;
+ final List<Expr> args;
public FunctionCall(XPathFunctionResolver resolver, String name)
{
- this(resolver, name, Collections.EMPTY_LIST);
+ this(resolver, name, null);
}
- public FunctionCall(XPathFunctionResolver resolver, String name, List args)
+ public FunctionCall(XPathFunctionResolver resolver, String name, List<Expr> args)
{
this.resolver = resolver;
this.name = name;
- this.args = args;
+ if (args == null)
+ this.args = Collections.emptyList();
+ else
+ this.args = args;
}
+ @Override
public Object evaluate(Node context, int pos, int len)
{
if (resolver != null)
@@ -92,7 +98,7 @@ public final class FunctionCall
}
else
{
- List values = new ArrayList(arity);
+ List<Object> values = new ArrayList<Object>(arity);
for (int i = 0; i < arity; i++)
{
Expr arg = (Expr) args.get(i);
@@ -117,10 +123,10 @@ public final class FunctionCall
public Expr clone(Object context)
{
int len = args.size();
- List args2 = new ArrayList(len);
+ List<Expr> args2 = new ArrayList<Expr>(len);
for (int i = 0; i < len; i++)
{
- args2.add(((Expr) args.get(i)).clone(context));
+ args2.add(args.get(i).clone(context));
}
XPathFunctionResolver r = resolver;
if (context instanceof XPathFunctionResolver)
@@ -132,9 +138,9 @@ public final class FunctionCall
public boolean references(QName var)
{
- for (Iterator i = args.iterator(); i.hasNext(); )
+ for (Iterator<Expr> i = args.iterator(); i.hasNext(); )
{
- if (((Expr) i.next()).references(var))
+ if (i.next().references(var))
{
return true;
}
@@ -144,7 +150,7 @@ public final class FunctionCall
public String toString()
{
- StringBuffer buf = new StringBuffer();
+ CPStringBuilder buf = new CPStringBuilder();
buf.append(name);
buf.append('(');
int len = args.size();
diff --git a/libjava/classpath/gnu/xml/xpath/IdFunction.java b/libjava/classpath/gnu/xml/xpath/IdFunction.java
index 74979541957..b3d2208c8e4 100644
--- a/libjava/classpath/gnu/xml/xpath/IdFunction.java
+++ b/libjava/classpath/gnu/xml/xpath/IdFunction.java
@@ -62,9 +62,9 @@ public final class IdFunction
final Expr arg;
- IdFunction(List args)
+ IdFunction(List<Expr> args)
{
- this((Expr) args.get(0));
+ this(args.get(0));
}
public IdFunction(Expr arg)
@@ -75,9 +75,10 @@ public final class IdFunction
public boolean matches(Node context)
{
Object ret = evaluate(context, 1, 1);
- return !((Collection) ret).isEmpty();
+ return !((Collection<?>) ret).isEmpty();
}
+ @Override
public Object evaluate(Node context, int pos, int len)
{
Object val = arg.evaluate(context, pos, len);
diff --git a/libjava/classpath/gnu/xml/xpath/LangFunction.java b/libjava/classpath/gnu/xml/xpath/LangFunction.java
index 584787efbf7..33cf8b0a2ab 100644
--- a/libjava/classpath/gnu/xml/xpath/LangFunction.java
+++ b/libjava/classpath/gnu/xml/xpath/LangFunction.java
@@ -64,9 +64,9 @@ final class LangFunction
final Expr arg;
- LangFunction(List args)
+ LangFunction(List<Expr> args)
{
- this((Expr) args.get(0));
+ this(args.get(0));
}
LangFunction(Expr arg)
@@ -74,6 +74,7 @@ final class LangFunction
this.arg = arg;
}
+ @Override
public Object evaluate(Node context, int pos, int len)
{
Object val = arg.evaluate(context, pos, len);
diff --git a/libjava/classpath/gnu/xml/xpath/LocalNameFunction.java b/libjava/classpath/gnu/xml/xpath/LocalNameFunction.java
index 84fb6d48288..dbad9d3b42a 100644
--- a/libjava/classpath/gnu/xml/xpath/LocalNameFunction.java
+++ b/libjava/classpath/gnu/xml/xpath/LocalNameFunction.java
@@ -59,9 +59,9 @@ final class LocalNameFunction
final Expr arg;
- LocalNameFunction(List args)
+ LocalNameFunction(List<Expr> args)
{
- this(args.size() > 0 ? (Expr) args.get(0) : null);
+ this(args.size() > 0 ? args.get(0) : null);
}
LocalNameFunction(Expr arg)
@@ -69,11 +69,14 @@ final class LocalNameFunction
this.arg = arg;
}
+ @Override
public Object evaluate(Node context, int pos, int len)
{
- Object val = (arg == null) ? Collections.singleton(context) :
- arg.evaluate(context, pos, len);
- return _local_name(context, (Collection) val);
+ /* Suppression is safe, as we know context produces Collection<Node> */
+ @SuppressWarnings("unchecked")
+ Collection<Node> val = (arg == null) ? Collections.singleton(context) :
+ (Collection<Node>) arg.evaluate(context, pos, len);
+ return _local_name(context, val);
}
public Expr clone(Object context)
diff --git a/libjava/classpath/gnu/xml/xpath/NameFunction.java b/libjava/classpath/gnu/xml/xpath/NameFunction.java
index ea49741fa57..239a53453be 100644
--- a/libjava/classpath/gnu/xml/xpath/NameFunction.java
+++ b/libjava/classpath/gnu/xml/xpath/NameFunction.java
@@ -67,9 +67,9 @@ final class NameFunction
final Expr arg;
- NameFunction(List args)
+ NameFunction(List<Expr> args)
{
- this(args.size() > 0 ? (Expr) args.get(0) : null);
+ this(args.size() > 0 ? args.get(0) : null);
}
NameFunction(Expr arg)
@@ -77,24 +77,30 @@ final class NameFunction
this.arg = arg;
}
+ @Override
public Object evaluate(Node context, int pos, int len)
{
- Object val = (arg == null) ? Collections.singleton(context) :
- arg.evaluate(context, pos, len);
- return _name(context, (Collection) val);
+ /* Suppression is safe, as we know context produces Collection<Node> */
+ @SuppressWarnings("unchecked")
+ Collection<Node> val = (arg == null) ? Collections.singleton(context) :
+ (Collection<Node>) arg.evaluate(context, pos, len);
+ return _name(context, val);
}
+ @Override
public Expr clone(Object context)
{
return new NameFunction((arg == null) ? null :
arg.clone(context));
}
-
+
+ @Override
public boolean references(QName var)
{
return (arg == null) ? false : arg.references(var);
}
+ @Override
public String toString()
{
return (arg == null) ? "name()" : "name(" + arg + ")";
diff --git a/libjava/classpath/gnu/xml/xpath/NamespaceUriFunction.java b/libjava/classpath/gnu/xml/xpath/NamespaceUriFunction.java
index 3ae46f7ee71..56da90f8c0a 100644
--- a/libjava/classpath/gnu/xml/xpath/NamespaceUriFunction.java
+++ b/libjava/classpath/gnu/xml/xpath/NamespaceUriFunction.java
@@ -59,9 +59,9 @@ final class NamespaceUriFunction
final Expr arg;
- NamespaceUriFunction(List args)
+ NamespaceUriFunction(List<Expr> args)
{
- this(args.size() > 0 ? (Expr) args.get(0) : null);
+ this(args.size() > 0 ? args.get(0) : null);
}
NamespaceUriFunction(Expr arg)
@@ -69,11 +69,14 @@ final class NamespaceUriFunction
this.arg = arg;
}
+ @Override
public Object evaluate(Node context, int pos, int len)
{
- Object val = (arg == null) ? Collections.singleton(context) :
- arg.evaluate(context, pos, len);
- return _namespace_uri(context, (Collection) val);
+ /* Suppression is safe, as we know context produces Collection<Node> */
+ @SuppressWarnings("unchecked")
+ Collection<Node> val = (arg == null) ? Collections.singleton(context) :
+ (Collection<Node>) arg.evaluate(context, pos, len);
+ return _namespace_uri(context, val);
}
public Expr clone(Object context)
diff --git a/libjava/classpath/gnu/xml/xpath/NormalizeSpaceFunction.java b/libjava/classpath/gnu/xml/xpath/NormalizeSpaceFunction.java
index b7358e8d8e4..30069acdc43 100644
--- a/libjava/classpath/gnu/xml/xpath/NormalizeSpaceFunction.java
+++ b/libjava/classpath/gnu/xml/xpath/NormalizeSpaceFunction.java
@@ -37,6 +37,8 @@ exception statement from your version. */
package gnu.xml.xpath;
+import gnu.java.lang.CPStringBuilder;
+
import java.util.List;
import java.util.StringTokenizer;
import javax.xml.namespace.QName;
@@ -59,9 +61,9 @@ final class NormalizeSpaceFunction
final Expr arg;
- NormalizeSpaceFunction(List args)
+ NormalizeSpaceFunction(List<Expr> args)
{
- this((Expr) args.get(0));
+ this(args.get(0));
}
NormalizeSpaceFunction(Expr arg)
@@ -69,12 +71,13 @@ final class NormalizeSpaceFunction
this.arg = arg;
}
+ @Override
public Object evaluate(Node context, int pos, int len)
{
Object val = (arg == null) ? null : arg.evaluate(context, pos, len);
String s = _string(context, val);
StringTokenizer st = new StringTokenizer(s, " \t\r\n");
- StringBuffer buf = new StringBuffer();
+ CPStringBuilder buf = new CPStringBuilder();
if (st.hasMoreTokens())
{
buf.append(st.nextToken());
diff --git a/libjava/classpath/gnu/xml/xpath/NotFunction.java b/libjava/classpath/gnu/xml/xpath/NotFunction.java
index bbed66a7311..188b3dbc40e 100644
--- a/libjava/classpath/gnu/xml/xpath/NotFunction.java
+++ b/libjava/classpath/gnu/xml/xpath/NotFunction.java
@@ -53,9 +53,9 @@ final class NotFunction
final Expr arg;
- NotFunction(List args)
+ NotFunction(List<Expr> args)
{
- this((Expr) args.get(0));
+ this(args.get(0));
}
NotFunction(Expr arg)
@@ -63,6 +63,7 @@ final class NotFunction
this.arg = arg;
}
+ @Override
public Object evaluate(Node context, int pos, int len)
{
Object val = arg.evaluate(context, pos, len);
diff --git a/libjava/classpath/gnu/xml/xpath/NumberFunction.java b/libjava/classpath/gnu/xml/xpath/NumberFunction.java
index 79553ce81fb..8804a788670 100644
--- a/libjava/classpath/gnu/xml/xpath/NumberFunction.java
+++ b/libjava/classpath/gnu/xml/xpath/NumberFunction.java
@@ -68,9 +68,9 @@ final class NumberFunction
final Expr arg;
- NumberFunction(List args)
+ NumberFunction(List<Expr> args)
{
- this(args.size() > 0 ? (Expr) args.get(0) : null);
+ this(args.size() > 0 ? args.get(0) : null);
}
NumberFunction(Expr arg)
@@ -78,6 +78,7 @@ final class NumberFunction
this.arg = arg;
}
+ @Override
public Object evaluate(Node context, int pos, int len)
{
Object val = (arg == null) ? null : arg.evaluate(context, pos, len);
diff --git a/libjava/classpath/gnu/xml/xpath/ParenthesizedExpr.java b/libjava/classpath/gnu/xml/xpath/ParenthesizedExpr.java
index f343857c313..adadd6745c4 100644
--- a/libjava/classpath/gnu/xml/xpath/ParenthesizedExpr.java
+++ b/libjava/classpath/gnu/xml/xpath/ParenthesizedExpr.java
@@ -60,12 +60,17 @@ final class ParenthesizedExpr
this.expr = expr;
}
+ @Override
public Object evaluate(Node context, int pos, int len)
{
Object ret = expr.evaluate(context, pos, len);
if (ret instanceof Collection)
{
- List list = new ArrayList((Collection) ret);
+ /* Suppression is safe, as we know context produces
+ Collection<Node> */
+ @SuppressWarnings("unchecked")
+ Collection<Node> nodes = (Collection<Node>) ret;
+ List<Node> list = new ArrayList<Node>(nodes);
Collections.sort(list, documentOrderComparator);
ret = list;
}
diff --git a/libjava/classpath/gnu/xml/xpath/Path.java b/libjava/classpath/gnu/xml/xpath/Path.java
index 4b01f0918ab..809f965ccef 100644
--- a/libjava/classpath/gnu/xml/xpath/Path.java
+++ b/libjava/classpath/gnu/xml/xpath/Path.java
@@ -49,6 +49,6 @@ abstract class Path
extends Pattern
{
- abstract Collection evaluate(Node context, Collection nodeSet);
+ abstract Collection<Node> evaluate(Node context, Collection<Node> nodeSet);
}
diff --git a/libjava/classpath/gnu/xml/xpath/Root.java b/libjava/classpath/gnu/xml/xpath/Root.java
index 1f79b395812..cbcb24999bc 100644
--- a/libjava/classpath/gnu/xml/xpath/Root.java
+++ b/libjava/classpath/gnu/xml/xpath/Root.java
@@ -39,6 +39,8 @@ package gnu.xml.xpath;
import java.util.Collection;
import java.util.Collections;
+import java.util.Set;
+
import javax.xml.namespace.QName;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
@@ -59,12 +61,14 @@ public final class Root
public Object evaluate(Node context, int pos, int len)
{
- return evaluate(context, Collections.EMPTY_SET);
+ Set<Node> emptySet = Collections.emptySet();
+ return evaluate(context, emptySet);
}
- Collection evaluate(Node context, Collection ns)
+ @Override
+ Collection<Node> evaluate(Node context, Collection<Node> ns)
{
- Document doc = (context instanceof Document) ? (Document) context :
+ Node doc = (context instanceof Document) ? context :
context.getOwnerDocument();
return Collections.singleton(doc);
}
diff --git a/libjava/classpath/gnu/xml/xpath/RoundFunction.java b/libjava/classpath/gnu/xml/xpath/RoundFunction.java
index bfbfd357da8..2d1bd544722 100644
--- a/libjava/classpath/gnu/xml/xpath/RoundFunction.java
+++ b/libjava/classpath/gnu/xml/xpath/RoundFunction.java
@@ -60,9 +60,9 @@ final class RoundFunction
final Expr arg;
- RoundFunction(List args)
+ RoundFunction(List<Expr> args)
{
- this((Expr) args.get(0));
+ this(args.get(0));
}
RoundFunction(Expr arg)
@@ -70,6 +70,7 @@ final class RoundFunction
this.arg = arg;
}
+ @Override
public Object evaluate(Node context, int pos, int len)
{
Object val = arg.evaluate(context, pos, len);
diff --git a/libjava/classpath/gnu/xml/xpath/Selector.java b/libjava/classpath/gnu/xml/xpath/Selector.java
index c7abb33e2ff..429b3f7e20b 100644
--- a/libjava/classpath/gnu/xml/xpath/Selector.java
+++ b/libjava/classpath/gnu/xml/xpath/Selector.java
@@ -37,6 +37,8 @@ exception statement from your version. */
package gnu.xml.xpath;
+import gnu.java.lang.CPStringBuilder;
+
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
@@ -82,7 +84,7 @@ public final class Selector
*/
final Test[] tests;
- public Selector(int axis, List tests)
+ public Selector(int axis, List<? extends Test> tests)
{
this.axis = axis;
int len = tests.size();
@@ -177,29 +179,31 @@ public final class Selector
return count;
}
+
+ @Override
public Object evaluate(Node context, int pos, int len)
{
- Set acc = new LinkedHashSet();
+ Set<Node> acc = new LinkedHashSet<Node>();
addCandidates(context, acc);
- List candidates = new ArrayList(acc);
- List ret = filterCandidates(candidates, false);
+ List<Node> candidates = new ArrayList<Node>(acc);
+ List<Node> ret = filterCandidates(candidates, false);
return ret;
}
- Collection evaluate(Node context, Collection ns)
+ Collection<Node> evaluate(Node context, Collection<Node> ns)
{
- Set acc = new LinkedHashSet();
- for (Iterator i = ns.iterator(); i.hasNext(); )
- addCandidates((Node) i.next(), acc);
- List candidates = new ArrayList(acc);
- List ret = filterCandidates(candidates, true);
+ Set<Node> acc = new LinkedHashSet<Node>();
+ for (Iterator<Node> i = ns.iterator(); i.hasNext(); )
+ addCandidates(i.next(), acc);
+ List<Node> candidates = new ArrayList<Node>(acc);
+ List<Node> ret = filterCandidates(candidates, true);
return ret;
}
/**
* Filter the given list of candidates according to the node tests.
*/
- List filterCandidates(List candidates, boolean cascade)
+ List<Node> filterCandidates(List<Node> candidates, boolean cascade)
{
int len = candidates.size();
int tlen = tests.length;
@@ -209,10 +213,10 @@ public final class Selector
for (int j = 0; j < tlen && len > 0; j++)
{
Test test = tests[j];
- List successful = new ArrayList(len);
+ List<Node> successful = new ArrayList<Node>(len);
for (int i = 0; i < len; i++)
{
- Node node = (Node) candidates.get(i);
+ Node node = candidates.get(i);
if (cascade)
{
// Documents and DocumentFragments should be considered
@@ -242,7 +246,7 @@ public final class Selector
return candidates;
}
- void addCandidates(Node context, Collection candidates)
+ void addCandidates(Node context, Collection<Node> candidates)
{
// Build list of candidates
switch (axis)
@@ -291,7 +295,7 @@ public final class Selector
}
}
- void addChildNodes(Node context, Collection acc, boolean recurse)
+ void addChildNodes(Node context, Collection<Node> acc, boolean recurse)
{
Node child = context.getFirstChild();
while (child != null)
@@ -303,7 +307,7 @@ public final class Selector
}
}
- void addParentNode(Node context, Collection acc, boolean recurse)
+ void addParentNode(Node context, Collection<Node> acc, boolean recurse)
{
Node parent = (context.getNodeType() == Node.ATTRIBUTE_NODE) ?
((Attr) context).getOwnerElement() : context.getParentNode();
@@ -315,7 +319,7 @@ public final class Selector
}
}
- void addFollowingNodes(Node context, Collection acc, boolean recurse)
+ void addFollowingNodes(Node context, Collection<Node> acc, boolean recurse)
{
if (context != null && recurse)
addChildNodes(context, acc, true);
@@ -349,7 +353,7 @@ public final class Selector
}
}
- void addPrecedingNodes(Node context, Collection acc, boolean recurse)
+ void addPrecedingNodes(Node context, Collection<Node> acc, boolean recurse)
{
Node cur = (context.getNodeType() == Node.ATTRIBUTE_NODE) ? null :
context.getPreviousSibling();
@@ -370,7 +374,7 @@ public final class Selector
}
}
- void addAttributes(Node context, Collection acc)
+ void addAttributes(Node context, Collection<Node> acc)
{
NamedNodeMap attrs = context.getAttributes();
if (attrs != null)
@@ -387,7 +391,7 @@ public final class Selector
}
}
- void addNamespaceAttributes(Node context, Collection acc)
+ void addNamespaceAttributes(Node context, Collection<Node> acc)
{
NamedNodeMap attrs = context.getAttributes();
if (attrs != null)
@@ -413,7 +417,7 @@ public final class Selector
public Expr clone(Object context)
{
int len = tests.length;
- List tests2 = new ArrayList(len);
+ List<Test> tests2 = new ArrayList<Test>(len);
for (int i = 0; i < len; i++)
tests2.add(tests[i].clone(context));
return new Selector(axis, tests2);
@@ -431,7 +435,7 @@ public final class Selector
public String toString()
{
- StringBuffer buf = new StringBuffer();
+ CPStringBuilder buf = new CPStringBuilder();
switch (axis)
{
case ANCESTOR:
diff --git a/libjava/classpath/gnu/xml/xpath/StartsWithFunction.java b/libjava/classpath/gnu/xml/xpath/StartsWithFunction.java
index ec021551e76..2dc2c409d8d 100644
--- a/libjava/classpath/gnu/xml/xpath/StartsWithFunction.java
+++ b/libjava/classpath/gnu/xml/xpath/StartsWithFunction.java
@@ -54,9 +54,9 @@ final class StartsWithFunction
final Expr arg1;
final Expr arg2;
- StartsWithFunction(List args)
+ StartsWithFunction(List<Expr> args)
{
- this((Expr) args.get(0), (Expr) args.get(1));
+ this(args.get(0), args.get(1));
}
StartsWithFunction(Expr arg1, Expr arg2)
diff --git a/libjava/classpath/gnu/xml/xpath/Steps.java b/libjava/classpath/gnu/xml/xpath/Steps.java
index 9ef6cd35f3d..427fbe20138 100644
--- a/libjava/classpath/gnu/xml/xpath/Steps.java
+++ b/libjava/classpath/gnu/xml/xpath/Steps.java
@@ -37,6 +37,8 @@ exception statement from your version. */
package gnu.xml.xpath;
+import gnu.java.lang.CPStringBuilder;
+
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
@@ -56,14 +58,14 @@ public final class Steps
extends Path
{
- final LinkedList path;
+ final LinkedList<Expr> path;
public Steps()
{
- this(new LinkedList());
+ this(new LinkedList<Expr>());
}
- Steps(LinkedList path)
+ Steps(LinkedList<Expr> path)
{
this.path = path;
}
@@ -84,10 +86,8 @@ public final class Steps
if (pos > 0)
{
Pattern left = (Pattern) path.get(pos - 1);
- Iterator j = possibleContexts(right, context).iterator();
- while (j.hasNext())
+ for (Node candidate : possibleContexts(right, context))
{
- Node candidate = (Node) j.next();
if (left.matches(candidate) &&
matches(candidate, pos - 1))
{
@@ -104,12 +104,12 @@ public final class Steps
* Essentially the reverse of Selector.addCandidates.
* The idea is to determine possible context nodes for a match.
*/
- Collection possibleContexts(Pattern pattern, Node context)
+ Collection<Node> possibleContexts(Pattern pattern, Node context)
{
if (pattern instanceof Selector)
{
Selector s = (Selector) pattern;
- Collection candidates = new LinkedHashSet();
+ Collection<Node> candidates = new LinkedHashSet<Node>();
switch (s.axis)
{
case Selector.PARENT:
@@ -157,46 +157,53 @@ public final class Steps
}
return candidates;
}
- return Collections.EMPTY_SET;
+ return Collections.emptySet();
}
+ @Override
public Object evaluate(Node context, int pos, int len)
{
//System.err.println(toString()+" evaluate");
// Left to right
- Iterator i = path.iterator();
- Expr lhs = (Expr) i.next();
+ Iterator<Expr> i = path.iterator();
+ Expr lhs = i.next();
Object val = lhs.evaluate(context, pos, len);
//System.err.println("\tevaluate "+lhs+" = "+val);
while (val instanceof Collection && i.hasNext())
{
Path rhs = (Path) i.next();
- val = rhs.evaluate(context, (Collection) val);
+ /* Suppression is safe, as we know context produces Collection<Node> */
+ @SuppressWarnings("unchecked")
+ Collection<Node> nodes = (Collection<Node>) val;
+ val = rhs.evaluate(context, nodes);
//System.err.println("\tevaluate "+rhs+" = "+val);
}
return val;
}
- Collection evaluate(Node context, Collection ns)
+ @Override
+ Collection<Node> evaluate(Node context, Collection<Node> ns)
{
// Left to right
- Iterator i = path.iterator();
- Expr lhs = (Expr) i.next();
+ Iterator<Expr> i = path.iterator();
+ Expr lhs = i.next();
if (lhs instanceof Path)
{
ns = ((Path) lhs).evaluate(context, ns);
}
else
{
- Set acc = new LinkedHashSet();
+ Set<Node> acc = new LinkedHashSet<Node>();
int pos = 1, len = ns.size();
- for (Iterator j = ns.iterator(); j.hasNext(); )
+ for (Node node : ns)
{
- Node node = (Node) j.next();
Object ret = lhs.evaluate(node, pos++, len);
if (ret instanceof Collection)
{
- acc.addAll((Collection) ret);
+ /* Suppression is safe, as we know context produces Collection<Node> */
+ @SuppressWarnings("unchecked")
+ Collection<Node> nodes = (Collection<Node>) ret;
+ acc.addAll(nodes);
}
}
ns = acc;
@@ -212,19 +219,19 @@ public final class Steps
public Expr clone(Object context)
{
int len = path.size();
- LinkedList path2 = new LinkedList();
+ LinkedList<Expr> path2 = new LinkedList<Expr>();
for (int i = 0; i < len; i++)
{
- path2.add(((Expr) path.get(i)).clone(context));
+ path2.add(path.get(i).clone(context));
}
return new Steps(path2);
}
public boolean references(QName var)
{
- for (Iterator i = path.iterator(); i.hasNext(); )
+ for (Iterator<Expr> i = path.iterator(); i.hasNext(); )
{
- if (((Expr) i.next()).references(var))
+ if (i.next().references(var))
{
return true;
}
@@ -234,16 +241,16 @@ public final class Steps
public String toString()
{
- StringBuffer buf = new StringBuffer();
- Iterator i = path.iterator();
- Expr expr = (Expr) i.next();
+ CPStringBuilder buf = new CPStringBuilder();
+ Iterator<Expr> i = path.iterator();
+ Expr expr = i.next();
if (!(expr instanceof Root))
{
buf.append(expr);
}
while (i.hasNext())
{
- expr = (Expr) i.next();
+ expr = i.next();
buf.append('/');
buf.append(expr);
}
diff --git a/libjava/classpath/gnu/xml/xpath/StringFunction.java b/libjava/classpath/gnu/xml/xpath/StringFunction.java
index 0a4c681d16b..b8cba3798de 100644
--- a/libjava/classpath/gnu/xml/xpath/StringFunction.java
+++ b/libjava/classpath/gnu/xml/xpath/StringFunction.java
@@ -84,9 +84,9 @@ final class StringFunction
final Expr arg;
- StringFunction(List args)
+ StringFunction(List<Expr> args)
{
- this(args.size() > 0 ? (Expr) args.get(0) : null);
+ this(args.size() > 0 ? args.get(0) : null);
}
StringFunction(Expr arg)
diff --git a/libjava/classpath/gnu/xml/xpath/StringLengthFunction.java b/libjava/classpath/gnu/xml/xpath/StringLengthFunction.java
index 7f5ceafeef5..561537e99ba 100644
--- a/libjava/classpath/gnu/xml/xpath/StringLengthFunction.java
+++ b/libjava/classpath/gnu/xml/xpath/StringLengthFunction.java
@@ -55,7 +55,7 @@ final class StringLengthFunction
final Expr arg;
- StringLengthFunction(List args)
+ StringLengthFunction(List<Expr> args)
{
this(args.isEmpty() ? null : (Expr) args.get(0));
}
@@ -65,6 +65,7 @@ final class StringLengthFunction
this.arg = arg;
}
+ @Override
public Object evaluate(Node context, int pos, int len)
{
Object val = (arg == null) ? null : arg.evaluate(context, pos, len);
diff --git a/libjava/classpath/gnu/xml/xpath/SubstringAfterFunction.java b/libjava/classpath/gnu/xml/xpath/SubstringAfterFunction.java
index 8144cf84433..ad75f2e3c67 100644
--- a/libjava/classpath/gnu/xml/xpath/SubstringAfterFunction.java
+++ b/libjava/classpath/gnu/xml/xpath/SubstringAfterFunction.java
@@ -58,9 +58,9 @@ final class SubstringAfterFunction
final Expr arg1;
final Expr arg2;
- SubstringAfterFunction(List args)
+ SubstringAfterFunction(List<Expr> args)
{
- this((Expr) args.get(0), (Expr) args.get(1));
+ this(args.get(0), args.get(1));
}
SubstringAfterFunction(Expr arg1, Expr arg2)
diff --git a/libjava/classpath/gnu/xml/xpath/SubstringBeforeFunction.java b/libjava/classpath/gnu/xml/xpath/SubstringBeforeFunction.java
index 2d92a3e0349..1bf165777d0 100644
--- a/libjava/classpath/gnu/xml/xpath/SubstringBeforeFunction.java
+++ b/libjava/classpath/gnu/xml/xpath/SubstringBeforeFunction.java
@@ -57,9 +57,9 @@ final class SubstringBeforeFunction
final Expr arg1;
final Expr arg2;
- SubstringBeforeFunction(List args)
+ SubstringBeforeFunction(List<Expr> args)
{
- this((Expr) args.get(0), (Expr) args.get(1));
+ this(args.get(0), args.get(1));
}
SubstringBeforeFunction(Expr arg1, Expr arg2)
diff --git a/libjava/classpath/gnu/xml/xpath/SubstringFunction.java b/libjava/classpath/gnu/xml/xpath/SubstringFunction.java
index e926f6c7aeb..33bcade0c2d 100644
--- a/libjava/classpath/gnu/xml/xpath/SubstringFunction.java
+++ b/libjava/classpath/gnu/xml/xpath/SubstringFunction.java
@@ -60,10 +60,10 @@ final class SubstringFunction
final Expr arg2;
final Expr arg3;
- SubstringFunction(List args)
+ SubstringFunction(List<Expr> args)
{
- this((Expr) args.get(0), (Expr) args.get(1),
- (args.size() > 2) ? (Expr) args.get(2) : null);
+ this(args.get(0), args.get(1),
+ (args.size() > 2) ? args.get(2) : null);
}
SubstringFunction(Expr arg1, Expr arg2, Expr arg3)
@@ -73,6 +73,7 @@ final class SubstringFunction
this.arg3 = arg3;
}
+ @Override
public Object evaluate(Node context, int pos, int len)
{
Object val1 = arg1.evaluate(context, pos, len);
diff --git a/libjava/classpath/gnu/xml/xpath/SumFunction.java b/libjava/classpath/gnu/xml/xpath/SumFunction.java
index 93c2e806d48..73db2a91dc6 100644
--- a/libjava/classpath/gnu/xml/xpath/SumFunction.java
+++ b/libjava/classpath/gnu/xml/xpath/SumFunction.java
@@ -56,9 +56,9 @@ final class SumFunction
final Expr arg;
- SumFunction(List args)
+ SumFunction(List<Expr> args)
{
- this((Expr) args.get(0));
+ this(args.get(0));
}
SumFunction(Expr arg)
@@ -66,15 +66,19 @@ final class SumFunction
this.arg = arg;
}
+ @Override
public Object evaluate(Node context, int pos, int len)
{
Object val = arg.evaluate(context, pos, len);
double sum = 0.0d;
if (val instanceof Collection)
{
- for (Iterator i = ((Collection) val).iterator(); i.hasNext(); )
+ /* Suppression is safe, as we know context produces
+ Collection<Node> */
+ @SuppressWarnings("unchecked")
+ Collection<Node> nodes = (Collection<Node>) val;
+ for (Node node : nodes)
{
- Node node = (Node) i.next();
String s = stringValue(node);
sum += _number(context, s);
}
diff --git a/libjava/classpath/gnu/xml/xpath/TranslateFunction.java b/libjava/classpath/gnu/xml/xpath/TranslateFunction.java
index 54e8b9c37f5..8b4b8b2338c 100644
--- a/libjava/classpath/gnu/xml/xpath/TranslateFunction.java
+++ b/libjava/classpath/gnu/xml/xpath/TranslateFunction.java
@@ -37,6 +37,8 @@ exception statement from your version. */
package gnu.xml.xpath;
+import gnu.java.lang.CPStringBuilder;
+
import java.util.List;
import javax.xml.namespace.QName;
import org.w3c.dom.Node;
@@ -66,9 +68,9 @@ final class TranslateFunction
final Expr arg2;
final Expr arg3;
- TranslateFunction(List args)
+ TranslateFunction(List<Expr> args)
{
- this((Expr) args.get(0), (Expr) args.get(1), (Expr) args.get(2));
+ this(args.get(0), args.get(1), args.get(2));
}
TranslateFunction(Expr arg1, Expr arg2, Expr arg3)
@@ -86,7 +88,7 @@ final class TranslateFunction
String string = _string(context, val1);
String search = _string(context, val2);
String replace = _string(context, val3);
- StringBuffer buf = new StringBuffer();
+ CPStringBuilder buf = new CPStringBuilder();
int l1 = string.length();
int l2 = search.length();
int l3 = replace.length();
@@ -110,7 +112,7 @@ final class TranslateFunction
buf.append(c);
}
}
- return new String(buf);
+ return buf.toString();
}
public Expr clone(Object context)
diff --git a/libjava/classpath/gnu/xml/xpath/UnionExpr.java b/libjava/classpath/gnu/xml/xpath/UnionExpr.java
index 5078713b693..03ae5c06d70 100644
--- a/libjava/classpath/gnu/xml/xpath/UnionExpr.java
+++ b/libjava/classpath/gnu/xml/xpath/UnionExpr.java
@@ -74,20 +74,29 @@ public final class UnionExpr
return false;
}
+ @Override
public Object evaluate(Node context, int pos, int len)
{
Object left = lhs.evaluate(context, pos, len);
Object right = rhs.evaluate(context, pos, len);
+ List<Node> list;
if (left instanceof Collection && right instanceof Collection)
{
- Set set = new HashSet();
- set.addAll ((Collection) left);
- set.addAll ((Collection) right);
- List list = new ArrayList(set);
+ Set<Node> set = new HashSet<Node>();
+ /* Suppression is safe as addAll will check the types
+ of the elements and throw a ClassCastException as necessary */
+ @SuppressWarnings("unchecked")
+ Collection<Node> l = (Collection<Node>) left;
+ @SuppressWarnings("unchecked")
+ Collection<Node> r = (Collection<Node>) right;
+ set.addAll (l);
+ set.addAll (r);
+ list = new ArrayList<Node>(set);
Collections.sort(list, documentOrderComparator);
- return list;
}
- return Collections.EMPTY_SET;
+ else
+ list = Collections.emptyList();
+ return list;
}
public Expr clone(Object context)
diff --git a/libjava/classpath/gnu/xml/xpath/VariableReference.java b/libjava/classpath/gnu/xml/xpath/VariableReference.java
index 813a37f96eb..9ef6f160ff8 100644
--- a/libjava/classpath/gnu/xml/xpath/VariableReference.java
+++ b/libjava/classpath/gnu/xml/xpath/VariableReference.java
@@ -37,6 +37,8 @@ exception statement from your version. */
package gnu.xml.xpath;
+import gnu.java.lang.CPStringBuilder;
+
import javax.xml.namespace.QName;
import javax.xml.xpath.XPathVariableResolver;
import org.w3c.dom.Node;
@@ -86,7 +88,7 @@ public class VariableReference
public String toString()
{
- StringBuffer buf = new StringBuffer("$");
+ CPStringBuilder buf = new CPStringBuilder("$");
String prefix = name.getPrefix();
if (prefix != null && !"".equals(prefix))
{
diff --git a/libjava/classpath/gnu/xml/xpath/XPathParser.java b/libjava/classpath/gnu/xml/xpath/XPathParser.java
index 9b7540a4a40..e8c8e94da79 100644
--- a/libjava/classpath/gnu/xml/xpath/XPathParser.java
+++ b/libjava/classpath/gnu/xml/xpath/XPathParser.java
@@ -79,7 +79,7 @@ public class XPathParser
return qName;
}
- Expr lookupFunction(String name, List args)
+ Expr lookupFunction(String name, List<Expr> args)
{
int arity = args.size();
if ("position".equals(name) && arity == 0)
@@ -491,7 +491,7 @@ case 5:
else
{
steps = new Steps();
- steps.path.addFirst(yyVals[0+yyTop]);
+ steps.path.addFirst((Expr) yyVals[0+yyTop]);
}
steps.path.addFirst(new Root());
yyVal = steps;
@@ -512,7 +512,7 @@ case 6:
else
{
steps = new Steps();
- steps.path.addFirst(yyVals[0+yyTop]);
+ steps.path.addFirst((Expr) yyVals[0+yyTop]);
}
steps.path.addFirst(s);
steps.path.addFirst(new Root());
@@ -532,9 +532,9 @@ case 8:
else
{
steps = new Steps();
- steps.path.addFirst(yyVals[-2+yyTop]);
+ steps.path.addFirst((Expr) yyVals[-2+yyTop]);
}
- steps.path.addLast(yyVals[0+yyTop]);
+ steps.path.addLast((Expr) yyVals[0+yyTop]);
yyVal = steps;
/*$$ = new Step((Expr) $1, (Path) $3);*/
}
@@ -553,10 +553,10 @@ case 9:
else
{
steps = new Steps();
- steps.path.addFirst(yyVals[-2+yyTop]);
+ steps.path.addFirst((Expr) yyVals[-2+yyTop]);
}
steps.path.addLast(s);
- steps.path.addLast(yyVals[0+yyTop]);
+ steps.path.addLast((Expr) yyVals[0+yyTop]);
yyVal = steps;
/*Step step = new Step(s, (Path) $3);*/
/*$$ = new Step((Expr) $1, step);*/
@@ -565,48 +565,56 @@ case 9:
case 10:
// line 362 "XPathParser.y"
{
- yyVal = new Selector (Selector.CHILD, (List) yyVals[0+yyTop]);
- }
+ @SuppressWarnings("unchecked") List<Test> tests = (List<Test>) yyVals[0+yyTop];
+ yyVal = new Selector (Selector.CHILD, tests);
+ }
break;
case 11:
// line 366 "XPathParser.y"
{
- yyVal = new Selector (Selector.ATTRIBUTE, (List) yyVals[0+yyTop]);
- }
+ /* This is safe as we create this in one of the other cases */
+ @SuppressWarnings("unchecked") List<Test> tests = (List<Test>) yyVals[0+yyTop];
+ yyVal = new Selector (Selector.ATTRIBUTE, tests);
+ }
break;
case 12:
// line 370 "XPathParser.y"
{
- yyVal = new Selector (((Integer) yyVals[-2+yyTop]).intValue (), (List) yyVals[0+yyTop]);
- }
+ /* This is safe as we create this in one of the other cases */
+ @SuppressWarnings("unchecked") List<Test> tests = (List<Test>) yyVals[0+yyTop];
+ yyVal = new Selector (((Integer) yyVals[-2+yyTop]).intValue (), tests);
+ }
break;
case 13:
// line 374 "XPathParser.y"
{
- yyVal = new Selector (Selector.SELF, Collections.EMPTY_LIST);
- }
+ List<Test> emptyList = Collections.emptyList();
+ yyVal = new Selector (Selector.SELF, emptyList);
+ }
break;
case 14:
// line 378 "XPathParser.y"
{
- yyVal = new Selector (Selector.PARENT, Collections.EMPTY_LIST);
- }
+ List<Test> emptyList = Collections.emptyList();
+ yyVal = new Selector (Selector.PARENT, emptyList);
+ }
break;
case 15:
// line 385 "XPathParser.y"
{
- List list = new ArrayList();
- list.add(yyVals[0+yyTop]);
+ List<Test> list = new ArrayList<Test>();
+ list.add((Test) yyVals[0+yyTop]);
yyVal = list;
}
break;
case 16:
// line 391 "XPathParser.y"
{
- List list = (List)yyVals[-1+yyTop];
- list.add(yyVals[0+yyTop]);
- yyVal = list;
- }
+ /* This is safe as we create this in one of the other cases */
+ @SuppressWarnings("unchecked") List<Test> tests = (List<Test>)yyVals[-1+yyTop];
+ tests.add((Test) yyVals[0+yyTop]);
+ yyVal = tests;
+ }
break;
case 17:
// line 415 "XPathParser.y"
@@ -725,30 +733,34 @@ case 37:
case 39:
// line 508 "XPathParser.y"
{
- yyVal = lookupFunction((String) yyVals[-2+yyTop], Collections.EMPTY_LIST);
- }
+ List<Expr> emptyList = Collections.emptyList();
+ yyVal = lookupFunction((String) yyVals[-2+yyTop], emptyList);
+ }
break;
case 40:
// line 512 "XPathParser.y"
{
- yyVal = lookupFunction((String) yyVals[-3+yyTop], (List) yyVals[-1+yyTop]);
- }
+ /* This is safe as we create this below */
+ @SuppressWarnings("unchecked") List<Expr> exprs = (List<Expr>) yyVals[-1+yyTop];
+ yyVal = lookupFunction((String) yyVals[-3+yyTop], exprs);
+ }
break;
case 41:
// line 519 "XPathParser.y"
{
- List list = new ArrayList();
- list.add(yyVals[0+yyTop]);
+ List<Expr> list = new ArrayList<Expr>();
+ list.add((Expr) yyVals[0+yyTop]);
yyVal = list;
}
break;
case 42:
// line 525 "XPathParser.y"
{
- List list = (List) yyVals[0+yyTop];
- list.add(0, yyVals[-2+yyTop]);
- yyVal = list;
- }
+ /* This is safe as we create this above */
+ @SuppressWarnings("unchecked") List<Expr> list = (List<Expr>) yyVals[0+yyTop];
+ list.add(0, (Expr) yyVals[-2+yyTop]);
+ yyVal = list;
+ }
break;
case 44:
// line 535 "XPathParser.y"
@@ -767,9 +779,9 @@ case 47:
else
{
steps = new Steps();
- steps.path.addFirst(yyVals[0+yyTop]);
+ steps.path.addFirst((Expr) yyVals[0+yyTop]);
}
- steps.path.addFirst(yyVals[-2+yyTop]);
+ steps.path.addFirst((Expr) yyVals[-2+yyTop]);
yyVal = steps;
/*$$ = new Step ((Expr) $1, (Path) $3);*/
}
@@ -788,10 +800,10 @@ case 48:
else
{
steps = new Steps();
- steps.path.addFirst(yyVals[0+yyTop]);
+ steps.path.addFirst((Expr) yyVals[0+yyTop]);
}
steps.path.addFirst(s);
- steps.path.addFirst(yyVals[-2+yyTop]);
+ steps.path.addFirst((Expr) yyVals[-2+yyTop]);
yyVal = steps;
/*Step step = new Step (s, (Path) $3);*/
/*$$ = new Step ((Expr) $1, step);*/
@@ -811,7 +823,7 @@ case 50:
else
{
steps = new Steps();
- steps.path.addFirst(yyVals[-1+yyTop]);
+ steps.path.addFirst((Expr) yyVals[-1+yyTop]);
}
steps.path.addLast(s);
yyVal = steps;
diff --git a/libjava/classpath/gnu/xml/xpath/XPathParser.y b/libjava/classpath/gnu/xml/xpath/XPathParser.y
index 55015138655..a6d3fd130b0 100644
--- a/libjava/classpath/gnu/xml/xpath/XPathParser.y
+++ b/libjava/classpath/gnu/xml/xpath/XPathParser.y
@@ -78,7 +78,7 @@ public class XPathParser
return qName;
}
- Expr lookupFunction(String name, List args)
+ Expr lookupFunction(String name, List<Expr> args)
{
int arity = args.size();
if ("position".equals(name) && arity == 0)
@@ -287,7 +287,7 @@ absolute_location_path:
else
{
steps = new Steps();
- steps.path.addFirst($2);
+ steps.path.addFirst((Expr) $2);
}
steps.path.addFirst(new Root());
$$ = steps;
@@ -306,7 +306,7 @@ absolute_location_path:
else
{
steps = new Steps();
- steps.path.addFirst($2);
+ steps.path.addFirst((Expr) $2);
}
steps.path.addFirst(s);
steps.path.addFirst(new Root());
@@ -328,9 +328,9 @@ relative_location_path:
else
{
steps = new Steps();
- steps.path.addFirst($1);
+ steps.path.addFirst((Expr) $1);
}
- steps.path.addLast($3);
+ steps.path.addLast((Expr) $3);
$$ = steps;
//$$ = new Step((Expr) $1, (Path) $3);
}
@@ -347,10 +347,10 @@ relative_location_path:
else
{
steps = new Steps();
- steps.path.addFirst($1);
+ steps.path.addFirst((Expr) $1);
}
steps.path.addLast(s);
- steps.path.addLast($3);
+ steps.path.addLast((Expr) $3);
$$ = steps;
//Step step = new Step(s, (Path) $3);
//$$ = new Step((Expr) $1, step);
@@ -360,37 +360,43 @@ relative_location_path:
step:
step_node_test
{
- $$ = new Selector (Selector.CHILD, (List) $1);
+ @SuppressWarnings("unchecked") List<Test> tests = (List<Test>) $1;
+ $$ = new Selector (Selector.CHILD, tests);
}
| AT step_node_test
{
- $$ = new Selector (Selector.ATTRIBUTE, (List) $2);
+ @SuppressWarnings("unchecked") List<Test> tests = (List<Test>) $2;
+ $$ = new Selector (Selector.ATTRIBUTE, tests);
}
| axis_name DOUBLE_COLON step_node_test
{
- $$ = new Selector (((Integer) $1).intValue (), (List) $3);
+ @SuppressWarnings("unchecked") List<Test> tests = (List<Test>) $3;
+ $$ = new Selector (((Integer) $1).intValue (), tests);
}
| DOT
{
- $$ = new Selector (Selector.SELF, Collections.EMPTY_LIST);
+ List<Test> emptyList = Collections.emptyList();
+ $$ = new Selector (Selector.SELF, emptyList);
}
| DOUBLE_DOT
{
- $$ = new Selector (Selector.PARENT, Collections.EMPTY_LIST);
+ List<Test> emptyList = Collections.emptyList();
+ $$ = new Selector (Selector.PARENT, emptyList);
}
;
step_node_test:
node_test
{
- List list = new ArrayList();
- list.add($1);
+ List<Test> list = new ArrayList<Test>();
+ list.add((Test) $1);
$$ = list;
}
| step_node_test predicate
{
- List list = (List)$1;
- list.add($2);
+ /* This is safe as we create this in one of the other cases */
+ @SuppressWarnings("unchecked") List<Test> tests = (List<Test>)$1;
+ tests.add((Test) $2);
$$ = list;
}
;
@@ -506,25 +512,29 @@ primary_expr:
function_call:
function_name LP RP
{
- $$ = lookupFunction((String) $1, Collections.EMPTY_LIST);
+ List<Expr> emptyList = Collections.emptyList();
+ $$ = lookupFunction((String) $1, emptyList);
}
| function_name LP argument_list RP
{
- $$ = lookupFunction((String) $1, (List) $3);
+ /* This is safe as we create this below */
+ @SuppressWarnings("unchecked") List<Expr> exprs = (List<Expr>) $3;
+ $$ = lookupFunction((String) $1, (List) exprs);
}
;
argument_list:
expr
{
- List list = new ArrayList();
- list.add($1);
+ List<Expr> list = new ArrayList<Expr>();
+ list.add((Expr) $1);
$$ = list;
}
| expr COMMA argument_list
{
- List list = (List) $3;
- list.add(0, $1);
+ /* This is safe as we create this above */
+ @SuppressWarnings("unchecked") List<Expr> list = (List<Expr>) $3;
+ list.add(0, (Expr) $1);
$$ = list;
}
;
@@ -550,9 +560,9 @@ path_expr:
else
{
steps = new Steps();
- steps.path.addFirst($3);
+ steps.path.addFirst((Expr) $3);
}
- steps.path.addFirst($1);
+ steps.path.addFirst((Expr) $1);
$$ = steps;
//$$ = new Step ((Expr) $1, (Path) $3);
}
@@ -572,7 +582,7 @@ path_expr:
steps.path.addFirst($3);
}
steps.path.addFirst(s);
- steps.path.addFirst($1);
+ steps.path.addFirst((Expr) $1);
$$ = steps;
//Step step = new Step (s, (Path) $3);
//$$ = new Step ((Expr) $1, step);
@@ -594,7 +604,7 @@ filter_expr:
else
{
steps = new Steps();
- steps.path.addFirst($1);
+ steps.path.addFirst((Expr) $1);
}
steps.path.addLast(s);
$$ = steps;
diff --git a/libjava/classpath/gnu/xml/xpath/XPathTokenizer.java b/libjava/classpath/gnu/xml/xpath/XPathTokenizer.java
index a287137827b..bf4516afae7 100644
--- a/libjava/classpath/gnu/xml/xpath/XPathTokenizer.java
+++ b/libjava/classpath/gnu/xml/xpath/XPathTokenizer.java
@@ -37,6 +37,8 @@ exception statement from your version. */
package gnu.xml.xpath;
+import gnu.java.lang.CPStringBuilder;
+
import java.io.BufferedReader;
import java.io.IOException;
import java.io.Reader;
@@ -90,7 +92,7 @@ implements XPathParser.yyInput
}
- static final Map keywords = new TreeMap ();
+ static final Map<String,Integer> keywords = new TreeMap<String,Integer> ();
static
{
keywords.put ("ancestor", new Integer (XPathParser.ANCESTOR));
@@ -314,7 +316,7 @@ implements XPathParser.yyInput
XPathToken consume_literal (int delimiter)
throws IOException
{
- StringBuffer buf = new StringBuffer ();
+ CPStringBuilder buf = new CPStringBuilder ();
while (true)
{
int c = in.read ();
@@ -336,7 +338,7 @@ implements XPathParser.yyInput
XPathToken consume_digits (int c)
throws IOException
{
- StringBuffer buf = new StringBuffer ();
+ CPStringBuilder buf = new CPStringBuilder ();
buf.append ((char) c);
while (true)
{
@@ -357,7 +359,7 @@ implements XPathParser.yyInput
XPathToken consume_name (int c)
throws IOException
{
- StringBuffer buf = new StringBuffer ();
+ CPStringBuilder buf = new CPStringBuilder ();
buf.append ((char) c);
while (true)
{