package com.juick.server.xmpp.router; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; import java.io.IOException; /** * Created by vitalyster on 03.02.2017. */ public class StreamError { private String condition; private String text; public StreamError() {} public StreamError(String condition) { this.condition = condition; } public static StreamError parse(XmlPullParser parser) throws IOException, XmlPullParserException { StreamError streamError = new StreamError(); final int initial = parser.getDepth(); while (true) { int eventType = parser.next(); if (eventType == XmlPullParser.START_TAG && parser.getDepth() == initial + 1) { final String tag = parser.getName(); final String xmlns = parser.getNamespace(); if (tag.equals("text") && xmlns.equals(StreamNamespaces.NS_XMPP_STREAMS)) { streamError.text = XmlUtils.getTagText(parser); } else if (xmlns.equals(StreamNamespaces.NS_XMPP_STREAMS)) { streamError.condition = tag; } else { XmlUtils.skip(parser); } } else if (eventType == XmlPullParser.END_TAG && parser.getDepth() == initial) { break; } } return streamError; } public String getCondition() { return condition; } @Override public String toString() { return String.format("<%s xmlns='%s'/>", condition, StreamNamespaces.NS_XMPP_STREAMS); } public String getText() { return text; } }