summaryrefslogtreecommitdiffstats
path: root/xml/src/test/java
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2009-12-09 16:05:29 -0800
committerElliott Hughes <enh@google.com>2009-12-09 17:03:35 -0800
commitc9b92b4c79529c5308b2621ac1abe9a5ab039f8d (patch)
tree6319b18a44fe663a8d7c5ad3bf62793c6d50f8eb /xml/src/test/java
parenta1e5d8a2c1594f7a6ed8aca6e82b106ec8ce79d6 (diff)
downloadlibcore-c9b92b4c79529c5308b2621ac1abe9a5ab039f8d.zip
libcore-c9b92b4c79529c5308b2621ac1abe9a5ab039f8d.tar.gz
libcore-c9b92b4c79529c5308b2621ac1abe9a5ab039f8d.tar.bz2
Implement DTDHandler support for ExpatParser.
Every time a third-party developer gets their DefaultHandler method signatures wrong (making it impossible for us to call them), they see this in the log and complain that SAX parsing is broken on Android: WARN/ExpatReader(704): DTD handlers aren't supported. This patch adds that support -- even though no-one wants it -- so we can get rid of the irrelevant log message.
Diffstat (limited to 'xml/src/test/java')
-rw-r--r--xml/src/test/java/org/apache/harmony/xml/ExpatParserTest.java63
1 files changed, 59 insertions, 4 deletions
diff --git a/xml/src/test/java/org/apache/harmony/xml/ExpatParserTest.java b/xml/src/test/java/org/apache/harmony/xml/ExpatParserTest.java
index 480bca3..f781611 100644
--- a/xml/src/test/java/org/apache/harmony/xml/ExpatParserTest.java
+++ b/xml/src/test/java/org/apache/harmony/xml/ExpatParserTest.java
@@ -501,27 +501,67 @@ public class ExpatParserTest extends TestCase {
}
}
- public void testDtd() throws Exception {
- Reader in = new StringReader(
- "<?xml version=\"1.0\"?><!DOCTYPE foo PUBLIC 'bar' 'tee'><a></a>");
+ private TestDtdHandler runDtdTest(String s) throws Exception {
+ Reader in = new StringReader(s);
ExpatReader reader = new ExpatReader();
TestDtdHandler handler = new TestDtdHandler();
reader.setContentHandler(handler);
+ reader.setDTDHandler(handler);
reader.setLexicalHandler(handler);
reader.parse(new InputSource(in));
+ return handler;
+ }
+ public void testDtdDoctype() throws Exception {
+ TestDtdHandler handler = runDtdTest("<?xml version=\"1.0\"?><!DOCTYPE foo PUBLIC 'bar' 'tee'><a></a>");
assertEquals("foo", handler.name);
assertEquals("bar", handler.publicId);
assertEquals("tee", handler.systemId);
-
assertTrue(handler.ended);
}
+ public void testDtdUnparsedEntity_system() throws Exception {
+ TestDtdHandler handler = runDtdTest("<?xml version=\"1.0\"?><!DOCTYPE foo PUBLIC 'bar' 'tee' [ <!ENTITY ent SYSTEM 'blah' NDATA poop> ]><a></a>");
+ assertEquals("ent", handler.ueName);
+ assertEquals(null, handler.uePublicId);
+ assertEquals("blah", handler.ueSystemId);
+ assertEquals("poop", handler.ueNotationName);
+ }
+
+ public void testDtdUnparsedEntity_public() throws Exception {
+ TestDtdHandler handler = runDtdTest("<?xml version=\"1.0\"?><!DOCTYPE foo PUBLIC 'bar' 'tee' [ <!ENTITY ent PUBLIC 'a' 'b' NDATA poop> ]><a></a>");
+ assertEquals("ent", handler.ueName);
+ assertEquals("a", handler.uePublicId);
+ assertEquals("b", handler.ueSystemId);
+ assertEquals("poop", handler.ueNotationName);
+ }
+
+ public void testDtdNotation_system() throws Exception {
+ TestDtdHandler handler = runDtdTest("<?xml version=\"1.0\"?><!DOCTYPE foo PUBLIC 'bar' 'tee' [ <!NOTATION sn SYSTEM 'nf2'> ]><a></a>");
+ assertEquals("sn", handler.ndName);
+ assertEquals(null, handler.ndPublicId);
+ assertEquals("nf2", handler.ndSystemId);
+ }
+
+ public void testDtdNotation_public() throws Exception {
+ TestDtdHandler handler = runDtdTest("<?xml version=\"1.0\"?><!DOCTYPE foo PUBLIC 'bar' 'tee' [ <!NOTATION pn PUBLIC 'nf1'> ]><a></a>");
+ assertEquals("pn", handler.ndName);
+ assertEquals("nf1", handler.ndPublicId);
+ assertEquals(null, handler.ndSystemId);
+ }
+
static class TestDtdHandler extends DefaultHandler2 {
String name;
String publicId;
String systemId;
+ String ndName;
+ String ndPublicId;
+ String ndSystemId;
+ String ueName;
+ String uePublicId;
+ String ueSystemId;
+ String ueNotationName;
boolean ended;
@@ -543,6 +583,21 @@ public class ExpatParserTest extends TestCase {
public void setDocumentLocator(Locator locator) {
this.locator = locator;
}
+
+ @Override
+ public void notationDecl(String name, String publicId, String systemId) {
+ this.ndName = name;
+ this.ndPublicId = publicId;
+ this.ndSystemId = systemId;
+ }
+
+ @Override
+ public void unparsedEntityDecl(String entityName, String publicId, String systemId, String notationName) {
+ this.ueName = entityName;
+ this.uePublicId = publicId;
+ this.ueSystemId = systemId;
+ this.ueNotationName = notationName;
+ }
}
public void testCdata() throws Exception {