From 034e16731323e7acf44380fda65486ead9db0772 Mon Sep 17 00:00:00 2001 From: Dominik Stadler Date: Fri, 1 Jan 2016 16:27:27 +0000 Subject: [PATCH] Combine common functionality in POIXMLTypeLoader into helper method git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1722500 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/org/apache/poi/POIXMLTypeLoader.java | 35 ++++++++----------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/src/ooxml/java/org/apache/poi/POIXMLTypeLoader.java b/src/ooxml/java/org/apache/poi/POIXMLTypeLoader.java index 3ff44c6cbb..a171f3201d 100644 --- a/src/ooxml/java/org/apache/poi/POIXMLTypeLoader.java +++ b/src/ooxml/java/org/apache/poi/POIXMLTypeLoader.java @@ -67,53 +67,48 @@ public class POIXMLTypeLoader { DEFAULT_XML_OPTIONS.setSaveSuggestedPrefixes(Collections.unmodifiableMap(map)); } - public static XmlObject newInstance(SchemaType type, XmlOptions options) { + private static XmlOptions getXmlOptions(XmlOptions options) { XmlOptions opt = (options == null) ? DEFAULT_XML_OPTIONS : options; - return XmlBeans.getContextTypeLoader().newInstance(type, opt); + return opt; + } + + public static XmlObject newInstance(SchemaType type, XmlOptions options) { + return XmlBeans.getContextTypeLoader().newInstance(type, getXmlOptions(options)); } public static XmlObject parse(String xmlText, SchemaType type, XmlOptions options) throws XmlException { - XmlOptions opt = (options == null) ? DEFAULT_XML_OPTIONS : options; - return XmlBeans.getContextTypeLoader().parse(xmlText, type, opt); + return XmlBeans.getContextTypeLoader().parse(xmlText, type, getXmlOptions(options)); } public static XmlObject parse(File file, SchemaType type, XmlOptions options) throws XmlException, IOException { - XmlOptions opt = (options == null) ? DEFAULT_XML_OPTIONS : options; - return XmlBeans.getContextTypeLoader().parse(file, type, opt); + return XmlBeans.getContextTypeLoader().parse(file, type, getXmlOptions(options)); } public static XmlObject parse(URL file, SchemaType type, XmlOptions options) throws XmlException, IOException { - XmlOptions opt = (options == null) ? DEFAULT_XML_OPTIONS : options; - return XmlBeans.getContextTypeLoader().parse(file, type, opt); + return XmlBeans.getContextTypeLoader().parse(file, type, getXmlOptions(options)); } public static XmlObject parse(InputStream jiois, SchemaType type, XmlOptions options) throws XmlException, IOException { - XmlOptions opt = (options == null) ? DEFAULT_XML_OPTIONS : options; - return XmlBeans.getContextTypeLoader().parse(jiois, type, opt); + return XmlBeans.getContextTypeLoader().parse(jiois, type, getXmlOptions(options)); } public static XmlObject parse(XMLStreamReader xsr, SchemaType type, XmlOptions options) throws XmlException { - XmlOptions opt = (options == null) ? DEFAULT_XML_OPTIONS : options; - return XmlBeans.getContextTypeLoader().parse(xsr, type, opt); + return XmlBeans.getContextTypeLoader().parse(xsr, type, getXmlOptions(options)); } public static XmlObject parse(Reader jior, SchemaType type, XmlOptions options) throws XmlException, IOException { - XmlOptions opt = (options == null) ? DEFAULT_XML_OPTIONS : options; - return XmlBeans.getContextTypeLoader().parse(jior, type, opt); + return XmlBeans.getContextTypeLoader().parse(jior, type, getXmlOptions(options)); } public static XmlObject parse(Node node, SchemaType type, XmlOptions options) throws XmlException { - XmlOptions opt = (options == null) ? DEFAULT_XML_OPTIONS : options; - return XmlBeans.getContextTypeLoader().parse(node, type, opt); + return XmlBeans.getContextTypeLoader().parse(node, type, getXmlOptions(options)); } public static XmlObject parse(XMLInputStream xis, SchemaType type, XmlOptions options) throws XmlException, XMLStreamException { - XmlOptions opt = (options == null) ? DEFAULT_XML_OPTIONS : options; - return XmlBeans.getContextTypeLoader().parse(xis, type, opt); + return XmlBeans.getContextTypeLoader().parse(xis, type, getXmlOptions(options)); } public static XMLInputStream newValidatingXMLInputStream ( XMLInputStream xis, SchemaType type, XmlOptions options ) throws XmlException, XMLStreamException { - XmlOptions opt = (options == null) ? DEFAULT_XML_OPTIONS : options; - return XmlBeans.getContextTypeLoader().newValidatingXMLInputStream(xis, type, opt); + return XmlBeans.getContextTypeLoader().newValidatingXMLInputStream(xis, type, getXmlOptions(options)); } } -- 2.39.5