mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-22 06:12:05 +01:00
Substitute MXParser with a call to XmlPullParserFactory
This makes Smack more portable, as there are platforms that support the XmlPullParser interface, but not MXParser (e.g. Android). Also enable checkstyle check that MXParser is not used.
This commit is contained in:
parent
4db0b101c2
commit
24b637876f
18 changed files with 40 additions and 35 deletions
|
@ -23,7 +23,7 @@ import org.jivesoftware.smack.sasl.SASLMechanism.Challenge;
|
|||
import org.jivesoftware.smack.sasl.SASLMechanism.Failure;
|
||||
import org.jivesoftware.smack.sasl.SASLMechanism.Success;
|
||||
import org.jivesoftware.smack.util.PacketParserUtils;
|
||||
import org.xmlpull.mxp1.MXParser;
|
||||
import org.xmlpull.v1.XmlPullParserFactory;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.igniterealtime.jbosh.AbstractBody;
|
||||
import org.igniterealtime.jbosh.BOSHClientResponseListener;
|
||||
|
@ -66,7 +66,7 @@ public class BOSHPacketReader implements BOSHClientResponseListener {
|
|||
if (connection.authID == null) {
|
||||
connection.authID = body.getAttribute(BodyQName.create(BOSHConnection.BOSH_URI, "authid"));
|
||||
}
|
||||
final XmlPullParser parser = new MXParser();
|
||||
final XmlPullParser parser = XmlPullParserFactory.newInstance().newPullParser();
|
||||
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES,
|
||||
true);
|
||||
parser.setInput(new StringReader(body.toXML()));
|
||||
|
|
|
@ -14,6 +14,10 @@
|
|||
<module name="NewlineAtEndOfFile">
|
||||
<property name="lineSeparator" value="lf"/>
|
||||
</module>
|
||||
<module name="RegexpSingleline">
|
||||
<property name="format" value="MXParser"/>
|
||||
<property name="message" value="Must not use MXParser, use XmlPullParserFactory instead"/>
|
||||
</module>
|
||||
<module name="TreeWalker">
|
||||
<module name="UnusedImports">
|
||||
<property name="processJavadoc" value="true"/>
|
||||
|
|
|
@ -16,7 +16,7 @@ package org.jivesoftware.smack.packet;
|
|||
|
||||
import org.jivesoftware.smack.provider.PrivacyProvider;
|
||||
import org.jivesoftware.smack.test.SmackTestCase;
|
||||
import org.xmlpull.mxp1.MXParser;
|
||||
import org.xmlpull.v1.XmlPullParserFactory;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
|
@ -372,7 +372,7 @@ public class PrivacyProviderTest extends SmackTestCase {
|
|||
}
|
||||
|
||||
private XmlPullParser getParserFromXML(String xml) throws XmlPullParserException {
|
||||
MXParser parser = new MXParser();
|
||||
XmlPullParser parser = XmlPullParserFactory.newInstance().newPullParser();
|
||||
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
|
||||
parser.setInput(new StringReader(xml));
|
||||
return parser;
|
||||
|
|
|
@ -32,7 +32,7 @@ import org.jivesoftware.smack.ConnectionConfiguration;
|
|||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smack.util.ConnectionUtils;
|
||||
import org.xmlpull.mxp1.MXParser;
|
||||
import org.xmlpull.v1.XmlPullParserFactory;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
|
||||
/**
|
||||
|
@ -411,7 +411,7 @@ public abstract class SmackTestCase extends TestCase {
|
|||
InputStream systemStream = null;
|
||||
try {
|
||||
systemStream = url.openStream();
|
||||
XmlPullParser parser = new MXParser();
|
||||
XmlPullParser parser = XmlPullParserFactory.newInstance().newPullParser();
|
||||
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
|
||||
parser.setInput(systemStream, "UTF-8");
|
||||
int eventType = parser.getEventType();
|
||||
|
|
|
@ -20,7 +20,7 @@ import java.io.StringReader;
|
|||
|
||||
import org.jivesoftware.smack.packet.XMPPError;
|
||||
import org.jivesoftware.smack.test.SmackTestCase;
|
||||
import org.xmlpull.mxp1.MXParser;
|
||||
import org.xmlpull.v1.XmlPullParserFactory;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
|
@ -191,7 +191,7 @@ public class XMPPErrorTest extends SmackTestCase {
|
|||
}
|
||||
|
||||
private XmlPullParser getParserFromXML(String xml) throws XmlPullParserException {
|
||||
MXParser parser = new MXParser();
|
||||
XmlPullParser parser = XmlPullParserFactory.newInstance().newPullParser();
|
||||
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
|
||||
parser.setInput(new StringReader(xml));
|
||||
return parser;
|
||||
|
|
|
@ -32,7 +32,7 @@ import org.jivesoftware.smack.packet.RosterPacket;
|
|||
import org.jivesoftware.smack.packet.RosterPacket.Item;
|
||||
import org.jivesoftware.smack.util.Base32Encoder;
|
||||
import org.jivesoftware.smack.util.StringUtils;
|
||||
import org.xmlpull.mxp1.MXParser;
|
||||
import org.xmlpull.v1.XmlPullParserFactory;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
|
@ -200,7 +200,7 @@ public class DefaultRosterStore implements RosterStore {
|
|||
List<String> groupNames = new ArrayList<String>();
|
||||
|
||||
try {
|
||||
XmlPullParser parser = new MXParser();
|
||||
XmlPullParser parser = XmlPullParserFactory.newInstance().newPullParser();
|
||||
parser.setInput(new StringReader(s));
|
||||
|
||||
boolean done = false;
|
||||
|
|
|
@ -26,7 +26,7 @@ import org.jivesoftware.smack.sasl.SASLMechanism.Failure;
|
|||
import org.jivesoftware.smack.sasl.SASLMechanism.Success;
|
||||
import org.jivesoftware.smack.util.PacketParserUtils;
|
||||
|
||||
import org.xmlpull.mxp1.MXParser;
|
||||
import org.xmlpull.v1.XmlPullParserFactory;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
|
@ -152,7 +152,7 @@ class PacketReader {
|
|||
*/
|
||||
private void resetParser() {
|
||||
try {
|
||||
parser = new MXParser();
|
||||
parser = XmlPullParserFactory.newInstance().newPullParser();
|
||||
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
|
||||
parser.setInput(connection.reader);
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ import org.jivesoftware.smack.initializer.SmackInitializer;
|
|||
import org.jivesoftware.smack.parsing.ExceptionThrowingCallback;
|
||||
import org.jivesoftware.smack.parsing.ParsingExceptionCallback;
|
||||
import org.jivesoftware.smack.util.FileUtils;
|
||||
import org.xmlpull.mxp1.MXParser;
|
||||
import org.xmlpull.v1.XmlPullParserFactory;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
|
@ -430,7 +430,7 @@ public final class SmackConfiguration {
|
|||
}
|
||||
|
||||
private static void readFile(InputStream cfgFileStream) throws Exception {
|
||||
XmlPullParser parser = new MXParser();
|
||||
XmlPullParser parser = XmlPullParserFactory.newInstance().newPullParser();
|
||||
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
|
||||
parser.setInput(cfgFileStream, "UTF-8");
|
||||
int eventType = parser.getEventType();
|
||||
|
|
|
@ -27,7 +27,7 @@ import java.util.logging.Logger;
|
|||
|
||||
import org.jivesoftware.smack.packet.IQ;
|
||||
import org.jivesoftware.smack.packet.PacketExtension;
|
||||
import org.xmlpull.mxp1.MXParser;
|
||||
import org.xmlpull.v1.XmlPullParserFactory;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
|
||||
/**
|
||||
|
@ -83,7 +83,7 @@ public class ProviderFileLoader implements ProviderLoader {
|
|||
|
||||
// Load processing providers.
|
||||
try {
|
||||
XmlPullParser parser = new MXParser();
|
||||
XmlPullParser parser = XmlPullParserFactory.newInstance().newPullParser();
|
||||
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
|
||||
parser.setInput(providerStream, "UTF-8");
|
||||
int eventType = parser.getEventType();
|
||||
|
|
|
@ -35,7 +35,7 @@ import org.jivesoftware.smack.util.PacketParserUtils;
|
|||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.xmlpull.mxp1.MXParser;
|
||||
import org.xmlpull.v1.XmlPullParserFactory;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
|
||||
/**
|
||||
|
@ -315,7 +315,7 @@ public class RosterTest {
|
|||
final String contactJID = "nurse@example.com";
|
||||
final Roster roster = connection.getRoster();
|
||||
assertNotNull("Can't get the roster from the provided connection!", roster);
|
||||
final MXParser parser = new MXParser();
|
||||
final XmlPullParser parser = XmlPullParserFactory.newInstance().newPullParser();
|
||||
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
sb.append("<iq id=\"rostertest1\" type=\"set\" ")
|
||||
|
@ -449,7 +449,7 @@ public class RosterTest {
|
|||
final String contactJID = "nurse@example.com";
|
||||
final Roster roster = connection.getRoster();
|
||||
assertNotNull("Can't get the roster from the provided connection!", roster);
|
||||
final MXParser parser = new MXParser();
|
||||
final XmlPullParser parser = XmlPullParserFactory.newInstance().newPullParser();
|
||||
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
sb.append("<iq id=\"rostertest2\" type=\"set\" ")
|
||||
|
|
|
@ -19,7 +19,7 @@ package org.jivesoftware.smack.test.util;
|
|||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
|
||||
import org.xmlpull.mxp1.MXParser;
|
||||
import org.xmlpull.v1.XmlPullParserFactory;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
|
@ -40,8 +40,9 @@ final public class TestUtils {
|
|||
}
|
||||
|
||||
public static XmlPullParser getParser(String stanza, String startTag) {
|
||||
XmlPullParser parser = new MXParser();
|
||||
XmlPullParser parser;
|
||||
try {
|
||||
parser = XmlPullParserFactory.newInstance().newPullParser();
|
||||
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
|
||||
parser.setInput(new StringReader(stanza));
|
||||
boolean found = false;
|
||||
|
|
|
@ -24,7 +24,7 @@ import java.util.List;
|
|||
import org.jivesoftware.smack.SmackConfiguration;
|
||||
import org.jivesoftware.smack.initializer.SmackInitializer;
|
||||
import org.jivesoftware.smack.util.FileUtils;
|
||||
import org.xmlpull.mxp1.MXParser;
|
||||
import org.xmlpull.v1.XmlPullParserFactory;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
|
||||
public class ExtensionsStartupClasses implements SmackInitializer {
|
||||
|
@ -41,7 +41,7 @@ public class ExtensionsStartupClasses implements SmackInitializer {
|
|||
int eventType;
|
||||
try {
|
||||
is = FileUtils.getStreamForUrl(EXTENSIONS_XML, null);
|
||||
parser = new MXParser();
|
||||
parser = XmlPullParserFactory.newInstance().newPullParser();
|
||||
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
|
||||
parser.setInput(is, "UTF-8");
|
||||
eventType = parser.getEventType();
|
||||
|
|
|
@ -34,7 +34,7 @@ import org.jivesoftware.smack.util.StringEncoder;
|
|||
import org.jivesoftware.smackx.caps.EntityCapsManager;
|
||||
import org.jivesoftware.smackx.disco.packet.DiscoverInfo;
|
||||
import org.jivesoftware.smackx.disco.provider.DiscoverInfoProvider;
|
||||
import org.xmlpull.mxp1.MXParser;
|
||||
import org.xmlpull.v1.XmlPullParserFactory;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
|
@ -159,7 +159,7 @@ public class SimpleDirectoryPersistentCache implements EntityCapsPersistentCache
|
|||
Reader reader = new StringReader(fileContent);
|
||||
XmlPullParser parser;
|
||||
try {
|
||||
parser = new MXParser();
|
||||
parser = XmlPullParserFactory.newInstance().newPullParser();
|
||||
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
|
||||
parser.setInput(reader);
|
||||
} catch (XmlPullParserException xppe) {
|
||||
|
|
|
@ -26,7 +26,7 @@ import org.jivesoftware.smackx.bytestreams.ibb.InBandBytestreamManager.StanzaTyp
|
|||
import org.jivesoftware.smackx.bytestreams.ibb.packet.Open;
|
||||
import org.jivesoftware.smackx.bytestreams.ibb.provider.OpenIQProvider;
|
||||
import org.junit.Test;
|
||||
import org.xmlpull.mxp1.MXParser;
|
||||
import org.xmlpull.v1.XmlPullParserFactory;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
|
@ -76,7 +76,7 @@ public class OpenIQProviderTest {
|
|||
|
||||
private XmlPullParser getParser(String control) throws XmlPullParserException,
|
||||
IOException {
|
||||
XmlPullParser parser = new MXParser();
|
||||
XmlPullParser parser = XmlPullParserFactory.newInstance().newPullParser();
|
||||
parser.setInput(new StringReader(control));
|
||||
while (true) {
|
||||
if (parser.next() == XmlPullParser.START_TAG
|
||||
|
|
|
@ -33,7 +33,7 @@ import org.jivesoftware.smackx.delay.packet.DelayInformation;
|
|||
import org.jivesoftware.smackx.delay.provider.DelayInfoProvider;
|
||||
import org.jivesoftware.smackx.delay.provider.DelayInformationProvider;
|
||||
import org.junit.Test;
|
||||
import org.xmlpull.mxp1.MXParser;
|
||||
import org.xmlpull.v1.XmlPullParserFactory;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
|
@ -237,7 +237,7 @@ public class DelayInformationTest {
|
|||
|
||||
private XmlPullParser getParser(String control, String startTag)
|
||||
throws XmlPullParserException, IOException {
|
||||
XmlPullParser parser = new MXParser();
|
||||
XmlPullParser parser = XmlPullParserFactory.newInstance().newPullParser();
|
||||
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
|
||||
parser.setInput(new StringReader(control));
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ import org.jivesoftware.smack.util.PacketParserUtils;
|
|||
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.xmlpull.mxp1.MXParser;
|
||||
import org.xmlpull.v1.XmlPullParserFactory;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
|
@ -132,7 +132,7 @@ public class DeliveryReceiptTest {
|
|||
|
||||
private XmlPullParser getParser(String control, String startTag)
|
||||
throws XmlPullParserException, IOException {
|
||||
XmlPullParser parser = new MXParser();
|
||||
XmlPullParser parser = XmlPullParserFactory.newInstance().newPullParser();
|
||||
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
|
||||
parser.setInput(new StringReader(control));
|
||||
while (true) {
|
||||
|
|
|
@ -28,7 +28,7 @@ import java.util.logging.Logger;
|
|||
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smackx.jingle.JingleSession;
|
||||
import org.xmlpull.mxp1.MXParser;
|
||||
import org.xmlpull.v1.XmlPullParserFactory;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
|
@ -138,7 +138,7 @@ public class STUNResolver extends TransportResolver {
|
|||
int serverPort;
|
||||
|
||||
try {
|
||||
XmlPullParser parser = new MXParser();
|
||||
XmlPullParser parser = XmlPullParserFactory.newInstance().newPullParser();
|
||||
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
|
||||
parser.setInput(stunConfigStream, "UTF-8");
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ import java.io.StringReader;
|
|||
import org.jivesoftware.smack.packet.IQ;
|
||||
import org.jivesoftware.smack.provider.IQProvider;
|
||||
import org.jivesoftware.smack.util.StringUtils;
|
||||
import org.xmlpull.mxp1.MXParser;
|
||||
import org.xmlpull.v1.XmlPullParserFactory;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
|
||||
/**
|
||||
|
@ -179,7 +179,7 @@ public class Macros extends IQ {
|
|||
public MacroGroup parseMacroGroups(String macros) throws Exception {
|
||||
|
||||
MacroGroup group = null;
|
||||
XmlPullParser parser = new MXParser();
|
||||
XmlPullParser parser = XmlPullParserFactory.newInstance().newPullParser();
|
||||
parser.setInput(new StringReader(macros));
|
||||
int eventType = parser.getEventType();
|
||||
while (eventType != XmlPullParser.END_DOCUMENT) {
|
||||
|
|
Loading…
Reference in a new issue