mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-26 05:52:06 +01:00
Better parser init.
git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@1954 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
parent
0ac19c6996
commit
a608313589
2 changed files with 12 additions and 69 deletions
|
@ -114,7 +114,9 @@ class PacketReader {
|
|||
listenerThread.setDaemon(true);
|
||||
|
||||
try {
|
||||
parser = getParserInstance();
|
||||
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
|
||||
factory.setNamespaceAware(true);
|
||||
parser = factory.newPullParser();
|
||||
parser.setInput(connection.reader);
|
||||
}
|
||||
catch (XmlPullParserException xppe) {
|
||||
|
@ -742,9 +744,12 @@ class PacketReader {
|
|||
int eventType = parser.next();
|
||||
if (eventType == XmlPullParser.START_TAG) {
|
||||
String name = parser.getName();
|
||||
String value = parser.nextText();
|
||||
parser.next();
|
||||
if (eventType == XmlPullParser.TEXT) {
|
||||
String value = parser.getText();
|
||||
extension.setValue(name, value);
|
||||
}
|
||||
}
|
||||
else if (eventType == XmlPullParser.END_TAG) {
|
||||
if (parser.getName().equals(elementName)) {
|
||||
done = true;
|
||||
|
@ -797,7 +802,7 @@ class PacketReader {
|
|||
}
|
||||
else if ("java-object".equals(type)) {
|
||||
try {
|
||||
byte [] bytes = StringUtils.decodeBase64(valueText).getBytes("ISO-8859-1");
|
||||
byte [] bytes = StringUtils.decodeBase64(valueText);
|
||||
ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bytes));
|
||||
value = in.readObject();
|
||||
}
|
||||
|
@ -818,38 +823,6 @@ class PacketReader {
|
|||
return properties;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an XML parser instance.
|
||||
*
|
||||
* @return an XML parser instance.
|
||||
*/
|
||||
private static XmlPullParser getParserInstance() {
|
||||
XmlPullParser parser = null;
|
||||
try {
|
||||
final String defaultProviderName = "org.xmlpull.mxp1.MXParserFactory";
|
||||
XmlPullParserFactory factory = null;
|
||||
try {
|
||||
// Attempt to load a factory implementation using a system property
|
||||
// and a classloader context.
|
||||
factory = XmlPullParserFactory.newInstance(
|
||||
System.getProperty(XmlPullParserFactory.PROPERTY_NAME),
|
||||
Thread.currentThread().getContextClassLoader().getClass());
|
||||
}
|
||||
catch (Exception e) {
|
||||
if (factory == null) {
|
||||
// Loading failed. Therefore, use the hardcoded default.
|
||||
factory = XmlPullParserFactory.newInstance(defaultProviderName, null);
|
||||
}
|
||||
}
|
||||
factory.setNamespaceAware(true);
|
||||
parser = factory.newPullParser();
|
||||
}
|
||||
catch (XmlPullParserException xppe) {
|
||||
xppe.printStackTrace();
|
||||
}
|
||||
return parser;
|
||||
}
|
||||
|
||||
/**
|
||||
* A wrapper class to associate a packet collector with a listener.
|
||||
*/
|
||||
|
|
|
@ -153,7 +153,9 @@ public class ProviderManager {
|
|||
java.io.InputStream providerStream = null;
|
||||
try {
|
||||
providerStream = url.openStream();
|
||||
XmlPullParser parser = getParserInstance();
|
||||
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
|
||||
factory.setNamespaceAware(true);
|
||||
XmlPullParser parser = factory.newPullParser();
|
||||
parser.setInput(providerStream, "UTF-8");
|
||||
int eventType = parser.getEventType();
|
||||
do {
|
||||
|
@ -299,36 +301,4 @@ public class ProviderManager {
|
|||
buf.append("<").append(elementName).append("/><").append(namespace).append("/>");
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an XML parser instance.
|
||||
*
|
||||
* @return an XML parser instance.
|
||||
*/
|
||||
private static XmlPullParser getParserInstance() {
|
||||
XmlPullParser parser = null;
|
||||
try {
|
||||
final String defaultProviderName = "org.xmlpull.mxp1.MXParserFactory";
|
||||
XmlPullParserFactory factory = null;
|
||||
try {
|
||||
// Attempt to load a factory implementation using a system property
|
||||
// and a classloader context.
|
||||
factory = XmlPullParserFactory.newInstance(
|
||||
System.getProperty(XmlPullParserFactory.PROPERTY_NAME),
|
||||
Thread.currentThread().getContextClassLoader().getClass());
|
||||
}
|
||||
catch (Exception e) {
|
||||
if (factory == null) {
|
||||
// Loading failed. Therefore, use the hardcoded default.
|
||||
factory = XmlPullParserFactory.newInstance(defaultProviderName, null);
|
||||
}
|
||||
}
|
||||
factory.setNamespaceAware(true);
|
||||
parser = factory.newPullParser();
|
||||
}
|
||||
catch (XmlPullParserException xppe) {
|
||||
xppe.printStackTrace();
|
||||
}
|
||||
return parser;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue