summaryrefslogtreecommitdiffstats
path: root/xml/src/main/java
diff options
context:
space:
mode:
authorJesse Wilson <jessewilson@google.com>2010-12-20 11:51:41 -0800
committerJesse Wilson <jessewilson@google.com>2010-12-20 12:38:23 -0800
commit38e84b835c2101206d846f7ab6fc444914661753 (patch)
tree67761c4da9cdce3b9fda132ea9196973b6aeb32a /xml/src/main/java
parent19b9b8115e2946ffbf68148d8755a76b37b082e5 (diff)
downloadlibcore-38e84b835c2101206d846f7ab6fc444914661753.zip
libcore-38e84b835c2101206d846f7ab6fc444914661753.tar.gz
libcore-38e84b835c2101206d846f7ab6fc444914661753.tar.bz2
Capture the DTD body while it is being parsed.
Change-Id: Ibef02ca759eb56a00f0f72f4063d129ef5350d21 http://b/3241492
Diffstat (limited to 'xml/src/main/java')
-rw-r--r--xml/src/main/java/org/kxml2/io/KXmlParser.java48
1 files changed, 36 insertions, 12 deletions
diff --git a/xml/src/main/java/org/kxml2/io/KXmlParser.java b/xml/src/main/java/org/kxml2/io/KXmlParser.java
index 9fb858b..f9d6461 100644
--- a/xml/src/main/java/org/kxml2/io/KXmlParser.java
+++ b/xml/src/main/java/org/kxml2/io/KXmlParser.java
@@ -110,6 +110,13 @@ public class KXmlParser implements XmlPullParser, Closeable {
private boolean keepNamespaceAttributes;
/**
+ * If non-null, the contents of the read buffer must be copied into this
+ * string builder before the read buffer is overwritten. This is used to
+ * capture the raw DTD text while parsing the DTD.
+ */
+ private StringBuilder bufferCapture;
+
+ /**
* Entities defined in or for this document. This map is created lazily.
*/
private Map<String, char[]> documentEntities;
@@ -408,10 +415,7 @@ public class KXmlParser implements XmlPullParser, Closeable {
}
break;
case DOCDECL:
- readDoctype();
- if (justOneToken) {
- text = ""; // TODO: support capturing the doctype text
- }
+ readDoctype(justOneToken);
break;
default:
@@ -563,16 +567,32 @@ public class KXmlParser implements XmlPullParser, Closeable {
* Read the document's DTD. Although this parser is non-validating, the DTD
* must be parsed to capture entity values and default attribute values.
*/
- private void readDoctype() throws IOException, XmlPullParserException {
+ private void readDoctype(boolean saveDtdText) throws IOException, XmlPullParserException {
read(START_DOCTYPE);
- skip();
- rootElementName = readName();
- readExternalId(true, true);
- skip();
- if (peekCharacter() == '[') {
- readInternalSubset();
+
+ int startPosition = -1;
+ if (saveDtdText) {
+ bufferCapture = new StringBuilder();
+ startPosition = position;
}
- skip();
+ try {
+ skip();
+ rootElementName = readName();
+ readExternalId(true, true);
+ skip();
+ if (peekCharacter() == '[') {
+ readInternalSubset();
+ }
+ skip();
+ } finally {
+ if (saveDtdText) {
+ bufferCapture.append(buffer, 0, position);
+ bufferCapture.delete(0, startPosition);
+ text = bufferCapture.toString();
+ bufferCapture = null;
+ }
+ }
+
read('>');
}
@@ -1456,6 +1476,10 @@ public class KXmlParser implements XmlPullParser, Closeable {
}
}
+ if (bufferCapture != null) {
+ bufferCapture.append(buffer, 0, position);
+ }
+
if (limit != position) {
limit -= position;
System.arraycopy(buffer, position, buffer, 0, limit);