Commit fe5c6144 authored by Derek DeMoro's avatar Derek DeMoro Committed by derek

Updated to parse individual elements while handling non well-formed packets.


git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@595 b35dd754-fafc-0310-a699-88a17e54d16e
parent dc8736f3
......@@ -9,14 +9,25 @@
package org.dom4j.io;
import org.dom4j.*;
import java.io.BufferedReader;
import java.io.CharArrayReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.URL;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentFactory;
import org.dom4j.Element;
import org.dom4j.ElementHandler;
import org.dom4j.QName;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;
import java.io.*;
import java.net.URL;
/**
* <p><code>XPPPacketReader</code> is a Reader of DOM4J documents that
* uses the fast
......@@ -103,7 +114,8 @@ public class XPPPacketReader {
if (systemID.indexOf(':') >= 0) {
// lets assume its a URL
return read(new URL(systemID));
} else {
}
else {
// lets assume that we are given a file name
return read(new File(systemID));
}
......@@ -252,18 +264,20 @@ public class XPPPacketReader {
// Implementation methods
//-------------------------------------------------------------------------
protected Document parseDocument() throws DocumentException, IOException, XmlPullParserException {
public Document parseDocument() throws DocumentException, IOException, XmlPullParserException {
DocumentFactory df = getDocumentFactory();
Document document = df.createDocument();
Element parent = null;
XmlPullParser pp = getXPPParser();
pp.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
// pp.setFeature(XmlPullParser.FEATURE_PROCESS_DOCDECL, true);
// pp.setFeature(XmlPullParser.FEATURE_VALIDATION, true);
// pp.setFeature("http://xmlpull.org/v1/doc/features.html#xml-roundtrip", true);
int count = 0;
while (true) {
// int type = pp.next();
int type = pp.nextToken();
int type = -1;
try {
type = pp.nextToken();
}
catch(Exception ex){
return null;
}
switch (type) {
case XmlPullParser.PROCESSING_INSTRUCTION:
{
......@@ -271,7 +285,8 @@ public class XPPPacketReader {
int loc = text.indexOf(" ");
if (loc >= 0) {
document.addProcessingInstruction(text.substring(0, loc), text.substring(loc + 1));
} else
}
else
document.addProcessingInstruction(text, "");
break;
}
......@@ -287,7 +302,8 @@ public class XPPPacketReader {
{
if (parent != null) {
parent.addCDATA(pp.getText());
} else {
}
else {
throw new DocumentException("Cannot have text content outside of the root document");
}
break;
......@@ -318,10 +334,12 @@ public class XPPPacketReader {
}
if (parent != null) {
parent.add(newElement);
} else {
}
else {
document.add(newElement);
}
parent = newElement;
count++;
break;
}
case XmlPullParser.END_TAG:
......@@ -329,6 +347,10 @@ public class XPPPacketReader {
if (parent != null) {
parent = parent.getParent();
}
count--;
if (count == 0) {
return document;
}
break;
}
case XmlPullParser.TEXT:
......@@ -336,7 +358,8 @@ public class XPPPacketReader {
String text = pp.getText();
if (parent != null) {
parent.addText(text);
} else {
}
else {
throw new DocumentException("Cannot have text content outside of the root document");
}
break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment