diff options
Diffstat (limited to 'libjava/classpath/gnu/xml/dom')
-rw-r--r-- | libjava/classpath/gnu/xml/dom/DomAttr.java | 36 | ||||
-rw-r--r-- | libjava/classpath/gnu/xml/dom/DomDocument.java | 8 | ||||
-rw-r--r-- | libjava/classpath/gnu/xml/dom/DomElement.java | 26 | ||||
-rw-r--r-- | libjava/classpath/gnu/xml/dom/DomEvent.java | 13 | ||||
-rw-r--r-- | libjava/classpath/gnu/xml/dom/DomNode.java | 12 | ||||
-rw-r--r-- | libjava/classpath/gnu/xml/dom/DomNsNode.java | 29 | ||||
-rw-r--r-- | libjava/classpath/gnu/xml/dom/DomText.java | 4 | ||||
-rw-r--r-- | libjava/classpath/gnu/xml/dom/ls/DomLSInput.java | 4 | ||||
-rw-r--r-- | libjava/classpath/gnu/xml/dom/ls/DomLSParser.java | 2 | ||||
-rw-r--r-- | libjava/classpath/gnu/xml/dom/ls/SAXEventSink.java | 7 |
10 files changed, 122 insertions, 19 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 { |