</classpath>
</xmlbean>
+ <replaceregexp byline="true"
+ match="(\s*)public static ([^ ]+) newInstance\(\) \{"
+ replace="\1private static org.apache.xmlbeans.SchemaTypeLoader getTypeLoader() { return org.apache.xmlbeans.XmlBeans.typeLoaderForClassLoader(\2.class.getClassLoader()); }${line.separator}${line.separator}\1public static \2 newInstance\(\) \{"
+ >
+ <fileset dir="${xmlbean.sources.dir}" includes="**/*.java" excludes="**/impl/**"/>
+ </replaceregexp>
+
<replace dir="${xmlbean.sources.dir}" includes="**/*.java" excludes="**/impl/**">
- <replacetoken>org.apache.xmlbeans.XmlBeans.getContextTypeLoader()</replacetoken>
- <replacevalue>org.apache.poi.ooxml.POIXMLTypeLoader</replacevalue>
+ <replacetoken>org.apache.xmlbeans.XmlBeans.getContextTypeLoader</replacetoken>
+ <replacevalue>getTypeLoader</replacevalue>
</replace>
<!-- remove deprecated warnings, as we prefer the array methods - see #56854 -->
]]></replacetoken>
</replace>
- <copy todir="${xmlbean.sources.dir}">
- <fileset dir="${ooxml.src}">
- <include name="org/apache/poi/ooxml/POIXMLTypeLoader.java"/>
- <include name="org/apache/poi/ooxml/util/DocumentHelper.java"/>
- <include name="org/apache/poi/ooxml/util/SAXHelper.java"/>
- <include name="org/apache/poi/openxml4j/opc/PackageNamespaces.java"/>
- </fileset>
- <fileset dir="${main.src}">
- <include name="org/apache/poi/util/POILogFactory.java"/>
- <include name="org/apache/poi/util/POILogger.java"/>
- <include name="org/apache/poi/util/NullLogger.java"/>
- <include name="org/apache/poi/util/Internal.java"/>
- <include name="org/apache/poi/util/Removal.java"/>
- </fileset>
- </copy>
-
<echo>Forking javac with max heap size ${ooxml.memory}</echo>
<javac target="${jdk.version.class}"
package org.apache.poi.ooxml;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.Reader;
-import java.io.StringReader;
-import java.net.URL;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
-import javax.xml.stream.XMLStreamReader;
-
import org.apache.poi.openxml4j.opc.PackageNamespaces;
-import org.apache.poi.ooxml.util.DocumentHelper;
-import org.apache.xmlbeans.SchemaType;
-import org.apache.xmlbeans.SchemaTypeLoader;
-import org.apache.xmlbeans.XmlBeans;
-import org.apache.xmlbeans.XmlException;
-import org.apache.xmlbeans.XmlObject;
import org.apache.xmlbeans.XmlOptions;
-import org.apache.xmlbeans.xml.stream.XMLInputStream;
-import org.apache.xmlbeans.xml.stream.XMLStreamException;
-import org.w3c.dom.Document;
-import org.w3c.dom.Node;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
-@SuppressWarnings("deprecation")
public class POIXMLTypeLoader {
- private static ThreadLocal<SchemaTypeLoader> typeLoader = new ThreadLocal<>();
-
// TODO: Do these have a good home like o.a.p.openxml4j.opc.PackageNamespaces and PackageRelationshipTypes?
// These constants should be common to all of POI and easy to use by other applications such as Tika
private static final String MS_OFFICE_URN = "urn:schemas-microsoft-com:office:office";
map.put(MS_VML_URN, "v");
DEFAULT_XML_OPTIONS.setSaveSuggestedPrefixes(Collections.unmodifiableMap(map));
}
-
- private static XmlOptions getXmlOptions(XmlOptions options) {
- return options == null ? DEFAULT_XML_OPTIONS : options;
- }
-
- private static SchemaTypeLoader getTypeLoader(SchemaType type) {
- SchemaTypeLoader tl = typeLoader.get();
- if (tl == null) {
- ClassLoader cl = type.getClass().getClassLoader();
- tl = XmlBeans.typeLoaderForClassLoader(cl);
- typeLoader.set(tl);
- }
- return tl;
- }
-
- public static XmlObject newInstance(SchemaType type, XmlOptions options) {
- return getTypeLoader(type).newInstance(type, getXmlOptions(options));
- }
-
- public static XmlObject parse(String xmlText, SchemaType type, XmlOptions options) throws XmlException {
- try {
- return parse(new StringReader(xmlText), type, options);
- } catch (IOException e) {
- throw new XmlException("Unable to parse xml bean", e);
- }
- }
-
- public static XmlObject parse(File file, SchemaType type, XmlOptions options) throws XmlException, IOException {
- try (InputStream is = new FileInputStream(file)) {
- return parse(is, type, options);
- }
- }
-
- public static XmlObject parse(URL file, SchemaType type, XmlOptions options) throws XmlException, IOException {
- try (InputStream is = file.openStream()) {
- return parse(is, type, options);
- }
- }
-
- public static XmlObject parse(InputStream jiois, SchemaType type, XmlOptions options) throws XmlException, IOException {
- try {
- Document doc = DocumentHelper.readDocument(jiois);
- return getTypeLoader(type).parse(doc.getDocumentElement(), type, getXmlOptions(options));
- } catch (SAXException e) {
- throw new IOException("Unable to parse xml bean", e);
- }
- }
-
- public static XmlObject parse(XMLStreamReader xsr, SchemaType type, XmlOptions options) throws XmlException {
- return getTypeLoader(type).parse(xsr, type, getXmlOptions(options));
- }
-
- public static XmlObject parse(Reader jior, SchemaType type, XmlOptions options) throws XmlException, IOException {
- try {
- Document doc = DocumentHelper.readDocument(new InputSource(jior));
- return getTypeLoader(type).parse(doc.getDocumentElement(), type, getXmlOptions(options));
- } catch (SAXException e) {
- throw new XmlException("Unable to parse xml bean", e);
- }
- }
-
- public static XmlObject parse(Node node, SchemaType type, XmlOptions options) throws XmlException {
- return getTypeLoader(type).parse(node, type, getXmlOptions(options));
- }
-
- public static XmlObject parse(XMLInputStream xis, SchemaType type, XmlOptions options) throws XmlException, XMLStreamException {
- return getTypeLoader(type).parse(xis, type, getXmlOptions(options));
- }
-
- public static XMLInputStream newValidatingXMLInputStream ( XMLInputStream xis, SchemaType type, XmlOptions options ) throws XmlException, XMLStreamException {
- return getTypeLoader(type).newValidatingXMLInputStream(xis, type, getXmlOptions(options));
- }
}