aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu/siacs/conversations/xml/XmlReader.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/eu/siacs/conversations/xml/XmlReader.java')
-rw-r--r--src/eu/siacs/conversations/xml/XmlReader.java82
1 files changed, 48 insertions, 34 deletions
diff --git a/src/eu/siacs/conversations/xml/XmlReader.java b/src/eu/siacs/conversations/xml/XmlReader.java
index cf6b8c73..52d3d46a 100644
--- a/src/eu/siacs/conversations/xml/XmlReader.java
+++ b/src/eu/siacs/conversations/xml/XmlReader.java
@@ -7,13 +7,14 @@ import java.io.InputStreamReader;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
+import eu.siacs.conversations.Config;
+
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;
import android.util.Log;
import android.util.Xml;
public class XmlReader {
- private static final String LOGTAG = "xmppService";
private XmlPullParser parser;
private PowerManager.WakeLock wakeLock;
private InputStream is;
@@ -21,15 +22,16 @@ public class XmlReader {
public XmlReader(WakeLock wakeLock) {
this.parser = Xml.newPullParser();
try {
- this.parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES,true);
+ this.parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES,
+ true);
} catch (XmlPullParserException e) {
- Log.d(LOGTAG,"error setting namespace feature on parser");
+ Log.d(Config.LOGTAG, "error setting namespace feature on parser");
}
this.wakeLock = wakeLock;
}
-
+
public void setInputStream(InputStream inputStream) throws IOException {
- if (inputStream==null) {
+ if (inputStream == null) {
throw new IOException();
}
this.is = inputStream;
@@ -41,14 +43,14 @@ public class XmlReader {
}
public InputStream getInputStream() throws IOException {
- if (this.is==null) {
+ if (this.is == null) {
throw new IOException();
}
return is;
}
public void reset() throws IOException {
- if (this.is==null) {
+ if (this.is == null) {
throw new IOException();
}
try {
@@ -57,62 +59,74 @@ public class XmlReader {
throw new IOException("error resetting parser");
}
}
-
+
public Tag readTag() throws XmlPullParserException, IOException {
if (wakeLock.isHeld()) {
- try { wakeLock.release();} catch (RuntimeException re) {}
+ try {
+ wakeLock.release();
+ } catch (RuntimeException re) {
+ }
}
try {
- while(this.is != null && parser.next() != XmlPullParser.END_DOCUMENT) {
- wakeLock.acquire();
- if (parser.getEventType() == XmlPullParser.START_TAG) {
- Tag tag = Tag.start(parser.getName());
- for(int i = 0; i < parser.getAttributeCount(); ++i) {
- tag.setAttribute(parser.getAttributeName(i), parser.getAttributeValue(i));
- }
- String xmlns = parser.getNamespace();
- if (xmlns!=null) {
- tag.setAttribute("xmlns",xmlns);
- }
- return tag;
- } else if (parser.getEventType() == XmlPullParser.END_TAG) {
- Tag tag = Tag.end(parser.getName());
- return tag;
- } else if (parser.getEventType() == XmlPullParser.TEXT) {
- Tag tag = Tag.no(parser.getText());
- return tag;
+ while (this.is != null
+ && parser.next() != XmlPullParser.END_DOCUMENT) {
+ wakeLock.acquire();
+ if (parser.getEventType() == XmlPullParser.START_TAG) {
+ Tag tag = Tag.start(parser.getName());
+ for (int i = 0; i < parser.getAttributeCount(); ++i) {
+ tag.setAttribute(parser.getAttributeName(i),
+ parser.getAttributeValue(i));
}
+ String xmlns = parser.getNamespace();
+ if (xmlns != null) {
+ tag.setAttribute("xmlns", xmlns);
+ }
+ return tag;
+ } else if (parser.getEventType() == XmlPullParser.END_TAG) {
+ Tag tag = Tag.end(parser.getName());
+ return tag;
+ } else if (parser.getEventType() == XmlPullParser.TEXT) {
+ Tag tag = Tag.no(parser.getText());
+ return tag;
}
+ }
if (wakeLock.isHeld()) {
- try { wakeLock.release();} catch (RuntimeException re) {}
+ try {
+ wakeLock.release();
+ } catch (RuntimeException re) {
+ }
}
} catch (ArrayIndexOutOfBoundsException e) {
- throw new IOException("xml parser mishandled ArrayIndexOufOfBounds", e);
+ throw new IOException(
+ "xml parser mishandled ArrayIndexOufOfBounds", e);
} catch (StringIndexOutOfBoundsException e) {
- throw new IOException("xml parser mishandled StringIndexOufOfBounds", e);
+ throw new IOException(
+ "xml parser mishandled StringIndexOufOfBounds", e);
} catch (NullPointerException e) {
- throw new IOException("xml parser mishandled NullPointerException", e);
+ throw new IOException("xml parser mishandled NullPointerException",
+ e);
} catch (IndexOutOfBoundsException e) {
throw new IOException("xml parser mishandled IndexOutOfBound", e);
}
return null;
}
- public Element readElement(Tag currentTag) throws XmlPullParserException, IOException {
+ public Element readElement(Tag currentTag) throws XmlPullParserException,
+ IOException {
Element element = new Element(currentTag.getName());
element.setAttributes(currentTag.getAttributes());
Tag nextTag = this.readTag();
if (nextTag == null) {
throw new IOException("unterupted mid tag");
}
- if(nextTag.isNo()) {
+ if (nextTag.isNo()) {
element.setContent(nextTag.getName());
nextTag = this.readTag();
if (nextTag == null) {
throw new IOException("unterupted mid tag");
}
}
- while(!nextTag.isEnd(element.getName())) {
+ while (!nextTag.isEnd(element.getName())) {
if (!nextTag.isNo()) {
Element child = this.readElement(nextTag);
element.addChild(child);