1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-12-09 04:12:07 +01:00

[smack-xmlparser] Allow override of used XmlPullParserFactory

This commit is contained in:
Florian Schmaus 2021-03-03 22:25:32 +01:00
parent 3bef905ef5
commit 4adbd21a0f

View file

@ -1,6 +1,6 @@
/**
*
* Copyright 2019 Florian Schmaus.
* Copyright 2019-2021 Florian Schmaus.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -28,7 +28,14 @@ public class SmackXmlParser {
xmlPullParserFactoryServiceLoader = ServiceLoader.load(XmlPullParserFactory.class);
}
private static XmlPullParserFactory xmlPullParserFactory;
public static XmlPullParserFactory getXmlPullParserFactory() {
final XmlPullParserFactory xmlPullParserFactory = SmackXmlParser.xmlPullParserFactory;
if (xmlPullParserFactory != null) {
return xmlPullParserFactory;
}
Iterator<XmlPullParserFactory> iterator = xmlPullParserFactoryServiceLoader.iterator();
if (!iterator.hasNext()) {
throw new IllegalStateException(
@ -37,6 +44,10 @@ public class SmackXmlParser {
return iterator.next();
}
public static void setXmlPullParserFactory(XmlPullParserFactory xmlPullParserFactory) {
SmackXmlParser.xmlPullParserFactory = xmlPullParserFactory;
}
/**
* Creates a new XmlPullParser suitable for parsing XMPP. This means in particular that
* FEATURE_PROCESS_NAMESPACES is enabled.