mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-22 22:32: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);
|
listenerThread.setDaemon(true);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
parser = getParserInstance();
|
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
|
||||||
|
factory.setNamespaceAware(true);
|
||||||
|
parser = factory.newPullParser();
|
||||||
parser.setInput(connection.reader);
|
parser.setInput(connection.reader);
|
||||||
}
|
}
|
||||||
catch (XmlPullParserException xppe) {
|
catch (XmlPullParserException xppe) {
|
||||||
|
@ -742,9 +744,12 @@ class PacketReader {
|
||||||
int eventType = parser.next();
|
int eventType = parser.next();
|
||||||
if (eventType == XmlPullParser.START_TAG) {
|
if (eventType == XmlPullParser.START_TAG) {
|
||||||
String name = parser.getName();
|
String name = parser.getName();
|
||||||
String value = parser.nextText();
|
parser.next();
|
||||||
|
if (eventType == XmlPullParser.TEXT) {
|
||||||
|
String value = parser.getText();
|
||||||
extension.setValue(name, value);
|
extension.setValue(name, value);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else if (eventType == XmlPullParser.END_TAG) {
|
else if (eventType == XmlPullParser.END_TAG) {
|
||||||
if (parser.getName().equals(elementName)) {
|
if (parser.getName().equals(elementName)) {
|
||||||
done = true;
|
done = true;
|
||||||
|
@ -797,7 +802,7 @@ class PacketReader {
|
||||||
}
|
}
|
||||||
else if ("java-object".equals(type)) {
|
else if ("java-object".equals(type)) {
|
||||||
try {
|
try {
|
||||||
byte [] bytes = StringUtils.decodeBase64(valueText).getBytes("ISO-8859-1");
|
byte [] bytes = StringUtils.decodeBase64(valueText);
|
||||||
ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bytes));
|
ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bytes));
|
||||||
value = in.readObject();
|
value = in.readObject();
|
||||||
}
|
}
|
||||||
|
@ -818,38 +823,6 @@ class PacketReader {
|
||||||
return properties;
|
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.
|
* A wrapper class to associate a packet collector with a listener.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -153,7 +153,9 @@ public class ProviderManager {
|
||||||
java.io.InputStream providerStream = null;
|
java.io.InputStream providerStream = null;
|
||||||
try {
|
try {
|
||||||
providerStream = url.openStream();
|
providerStream = url.openStream();
|
||||||
XmlPullParser parser = getParserInstance();
|
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
|
||||||
|
factory.setNamespaceAware(true);
|
||||||
|
XmlPullParser parser = factory.newPullParser();
|
||||||
parser.setInput(providerStream, "UTF-8");
|
parser.setInput(providerStream, "UTF-8");
|
||||||
int eventType = parser.getEventType();
|
int eventType = parser.getEventType();
|
||||||
do {
|
do {
|
||||||
|
@ -299,36 +301,4 @@ public class ProviderManager {
|
||||||
buf.append("<").append(elementName).append("/><").append(namespace).append("/>");
|
buf.append("<").append(elementName).append("/><").append(namespace).append("/>");
|
||||||
return buf.toString();
|
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