From 4adbd21a0f57574497dc93ad0b44ddcd1f611bba Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Wed, 3 Mar 2021 22:25:32 +0100 Subject: [PATCH] [smack-xmlparser] Allow override of used XmlPullParserFactory --- .../org/jivesoftware/smack/xml/SmackXmlParser.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/smack-xmlparser/src/main/java/org/jivesoftware/smack/xml/SmackXmlParser.java b/smack-xmlparser/src/main/java/org/jivesoftware/smack/xml/SmackXmlParser.java index a8e76c294..0e23fbea7 100644 --- a/smack-xmlparser/src/main/java/org/jivesoftware/smack/xml/SmackXmlParser.java +++ b/smack-xmlparser/src/main/java/org/jivesoftware/smack/xml/SmackXmlParser.java @@ -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 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.