mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-12-26 12:37:58 +01:00
Cache the parser availability of the roundtrip feature
As otherwise there would be multiple log statements (which are of level fine but nevertheless). PacketParserUtils: XmlPullParser does not support XML_ROUNDTRIP org.xmlpull.v1.XmlPullParserException: unsupported feature: http://xmlpull.org/v1/doc/features.html#xml-roundtrip (position:START_DOCUMENT null@1:1) PacketParserUtils: at org.kxml2.io.KXmlParser.setFeature(KXmlParser.java:2091) PacketParserUtils: at org.jivesoftware.smack.util.PacketParserUtils.newXmppParser(PacketParserUtils.java:150) PacketParserUtils: at org.jivesoftware.smack.util.PacketParserUtils.newXmppParser(PacketParserUtils.java:172) PacketParserUtils: at org.jivesoftware.smack.tcp.XMPPTCPConnection.openStream(XMPPTCPConnection.java:963) PacketParserUtils: at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketWriter.access$2600(XMPPTCPConnection.java:1224) PacketParserUtils: at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketWriter$1.run(XMPPTCPConnection.java:1263) PacketParserUtils: XmlPullParser does not support XML_ROUNDTRIP org.xmlpull.v1.XmlPullParserException: unsupported feature: http://xmlpull.org/v1/doc/features.html#xml-roundtrip (position:START_DOCUMENT null@1:1) PacketParserUtils: at org.kxml2.io.KXmlParser.setFeature(KXmlParser.java:2091) PacketParserUtils: at org.jivesoftware.smack.util.PacketParserUtils.newXmppParser(PacketParserUtils.java:150) PacketParserUtils: at org.jivesoftware.smack.util.PacketParserUtils.newXmppParser(PacketParserUtils.java:172) PacketParserUtils: at org.jivesoftware.smack.tcp.XMPPTCPConnection.openStream(XMPPTCPConnection.java:963) PacketParserUtils: at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.access$200(XMPPTCPConnection.java:970) PacketParserUtils: at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader$1.run(XMPPTCPConnection.java:989) PacketParserUtils: XmlPullParser does not support XML_ROUNDTRIP org.xmlpull.v1.XmlPullParserException: unsupported feature: http://xmlpull.org/v1/doc/features.html#xml-roundtrip (position:START_DOCUMENT null@1:1) PacketParserUtils: at org.kxml2.io.KXmlParser.setFeature(KXmlParser.java:2091) PacketParserUtils: at org.jivesoftware.smack.util.PacketParserUtils.newXmppParser(PacketParserUtils.java:150) PacketParserUtils: at org.jivesoftware.smack.util.PacketParserUtils.newXmppParser(PacketParserUtils.java:172) PacketParserUtils: at org.jivesoftware.smack.tcp.XMPPTCPConnection.openStream(XMPPTCPConnection.java:963) PacketParserUtils: at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.access$200(XMPPTCPConnection.java:970) PacketParserUtils: at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader$1.run(XMPPTCPConnection.java:989) PacketParserUtils: XmlPullParser does not support XML_ROUNDTRIP org.xmlpull.v1.XmlPullParserException: unsupported feature: http://xmlpull.org/v1/doc/features.html#xml-roundtrip (position:START_DOCUMENT null@1:1) PacketParserUtils: at org.kxml2.io.KXmlParser.setFeature(KXmlParser.java:2091) PacketParserUtils: at org.jivesoftware.smack.util.PacketParserUtils.newXmppParser(PacketParserUtils.java:150) PacketParserUtils: at org.jivesoftware.smack.util.PacketParserUtils.newXmppParser(PacketParserUtils.java:172) PacketParserUtils: at org.jivesoftware.smack.tcp.XMPPTCPConnection.openStream(XMPPTCPConnection.java:963) PacketParserUtils: at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.access$200(XMPPTCPConnection.java:970) PacketParserUtils: at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader$1.run(XMPPTCPConnection.java:989)
This commit is contained in:
parent
ee67bb8aa5
commit
3733a6aaa5
1 changed files with 38 additions and 5 deletions
|
@ -61,6 +61,35 @@ public class PacketParserUtils {
|
|||
|
||||
public static final String FEATURE_XML_ROUNDTRIP = "http://xmlpull.org/v1/doc/features.html#xml-roundtrip";
|
||||
|
||||
private static final XmlPullParserFactory XML_PULL_PARSER_FACTORY;
|
||||
|
||||
/**
|
||||
* True if the XmlPullParser supports the XML_ROUNDTRIP feature.
|
||||
*/
|
||||
public static final boolean XML_PULL_PARSER_SUPPORTS_ROUNDTRIP;
|
||||
|
||||
static {
|
||||
XmlPullParser xmlPullParser;
|
||||
boolean roundtrip = false;
|
||||
try {
|
||||
XML_PULL_PARSER_FACTORY = XmlPullParserFactory.newInstance();
|
||||
xmlPullParser = XML_PULL_PARSER_FACTORY.newPullParser();
|
||||
try {
|
||||
xmlPullParser.setFeature(FEATURE_XML_ROUNDTRIP, true);
|
||||
// We could successfully set the feature
|
||||
roundtrip = true;
|
||||
} catch (XmlPullParserException e) {
|
||||
// Doesn't matter if FEATURE_XML_ROUNDTRIP isn't available
|
||||
LOGGER.log(Level.FINEST, "XmlPullParser does not support XML_ROUNDTRIP", e);
|
||||
}
|
||||
}
|
||||
catch (XmlPullParserException e) {
|
||||
// Something really bad happened
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
XML_PULL_PARSER_SUPPORTS_ROUNDTRIP = roundtrip;
|
||||
}
|
||||
|
||||
public static XmlPullParser getParserFor(String stanza) throws XmlPullParserException, IOException {
|
||||
return getParserFor(new StringReader(stanza));
|
||||
}
|
||||
|
@ -146,11 +175,15 @@ public class PacketParserUtils {
|
|||
public static XmlPullParser newXmppParser() throws XmlPullParserException {
|
||||
XmlPullParser parser = XmlPullParserFactory.newInstance().newPullParser();
|
||||
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
|
||||
try {
|
||||
parser.setFeature(FEATURE_XML_ROUNDTRIP, true);
|
||||
} catch (XmlPullParserException e) {
|
||||
// Doesn't matter if FEATURE_XML_ROUNDTRIP isn't available
|
||||
LOGGER.log(Level.FINEST, "XmlPullParser does not support XML_ROUNDTRIP", e);
|
||||
if (XML_PULL_PARSER_SUPPORTS_ROUNDTRIP) {
|
||||
try {
|
||||
parser.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",
|
||||
e);
|
||||
}
|
||||
}
|
||||
return parser;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue