diff options
author | Jesse Wilson <jessewilson@google.com> | 2010-02-26 12:17:32 -0800 |
---|---|---|
committer | Jesse Wilson <jessewilson@google.com> | 2010-02-26 12:50:57 -0800 |
commit | 5213a38431ea28c97d29e76c5b2d8e156c2d1705 (patch) | |
tree | 05983b55de5441a5c77c61af2485c9c86448a648 /xml/src/main/java | |
parent | 13a40719e8f66d75ea3277fdd4305772623cf84c (diff) | |
download | libcore-5213a38431ea28c97d29e76c5b2d8e156c2d1705.zip libcore-5213a38431ea28c97d29e76c5b2d8e156c2d1705.tar.gz libcore-5213a38431ea28c97d29e76c5b2d8e156c2d1705.tar.bz2 |
Adding tests to parse document attributes from the DOM.
This adds implementation and tests for these methods:
getInputEncoding(), getDocumentURI().
And tests for these methods:
getXmlEncoding(), getXmlVersion(), getXmlStandalone().
Diffstat (limited to 'xml/src/main/java')
3 files changed, 38 insertions, 24 deletions
diff --git a/xml/src/main/java/org/apache/harmony/xml/dom/DOMImplementationImpl.java b/xml/src/main/java/org/apache/harmony/xml/dom/DOMImplementationImpl.java index 1283eeb..991a707 100644 --- a/xml/src/main/java/org/apache/harmony/xml/dom/DOMImplementationImpl.java +++ b/xml/src/main/java/org/apache/harmony/xml/dom/DOMImplementationImpl.java @@ -41,7 +41,7 @@ public final class DOMImplementationImpl implements DOMImplementation { public Document createDocument(String namespaceURI, String qualifiedName, DocumentType doctype) throws DOMException { - return new DocumentImpl(this, namespaceURI, qualifiedName, doctype); + return new DocumentImpl(this, namespaceURI, qualifiedName, doctype, null); } public DocumentType createDocumentType(String qualifiedName, diff --git a/xml/src/main/java/org/apache/harmony/xml/dom/DocumentImpl.java b/xml/src/main/java/org/apache/harmony/xml/dom/DocumentImpl.java index b2f16d1..e297280 100644 --- a/xml/src/main/java/org/apache/harmony/xml/dom/DocumentImpl.java +++ b/xml/src/main/java/org/apache/harmony/xml/dom/DocumentImpl.java @@ -48,11 +48,23 @@ public class DocumentImpl extends InnerNodeImpl implements Document { private DOMImplementation domImplementation; + /* + * The default values of these fields are specified by the Document + * interface. + */ + private String documentUri; + private String inputEncoding; + private String xmlEncoding; + private String xmlVersion = "1.0"; + private boolean xmlStandalone = false; + private boolean strictErrorChecking = true; + public DocumentImpl(DOMImplementationImpl impl, String namespaceURI, - String qualifiedName, DocumentType doctype) { + String qualifiedName, DocumentType doctype, String inputEncoding) { super(null); this.domImplementation = impl; + this.inputEncoding = inputEncoding; // this.document = this; if (doctype != null) { @@ -304,43 +316,43 @@ public class DocumentImpl extends InnerNodeImpl implements Document { } public String getInputEncoding() { - throw new UnsupportedOperationException(); // TODO + return inputEncoding; } public String getXmlEncoding() { - throw new UnsupportedOperationException(); // TODO + return xmlEncoding; } public boolean getXmlStandalone() { - throw new UnsupportedOperationException(); // TODO + return xmlStandalone; } public void setXmlStandalone(boolean xmlStandalone) throws DOMException { - throw new UnsupportedOperationException(); // TODO + this.xmlStandalone = xmlStandalone; } public String getXmlVersion() { - throw new UnsupportedOperationException(); // TODO + return xmlVersion; } public void setXmlVersion(String xmlVersion) throws DOMException { - throw new UnsupportedOperationException(); // TODO + this.xmlVersion = xmlVersion; } public boolean getStrictErrorChecking() { - throw new UnsupportedOperationException(); // TODO + return strictErrorChecking; } public void setStrictErrorChecking(boolean strictErrorChecking) { - throw new UnsupportedOperationException(); // TODO + this.strictErrorChecking = strictErrorChecking; } public String getDocumentURI() { - throw new UnsupportedOperationException(); // TODO + return documentUri; } - public void setDocumentURI(String documentURI) { - throw new UnsupportedOperationException(); // TODO + public void setDocumentURI(String documentUri) { + this.documentUri = documentUri; } public Node adoptNode(Node source) throws DOMException { diff --git a/xml/src/main/java/org/apache/harmony/xml/parsers/DocumentBuilderImpl.java b/xml/src/main/java/org/apache/harmony/xml/parsers/DocumentBuilderImpl.java index ca2ff98..4b273fe 100644 --- a/xml/src/main/java/org/apache/harmony/xml/parsers/DocumentBuilderImpl.java +++ b/xml/src/main/java/org/apache/harmony/xml/parsers/DocumentBuilderImpl.java @@ -100,25 +100,27 @@ class DocumentBuilderImpl extends DocumentBuilder { String namespaceURI = null; String qualifiedName = null; DocumentType doctype = null; - DocumentImpl document = new DocumentImpl(dom, namespaceURI, qualifiedName, doctype); + String inputEncoding = source.getEncoding(); + String systemId = source.getSystemId(); + DocumentImpl document = new DocumentImpl( + dom, namespaceURI, qualifiedName, doctype, inputEncoding); + document.setDocumentURI(systemId); try { KXmlParser parser = new KXmlParser(); parser.keepNamespaceAttributes(); - parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, - namespaceAware); - + parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, namespaceAware); + if (source.getByteStream() != null) { - parser.setInput(source.getByteStream(), source.getEncoding()); + parser.setInput(source.getByteStream(), inputEncoding); } else if (source.getCharacterStream() != null) { parser.setInput(source.getCharacterStream()); - } else if (source.getSystemId() != null) { - URL url = new URL(source.getSystemId()); + } else if (systemId != null) { + URL url = new URL(systemId); URLConnection urlConnection = url.openConnection(); urlConnection.connect(); - String encoding = source.getEncoding(); - // TODO: if null, extract the encoding from the Content-Type header? - parser.setInput(urlConnection.getInputStream(), encoding); + // TODO: if null, extract the inputEncoding from the Content-Type header? + parser.setInput(urlConnection.getInputStream(), inputEncoding); } else { throw new SAXParseException( "InputSource needs a stream, reader or URI", null); @@ -143,7 +145,7 @@ class DocumentBuilderImpl extends DocumentBuilder { LocatorImpl locator = new LocatorImpl(); locator.setPublicId(source.getPublicId()); - locator.setSystemId(source.getSystemId()); + locator.setSystemId(systemId); locator.setLineNumber(ex.getLineNumber()); locator.setColumnNumber(ex.getColumnNumber()); |