[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
1 changed files with 12 additions and 1 deletions

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.