思特奇智慧酒店云平台 v0.0.5版本的 MD5 值为:dedb172bb322639d79d7e0e26262fb5c
以下内容为反编译后的 PacketParserUtils.java 源代码,内容仅作参考
package org.jivesoftware.smack.util;
import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jivesoftware.smack.SmackConfiguration;
import org.jivesoftware.smack.compress.packet.Compress;
import org.jivesoftware.smack.packet.EmptyResultIQ;
import org.jivesoftware.smack.packet.ErrorIQ;
import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.Mechanisms;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.smack.packet.Session;
import org.jivesoftware.smack.packet.Stanza;
import org.jivesoftware.smack.packet.StanzaError;
import org.jivesoftware.smack.packet.StartTls;
import org.jivesoftware.smack.packet.StreamError;
import org.jivesoftware.smack.packet.UnparsedIQ;
import org.jivesoftware.smack.parsing.StandardExtensionElementProvider;
import org.jivesoftware.smack.provider.ExtensionElementProvider;
import org.jivesoftware.smack.provider.IQProvider;
import org.jivesoftware.smack.provider.ProviderManager;
import org.jivesoftware.smack.sasl.packet.SaslStreamElements;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;
public class PacketParserUtils {
public static final boolean $assertionsDisabled = false;
public static final String FEATURE_XML_ROUNDTRIP = "http://xmlpull.org/v1/doc/features.html#xml-roundtrip";
public static final Logger LOGGER = Logger.getLogger(PacketParserUtils.class.getName());
public static final XmlPullParserFactory XML_PULL_PARSER_FACTORY;
public static final boolean XML_PULL_PARSER_SUPPORTS_ROUNDTRIP;
public static class AnonymousClass1 {
public static final int[] $SwitchMap$org$jivesoftware$smack$packet$IQ$Type = new int[IQ.Type.values().length];
static {
try {
$SwitchMap$org$jivesoftware$smack$packet$IQ$Type[IQ.Type.error.ordinal()] = 1;
} catch (NoSuchFieldError unused) {
}
try {
$SwitchMap$org$jivesoftware$smack$packet$IQ$Type[IQ.Type.result.ordinal()] = 2;
} catch (NoSuchFieldError unused2) {
}
}
}
static {
SmackConfiguration.getVersion();
boolean z = false;
try {
XML_PULL_PARSER_FACTORY = XmlPullParserFactory.newInstance();
try {
XML_PULL_PARSER_FACTORY.newPullParser().setFeature(FEATURE_XML_ROUNDTRIP, true);
z = true;
} catch (XmlPullParserException e) {
LOGGER.log(Level.FINEST, "XmlPullParser does not support XML_ROUNDTRIP", (Throwable) e);
}
XML_PULL_PARSER_SUPPORTS_ROUNDTRIP = z;
} catch (XmlPullParserException e2) {
throw new AssertionError(e2);
}
}
public static void addExtensionElement(Stanza stanza, XmlPullParser xmlPullParser) throws Exception {
ParserUtils.assertAtStartTag(xmlPullParser);
addExtensionElement(stanza, xmlPullParser, xmlPullParser.getName(), xmlPullParser.getNamespace());
}
public static XmlPullParser getParserFor(String str) throws XmlPullParserException, IOException {
return getParserFor(new StringReader(str));
}
public static XmlPullParser newXmppParser() throws XmlPullParserException {
XmlPullParser newPullParser = XmlPullParserFactory.newInstance().newPullParser();
newPullParser.setFeature("http://xmlpull.org/v1/doc/features.html#process-namespaces", true);
if (XML_PULL_PARSER_SUPPORTS_ROUNDTRIP) {
try {
newPullParser.setFeature(FEATURE_XML_ROUNDTRIP, true);
} catch (XmlPullParserException e) {
LOGGER.log(Level.SEVERE, "XmlPullParser does not support XML_ROUNDTRIP, although it was first determined to be supported", (Throwable) e);
}
}
return newPullParser;
}
public static Compress.Feature parseCompressionFeature(XmlPullParser xmlPullParser) throws IOException, XmlPullParserException {
int depth = xmlPullParser.getDepth();
LinkedList linkedList = new LinkedList();
while (true) {
int next = xmlPullParser.next();
char c = 0;
if (next == 2) {
String name = xmlPullParser.getName();
if (((name.hashCode() == -1077554975 && name.equals("method")) ? (char) 65535 : (char) 65535) == 0) {
linkedList.add(xmlPullParser.nextText());
}
} else if (next != 3) {
continue;
} else {
String name2 = xmlPullParser.getName();
if (((name2.hashCode() == 1431984486 && name2.equals(Compress.Feature.ELEMENT)) ? (char) 65535 : (char) 65535) == 0 && xmlPullParser.getDepth() == depth) {
return new Compress.Feature(linkedList);
}
}
}
}
public static CharSequence parseContent(XmlPullParser xmlPullParser) throws XmlPullParserException, IOException {
if (xmlPullParser.isEmptyElementTag()) {
return "";
}
xmlPullParser.next();
return parseContentDepth(xmlPullParser, xmlPullParser.getDepth(), false);
}
public static CharSequence parseContentDepth(XmlPullParser xmlPullParser, int i) throws XmlPullParserException, IOException {
return parseContentDepth(xmlPullParser, i, false);
}
public static CharSequence parseContentDepthWithRoundtrip(XmlPullParser xmlPullParser, int i, boolean z) throws XmlPullParserException, IOException {
StringBuilder sb = new StringBuilder();
int eventType = xmlPullParser.getEventType();
while (true) {
if (eventType != 2 || !xmlPullParser.isEmptyElementTag()) {
CharSequence text = xmlPullParser.getText();
if (eventType == 4) {
text = StringUtils.escapeForXmlText(text);
}
sb.append(text);
}
if (eventType == 3 && xmlPullParser.getDepth() <= i) {
return sb;
}
eventType = xmlPullParser.next();
}
}
public static CharSequence parseContentDepthWithoutRoundtrip(XmlPullParser xmlPullParser, int i, boolean z) throws XmlPullParserException, IOException {
XmlStringBuilder xmlStringBuilder = new XmlStringBuilder();
int eventType = xmlPullParser.getEventType();
String str = null;
boolean z2 = false;
while (true) {
if (eventType == 2) {
xmlStringBuilder.halfOpenElement(xmlPullParser.getName());
if (str == null || z) {
String namespace = xmlPullParser.getNamespace();
if (StringUtils.isNotEmpty(namespace)) {
xmlStringBuilder.attribute("xmlns", namespace);
str = xmlPullParser.getName();
}
}
for (int i2 = 0; i2 < xmlPullParser.getAttributeCount(); i2++) {
xmlStringBuilder.attribute(xmlPullParser.getAttributeName(i2), xmlPullParser.getAttributeValue(i2));
}
if (xmlPullParser.isEmptyElementTag()) {
xmlStringBuilder.closeEmptyElement();
z2 = true;
} else {
xmlStringBuilder.rightAngleBracket();
}
} else if (eventType == 3) {
if (z2) {
z2 = false;
} else {
xmlStringBuilder.closeElement(xmlPullParser.getName());
}
if (str != null && str.equals(xmlPullParser.getName())) {
str = null;
}
if (xmlPullParser.getDepth() <= i) {
return xmlStringBuilder;
}
} else if (eventType == 4) {
xmlStringBuilder.escape(xmlPullParser.getText());
}
eventType = xmlPullParser.next();
}
}
public static Map<String, String> parseDescriptiveTexts(XmlPullParser xmlPullParser, Map<String, String> map) throws XmlPullParserException, IOException {
if (map == null) {
map = new HashMap<>();
}
String xmlLang = ParserUtils.getXmlLang(xmlPullParser);
if (xmlLang == null) {
xmlLang = "";
}
map.put(xmlLang, xmlPullParser.nextText());
return map;
}
public static CharSequence parseElement(XmlPullParser xmlPullParser) throws XmlPullParserException, IOException {
return parseElement(xmlPullParser, false);
}
public static String parseElementText(XmlPullParser xmlPullParser) throws XmlPullParserException, IOException {
String str = "";
if (!xmlPullParser.isEmptyElementTag()) {
int next = xmlPullParser.next();
if (next != 4) {
if (next == 3) {
return "";
}
throw new XmlPullParserException("Non-empty element tag not followed by text, while Mixed Content (XML 3.2.2) is disallowed");
}
str = xmlPullParser.getText();
if (xmlPullParser.next() != 3) {
throw new XmlPullParserException("Non-empty element tag contains child-elements, while Mixed Content (XML 3.2.2) is disallowed");
}
}
return str;
}
public static StanzaError.Builder parseError(XmlPullParser xmlPullParser) throws Exception {
int depth = xmlPullParser.getDepth();
ArrayList arrayList = new ArrayList();
StanzaError.Builder builder = StanzaError.getBuilder();
builder.setType(StanzaError.Type.fromString(xmlPullParser.getAttributeValue("", "type")));
builder.setErrorGenerator(xmlPullParser.getAttributeValue("", "by"));
Map<String, String> map = null;
while (true) {
int next = xmlPullParser.next();
if (next != 2) {
if (next == 3 && xmlPullParser.getDepth() == depth) {
builder.setExtensions(arrayList).setDescriptiveTexts(map);
return builder;
}
} else {
String name = xmlPullParser.getName();
String namespace = xmlPullParser.getNamespace();
char c = 0;
if (((namespace.hashCode() == 888780199 && namespace.equals("urn:ietf:params:xml:ns:xmpp-stanzas")) ? (char) 0 : (char) 65535) != 0) {
addExtensionElement(arrayList, xmlPullParser, name, namespace);
} else {
if (((name.hashCode() == 3556653 && name.equals("text")) ? (char) 65535 : (char) 65535) != 0) {
builder.setCondition(StanzaError.Condition.fromString(name));
if (!xmlPullParser.isEmptyElementTag()) {
builder.setConditionText(xmlPullParser.nextText());
}
} else {
map = parseDescriptiveTexts(xmlPullParser, map);
}
}
}
}
}
public static ExtensionElement parseExtensionElement(String str, String str2, XmlPullParser xmlPullParser) throws Exception {
ParserUtils.assertAtStartTag(xmlPullParser);
ExtensionElementProvider<ExtensionElement> extensionProvider = ProviderManager.getExtensionProvider(str, str2);
if (extensionProvider != null) {
return (ExtensionElement) extensionProvider.parse(xmlPullParser);
}
return (ExtensionElement) StandardExtensionElementProvider.INSTANCE.parse(xmlPullParser);
}
public static IQ parseIQ(XmlPullParser xmlPullParser) throws Exception {
ParserUtils.assertAtStartTag(xmlPullParser);
int depth = xmlPullParser.getDepth();
String attributeValue = xmlPullParser.getAttributeValue("", "id");
xw3 jidAttribute = ParserUtils.getJidAttribute(xmlPullParser, "to");
xw3 jidAttribute2 = ParserUtils.getJidAttribute(xmlPullParser, "from");
IQ.Type fromString = IQ.Type.fromString(xmlPullParser.getAttributeValue("", "type"));
IQ iq = null;
StanzaError.Builder builder = null;
while (true) {
int next = xmlPullParser.next();
if (next != 2) {
if (next == 3 && xmlPullParser.getDepth() == depth) {
break;
}
} else {
String name = xmlPullParser.getName();
String namespace = xmlPullParser.getNamespace();
char c = 65535;
if (name.hashCode() == 96784904 && name.equals("error")) {
c = 0;
}
if (c != 0) {
IQProvider<IQ> iQProvider = ProviderManager.getIQProvider(name, namespace);
if (iQProvider != null) {
iq = (IQ) iQProvider.parse(xmlPullParser);
} else {
iq = new UnparsedIQ(name, namespace, parseElement(xmlPullParser));
}
} else {
builder = parseError(xmlPullParser);
}
}
}
if (iq == null) {
int i = AnonymousClass1.$SwitchMap$org$jivesoftware$smack$packet$IQ$Type[fromString.ordinal()];
if (i == 1) {
iq = new ErrorIQ(builder);
} else if (i == 2) {
iq = new EmptyResultIQ();
}
}
iq.setStanzaId(attributeValue);
iq.setTo(jidAttribute);
iq.setFrom(jidAttribute2);
iq.setType(fromString);
iq.setError(builder);
return iq;
}
public static Collection<String> parseMechanisms(XmlPullParser xmlPullParser) throws XmlPullParserException, IOException {
ArrayList arrayList = new ArrayList();
boolean z = false;
while (!z) {
int next = xmlPullParser.next();
if (next == 2) {
if (xmlPullParser.getName().equals("mechanism")) {
arrayList.add(xmlPullParser.nextText());
}
} else if (next == 3 && xmlPullParser.getName().equals(Mechanisms.ELEMENT)) {
z = true;
}
}
return arrayList;
}
public static Message parseMessage(XmlPullParser xmlPullParser) throws Exception {
ParserUtils.assertAtStartTag(xmlPullParser);
int depth = xmlPullParser.getDepth();
Message message = new Message();
message.setStanzaId(xmlPullParser.getAttributeValue("", "id"));
message.setTo(ParserUtils.getJidAttribute(xmlPullParser, "to"));
message.setFrom(ParserUtils.getJidAttribute(xmlPullParser, "from"));
String attributeValue = xmlPullParser.getAttributeValue("", "type");
if (attributeValue != null) {
message.setType(Message.Type.fromString(attributeValue));
}
message.setLanguage(ParserUtils.getXmlLang(xmlPullParser));
String str = null;
while (true) {
int next = xmlPullParser.next();
if (next != 2) {
if (next == 3 && xmlPullParser.getDepth() == depth) {
message.setThread(str);
return message;
}
} else {
String name = xmlPullParser.getName();
String namespace = xmlPullParser.getNamespace();
char c = 65535;
int hashCode = name.hashCode();
if (hashCode != -1867885268) {
if (hashCode != -874443254) {
if (hashCode == 96784904 && name.equals("error")) {
c = 2;
}
} else if (name.equals("thread")) {
c = 1;
}
} else if (name.equals("subject")) {
c = 0;
}
if (c == 0) {
String xmlLang = ParserUtils.getXmlLang(xmlPullParser);
String parseElementText = parseElementText(xmlPullParser);
if (message.getSubject(xmlLang) == null) {
message.addSubject(xmlLang, parseElementText);
}
} else if (c != 1) {
if (c != 2) {
addExtensionElement(message, xmlPullParser, name, namespace);
} else {
message.setError(parseError(xmlPullParser));
}
} else if (str == null) {
str = xmlPullParser.nextText();
}
}
}
}
@Deprecated
public static ExtensionElement parsePacketExtension(String str, String str2, XmlPullParser xmlPullParser) throws Exception {
return parseExtensionElement(str, str2, xmlPullParser);
}
public static Presence parsePresence(XmlPullParser xmlPullParser) throws Exception {
ParserUtils.assertAtStartTag(xmlPullParser);
int depth = xmlPullParser.getDepth();
Presence.Type type = Presence.Type.available;
String attributeValue = xmlPullParser.getAttributeValue("", "type");
if (attributeValue != null && !attributeValue.equals("")) {
type = Presence.Type.fromString(attributeValue);
}
Presence presence = new Presence(type);
presence.setTo(ParserUtils.getJidAttribute(xmlPullParser, "to"));
presence.setFrom(ParserUtils.getJidAttribute(xmlPullParser, "from"));
presence.setStanzaId(xmlPullParser.getAttributeValue("", "id"));
String xmlLang = ParserUtils.getXmlLang(xmlPullParser);
if (xmlLang != null && !"".equals(xmlLang.trim())) {
presence.setLanguage(xmlLang);
}
while (true) {
int next = xmlPullParser.next();
if (next != 2) {
if (next == 3 && xmlPullParser.getDepth() == depth) {
return presence;
}
} else {
String name = xmlPullParser.getName();
String namespace = xmlPullParser.getNamespace();
char c = 65535;
switch (name.hashCode()) {
case -1165461084:
if (name.equals("priority")) {
c = 1;
break;
}
break;
case -892481550:
if (name.equals("status")) {
c = 0;
break;
}
break;
case 3529469:
if (name.equals("show")) {
c = 2;
break;
}
break;
case 96784904:
if (name.equals("error")) {
c = 3;
break;
}
break;
}
if (c == 0) {
presence.setStatus(xmlPullParser.nextText());
} else if (c == 1) {
presence.setPriority(Integer.parseInt(xmlPullParser.nextText()));
} else if (c == 2) {
String nextText = xmlPullParser.nextText();
if (StringUtils.isNotEmpty(nextText)) {
presence.setMode(Presence.Mode.fromString(nextText));
} else {
Logger logger = LOGGER;
logger.warning("Empty or null mode text in presence show element form " + ((Object) presence.getFrom()) + " with id '" + presence.getStanzaId() + "' which is invalid according to RFC6121 4.7.2.1");
}
} else if (c != 3) {
try {
addExtensionElement(presence, xmlPullParser, name, namespace);
} catch (Exception e) {
Logger logger2 = LOGGER;
logger2.warning("Failed to parse extension element in Presence stanza: \"" + e + "\" from: '" + ((Object) presence.getFrom()) + " id: '" + presence.getStanzaId() + "'");
}
} else {
presence.setError(parseError(xmlPullParser));
}
}
}
}
public static SaslStreamElements.SASLFailure parseSASLFailure(XmlPullParser xmlPullParser) throws XmlPullParserException, IOException {
int depth = xmlPullParser.getDepth();
Map<String, String> map = null;
String str = null;
while (true) {
int next = xmlPullParser.next();
if (next != 2) {
if (next == 3 && xmlPullParser.getDepth() == depth) {
return new SaslStreamElements.SASLFailure(str, map);
}
} else if (xmlPullParser.getName().equals("text")) {
map = parseDescriptiveTexts(xmlPullParser, map);
} else {
str = xmlPullParser.getName();
}
}
}
public static Session.Feature parseSessionFeature(XmlPullParser xmlPullParser) throws XmlPullParserException, IOException {
ParserUtils.assertAtStartTag(xmlPullParser);
int depth = xmlPullParser.getDepth();
if (xmlPullParser.isEmptyElementTag()) {
return new Session.Feature(false);
}
boolean z = false;
while (true) {
int next = xmlPullParser.next();
if (next != 2) {
if (next == 3 && xmlPullParser.getDepth() == depth) {
return new Session.Feature(z);
}
} else {
String name = xmlPullParser.getName();
char c = 65535;
if (name.hashCode() == -79017120 && name.equals(Session.Feature.OPTIONAL_ELEMENT)) {
c = 0;
}
if (c == 0) {
z = true;
}
}
}
}
public static <S extends Stanza> S parseStanza(String str) throws Exception {
return (S) parseStanza(getParserFor(str));
}
public static StartTls parseStartTlsFeature(XmlPullParser xmlPullParser) throws XmlPullParserException, IOException {
int depth = xmlPullParser.getDepth();
boolean z = false;
while (true) {
int next = xmlPullParser.next();
if (next != 2) {
if (next == 3 && xmlPullParser.getDepth() == depth) {
return new StartTls(z);
}
} else {
String name = xmlPullParser.getName();
char c = 65535;
if (name.hashCode() == -393139297 && name.equals("required")) {
c = 0;
}
if (c == 0) {
z = true;
}
}
}
}
public static StreamError parseStreamError(XmlPullParser xmlPullParser) throws Exception {
int depth = xmlPullParser.getDepth();
ArrayList arrayList = new ArrayList();
StreamError.Condition condition = null;
String str = null;
Map<String, String> map = null;
while (true) {
int next = xmlPullParser.next();
if (next != 2) {
if (next == 3 && xmlPullParser.getDepth() == depth) {
return new StreamError(condition, str, map, arrayList);
}
} else {
String name = xmlPullParser.getName();
String namespace = xmlPullParser.getNamespace();
char c = 0;
if (((namespace.hashCode() == 904188284 && namespace.equals(StreamError.NAMESPACE)) ? (char) 0 : (char) 65535) != 0) {
addExtensionElement(arrayList, xmlPullParser, name, namespace);
} else {
if (((name.hashCode() == 3556653 && name.equals("text")) ? (char) 65535 : (char) 65535) != 0) {
condition = StreamError.Condition.fromString(name);
if (!xmlPullParser.isEmptyElementTag()) {
str = xmlPullParser.nextText();
}
} else {
map = parseDescriptiveTexts(xmlPullParser, map);
}
}
}
}
}
public static XmlPullParser getParserFor(Reader reader) throws XmlPullParserException, IOException {
XmlPullParser newXmppParser = newXmppParser(reader);
for (int eventType = newXmppParser.getEventType(); eventType != 2; eventType = newXmppParser.next()) {
if (eventType == 1) {
throw new IllegalArgumentException("Document contains no start tag");
}
}
return newXmppParser;
}
public static CharSequence parseContentDepth(XmlPullParser xmlPullParser, int i, boolean z) throws XmlPullParserException, IOException {
if (xmlPullParser.getFeature(FEATURE_XML_ROUNDTRIP)) {
return parseContentDepthWithRoundtrip(xmlPullParser, i, z);
}
return parseContentDepthWithoutRoundtrip(xmlPullParser, i, z);
}
public static CharSequence parseElement(XmlPullParser xmlPullParser, boolean z) throws XmlPullParserException, IOException {
return parseContentDepth(xmlPullParser, xmlPullParser.getDepth(), z);
}
public static Stanza parseStanza(XmlPullParser xmlPullParser) throws Exception {
char c;
ParserUtils.assertAtStartTag(xmlPullParser);
String name = xmlPullParser.getName();
int hashCode = name.hashCode();
if (hashCode == -1276666629) {
if (name.equals(Presence.ELEMENT)) {
c = 2;
}
c = 65535;
} else if (hashCode != 3368) {
if (hashCode == 954925063 && name.equals("message")) {
c = 0;
}
c = 65535;
} else {
if (name.equals(IQ.IQ_ELEMENT)) {
c = 1;
}
c = 65535;
}
if (c != 0) {
if (c != 1) {
if (c == 2) {
return parsePresence(xmlPullParser);
}
throw new IllegalArgumentException("Can only parse message, iq or presence, not " + name);
}
return parseIQ(xmlPullParser);
}
return parseMessage(xmlPullParser);
}
public static void addExtensionElement(Stanza stanza, XmlPullParser xmlPullParser, String str, String str2) throws Exception {
stanza.addExtension(parseExtensionElement(str, str2, xmlPullParser));
}
public static void addExtensionElement(Collection<ExtensionElement> collection, XmlPullParser xmlPullParser) throws Exception {
addExtensionElement(collection, xmlPullParser, xmlPullParser.getName(), xmlPullParser.getNamespace());
}
public static void addExtensionElement(Collection<ExtensionElement> collection, XmlPullParser xmlPullParser, String str, String str2) throws Exception {
collection.add(parseExtensionElement(str, str2, xmlPullParser));
}
public static XmlPullParser getParserFor(String str, String str2) throws XmlPullParserException, IOException {
XmlPullParser parserFor = getParserFor(str);
while (true) {
int eventType = parserFor.getEventType();
String name = parserFor.getName();
if (eventType == 2 && name.equals(str2)) {
return parserFor;
}
if (eventType != 1) {
parserFor.next();
} else {
throw new IllegalArgumentException("Could not find start tag '" + str2 + "' in stanza: " + str);
}
}
}
public static XmlPullParser newXmppParser(Reader reader) throws XmlPullParserException {
XmlPullParser newXmppParser = newXmppParser();
newXmppParser.setInput(reader);
return newXmppParser;
}
}