use of org.xmlpull.mxp1.MXParser in project Spark by igniterealtime.
the class PluginClassLoader method loadSmackProvider.
private void loadSmackProvider(InputStream providerStream) throws Exception {
try {
XmlPullParser parser = new MXParser();
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
parser.setInput(providerStream, "UTF-8");
int eventType = parser.getEventType();
do {
if (eventType == XmlPullParser.START_TAG) {
if (parser.getName().equals("iqProvider")) {
parser.next();
parser.next();
String elementName = parser.nextText();
parser.next();
parser.next();
String namespace = parser.nextText();
parser.next();
parser.next();
String className = parser.nextText();
// reflection later to create instances of the class.
try {
// Add the provider to the map.
Class<?> provider = this.loadClass(className);
if (IQProvider.class.isAssignableFrom(provider)) {
ProviderManager.addIQProvider(elementName, namespace, provider.newInstance());
} else if (IQ.class.isAssignableFrom(provider)) {
ProviderManager.addIQProvider(elementName, namespace, provider.newInstance());
}
} catch (ClassNotFoundException cnfe) {
cnfe.printStackTrace();
}
} else if (parser.getName().equals("extensionProvider")) {
parser.next();
parser.next();
String elementName = parser.nextText();
parser.next();
parser.next();
String namespace = parser.nextText();
parser.next();
parser.next();
String className = parser.nextText();
// of the class.
try {
// Add the provider to the map.
Class<?> provider = this.loadClass(className);
if (ExtensionElementProvider.class.isAssignableFrom(provider)) {
ProviderManager.addExtensionProvider(elementName, namespace, provider.newInstance());
} else if (ExtensionElement.class.isAssignableFrom(provider)) {
ProviderManager.addExtensionProvider(elementName, namespace, provider.newInstance());
}
} catch (ClassNotFoundException cnfe) {
cnfe.printStackTrace();
}
}
}
eventType = parser.next();
} while (eventType != XmlPullParser.END_DOCUMENT);
} finally {
try {
providerStream.close();
} catch (Exception e) {
// Nothing to do
}
}
}
use of org.xmlpull.mxp1.MXParser in project ecf by eclipse.
the class PacketReader method resetParser.
/**
* Resets the parser using the latest connection's reader. Reseting the parser is necessary
* when the plain connection has been secured or when a new opening stream element is going
* to be sent by the server.
*/
private void resetParser() {
try {
parser = new MXParser();
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
parser.setInput(connection.reader);
} catch (XmlPullParserException xppe) {
xppe.printStackTrace();
}
}
use of org.xmlpull.mxp1.MXParser in project ecf by eclipse.
the class ProviderManager method initialize.
protected void initialize() {
// Load IQ processing providers.
try {
// Get an array of class loaders to try loading the providers files from.
ClassLoader[] classLoaders = getClassLoaders();
for (ClassLoader classLoader : classLoaders) {
Enumeration<URL> providerEnum = classLoader.getResources("META-INF/smack.providers");
while (providerEnum.hasMoreElements()) {
URL url = providerEnum.nextElement();
InputStream providerStream = null;
try {
providerStream = url.openStream();
XmlPullParser parser = new MXParser();
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
parser.setInput(providerStream, "UTF-8");
int eventType = parser.getEventType();
do {
if (eventType == XmlPullParser.START_TAG) {
if (parser.getName().equals("iqProvider")) {
parser.next();
parser.next();
String elementName = parser.nextText();
parser.next();
parser.next();
String namespace = parser.nextText();
parser.next();
parser.next();
String className = parser.nextText();
// Only add the provider for the namespace if one isn't
// already registered.
String key = getProviderKey(elementName, namespace);
if (!iqProviders.containsKey(key)) {
// reflection later to create instances of the class.
try {
// Add the provider to the map.
Class<?> provider = Class.forName(className);
if (IQProvider.class.isAssignableFrom(provider)) {
iqProviders.put(key, provider.newInstance());
} else if (IQ.class.isAssignableFrom(provider)) {
iqProviders.put(key, provider);
}
} catch (ClassNotFoundException cnfe) {
cnfe.printStackTrace();
}
}
} else if (parser.getName().equals("extensionProvider")) {
parser.next();
parser.next();
String elementName = parser.nextText();
parser.next();
parser.next();
String namespace = parser.nextText();
parser.next();
parser.next();
String className = parser.nextText();
// Only add the provider for the namespace if one isn't
// already registered.
String key = getProviderKey(elementName, namespace);
if (!extensionProviders.containsKey(key)) {
// of the class.
try {
// Add the provider to the map.
Class<?> provider = Class.forName(className);
if (PacketExtensionProvider.class.isAssignableFrom(provider)) {
extensionProviders.put(key, provider.newInstance());
} else if (PacketExtension.class.isAssignableFrom(provider)) {
extensionProviders.put(key, provider);
}
} catch (ClassNotFoundException cnfe) {
cnfe.printStackTrace();
}
}
}
}
eventType = parser.next();
} while (eventType != XmlPullParser.END_DOCUMENT);
} finally {
try {
providerStream.close();
} catch (Exception e) {
// Ignore.
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
Aggregations