aboutsummaryrefslogtreecommitdiffstats
path: root/src/de/gultsch/chat/xml/XmlReader.java
diff options
context:
space:
mode:
authorDaniel Gultsch <daniel.gultsch@rwth-aachen.de>2014-02-28 18:46:01 +0100
committerDaniel Gultsch <daniel.gultsch@rwth-aachen.de>2014-02-28 18:46:01 +0100
commitacf80bddd07d5579cdb20a888b3f9e99e53030a5 (patch)
tree034a8e364488c89c8e1997f56313d919019afa65 /src/de/gultsch/chat/xml/XmlReader.java
parent03d96266f8bbb76e25610e903d74a0afa7dcd03b (diff)
rebranding
Diffstat (limited to 'src/de/gultsch/chat/xml/XmlReader.java')
-rw-r--r--src/de/gultsch/chat/xml/XmlReader.java102
1 files changed, 0 insertions, 102 deletions
diff --git a/src/de/gultsch/chat/xml/XmlReader.java b/src/de/gultsch/chat/xml/XmlReader.java
deleted file mode 100644
index 0ff2e785..00000000
--- a/src/de/gultsch/chat/xml/XmlReader.java
+++ /dev/null
@@ -1,102 +0,0 @@
-package de.gultsch.chat.xml;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-
-import org.xmlpull.v1.XmlPullParser;
-import org.xmlpull.v1.XmlPullParserException;
-
-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;
-
- public XmlReader(WakeLock wakeLock) {
- this.parser = Xml.newPullParser();
- try {
- this.parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES,true);
- } catch (XmlPullParserException e) {
- Log.d(LOGTAG,"error setting namespace feature on parser");
- }
- this.wakeLock = wakeLock;
- }
-
- public void setInputStream(InputStream inputStream) {
- this.is = inputStream;
- try {
- parser.setInput(new InputStreamReader(this.is));
- } catch (XmlPullParserException e) {
- Log.d(LOGTAG,"error setting input stream");
- }
- }
-
- public void reset() {
- try {
- parser.setInput(new InputStreamReader(this.is));
- } catch (XmlPullParserException e) {
- Log.d(LOGTAG,"error resetting input stream");
- }
- }
-
- public Tag readTag() throws XmlPullParserException, IOException {
- if (wakeLock.isHeld()) {
- //Log.d(LOGTAG,"there was a wake lock. releasing it till next event");
- wakeLock.release(); //release wake look while waiting on next parser event
- }
- //Log.d(LOGTAG,"waiting for new event...");
- while(parser.next() != XmlPullParser.END_DOCUMENT) {
- //Log.d(LOGTAG,"found new event. acquiring wake lock");
- 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()) {
- wakeLock.release();
- }
- return null; //end document;
- }
-
- public Element readElement(Tag currentTag) throws XmlPullParserException, IOException {
- Element element = new Element(currentTag.getName());
- //Log.d(LOGTAG,"trying to read element "+element.getName());
- element.setAttributes(currentTag.getAttributes());
- Tag nextTag = this.readTag();
- //Log.d(LOGTAG,"next Tag is: "+nextTag.toString());
- if(nextTag.isNo()) {
- element.setContent(nextTag.getName());
- nextTag = this.readTag();
- }
- //Log.d(LOGTAG,"reading till the end of "+element.getName());
- while(!nextTag.isEnd(element.getName())) {
- if (!nextTag.isNo()) {
- Element child = this.readElement(nextTag);
- element.addChild(child);
- }
- nextTag = this.readTag();
- }
- //Log.d(LOGTAG,"return with element"+element);
- return element;
- }
-}