From 01a6730ea7798a5e506053e48b97feae2fded60d Mon Sep 17 00:00:00 2001 From: Andreas Beeker Date: Sat, 21 Nov 2015 19:37:26 +0000 Subject: [PATCH] #58617 - Add custom safe XmlBeans type loader / rename vendor specific schema packages git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1715555 13f79535-47bb-0310-9956-ffa450edef68 --- .project | 1 + build.xml | 167 +++++---- sonar/ooxml-schema-encryption/pom.xml | 30 +- sonar/ooxml-schema-security/pom.xml | 33 +- sonar/ooxml-schema/pom.xml | 96 +---- sonar/pom.xml | 333 ++++++++++++------ .../org/apache/poi/POIXMLDocumentPart.java | 11 - .../java/org/apache/poi/POIXMLProperties.java | 26 +- .../java/org/apache/poi/POIXMLTypeLoader.java | 119 +++++++ .../agile/AgileEncryptionInfoBuilder.java | 7 +- .../poi/poifs/crypt/dsig/SignatureInfo.java | 6 +- .../dsig/facets/Office2010SignatureFacet.java | 5 +- .../dsig/facets/XAdESXLSignatureFacet.java | 4 +- .../RelationshipTransformService.java | 7 +- .../java/org/apache/poi/util/XmlSort.java | 5 +- .../poi/xslf/usermodel/XMLSlideShow.java | 13 +- .../apache/poi/xslf/usermodel/XSLFChart.java | 22 +- .../xslf/usermodel/XSLFCommentAuthors.java | 5 +- .../poi/xslf/usermodel/XSLFComments.java | 9 +- .../xslf/usermodel/XSLFCommonSlideData.java | 5 +- .../poi/xslf/usermodel/XSLFMetroShape.java | 5 +- .../apache/poi/xslf/usermodel/XSLFNotes.java | 5 +- .../poi/xslf/usermodel/XSLFNotesMaster.java | 7 +- .../apache/poi/xslf/usermodel/XSLFSheet.java | 11 +- .../apache/poi/xslf/usermodel/XSLFSlide.java | 4 +- .../poi/xslf/usermodel/XSLFSlideLayout.java | 4 +- .../poi/xslf/usermodel/XSLFSlideMaster.java | 4 +- .../poi/xslf/usermodel/XSLFSlideShow.java | 13 +- .../apache/poi/xslf/usermodel/XSLFTable.java | 5 +- .../poi/xslf/usermodel/XSLFTableStyles.java | 5 +- .../apache/poi/xslf/usermodel/XSLFTheme.java | 11 +- .../org/apache/poi/xssf/dev/XSSFDump.java | 5 +- .../poi/xssf/eventusermodel/XSSFReader.java | 5 +- .../poi/xssf/model/CalculationChain.java | 11 +- .../apache/poi/xssf/model/CommentsTable.java | 5 +- .../poi/xssf/model/ExternalLinksTable.java | 5 +- .../org/apache/poi/xssf/model/MapInfo.java | 5 +- .../poi/xssf/model/SharedStringsTable.java | 4 +- .../apache/poi/xssf/model/SingleXmlCells.java | 5 +- .../apache/poi/xssf/model/StylesTable.java | 9 +- .../apache/poi/xssf/model/ThemesTable.java | 10 +- .../poi/xssf/usermodel/XSSFCellStyle.java | 9 +- .../apache/poi/xssf/usermodel/XSSFChart.java | 17 +- .../poi/xssf/usermodel/XSSFChartSheet.java | 12 +- .../poi/xssf/usermodel/XSSFComment.java | 2 +- .../poi/xssf/usermodel/XSSFDrawing.java | 22 +- .../poi/xssf/usermodel/XSSFPivotCache.java | 7 +- .../usermodel/XSSFPivotCacheDefinition.java | 2 + .../xssf/usermodel/XSSFPivotCacheRecords.java | 2 + .../poi/xssf/usermodel/XSSFPivotTable.java | 2 + .../apache/poi/xssf/usermodel/XSSFSheet.java | 7 +- .../apache/poi/xssf/usermodel/XSSFTable.java | 5 +- .../poi/xssf/usermodel/XSSFVMLDrawing.java | 62 ++-- .../poi/xssf/usermodel/XSSFWorkbook.java | 7 +- .../xwpf/model/XWPFHeaderFooterPolicy.java | 53 +-- .../poi/xwpf/usermodel/XWPFDocument.java | 21 +- .../apache/poi/xwpf/usermodel/XWPFFooter.java | 18 +- .../poi/xwpf/usermodel/XWPFFootnotes.java | 19 +- .../apache/poi/xwpf/usermodel/XWPFHeader.java | 18 +- .../poi/xwpf/usermodel/XWPFNumbering.java | 18 +- .../apache/poi/xwpf/usermodel/XWPFRun.java | 7 +- .../poi/xwpf/usermodel/XWPFSettings.java | 10 +- .../apache/poi/xwpf/usermodel/XWPFStyles.java | 31 +- .../apache/poi/schemas/ooxmlSchemas.xsdconfig | 42 +++ .../poi/xssf/usermodel/TestXSSFComment.java | 6 +- .../xssf/usermodel/TestXSSFVMLDrawing.java | 22 +- 66 files changed, 791 insertions(+), 672 deletions(-) create mode 100644 src/ooxml/java/org/apache/poi/POIXMLTypeLoader.java create mode 100644 src/ooxml/resources/org/apache/poi/schemas/ooxmlSchemas.xsdconfig diff --git a/.project b/.project index 40d6466b28..274051f30a 100644 --- a/.project +++ b/.project @@ -12,6 +12,7 @@ + org.sonar.ide.eclipse.core.sonarNature org.eclipse.jdt.core.javanature diff --git a/build.xml b/build.xml index 5756ffb568..9ba80ef04a 100644 --- a/build.xml +++ b/build.xml @@ -206,8 +206,8 @@ under the License. - - + + @@ -226,6 +226,8 @@ under the License. + + @@ -657,77 +659,108 @@ under the License. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + org.apache.xmlbeans.XmlBeans.getContextTypeLoader() + org.apache.poi.POIXMLTypeLoader + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - + + + + + + + - - - - - - - - - - - - - - - + + + + + + + + + + + - - ../../src/ooxml/resources/org/apache/poi/poifs/crypt - - encryptionInfo.xsd - - - ../../src/ooxml/resources/org/apache/poi/poifs/crypt/encryptionInfo.xsdconfig - - 1.5 - yes - diff --git a/sonar/ooxml-schema-security/pom.xml b/sonar/ooxml-schema-security/pom.xml index c947a16411..4a9d0993bb 100644 --- a/sonar/ooxml-schema-security/pom.xml +++ b/sonar/ooxml-schema-security/pom.xml @@ -7,18 +7,20 @@ org.apache.poi poi-parent 3.14-beta1-SNAPSHOT + .. poi-ooxml-schema-security jar - Apach POI - Openxmlformats Security-Schema package + Apache POI - Openxmlformats Security-Schema package target/generated-sources/* true + true + true - @@ -104,6 +106,9 @@ unzip-schema generate-sources + + run + @@ -112,34 +117,10 @@ todir="target/schemas"/> - - run - - - org.codehaus.mojo - xmlbeans-maven-plugin - 2.3.3 - - - generate-sources - - xmlbeans - - - - - target/schemas - true - true - true - 1.5 - yes - - diff --git a/sonar/ooxml-schema/pom.xml b/sonar/ooxml-schema/pom.xml index a40fb9a2ac..3d234e02cc 100644 --- a/sonar/ooxml-schema/pom.xml +++ b/sonar/ooxml-schema/pom.xml @@ -7,50 +7,20 @@ org.apache.poi poi-parent 3.14-beta1-SNAPSHOT + .. poi-ooxml-schema jar - Apach POI - Openxmlformats Schema package + Apache POI - Openxmlformats Schema package target/generated-sources/* true + ${basedir}/../../src/ooxml/resources/org/apache/poi/schemas/ooxmlSchemas.xsdconfig - - - - - - - 32bitstuff - - - sun.arch.data.model - 32 - - - - 512m - - - - - 64bitstuff - - - sun.arch.data.model - 64 - - - - 768m - - - - @@ -60,7 +30,7 @@ 1.1.0 - install-xsds-part-4 + download-xsds generate-sources wget @@ -85,7 +55,9 @@ - + + @@ -94,49 +66,6 @@ - - - - maven-resources-plugin - 2.6 - - - copy-sources - generate-sources - - copy-resources - - - target/schemas/ - - - ../../src/ooxml/resources/org/apache/poi/xdgf/ - - - - - - - - - org.codehaus.mojo - xmlbeans-maven-plugin - 2.3.3 - - - generate-sources - - xmlbeans - - - - - target/schemas - 1.5 - yes - true - - @@ -151,11 +80,10 @@ poi-scratchpad ${project.version} - - - org.apache.xmlbeans - xmlbeans - 2.6.0 - + + org.apache.xmlbeans + xmlbeans + 2.6.0 + diff --git a/sonar/pom.xml b/sonar/pom.xml index f17c0655af..fe10ac3b01 100644 --- a/sonar/pom.xml +++ b/sonar/pom.xml @@ -1,58 +1,52 @@ - - 4.0.0 - - org.apache.poi - poi-parent - pom - 3.14-beta1-SNAPSHOT - - Apache POI - the Java API for Microsoft Documents - - Maven build of Apache POI for Sonar checks - http://poi.apache.org/ - - - - POI Users List - user-subscribe@poi.apache.org - user-unsubscribe@poi.apache.org - http://mail-archives.apache.org/mod_mbox/poi-user/ - - - POI Developer List - dev-subscribe@poi.apache.org - dev-unsubscribe@poi.apache.org - http://mail-archives.apache.org/mod_mbox/poi-dev/ - - - - - - The Apache Software License, Version 2.0 - http://www.apache.org/licenses/LICENSE-2.0.txt - - - - - Apache Software Foundation - http://www.apache.org/ - - - + + 4.0.0 + org.apache.poi + poi-parent + pom + 3.14-beta1-SNAPSHOT + Apache POI - the Java API for Microsoft Documents + Maven build of Apache POI for Sonar checks + http://poi.apache.org/ + + + + POI Users List + user-subscribe@poi.apache.org + user-unsubscribe@poi.apache.org + http://mail-archives.apache.org/mod_mbox/poi-user/ + + + POI Developer List + dev-subscribe@poi.apache.org + dev-unsubscribe@poi.apache.org + http://mail-archives.apache.org/mod_mbox/poi-dev/ + + + + + + The Apache Software License, Version 2.0 + http://www.apache.org/licenses/LICENSE-2.0.txt + + + + + Apache Software Foundation + http://www.apache.org/ + + + bugzilla https://issues.apache.org/bugzilla/ - - + + scm:svn:http://svn.apache.org/repos/asf/poi/trunk scm:svn:https://svn.apache.org/repos/asf/poi/trunk http://svn.apache.org/viewvc/poi - - - + + + main ooxml-schema ooxml-schema-encryption @@ -60,76 +54,193 @@ ooxml scratchpad excelant - examples - - + examples + + ASCII - true - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.1 - - 1.6 - 1.6 - - - - - + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.1 + + 1.6 + 1.6 + + + + - - org.apache.maven.plugins - maven-surefire-plugin - 2.16 - - - org.apache.maven.surefire - surefire-junit47 - 2.16 - - - - - - ../../test-data - true - org.apache.poi.util.NullLogger - - - -Duser.language=en -Duser.country=US -Xmx1024m - - **/All*Tests.java - **/TestUnfixedBugs.java - **/TestcaseRecordInputStream.java - **/POITestCase.java - - - **/TestWordToConverterSuite*.java - **/TestExcelConverterSuite*.java - - - + -Duser.language=en -Duser.country=US -Xmx1024m + + **/All*Tests.java + **/TestUnfixedBugs.java + **/TestcaseRecordInputStream.java + **/POITestCase.java + + **/TestWordToConverterSuite*.java + **/TestExcelConverterSuite*.java + + + - - - - + + + + + + + + junit + junit + 4.12 + test + + + + + + + + + 32bitstuff + + + sun.arch.data.model + 32 + + + + 512m + + + + + 64bitstuff + + + sun.arch.data.model + 64 + + + + 768m + + + + + xmlbean + + xmlbeans.marker + + + + + org.codehaus.mojo + xmlbeans-maven-plugin + 2.3.3 + + + process-sources + + xmlbeans + + + ${basedir}/target/schemas + 1.5 + true + ${xmlbeans.noUpa} + ${xmlbeans.noPvr} + + ${basedir}/../../src/ooxml/resources/org/apache/poi/poifs/crypt/encryptionCertificate.xsdconfig + ${basedir}/../../src/ooxml/resources/org/apache/poi/poifs/crypt/encryptionInfo.xsdconfig + ${basedir}/../../src/ooxml/resources/org/apache/poi/poifs/crypt/encryptionPassword.xsdconfig + ${basedir}/../../src/ooxml/resources/org/apache/poi/schemas/ooxmlSchemas.xsdconfig + + + + + - + + maven-antrun-plugin + 1.8 + + + copy-xmltype-and-xsdconfig + generate-sources + run + + + + + + + + + + + + + replace-xmltypeloader + process-sources + run + + + + org.apache.xmlbeans.XmlBeans.getContextTypeLoader() + org.apache.poi.POIXMLTypeLoader + + + + + + remove-xmltypeloader-from-schema-jar + prepare-package + run + + + + + + + + + + + + - junit - junit - 4.12 - test + org.apache.xmlbeans + xmlbeans + 2.6.0 - + + + diff --git a/src/ooxml/java/org/apache/poi/POIXMLDocumentPart.java b/src/ooxml/java/org/apache/poi/POIXMLDocumentPart.java index 842c37b6a5..1abf91be0a 100644 --- a/src/ooxml/java/org/apache/poi/POIXMLDocumentPart.java +++ b/src/ooxml/java/org/apache/poi/POIXMLDocumentPart.java @@ -41,7 +41,6 @@ import org.apache.poi.openxml4j.opc.TargetMode; import org.apache.poi.util.Internal; import org.apache.poi.util.POILogFactory; import org.apache.poi.util.POILogger; -import org.apache.xmlbeans.XmlOptions; /** * Represents an entry of a OOXML package. @@ -55,16 +54,6 @@ import org.apache.xmlbeans.XmlOptions; public class POIXMLDocumentPart { private static final POILogger logger = POILogFactory.getLogger(POIXMLDocumentPart.class); - public static final XmlOptions DEFAULT_XML_OPTIONS; - static { - DEFAULT_XML_OPTIONS = new XmlOptions(); - DEFAULT_XML_OPTIONS.setSaveOuter(); - DEFAULT_XML_OPTIONS.setUseDefaultNamespace(); - DEFAULT_XML_OPTIONS.setSaveAggressiveNamespaces(); - DEFAULT_XML_OPTIONS.setCharacterEncoding("UTF-8"); - DEFAULT_XML_OPTIONS.setLoadEntityBytesLimit(4096); - } - private String coreDocumentRel = PackageRelationshipTypes.CORE_DOCUMENT; private PackagePart packagePart; private PackageRelationship packageRel; diff --git a/src/ooxml/java/org/apache/poi/POIXMLProperties.java b/src/ooxml/java/org/apache/poi/POIXMLProperties.java index e6f68691e9..48ce99fce1 100644 --- a/src/ooxml/java/org/apache/poi/POIXMLProperties.java +++ b/src/ooxml/java/org/apache/poi/POIXMLProperties.java @@ -16,11 +16,11 @@ ==================================================================== */ package org.apache.poi; +import static org.apache.poi.POIXMLTypeLoader.DEFAULT_XML_OPTIONS; + import java.io.IOException; import java.io.OutputStream; import java.util.Date; -import java.util.HashMap; -import java.util.Map; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.openxml4j.exceptions.OpenXML4JException; @@ -33,9 +33,7 @@ import org.apache.poi.openxml4j.opc.PackagingURIHelper; import org.apache.poi.openxml4j.opc.TargetMode; import org.apache.poi.openxml4j.opc.internal.PackagePropertiesPart; import org.apache.poi.openxml4j.util.Nullable; -import org.apache.poi.util.DocumentHelper; import org.apache.xmlbeans.XmlException; -import org.apache.xmlbeans.XmlOptions; import org.openxmlformats.schemas.officeDocument.x2006.customProperties.CTProperty; /** @@ -74,7 +72,7 @@ public class POIXMLProperties { if(extRel.size() == 1) { extPart = pkg.getPart( extRel.getRelationship(0)); org.openxmlformats.schemas.officeDocument.x2006.extendedProperties.PropertiesDocument props = org.openxmlformats.schemas.officeDocument.x2006.extendedProperties.PropertiesDocument.Factory.parse( - extPart.getInputStream(), POIXMLDocumentPart.DEFAULT_XML_OPTIONS + extPart.getInputStream(), DEFAULT_XML_OPTIONS ); ext = new ExtendedProperties(props); } else { @@ -88,7 +86,7 @@ public class POIXMLProperties { if(custRel.size() == 1) { custPart = pkg.getPart( custRel.getRelationship(0)); org.openxmlformats.schemas.officeDocument.x2006.customProperties.PropertiesDocument props = org.openxmlformats.schemas.officeDocument.x2006.customProperties.PropertiesDocument.Factory.parse( - custPart.getInputStream(), POIXMLDocumentPart.DEFAULT_XML_OPTIONS + custPart.getInputStream(), DEFAULT_XML_OPTIONS ); cust = new CustomProperties(props); } else { @@ -142,28 +140,16 @@ public class POIXMLProperties { } } if(extPart != null){ - XmlOptions xmlOptions = new XmlOptions(POIXMLDocumentPart.DEFAULT_XML_OPTIONS); - - Map map = new HashMap(); - map.put("http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes", "vt"); - xmlOptions.setSaveSuggestedPrefixes(map); - OutputStream out = extPart.getOutputStream(); if (extPart.getSize() > 0) { extPart.clear(); } - ext.props.save(out, xmlOptions); + ext.props.save(out, DEFAULT_XML_OPTIONS); out.close(); } if(custPart != null){ - XmlOptions xmlOptions = new XmlOptions(POIXMLDocumentPart.DEFAULT_XML_OPTIONS); - - Map map = new HashMap(); - map.put("http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes", "vt"); - xmlOptions.setSaveSuggestedPrefixes(map); - OutputStream out = custPart.getOutputStream(); - cust.props.save(out, xmlOptions); + cust.props.save(out, DEFAULT_XML_OPTIONS); out.close(); } } diff --git a/src/ooxml/java/org/apache/poi/POIXMLTypeLoader.java b/src/ooxml/java/org/apache/poi/POIXMLTypeLoader.java new file mode 100644 index 0000000000..3ff44c6cbb --- /dev/null +++ b/src/ooxml/java/org/apache/poi/POIXMLTypeLoader.java @@ -0,0 +1,119 @@ +/* ==================================================================== + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +==================================================================== */ + +package org.apache.poi; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.Reader; +import java.net.URL; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +import javax.xml.stream.XMLStreamReader; + +import org.apache.xmlbeans.SchemaType; +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.Node; + +@SuppressWarnings("deprecation") +public class POIXMLTypeLoader { + + public static final XmlOptions DEFAULT_XML_OPTIONS; + static { + DEFAULT_XML_OPTIONS = new XmlOptions(); + DEFAULT_XML_OPTIONS.setSaveOuter(); + DEFAULT_XML_OPTIONS.setUseDefaultNamespace(); + DEFAULT_XML_OPTIONS.setSaveAggressiveNamespaces(); + DEFAULT_XML_OPTIONS.setCharacterEncoding("UTF-8"); + DEFAULT_XML_OPTIONS.setLoadEntityBytesLimit(4096); + + Map map = new HashMap(); + map.put("http://schemas.openxmlformats.org/drawingml/2006/main", "a"); + map.put("http://schemas.openxmlformats.org/drawingml/2006/chart", "c"); + map.put("http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing", "wp"); + map.put("http://schemas.openxmlformats.org/markup-compatibility/2006", "ve"); + map.put("http://schemas.openxmlformats.org/officeDocument/2006/math", "m"); + map.put("http://schemas.openxmlformats.org/officeDocument/2006/relationships", "r"); + map.put("http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes", "vt"); + map.put("http://schemas.openxmlformats.org/presentationml/2006/main", "p"); + map.put("http://schemas.openxmlformats.org/wordprocessingml/2006/main", "w"); + map.put("http://schemas.microsoft.com/office/word/2006/wordml", "wne"); + map.put("urn:schemas-microsoft-com:office:office", "o"); + map.put("urn:schemas-microsoft-com:office:excel", "x"); + map.put("urn:schemas-microsoft-com:office:word", "w10"); + map.put("urn:schemas-microsoft-com:vml", "v"); + DEFAULT_XML_OPTIONS.setSaveSuggestedPrefixes(Collections.unmodifiableMap(map)); + } + + public static XmlObject newInstance(SchemaType type, XmlOptions options) { + XmlOptions opt = (options == null) ? DEFAULT_XML_OPTIONS : options; + return XmlBeans.getContextTypeLoader().newInstance(type, opt); + } + + 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); + } + + 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); + } + + 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); + } + + 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); + } + + 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); + } + + 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); + } + + 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); + } + + 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); + } + + 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); + } +} diff --git a/src/ooxml/java/org/apache/poi/poifs/crypt/agile/AgileEncryptionInfoBuilder.java b/src/ooxml/java/org/apache/poi/poifs/crypt/agile/AgileEncryptionInfoBuilder.java index 37447cea51..39c6acf742 100644 --- a/src/ooxml/java/org/apache/poi/poifs/crypt/agile/AgileEncryptionInfoBuilder.java +++ b/src/ooxml/java/org/apache/poi/poifs/crypt/agile/AgileEncryptionInfoBuilder.java @@ -16,11 +16,12 @@ ==================================================================== */ package org.apache.poi.poifs.crypt.agile; +import static org.apache.poi.POIXMLTypeLoader.DEFAULT_XML_OPTIONS; + import java.io.IOException; import java.io.InputStream; import org.apache.poi.EncryptedDocumentException; -import org.apache.poi.POIXMLDocumentPart; import org.apache.poi.poifs.crypt.ChainingMode; import org.apache.poi.poifs.crypt.CipherAlgorithm; import org.apache.poi.poifs.crypt.EncryptionInfo; @@ -112,7 +113,7 @@ public class AgileEncryptionInfoBuilder implements EncryptionInfoBuilder { protected static EncryptionDocument parseDescriptor(String descriptor) { try { - return EncryptionDocument.Factory.parse(descriptor, POIXMLDocumentPart.DEFAULT_XML_OPTIONS); + return EncryptionDocument.Factory.parse(descriptor, DEFAULT_XML_OPTIONS); } catch (XmlException e) { throw new EncryptedDocumentException("Unable to parse encryption descriptor", e); } @@ -120,7 +121,7 @@ public class AgileEncryptionInfoBuilder implements EncryptionInfoBuilder { protected static EncryptionDocument parseDescriptor(InputStream descriptor) { try { - return EncryptionDocument.Factory.parse(descriptor, POIXMLDocumentPart.DEFAULT_XML_OPTIONS); + return EncryptionDocument.Factory.parse(descriptor, DEFAULT_XML_OPTIONS); } catch (Exception e) { throw new EncryptedDocumentException("Unable to parse encryption descriptor", e); } diff --git a/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/SignatureInfo.java b/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/SignatureInfo.java index 49c6828e93..9646ba07ad 100644 --- a/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/SignatureInfo.java +++ b/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/SignatureInfo.java @@ -24,6 +24,7 @@ package org.apache.poi.poifs.crypt.dsig; +import static org.apache.poi.POIXMLTypeLoader.DEFAULT_XML_OPTIONS; import static org.apache.poi.poifs.crypt.dsig.facets.SignatureFacet.XML_DIGSIG_NS; import java.io.ByteArrayOutputStream; @@ -68,7 +69,6 @@ import javax.xml.xpath.XPathFactory; import org.apache.jcp.xml.dsig.internal.dom.DOMReference; import org.apache.jcp.xml.dsig.internal.dom.DOMSignedInfo; import org.apache.poi.EncryptedDocumentException; -import org.apache.poi.POIXMLDocumentPart; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.openxml4j.opc.ContentTypes; import org.apache.poi.openxml4j.opc.OPCPackage; @@ -213,7 +213,7 @@ public class SignatureInfo implements SignatureConfigurable { */ public SignatureDocument getSignatureDocument() throws IOException, XmlException { // TODO: check for XXE - return SignatureDocument.Factory.parse(signaturePart.getInputStream(), POIXMLDocumentPart.DEFAULT_XML_OPTIONS); + return SignatureDocument.Factory.parse(signaturePart.getInputStream(), DEFAULT_XML_OPTIONS); } /** @@ -631,7 +631,7 @@ public class SignatureInfo implements SignatureConfigurable { try { OutputStream os = sigPart.getOutputStream(); - SignatureDocument sigDoc = SignatureDocument.Factory.parse(document, POIXMLDocumentPart.DEFAULT_XML_OPTIONS); + SignatureDocument sigDoc = SignatureDocument.Factory.parse(document, DEFAULT_XML_OPTIONS); sigDoc.save(os, xo); os.close(); } catch (Exception e) { diff --git a/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/facets/Office2010SignatureFacet.java b/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/facets/Office2010SignatureFacet.java index de12275c40..c6dc2491e6 100644 --- a/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/facets/Office2010SignatureFacet.java +++ b/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/facets/Office2010SignatureFacet.java @@ -24,9 +24,10 @@ package org.apache.poi.poifs.crypt.dsig.facets; +import static org.apache.poi.POIXMLTypeLoader.DEFAULT_XML_OPTIONS; + import javax.xml.crypto.MarshalException; -import org.apache.poi.POIXMLDocumentPart; import org.apache.xmlbeans.XmlException; import org.etsi.uri.x01903.v13.QualifyingPropertiesType; import org.etsi.uri.x01903.v13.UnsignedPropertiesType; @@ -57,7 +58,7 @@ public class Office2010SignatureFacet extends SignatureFacet { QualifyingPropertiesType qualProps; try { - qualProps = QualifyingPropertiesType.Factory.parse(nl.item(0), POIXMLDocumentPart.DEFAULT_XML_OPTIONS); + qualProps = QualifyingPropertiesType.Factory.parse(nl.item(0), DEFAULT_XML_OPTIONS); } catch (XmlException e) { throw new MarshalException(e); } diff --git a/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/facets/XAdESXLSignatureFacet.java b/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/facets/XAdESXLSignatureFacet.java index 61d61cf810..d25bd7d1b8 100644 --- a/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/facets/XAdESXLSignatureFacet.java +++ b/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/facets/XAdESXLSignatureFacet.java @@ -24,6 +24,7 @@ package org.apache.poi.poifs.crypt.dsig.facets; +import static org.apache.poi.POIXMLTypeLoader.DEFAULT_XML_OPTIONS; import static org.apache.poi.poifs.crypt.dsig.facets.XAdESSignatureFacet.insertXChild; import java.io.ByteArrayInputStream; @@ -46,7 +47,6 @@ import java.util.UUID; import javax.xml.crypto.MarshalException; -import org.apache.poi.POIXMLDocumentPart; import org.apache.poi.poifs.crypt.dsig.services.RevocationData; import org.apache.poi.util.POILogFactory; import org.apache.poi.util.POILogger; @@ -129,7 +129,7 @@ public class XAdESXLSignatureFacet extends SignatureFacet { NodeList qualNl = document.getElementsByTagNameNS(XADES_132_NS, "QualifyingProperties"); if (qualNl.getLength() == 1) { try { - qualDoc = QualifyingPropertiesDocument.Factory.parse(qualNl.item(0), POIXMLDocumentPart.DEFAULT_XML_OPTIONS); + qualDoc = QualifyingPropertiesDocument.Factory.parse(qualNl.item(0), DEFAULT_XML_OPTIONS); } catch (XmlException e) { throw new MarshalException(e); } diff --git a/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/services/RelationshipTransformService.java b/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/services/RelationshipTransformService.java index 656672d509..495d843b4c 100644 --- a/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/services/RelationshipTransformService.java +++ b/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/services/RelationshipTransformService.java @@ -24,6 +24,8 @@ package org.apache.poi.poifs.crypt.dsig.services; +import static org.apache.poi.POIXMLTypeLoader.DEFAULT_XML_OPTIONS; + import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -48,7 +50,6 @@ import javax.xml.crypto.dsig.TransformException; import javax.xml.crypto.dsig.TransformService; import javax.xml.crypto.dsig.spec.TransformParameterSpec; -import org.apache.poi.POIXMLDocumentPart; import org.apache.poi.util.POILogFactory; import org.apache.poi.util.POILogger; import org.apache.poi.util.XmlSort; @@ -142,7 +143,7 @@ public class RelationshipTransformService extends TransformService { Node parentNode = domParent.getNode(); try { - TransformDocument transDoc = TransformDocument.Factory.parse(parentNode, POIXMLDocumentPart.DEFAULT_XML_OPTIONS); + TransformDocument transDoc = TransformDocument.Factory.parse(parentNode, DEFAULT_XML_OPTIONS); XmlObject xoList[] = transDoc.getTransform().selectChildren(RelationshipReferenceDocument.type.getDocumentElementName()); if (xoList.length == 0) { LOG.log(POILogger.WARN, "no RelationshipReference/@SourceId parameters present"); @@ -188,7 +189,7 @@ public class RelationshipTransformService extends TransformService { RelationshipsDocument relDoc; try { - relDoc = RelationshipsDocument.Factory.parse(octetStream, POIXMLDocumentPart.DEFAULT_XML_OPTIONS); + relDoc = RelationshipsDocument.Factory.parse(octetStream, DEFAULT_XML_OPTIONS); } catch (Exception e) { throw new TransformException(e.getMessage(), e); } diff --git a/src/ooxml/java/org/apache/poi/util/XmlSort.java b/src/ooxml/java/org/apache/poi/util/XmlSort.java index 93ff71d692..68d2c0874f 100644 --- a/src/ooxml/java/org/apache/poi/util/XmlSort.java +++ b/src/ooxml/java/org/apache/poi/util/XmlSort.java @@ -17,13 +17,14 @@ package org.apache.poi.util; +import static org.apache.poi.POIXMLTypeLoader.DEFAULT_XML_OPTIONS; + import java.io.File; import java.io.IOException; import java.util.Comparator; import javax.xml.namespace.QName; -import org.apache.poi.POIXMLDocumentPart; import org.apache.xmlbeans.XmlCursor; import org.apache.xmlbeans.XmlException; import org.apache.xmlbeans.XmlObject; @@ -50,7 +51,7 @@ public final class XmlSort File f = new File(args[0]); try { - XmlObject docInstance = XmlObject.Factory.parse(f, POIXMLDocumentPart.DEFAULT_XML_OPTIONS); + XmlObject docInstance = XmlObject.Factory.parse(f, DEFAULT_XML_OPTIONS); XmlObject element = null; if (args.length > 1) { diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java index bd150811a2..1cc257c51d 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java @@ -16,6 +16,8 @@ ==================================================================== */ package org.apache.poi.xslf.usermodel; +import static org.apache.poi.POIXMLTypeLoader.DEFAULT_XML_OPTIONS; + import java.awt.Dimension; import java.io.IOException; import java.io.InputStream; @@ -51,9 +53,7 @@ import org.apache.poi.util.PackageHelper; import org.apache.poi.util.Units; import org.apache.xmlbeans.XmlException; import org.apache.xmlbeans.XmlObject; -import org.apache.xmlbeans.XmlOptions; import org.openxmlformats.schemas.drawingml.x2006.main.CTTextParagraphProperties; -import org.openxmlformats.schemas.officeDocument.x2006.relationships.STRelationshipId; import org.openxmlformats.schemas.presentationml.x2006.main.CTNotesMasterIdList; import org.openxmlformats.schemas.presentationml.x2006.main.CTNotesMasterIdListEntry; import org.openxmlformats.schemas.presentationml.x2006.main.CTPresentation; @@ -127,7 +127,7 @@ implements SlideShow { protected void onDocumentRead() throws IOException { try { PresentationDocument doc = - PresentationDocument.Factory.parse(getCorePart().getInputStream(), POIXMLDocumentPart.DEFAULT_XML_OPTIONS); + PresentationDocument.Factory.parse(getCorePart().getInputStream(), DEFAULT_XML_OPTIONS); _presentation = doc.getPresentation(); Map masterMap = new HashMap(); @@ -170,14 +170,9 @@ implements SlideShow { @Override protected void commit() throws IOException { - XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS); - Map map = new HashMap(); - map.put(STRelationshipId.type.getName().getNamespaceURI(), "r"); - xmlOptions.setSaveSuggestedPrefixes(map); - PackagePart part = getPackagePart(); OutputStream out = part.getOutputStream(); - _presentation.save(out, xmlOptions); + _presentation.save(out, DEFAULT_XML_OPTIONS); out.close(); } diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFChart.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFChart.java index 5ded5a7aed..db8df4e9fa 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFChart.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFChart.java @@ -19,11 +19,17 @@ package org.apache.poi.xslf.usermodel; +import static org.apache.poi.POIXMLTypeLoader.DEFAULT_XML_OPTIONS; + +import java.io.IOException; +import java.io.OutputStream; + +import javax.xml.namespace.QName; + import org.apache.poi.POIXMLDocumentPart; import org.apache.poi.openxml4j.opc.PackagePart; import org.apache.poi.openxml4j.opc.PackageRelationship; import org.apache.poi.util.Beta; -import org.apache.poi.util.DocumentHelper; import org.apache.poi.util.Internal; import org.apache.xmlbeans.XmlException; import org.apache.xmlbeans.XmlOptions; @@ -31,12 +37,6 @@ import org.openxmlformats.schemas.drawingml.x2006.chart.CTChart; import org.openxmlformats.schemas.drawingml.x2006.chart.CTChartSpace; import org.openxmlformats.schemas.drawingml.x2006.chart.ChartSpaceDocument; -import javax.xml.namespace.QName; -import java.io.IOException; -import java.io.OutputStream; -import java.util.HashMap; -import java.util.Map; - /** * Represents a Chart in a .pptx presentation * @@ -66,7 +66,7 @@ public final class XSLFChart extends POIXMLDocumentPart { protected XSLFChart(PackagePart part, PackageRelationship rel) throws IOException, XmlException { super(part, rel); - chartSpace = ChartSpaceDocument.Factory.parse(part.getInputStream(), POIXMLDocumentPart.DEFAULT_XML_OPTIONS).getChartSpace(); + chartSpace = ChartSpaceDocument.Factory.parse(part.getInputStream(), DEFAULT_XML_OPTIONS).getChartSpace(); chart = chartSpace.getChart(); } @@ -93,13 +93,7 @@ public final class XSLFChart extends POIXMLDocumentPart { @Override protected void commit() throws IOException { XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS); - xmlOptions.setSaveSyntheticDocumentElement(new QName(CTChartSpace.type.getName().getNamespaceURI(), "chartSpace", "c")); - Map map = new HashMap(); - map.put("http://schemas.openxmlformats.org/drawingml/2006/main", "a"); - map.put("http://schemas.openxmlformats.org/drawingml/2006/chart", "c"); - map.put("http://schemas.openxmlformats.org/officeDocument/2006/relationships", "r"); - xmlOptions.setSaveSuggestedPrefixes(map); PackagePart part = getPackagePart(); OutputStream out = part.getOutputStream(); diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFCommentAuthors.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFCommentAuthors.java index 4274ba7847..1fe05a48cf 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFCommentAuthors.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFCommentAuthors.java @@ -17,13 +17,14 @@ package org.apache.poi.xslf.usermodel; +import static org.apache.poi.POIXMLTypeLoader.DEFAULT_XML_OPTIONS; + import java.io.IOException; import org.apache.poi.POIXMLDocumentPart; import org.apache.poi.openxml4j.opc.PackagePart; import org.apache.poi.openxml4j.opc.PackageRelationship; import org.apache.poi.util.Beta; -import org.apache.poi.util.DocumentHelper; import org.apache.xmlbeans.XmlException; import org.openxmlformats.schemas.presentationml.x2006.main.CTCommentAuthor; import org.openxmlformats.schemas.presentationml.x2006.main.CTCommentAuthorList; @@ -54,7 +55,7 @@ public class XSLFCommentAuthors extends POIXMLDocumentPart { super(part, rel); CmAuthorLstDocument doc = - CmAuthorLstDocument.Factory.parse(getPackagePart().getInputStream(), POIXMLDocumentPart.DEFAULT_XML_OPTIONS); + CmAuthorLstDocument.Factory.parse(getPackagePart().getInputStream(), DEFAULT_XML_OPTIONS); _authors = doc.getCmAuthorLst(); } diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFComments.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFComments.java index 16190c64c8..8331289b4e 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFComments.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFComments.java @@ -17,18 +17,19 @@ package org.apache.poi.xslf.usermodel; +import static org.apache.poi.POIXMLTypeLoader.DEFAULT_XML_OPTIONS; + +import java.io.IOException; + import org.apache.poi.POIXMLDocumentPart; import org.apache.poi.openxml4j.opc.PackagePart; import org.apache.poi.openxml4j.opc.PackageRelationship; import org.apache.poi.util.Beta; -import org.apache.poi.util.DocumentHelper; import org.apache.xmlbeans.XmlException; import org.openxmlformats.schemas.presentationml.x2006.main.CTComment; import org.openxmlformats.schemas.presentationml.x2006.main.CTCommentList; import org.openxmlformats.schemas.presentationml.x2006.main.CmLstDocument; -import java.io.IOException; - @Beta public class XSLFComments extends POIXMLDocumentPart { private final CTCommentList _comments; @@ -54,7 +55,7 @@ public class XSLFComments extends POIXMLDocumentPart { super(part, rel); CmLstDocument doc = - CmLstDocument.Factory.parse(getPackagePart().getInputStream(), POIXMLDocumentPart.DEFAULT_XML_OPTIONS); + CmLstDocument.Factory.parse(getPackagePart().getInputStream(), DEFAULT_XML_OPTIONS); _comments = doc.getCmLst(); } diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFCommonSlideData.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFCommonSlideData.java index 7f87f6d695..34d4e0031a 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFCommonSlideData.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFCommonSlideData.java @@ -17,11 +17,12 @@ package org.apache.poi.xslf.usermodel; +import static org.apache.poi.POIXMLTypeLoader.DEFAULT_XML_OPTIONS; + import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import org.apache.poi.POIXMLDocumentPart; import org.apache.poi.POIXMLException; import org.apache.poi.util.Beta; import org.apache.xmlbeans.XmlCursor; @@ -68,7 +69,7 @@ public class XSLFCommonSlideData { if (o instanceof XmlAnyTypeImpl) { // Pesky XmlBeans bug - see Bugzilla #49934 try { - o = CTTable.Factory.parse(o.toString(), POIXMLDocumentPart.DEFAULT_XML_OPTIONS); + o = CTTable.Factory.parse(o.toString(), DEFAULT_XML_OPTIONS); } catch (XmlException e) { throw new POIXMLException(e); } diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFMetroShape.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFMetroShape.java index 283981d99d..652cedcb50 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFMetroShape.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFMetroShape.java @@ -18,10 +18,11 @@ package org.apache.poi.xslf.usermodel; +import static org.apache.poi.POIXMLTypeLoader.DEFAULT_XML_OPTIONS; + import java.io.ByteArrayInputStream; import java.io.IOException; -import org.apache.poi.POIXMLDocumentPart; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.openxml4j.opc.OPCPackage; import org.apache.poi.openxml4j.opc.PackagePart; @@ -49,7 +50,7 @@ public class XSLFMetroShape { try { pkg = OPCPackage.open(new ByteArrayInputStream(metroBytes)); PackagePart shapePart = pkg.getPart(shapePN); - CTGroupShape gs = CTGroupShape.Factory.parse(shapePart.getInputStream(), POIXMLDocumentPart.DEFAULT_XML_OPTIONS); + CTGroupShape gs = CTGroupShape.Factory.parse(shapePart.getInputStream(), DEFAULT_XML_OPTIONS); XSLFGroupShape xgs = new XSLFGroupShape(gs, null); return xgs.getShapes().get(0); } finally { diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFNotes.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFNotes.java index 22b1607dda..d69125e056 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFNotes.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFNotes.java @@ -16,6 +16,8 @@ ==================================================================== */ package org.apache.poi.xslf.usermodel; +import static org.apache.poi.POIXMLTypeLoader.DEFAULT_XML_OPTIONS; + import java.io.IOException; import java.util.ArrayList; import java.util.List; @@ -25,7 +27,6 @@ import org.apache.poi.openxml4j.opc.PackagePart; import org.apache.poi.openxml4j.opc.PackageRelationship; import org.apache.poi.sl.usermodel.Notes; import org.apache.poi.util.Beta; -import org.apache.poi.util.DocumentHelper; import org.apache.xmlbeans.XmlException; import org.openxmlformats.schemas.presentationml.x2006.main.CTCommonSlideData; import org.openxmlformats.schemas.presentationml.x2006.main.CTNotesSlide; @@ -57,7 +58,7 @@ implements Notes { super(part, rel); NotesDocument doc = - NotesDocument.Factory.parse(getPackagePart().getInputStream(), POIXMLDocumentPart.DEFAULT_XML_OPTIONS); + NotesDocument.Factory.parse(getPackagePart().getInputStream(), DEFAULT_XML_OPTIONS); _notes = doc.getNotes(); setCommonSlideData(_notes.getCSld()); } diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFNotesMaster.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFNotesMaster.java index b3d1777ac5..c93c9cc26e 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFNotesMaster.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFNotesMaster.java @@ -16,6 +16,8 @@ ==================================================================== */ package org.apache.poi.xslf.usermodel; +import static org.apache.poi.POIXMLTypeLoader.DEFAULT_XML_OPTIONS; + import java.io.IOException; import java.io.InputStream; @@ -25,7 +27,6 @@ import org.apache.poi.openxml4j.opc.PackagePart; import org.apache.poi.openxml4j.opc.PackageRelationship; import org.apache.poi.sl.usermodel.MasterSheet; import org.apache.poi.util.Beta; -import org.apache.poi.util.DocumentHelper; import org.apache.xmlbeans.XmlException; import org.openxmlformats.schemas.drawingml.x2006.main.CTColorMapping; import org.openxmlformats.schemas.presentationml.x2006.main.CTNotesMaster; @@ -61,7 +62,7 @@ import org.openxmlformats.schemas.presentationml.x2006.main.NotesMasterDocument; protected XSLFNotesMaster(PackagePart part, PackageRelationship rel) throws IOException, XmlException { super(part, rel); NotesMasterDocument doc = - NotesMasterDocument.Factory.parse(getPackagePart().getInputStream(), POIXMLDocumentPart.DEFAULT_XML_OPTIONS); + NotesMasterDocument.Factory.parse(getPackagePart().getInputStream(), DEFAULT_XML_OPTIONS); _slide = doc.getNotesMaster(); setCommonSlideData(_slide.getCSld()); } @@ -74,7 +75,7 @@ import org.openxmlformats.schemas.presentationml.x2006.main.NotesMasterDocument; try { try { - NotesMasterDocument doc = NotesMasterDocument.Factory.parse(is, POIXMLDocumentPart.DEFAULT_XML_OPTIONS); + NotesMasterDocument doc = NotesMasterDocument.Factory.parse(is, DEFAULT_XML_OPTIONS); CTNotesMaster slide = doc.getNotesMaster(); return slide; } finally { diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSheet.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSheet.java index 547e01fe8a..f999c6c4b6 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSheet.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSheet.java @@ -16,6 +16,8 @@ ==================================================================== */ package org.apache.poi.xslf.usermodel; +import static org.apache.poi.POIXMLTypeLoader.DEFAULT_XML_OPTIONS; + import java.awt.Graphics2D; import java.io.IOException; import java.io.InputStream; @@ -25,6 +27,7 @@ import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; + import javax.xml.namespace.QName; import org.apache.poi.POIXMLDocumentPart; @@ -39,8 +42,8 @@ import org.apache.poi.sl.draw.DrawFactory; import org.apache.poi.sl.draw.DrawPictureShape; import org.apache.poi.sl.draw.Drawable; import org.apache.poi.sl.usermodel.PictureData; -import org.apache.poi.sl.usermodel.SimpleShape.Placeholder; import org.apache.poi.sl.usermodel.Sheet; +import org.apache.poi.sl.usermodel.SimpleShape.Placeholder; import org.apache.poi.util.Beta; import org.apache.poi.util.IOUtils; import org.apache.poi.util.Internal; @@ -312,12 +315,6 @@ implements XSLFShapeContainer, Sheet { protected final void commit() throws IOException { XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS); - - Map map = new HashMap(); - map.put(STRelationshipId.type.getName().getNamespaceURI(), "r"); - map.put("http://schemas.openxmlformats.org/drawingml/2006/main", "a"); - map.put("http://schemas.openxmlformats.org/presentationml/2006/main", "p"); - xmlOptions.setSaveSuggestedPrefixes(map); String docName = getRootElementName(); if(docName != null) { xmlOptions.setSaveSyntheticDocumentElement( diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlide.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlide.java index 1d0d854bda..4be19ea435 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlide.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlide.java @@ -16,6 +16,8 @@ ==================================================================== */ package org.apache.poi.xslf.usermodel; +import static org.apache.poi.POIXMLTypeLoader.DEFAULT_XML_OPTIONS; + import java.awt.Graphics2D; import java.io.IOException; @@ -71,7 +73,7 @@ implements Slide { super(part, rel); SldDocument doc = - SldDocument.Factory.parse(getPackagePart().getInputStream(), POIXMLDocumentPart.DEFAULT_XML_OPTIONS); + SldDocument.Factory.parse(getPackagePart().getInputStream(), DEFAULT_XML_OPTIONS); _slide = doc.getSld(); setCommonSlideData(_slide.getCSld()); } diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlideLayout.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlideLayout.java index 329ebf8994..95835e4952 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlideLayout.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlideLayout.java @@ -16,6 +16,8 @@ ==================================================================== */ package org.apache.poi.xslf.usermodel; +import static org.apache.poi.POIXMLTypeLoader.DEFAULT_XML_OPTIONS; + import java.io.IOException; import org.apache.poi.POIXMLDocumentPart; @@ -45,7 +47,7 @@ implements MasterSheet { public XSLFSlideLayout(PackagePart part, PackageRelationship rel) throws IOException, XmlException { super(part, rel); SldLayoutDocument doc = - SldLayoutDocument.Factory.parse(getPackagePart().getInputStream(), POIXMLDocumentPart.DEFAULT_XML_OPTIONS); + SldLayoutDocument.Factory.parse(getPackagePart().getInputStream(), DEFAULT_XML_OPTIONS); _layout = doc.getSldLayout(); setCommonSlideData(_layout.getCSld()); } diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlideMaster.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlideMaster.java index 302e064b6a..cf45bf7446 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlideMaster.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlideMaster.java @@ -16,6 +16,8 @@ ==================================================================== */ package org.apache.poi.xslf.usermodel; +import static org.apache.poi.POIXMLTypeLoader.DEFAULT_XML_OPTIONS; + import java.io.IOException; import java.util.HashMap; import java.util.Locale; @@ -70,7 +72,7 @@ import org.openxmlformats.schemas.presentationml.x2006.main.SldMasterDocument; protected XSLFSlideMaster(PackagePart part, PackageRelationship rel) throws IOException, XmlException { super(part, rel); SldMasterDocument doc = - SldMasterDocument.Factory.parse(getPackagePart().getInputStream(), POIXMLDocumentPart.DEFAULT_XML_OPTIONS); + SldMasterDocument.Factory.parse(getPackagePart().getInputStream(), DEFAULT_XML_OPTIONS); _slide = doc.getSldMaster(); setCommonSlideData(_slide.getCSld()); } diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlideShow.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlideShow.java index 2646316415..8c69bbfa99 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlideShow.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlideShow.java @@ -16,12 +16,13 @@ ==================================================================== */ package org.apache.poi.xslf.usermodel; +import static org.apache.poi.POIXMLTypeLoader.DEFAULT_XML_OPTIONS; + import java.io.IOException; import java.util.LinkedList; import java.util.List; import org.apache.poi.POIXMLDocument; -import org.apache.poi.POIXMLDocumentPart; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.openxml4j.exceptions.OpenXML4JException; import org.apache.poi.openxml4j.opc.OPCPackage; @@ -74,7 +75,7 @@ public class XSLFSlideShow extends POIXMLDocument { } presentationDoc = - PresentationDocument.Factory.parse(getCorePart().getInputStream(), POIXMLDocumentPart.DEFAULT_XML_OPTIONS); + PresentationDocument.Factory.parse(getCorePart().getInputStream(), DEFAULT_XML_OPTIONS); embedds = new LinkedList(); for (CTSlideIdListEntry ctSlide : getSlideReferences().getSldIdArray()) { @@ -146,7 +147,7 @@ public class XSLFSlideShow extends POIXMLDocument { public CTSlideMaster getSlideMaster(CTSlideMasterIdListEntry master) throws IOException, XmlException { PackagePart masterPart = getSlideMasterPart(master); SldMasterDocument masterDoc = - SldMasterDocument.Factory.parse(masterPart.getInputStream(), POIXMLDocumentPart.DEFAULT_XML_OPTIONS); + SldMasterDocument.Factory.parse(masterPart.getInputStream(), DEFAULT_XML_OPTIONS); return masterDoc.getSldMaster(); } @@ -166,7 +167,7 @@ public class XSLFSlideShow extends POIXMLDocument { public CTSlide getSlide(CTSlideIdListEntry slide) throws IOException, XmlException { PackagePart slidePart = getSlidePart(slide); SldDocument slideDoc = - SldDocument.Factory.parse(slidePart.getInputStream(), POIXMLDocumentPart.DEFAULT_XML_OPTIONS); + SldDocument.Factory.parse(slidePart.getInputStream(), DEFAULT_XML_OPTIONS); return slideDoc.getSld(); } @@ -209,7 +210,7 @@ public class XSLFSlideShow extends POIXMLDocument { return null; NotesDocument notesDoc = - NotesDocument.Factory.parse(notesPart.getInputStream(), POIXMLDocumentPart.DEFAULT_XML_OPTIONS); + NotesDocument.Factory.parse(notesPart.getInputStream(), DEFAULT_XML_OPTIONS); return notesDoc.getNotes(); } @@ -241,7 +242,7 @@ public class XSLFSlideShow extends POIXMLDocument { commentRels.getRelationship(0) ); CmLstDocument commDoc = - CmLstDocument.Factory.parse(cPart.getInputStream(), POIXMLDocumentPart.DEFAULT_XML_OPTIONS); + CmLstDocument.Factory.parse(cPart.getInputStream(), DEFAULT_XML_OPTIONS); return commDoc.getCmLst(); } catch(InvalidFormatException e) { throw new IllegalStateException(e); diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTable.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTable.java index 16a7c59c71..d0d474944a 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTable.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTable.java @@ -19,6 +19,8 @@ package org.apache.poi.xslf.usermodel; +import static org.apache.poi.POIXMLTypeLoader.DEFAULT_XML_OPTIONS; + import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; @@ -26,7 +28,6 @@ import java.util.List; import javax.xml.namespace.QName; -import org.apache.poi.POIXMLDocumentPart; import org.apache.poi.POIXMLException; import org.apache.poi.sl.usermodel.TableShape; import org.apache.poi.util.Internal; @@ -68,7 +69,7 @@ public class XSLFTable extends XSLFGraphicFrame implements Iterable(tblStyleArray.length); for(CTTableStyle c : tblStyleArray){ diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTheme.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTheme.java index 88b72602d9..f51c2daace 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTheme.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTheme.java @@ -16,6 +16,8 @@ ==================================================================== */ package org.apache.poi.xslf.usermodel; +import static org.apache.poi.POIXMLTypeLoader.DEFAULT_XML_OPTIONS; + import java.io.IOException; import java.io.OutputStream; import java.util.HashMap; @@ -27,7 +29,6 @@ import org.apache.poi.POIXMLDocumentPart; import org.apache.poi.openxml4j.opc.PackagePart; import org.apache.poi.openxml4j.opc.PackageRelationship; import org.apache.poi.util.Beta; -import org.apache.poi.util.DocumentHelper; import org.apache.poi.util.Internal; import org.apache.xmlbeans.XmlException; import org.apache.xmlbeans.XmlObject; @@ -58,7 +59,7 @@ public class XSLFTheme extends POIXMLDocumentPart { public XSLFTheme(PackagePart part, PackageRelationship rel) throws IOException, XmlException { super(part, rel); ThemeDocument doc = - ThemeDocument.Factory.parse(getPackagePart().getInputStream(), POIXMLDocumentPart.DEFAULT_XML_OPTIONS); + ThemeDocument.Factory.parse(getPackagePart().getInputStream(), DEFAULT_XML_OPTIONS); _theme = doc.getTheme(); initialize(); } @@ -128,12 +129,8 @@ public class XSLFTheme extends POIXMLDocumentPart { protected final void commit() throws IOException { XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS); - - Map map = new HashMap(); - map.put("http://schemas.openxmlformats.org/drawingml/2006/main", "a"); - xmlOptions.setSaveSuggestedPrefixes(map); xmlOptions.setSaveSyntheticDocumentElement( - new QName("http://schemas.openxmlformats.org/drawingml/2006/main", "theme")); + new QName("http://schemas.openxmlformats.org/drawingml/2006/main", "theme")); PackagePart part = getPackagePart(); OutputStream out = part.getOutputStream(); diff --git a/src/ooxml/java/org/apache/poi/xssf/dev/XSSFDump.java b/src/ooxml/java/org/apache/poi/xssf/dev/XSSFDump.java index ecfcca717b..2e660ac91f 100644 --- a/src/ooxml/java/org/apache/poi/xssf/dev/XSSFDump.java +++ b/src/ooxml/java/org/apache/poi/xssf/dev/XSSFDump.java @@ -17,6 +17,8 @@ package org.apache.poi.xssf.dev; +import static org.apache.poi.POIXMLTypeLoader.DEFAULT_XML_OPTIONS; + import java.io.File; import java.io.FileOutputStream; import java.io.OutputStream; @@ -24,7 +26,6 @@ import java.util.Enumeration; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; -import org.apache.poi.POIXMLDocumentPart; import org.apache.poi.openxml4j.opc.internal.ZipHelper; import org.apache.poi.util.IOUtils; import org.apache.xmlbeans.XmlObject; @@ -71,7 +72,7 @@ public final class XSSFDump { try { if(entry.getName().endsWith(".xml") || entry.getName().endsWith(".vml") || entry.getName().endsWith(".rels")){ try { - XmlObject xml = XmlObject.Factory.parse(zip.getInputStream(entry), POIXMLDocumentPart.DEFAULT_XML_OPTIONS); + XmlObject xml = XmlObject.Factory.parse(zip.getInputStream(entry), DEFAULT_XML_OPTIONS); XmlOptions options = new XmlOptions(); options.setSavePrettyPrint(); xml.save(out, options); diff --git a/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFReader.java b/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFReader.java index 172cf7a3b6..cc5fbb2cd4 100644 --- a/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFReader.java +++ b/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFReader.java @@ -16,6 +16,8 @@ ==================================================================== */ package org.apache.poi.xssf.eventusermodel; +import static org.apache.poi.POIXMLTypeLoader.DEFAULT_XML_OPTIONS; + import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; @@ -25,7 +27,6 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; -import org.apache.poi.POIXMLDocumentPart; import org.apache.poi.POIXMLException; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.openxml4j.exceptions.OpenXML4JException; @@ -209,7 +210,7 @@ public class XSSFReader { } //step 2. Read array of CTSheet elements, wrap it in a ArayList and construct an iterator //Note, using XMLBeans might be expensive, consider refactoring to use SAX or a plain regexp search - CTWorkbook wbBean = WorkbookDocument.Factory.parse(wb.getInputStream(), POIXMLDocumentPart.DEFAULT_XML_OPTIONS).getWorkbook(); + CTWorkbook wbBean = WorkbookDocument.Factory.parse(wb.getInputStream(), DEFAULT_XML_OPTIONS).getWorkbook(); sheetIterator = wbBean.getSheets().getSheetList().iterator(); } catch (InvalidFormatException e){ throw new POIXMLException(e); diff --git a/src/ooxml/java/org/apache/poi/xssf/model/CalculationChain.java b/src/ooxml/java/org/apache/poi/xssf/model/CalculationChain.java index 8553537328..13133f4fb1 100644 --- a/src/ooxml/java/org/apache/poi/xssf/model/CalculationChain.java +++ b/src/ooxml/java/org/apache/poi/xssf/model/CalculationChain.java @@ -16,16 +16,19 @@ ==================================================================== */ package org.apache.poi.xssf.model; +import static org.apache.poi.POIXMLTypeLoader.DEFAULT_XML_OPTIONS; + import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import org.apache.poi.POIXMLDocumentPart; -import org.apache.xmlbeans.XmlException; -import org.openxmlformats.schemas.spreadsheetml.x2006.main.*; import org.apache.poi.openxml4j.opc.PackagePart; import org.apache.poi.openxml4j.opc.PackageRelationship; -import org.apache.poi.util.DocumentHelper; +import org.apache.xmlbeans.XmlException; +import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCalcCell; +import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCalcChain; +import org.openxmlformats.schemas.spreadsheetml.x2006.main.CalcChainDocument; /** * The cells in a workbook can be calculated in different orders depending on various optimizations and @@ -48,7 +51,7 @@ public class CalculationChain extends POIXMLDocumentPart { public void readFrom(InputStream is) throws IOException { try { - CalcChainDocument doc = CalcChainDocument.Factory.parse(is, POIXMLDocumentPart.DEFAULT_XML_OPTIONS); + CalcChainDocument doc = CalcChainDocument.Factory.parse(is, DEFAULT_XML_OPTIONS); chain = doc.getCalcChain(); } catch (XmlException e) { throw new IOException(e.getLocalizedMessage()); diff --git a/src/ooxml/java/org/apache/poi/xssf/model/CommentsTable.java b/src/ooxml/java/org/apache/poi/xssf/model/CommentsTable.java index b9ef88a9fa..3cbc49dd50 100644 --- a/src/ooxml/java/org/apache/poi/xssf/model/CommentsTable.java +++ b/src/ooxml/java/org/apache/poi/xssf/model/CommentsTable.java @@ -16,6 +16,8 @@ ==================================================================== */ package org.apache.poi.xssf.model; +import static org.apache.poi.POIXMLTypeLoader.DEFAULT_XML_OPTIONS; + import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -25,7 +27,6 @@ import java.util.Map; import org.apache.poi.POIXMLDocumentPart; import org.apache.poi.openxml4j.opc.PackagePart; import org.apache.poi.openxml4j.opc.PackageRelationship; -import org.apache.poi.util.DocumentHelper; import org.apache.poi.xssf.usermodel.XSSFComment; import org.apache.xmlbeans.XmlException; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComment; @@ -56,7 +57,7 @@ public class CommentsTable extends POIXMLDocumentPart { public void readFrom(InputStream is) throws IOException { try { - CommentsDocument doc = CommentsDocument.Factory.parse(is, POIXMLDocumentPart.DEFAULT_XML_OPTIONS); + CommentsDocument doc = CommentsDocument.Factory.parse(is, DEFAULT_XML_OPTIONS); comments = doc.getComments(); } catch (XmlException e) { throw new IOException(e.getLocalizedMessage()); diff --git a/src/ooxml/java/org/apache/poi/xssf/model/ExternalLinksTable.java b/src/ooxml/java/org/apache/poi/xssf/model/ExternalLinksTable.java index a96081ef30..42fce11597 100644 --- a/src/ooxml/java/org/apache/poi/xssf/model/ExternalLinksTable.java +++ b/src/ooxml/java/org/apache/poi/xssf/model/ExternalLinksTable.java @@ -16,6 +16,8 @@ ==================================================================== */ package org.apache.poi.xssf.model; +import static org.apache.poi.POIXMLTypeLoader.DEFAULT_XML_OPTIONS; + import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -28,7 +30,6 @@ import org.apache.poi.openxml4j.opc.PackageRelationship; import org.apache.poi.openxml4j.opc.PackageRelationshipTypes; import org.apache.poi.openxml4j.opc.TargetMode; import org.apache.poi.ss.usermodel.Name; -import org.apache.poi.util.DocumentHelper; import org.apache.xmlbeans.XmlException; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTExternalDefinedName; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTExternalLink; @@ -55,7 +56,7 @@ public class ExternalLinksTable extends POIXMLDocumentPart { public void readFrom(InputStream is) throws IOException { try { - ExternalLinkDocument doc = ExternalLinkDocument.Factory.parse(is, POIXMLDocumentPart.DEFAULT_XML_OPTIONS); + ExternalLinkDocument doc = ExternalLinkDocument.Factory.parse(is, DEFAULT_XML_OPTIONS); link = doc.getExternalLink(); } catch (XmlException e) { throw new IOException(e.getLocalizedMessage()); diff --git a/src/ooxml/java/org/apache/poi/xssf/model/MapInfo.java b/src/ooxml/java/org/apache/poi/xssf/model/MapInfo.java index 959df17b46..c8032e6021 100644 --- a/src/ooxml/java/org/apache/poi/xssf/model/MapInfo.java +++ b/src/ooxml/java/org/apache/poi/xssf/model/MapInfo.java @@ -17,6 +17,8 @@ package org.apache.poi.xssf.model; +import static org.apache.poi.POIXMLTypeLoader.DEFAULT_XML_OPTIONS; + import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -27,7 +29,6 @@ import java.util.Map; import org.apache.poi.POIXMLDocumentPart; import org.apache.poi.openxml4j.opc.PackagePart; import org.apache.poi.openxml4j.opc.PackageRelationship; -import org.apache.poi.util.DocumentHelper; import org.apache.poi.xssf.usermodel.XSSFMap; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.apache.xmlbeans.XmlException; @@ -69,7 +70,7 @@ public class MapInfo extends POIXMLDocumentPart { @SuppressWarnings("deprecation") public void readFrom(InputStream is) throws IOException { try { - MapInfoDocument doc = MapInfoDocument.Factory.parse(is, POIXMLDocumentPart.DEFAULT_XML_OPTIONS); + MapInfoDocument doc = MapInfoDocument.Factory.parse(is, DEFAULT_XML_OPTIONS); mapInfo = doc.getMapInfo(); maps= new HashMap(); diff --git a/src/ooxml/java/org/apache/poi/xssf/model/SharedStringsTable.java b/src/ooxml/java/org/apache/poi/xssf/model/SharedStringsTable.java index 7f56448795..96a8ce89f2 100644 --- a/src/ooxml/java/org/apache/poi/xssf/model/SharedStringsTable.java +++ b/src/ooxml/java/org/apache/poi/xssf/model/SharedStringsTable.java @@ -17,6 +17,8 @@ package org.apache.poi.xssf.model; +import static org.apache.poi.POIXMLTypeLoader.DEFAULT_XML_OPTIONS; + import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -116,7 +118,7 @@ public class SharedStringsTable extends POIXMLDocumentPart { public void readFrom(InputStream is) throws IOException { try { int cnt = 0; - _sstDoc = SstDocument.Factory.parse(is, POIXMLDocumentPart.DEFAULT_XML_OPTIONS); + _sstDoc = SstDocument.Factory.parse(is, DEFAULT_XML_OPTIONS); CTSst sst = _sstDoc.getSst(); count = (int)sst.getCount(); uniqueCount = (int)sst.getUniqueCount(); diff --git a/src/ooxml/java/org/apache/poi/xssf/model/SingleXmlCells.java b/src/ooxml/java/org/apache/poi/xssf/model/SingleXmlCells.java index effcde544f..953bad409c 100644 --- a/src/ooxml/java/org/apache/poi/xssf/model/SingleXmlCells.java +++ b/src/ooxml/java/org/apache/poi/xssf/model/SingleXmlCells.java @@ -17,6 +17,8 @@ package org.apache.poi.xssf.model; +import static org.apache.poi.POIXMLTypeLoader.DEFAULT_XML_OPTIONS; + import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -26,7 +28,6 @@ import java.util.Vector; import org.apache.poi.POIXMLDocumentPart; import org.apache.poi.openxml4j.opc.PackagePart; import org.apache.poi.openxml4j.opc.PackageRelationship; -import org.apache.poi.util.DocumentHelper; import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.helpers.XSSFSingleXmlCell; import org.apache.xmlbeans.XmlException; @@ -62,7 +63,7 @@ public class SingleXmlCells extends POIXMLDocumentPart { public void readFrom(InputStream is) throws IOException { try { - SingleXmlCellsDocument doc = SingleXmlCellsDocument.Factory.parse(is, POIXMLDocumentPart.DEFAULT_XML_OPTIONS); + SingleXmlCellsDocument doc = SingleXmlCellsDocument.Factory.parse(is, DEFAULT_XML_OPTIONS); singleXMLCells = doc.getSingleXmlCells(); } catch (XmlException e) { throw new IOException(e.getLocalizedMessage()); diff --git a/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java b/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java index be3855a067..d413b64c51 100644 --- a/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java +++ b/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java @@ -17,6 +17,8 @@ package org.apache.poi.xssf.model; +import static org.apache.poi.POIXMLTypeLoader.DEFAULT_XML_OPTIONS; + import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -42,7 +44,6 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.apache.poi.xssf.usermodel.extensions.XSSFCellBorder; import org.apache.poi.xssf.usermodel.extensions.XSSFCellFill; import org.apache.xmlbeans.XmlException; -import org.apache.xmlbeans.XmlOptions; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBorder; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBorders; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCellStyleXfs; @@ -147,7 +148,7 @@ public class StylesTable extends POIXMLDocumentPart { @SuppressWarnings("deprecation") //YK: getXYZArray() array accessors are deprecated in xmlbeans with JDK 1.5 support protected void readFrom(InputStream is) throws IOException { try { - doc = StyleSheetDocument.Factory.parse(is, POIXMLDocumentPart.DEFAULT_XML_OPTIONS); + doc = StyleSheetDocument.Factory.parse(is, DEFAULT_XML_OPTIONS); CTStylesheet styleSheet = doc.getStyleSheet(); @@ -392,8 +393,6 @@ public class StylesTable extends POIXMLDocumentPart { * @throws IOException if an error occurs while writing. */ public void writeTo(OutputStream out) throws IOException { - XmlOptions options = new XmlOptions(DEFAULT_XML_OPTIONS); - // Work on the current one // Need to do this, as we don't handle // all the possible entries yet @@ -486,7 +485,7 @@ public class StylesTable extends POIXMLDocumentPart { } // Save - doc.save(out, options); + doc.save(out, DEFAULT_XML_OPTIONS); } @Override diff --git a/src/ooxml/java/org/apache/poi/xssf/model/ThemesTable.java b/src/ooxml/java/org/apache/poi/xssf/model/ThemesTable.java index 0873f07577..6d79ddeb71 100644 --- a/src/ooxml/java/org/apache/poi/xssf/model/ThemesTable.java +++ b/src/ooxml/java/org/apache/poi/xssf/model/ThemesTable.java @@ -16,16 +16,16 @@ ==================================================================== */ package org.apache.poi.xssf.model; +import static org.apache.poi.POIXMLTypeLoader.DEFAULT_XML_OPTIONS; + import java.io.IOException; import java.io.OutputStream; import org.apache.poi.POIXMLDocumentPart; import org.apache.poi.openxml4j.opc.PackagePart; import org.apache.poi.openxml4j.opc.PackageRelationship; -import org.apache.poi.util.DocumentHelper; import org.apache.poi.xssf.usermodel.XSSFColor; import org.apache.xmlbeans.XmlException; -import org.apache.xmlbeans.XmlOptions; import org.openxmlformats.schemas.drawingml.x2006.main.CTColor; import org.openxmlformats.schemas.drawingml.x2006.main.CTColorScheme; import org.openxmlformats.schemas.drawingml.x2006.main.ThemeDocument; @@ -81,7 +81,7 @@ public class ThemesTable extends POIXMLDocumentPart { super(part, rel); try { - theme = ThemeDocument.Factory.parse(part.getInputStream(), POIXMLDocumentPart.DEFAULT_XML_OPTIONS); + theme = ThemeDocument.Factory.parse(part.getInputStream(), DEFAULT_XML_OPTIONS); } catch(XmlException e) { throw new IOException(e.getLocalizedMessage(), e); } @@ -166,9 +166,7 @@ public class ThemesTable extends POIXMLDocumentPart { * @throws IOException if an error occurs while writing. */ public void writeTo(OutputStream out) throws IOException { - XmlOptions options = new XmlOptions(DEFAULT_XML_OPTIONS); - - theme.save(out, options); + theme.save(out, DEFAULT_XML_OPTIONS); } @Override diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java index 37be561891..93798d1b53 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java @@ -17,7 +17,8 @@ package org.apache.poi.xssf.usermodel; -import org.apache.poi.POIXMLDocumentPart; +import static org.apache.poi.POIXMLTypeLoader.DEFAULT_XML_OPTIONS; + import org.apache.poi.POIXMLException; import org.apache.poi.ss.usermodel.BorderStyle; import org.apache.poi.ss.usermodel.CellStyle; @@ -154,12 +155,12 @@ public class XSSFCellStyle implements CellStyle { // Create a new Xf with the same contents _cellXf = CTXf.Factory.parse( - src.getCoreXf().toString(), POIXMLDocumentPart.DEFAULT_XML_OPTIONS + src.getCoreXf().toString(), DEFAULT_XML_OPTIONS ); // bug 56295: ensure that the fills is available and set correctly CTFill fill = CTFill.Factory.parse( - src.getCTFill().toString(), POIXMLDocumentPart.DEFAULT_XML_OPTIONS + src.getCTFill().toString(), DEFAULT_XML_OPTIONS ); addFill(fill); @@ -178,7 +179,7 @@ public class XSSFCellStyle implements CellStyle { // Copy the font try { CTFont ctFont = CTFont.Factory.parse( - src.getFont().getCTFont().toString(), POIXMLDocumentPart.DEFAULT_XML_OPTIONS + src.getFont().getCTFont().toString(), DEFAULT_XML_OPTIONS ); XSSFFont font = new XSSFFont(ctFont); font.registerTo(_stylesSource); diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFChart.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFChart.java index a31d2e8c1e..3dcb00d3ab 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFChart.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFChart.java @@ -17,12 +17,12 @@ package org.apache.poi.xssf.usermodel; +import static org.apache.poi.POIXMLTypeLoader.DEFAULT_XML_OPTIONS; + import java.io.IOException; import java.io.OutputStream; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; import javax.xml.namespace.QName; @@ -34,7 +34,6 @@ import org.apache.poi.ss.usermodel.charts.AxisPosition; import org.apache.poi.ss.usermodel.charts.ChartAxis; import org.apache.poi.ss.usermodel.charts.ChartAxisFactory; import org.apache.poi.ss.usermodel.charts.ChartData; -import org.apache.poi.util.DocumentHelper; import org.apache.poi.util.Internal; import org.apache.poi.xssf.usermodel.charts.XSSFCategoryAxis; import org.apache.poi.xssf.usermodel.charts.XSSFChartAxis; @@ -54,7 +53,6 @@ import org.openxmlformats.schemas.drawingml.x2006.chart.CTPrintSettings; import org.openxmlformats.schemas.drawingml.x2006.chart.CTTitle; import org.openxmlformats.schemas.drawingml.x2006.chart.CTValAx; import org.openxmlformats.schemas.drawingml.x2006.chart.ChartSpaceDocument; -import org.openxmlformats.schemas.officeDocument.x2006.relationships.STRelationshipId; import org.w3c.dom.NodeList; import org.w3c.dom.Text; @@ -101,7 +99,7 @@ public final class XSSFChart extends POIXMLDocumentPart implements Chart, ChartA protected XSSFChart(PackagePart part, PackageRelationship rel) throws IOException, XmlException { super(part, rel); - chartSpace = ChartSpaceDocument.Factory.parse(part.getInputStream(), POIXMLDocumentPart.DEFAULT_XML_OPTIONS).getChartSpace(); + chartSpace = ChartSpaceDocument.Factory.parse(part.getInputStream(), DEFAULT_XML_OPTIONS).getChartSpace(); chart = chartSpace.getChart(); } @@ -164,11 +162,6 @@ public final class XSSFChart extends POIXMLDocumentPart implements Chart, ChartA xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"> */ xmlOptions.setSaveSyntheticDocumentElement(new QName(CTChartSpace.type.getName().getNamespaceURI(), "chartSpace", "c")); - Map map = new HashMap(); - map.put(XSSFDrawing.NAMESPACE_A, "a"); - map.put(XSSFDrawing.NAMESPACE_C, "c"); - map.put(STRelationshipId.type.getName().getNamespaceURI(), "r"); - xmlOptions.setSaveSuggestedPrefixes(map); PackagePart part = getPackagePart(); OutputStream out = part.getOutputStream(); @@ -199,8 +192,8 @@ public final class XSSFChart extends POIXMLDocumentPart implements Chart, ChartA return this; } - public void plot(ChartData data, ChartAxis... axis) { - data.fillChart(this, axis); + public void plot(ChartData data, ChartAxis... chartAxis) { + data.fillChart(this, chartAxis); } public XSSFValueAxis createValueAxis(AxisPosition pos) { diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFChartSheet.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFChartSheet.java index 5c8aae3c03..65a9adbe18 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFChartSheet.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFChartSheet.java @@ -17,23 +17,21 @@ package org.apache.poi.xssf.usermodel; +import static org.apache.poi.POIXMLTypeLoader.DEFAULT_XML_OPTIONS; + import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import java.util.HashMap; -import java.util.Map; import javax.xml.namespace.QName; -import org.apache.poi.POIXMLDocumentPart; import org.apache.poi.POIXMLException; import org.apache.poi.openxml4j.opc.PackagePart; import org.apache.poi.openxml4j.opc.PackageRelationship; import org.apache.xmlbeans.XmlException; import org.apache.xmlbeans.XmlOptions; -import org.openxmlformats.schemas.officeDocument.x2006.relationships.STRelationshipId; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTChartsheet; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDrawing; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTLegacyDrawing; @@ -62,7 +60,7 @@ public class XSSFChartSheet extends XSSFSheet { super.read(new ByteArrayInputStream(BLANK_WORKSHEET)); try { - chartsheet = ChartsheetDocument.Factory.parse(is, POIXMLDocumentPart.DEFAULT_XML_OPTIONS).getChartsheet(); + chartsheet = ChartsheetDocument.Factory.parse(is, DEFAULT_XML_OPTIONS).getChartsheet(); } catch (XmlException e){ throw new POIXMLException(e); } @@ -92,10 +90,6 @@ public class XSSFChartSheet extends XSSFSheet { XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS); xmlOptions.setSaveSyntheticDocumentElement( new QName(CTChartsheet.type.getName().getNamespaceURI(), "chartsheet")); - Map map = new HashMap(); - map.put(STRelationshipId.type.getName().getNamespaceURI(), "r"); - xmlOptions.setSaveSuggestedPrefixes(map); - chartsheet.save(out, xmlOptions); } diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFComment.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFComment.java index 65eefec559..642aa9e0fb 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFComment.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFComment.java @@ -28,7 +28,7 @@ import org.apache.poi.xssf.model.CommentsTable; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComment; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRst; -import schemasMicrosoftComVml.CTShape; +import com.microsoft.schemas.vml.CTShape; public class XSSFComment implements Comment { diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDrawing.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDrawing.java index b2103e2893..2f3853973d 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDrawing.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDrawing.java @@ -17,12 +17,12 @@ package org.apache.poi.xssf.usermodel; +import static org.apache.poi.POIXMLTypeLoader.DEFAULT_XML_OPTIONS; + import java.io.IOException; import java.io.OutputStream; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; import javax.xml.namespace.QName; @@ -41,8 +41,16 @@ import org.apache.xmlbeans.XmlCursor; import org.apache.xmlbeans.XmlException; import org.apache.xmlbeans.XmlObject; import org.apache.xmlbeans.XmlOptions; -import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.*; -import org.openxmlformats.schemas.officeDocument.x2006.relationships.STRelationshipId; +import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTConnector; +import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTDrawing; +import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTGraphicalObjectFrame; +import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTGroupShape; +import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTMarker; +import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTOneCellAnchor; +import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTPicture; +import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTShape; +import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTTwoCellAnchor; +import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.STEditAs; /** * Represents a SpreadsheetML drawing @@ -117,10 +125,6 @@ public final class XSSFDrawing extends POIXMLDocumentPart implements Drawing { xmlOptions.setSaveSyntheticDocumentElement( new QName(CTDrawing.type.getName().getNamespaceURI(), "wsDr", "xdr") ); - Map map = new HashMap(); - map.put(NAMESPACE_A, "a"); - map.put(STRelationshipId.type.getName().getNamespaceURI(), "r"); - xmlOptions.setSaveSuggestedPrefixes(map); PackagePart part = getPackagePart(); OutputStream out = part.getOutputStream(); @@ -297,7 +301,7 @@ public final class XSSFDrawing extends POIXMLDocumentPart implements Drawing { //create comments and vmlDrawing parts if they don't exist CommentsTable comments = sheet.getCommentsTable(true); XSSFVMLDrawing vml = sheet.getVMLDrawing(true); - schemasMicrosoftComVml.CTShape vmlShape = vml.newCommentShape(); + com.microsoft.schemas.vml.CTShape vmlShape = vml.newCommentShape(); if(ca.isSet()){ // convert offsets from emus to pixels since we get a DrawingML-anchor // but create a VML Drawing diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPivotCache.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPivotCache.java index e5896e73a1..c6fb592056 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPivotCache.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPivotCache.java @@ -16,18 +16,17 @@ ==================================================================== */ package org.apache.poi.xssf.usermodel; +import static org.apache.poi.POIXMLTypeLoader.DEFAULT_XML_OPTIONS; + import java.io.IOException; import java.io.InputStream; import org.apache.poi.POIXMLDocumentPart; -import static org.apache.poi.POIXMLDocumentPart.DEFAULT_XML_OPTIONS; import org.apache.poi.openxml4j.opc.PackagePart; import org.apache.poi.openxml4j.opc.PackageRelationship; import org.apache.poi.util.Beta; - import org.apache.xmlbeans.XmlException; import org.apache.xmlbeans.XmlOptions; - import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPivotCache; public class XSSFPivotCache extends POIXMLDocumentPart { @@ -65,7 +64,7 @@ public class XSSFPivotCache extends POIXMLDocumentPart { XmlOptions options = new XmlOptions(DEFAULT_XML_OPTIONS); //Removing root element options.setLoadReplaceDocumentElement(null); - ctPivotCache = CTPivotCache.Factory.parse(is, options); + ctPivotCache = CTPivotCache.Factory.parse(is, options); } catch (XmlException e) { throw new IOException(e.getLocalizedMessage()); } diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPivotCacheDefinition.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPivotCacheDefinition.java index d63a18588d..f5c4fcad00 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPivotCacheDefinition.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPivotCacheDefinition.java @@ -16,6 +16,8 @@ ==================================================================== */ package org.apache.poi.xssf.usermodel; +import static org.apache.poi.POIXMLTypeLoader.DEFAULT_XML_OPTIONS; + import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPivotCacheRecords.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPivotCacheRecords.java index 93e04a022d..a8fca93c5d 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPivotCacheRecords.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPivotCacheRecords.java @@ -16,6 +16,8 @@ ==================================================================== */ package org.apache.poi.xssf.usermodel; +import static org.apache.poi.POIXMLTypeLoader.DEFAULT_XML_OPTIONS; + import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPivotTable.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPivotTable.java index 07bfb77bcd..cd132c8310 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPivotTable.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPivotTable.java @@ -16,6 +16,8 @@ ==================================================================== */ package org.apache.poi.xssf.usermodel; +import static org.apache.poi.POIXMLTypeLoader.DEFAULT_XML_OPTIONS; + import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java index 610ec2ecd6..6a35bf7d12 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java @@ -17,6 +17,7 @@ package org.apache.poi.xssf.usermodel; +import static org.apache.poi.POIXMLTypeLoader.DEFAULT_XML_OPTIONS; import static org.apache.poi.xssf.usermodel.helpers.XSSFPaswordHelper.setPassword; import static org.apache.poi.xssf.usermodel.helpers.XSSFPaswordHelper.validatePassword; @@ -76,7 +77,6 @@ import org.apache.poi.xssf.usermodel.helpers.ColumnHelper; import org.apache.poi.xssf.usermodel.helpers.XSSFRowShifter; import org.apache.xmlbeans.XmlException; import org.apache.xmlbeans.XmlOptions; -import org.openxmlformats.schemas.officeDocument.x2006.relationships.STRelationshipId; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTAutoFilter; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBreak; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCalcPr; @@ -195,7 +195,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet { protected void read(InputStream is) throws IOException { try { - worksheet = WorksheetDocument.Factory.parse(is, POIXMLDocumentPart.DEFAULT_XML_OPTIONS).getWorksheet(); + worksheet = WorksheetDocument.Factory.parse(is, DEFAULT_XML_OPTIONS).getWorksheet(); } catch (XmlException e){ throw new POIXMLException(e); } @@ -3306,9 +3306,6 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet { XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS); xmlOptions.setSaveSyntheticDocumentElement(new QName(CTWorksheet.type.getName().getNamespaceURI(), "worksheet")); - Map map = new HashMap(); - map.put(STRelationshipId.type.getName().getNamespaceURI(), "r"); - xmlOptions.setSaveSuggestedPrefixes(map); worksheet.save(out, xmlOptions); diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFTable.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFTable.java index 8cd1e10cdb..dcf5375023 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFTable.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFTable.java @@ -17,6 +17,8 @@ package org.apache.poi.xssf.usermodel; +import static org.apache.poi.POIXMLTypeLoader.DEFAULT_XML_OPTIONS; + import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -28,7 +30,6 @@ import org.apache.poi.POIXMLDocumentPart; import org.apache.poi.openxml4j.opc.PackagePart; import org.apache.poi.openxml4j.opc.PackageRelationship; import org.apache.poi.ss.util.CellReference; -import org.apache.poi.util.DocumentHelper; import org.apache.poi.xssf.usermodel.helpers.XSSFXmlColumnPr; import org.apache.xmlbeans.XmlException; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTTable; @@ -70,7 +71,7 @@ public class XSSFTable extends POIXMLDocumentPart { public void readFrom(InputStream is) throws IOException { try { - TableDocument doc = TableDocument.Factory.parse(is, POIXMLDocumentPart.DEFAULT_XML_OPTIONS); + TableDocument doc = TableDocument.Factory.parse(is, DEFAULT_XML_OPTIONS); ctTable = doc.getTable(); } catch (XmlException e) { throw new IOException(e.getLocalizedMessage()); diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFVMLDrawing.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFVMLDrawing.java index eb249f4148..96dfede0d2 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFVMLDrawing.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFVMLDrawing.java @@ -17,29 +17,41 @@ package org.apache.poi.xssf.usermodel; +import static org.apache.poi.POIXMLTypeLoader.DEFAULT_XML_OPTIONS; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import javax.xml.namespace.QName; + import org.apache.poi.POIXMLDocumentPart; import org.apache.poi.openxml4j.opc.PackagePart; import org.apache.poi.openxml4j.opc.PackageRelationship; -import org.apache.poi.util.DocumentHelper; import org.apache.poi.xssf.util.EvilUnclosedBRFixingInputStream; +import org.apache.xmlbeans.XmlCursor; import org.apache.xmlbeans.XmlException; -import org.apache.xmlbeans.XmlOptions; import org.apache.xmlbeans.XmlObject; -import org.apache.xmlbeans.XmlCursor; import org.w3c.dom.Node; -import schemasMicrosoftComOfficeOffice.*; -import javax.xml.namespace.QName; -import java.io.*; -import java.util.*; -import java.util.regex.Pattern; -import java.util.regex.Matcher; -import java.math.BigInteger; - -import schemasMicrosoftComVml.*; -import schemasMicrosoftComVml.STTrueFalse; -import schemasMicrosoftComOfficeExcel.CTClientData; -import schemasMicrosoftComOfficeExcel.STObjectType; +import com.microsoft.schemas.office.excel.CTClientData; +import com.microsoft.schemas.office.excel.STObjectType; +import com.microsoft.schemas.office.office.CTIdMap; +import com.microsoft.schemas.office.office.CTShapeLayout; +import com.microsoft.schemas.office.office.STConnectType; +import com.microsoft.schemas.office.office.STInsetMode; +import com.microsoft.schemas.vml.CTPath; +import com.microsoft.schemas.vml.CTShadow; +import com.microsoft.schemas.vml.CTShape; +import com.microsoft.schemas.vml.CTShapetype; +import com.microsoft.schemas.vml.STExt; +import com.microsoft.schemas.vml.STStrokeJoinStyle; +import com.microsoft.schemas.vml.STTrueFalse; /** * Represents a SpreadsheetML VML drawing. @@ -107,7 +119,7 @@ public final class XSSFVMLDrawing extends POIXMLDocumentPart { protected void read(InputStream is) throws IOException, XmlException { XmlObject root = XmlObject.Factory.parse( - new EvilUnclosedBRFixingInputStream(is), POIXMLDocumentPart.DEFAULT_XML_OPTIONS + new EvilUnclosedBRFixingInputStream(is), DEFAULT_XML_OPTIONS ); _qnames = new ArrayList(); @@ -116,13 +128,13 @@ public final class XSSFVMLDrawing extends POIXMLDocumentPart { Node nd = obj.getDomNode(); QName qname = new QName(nd.getNamespaceURI(), nd.getLocalName()); if (qname.equals(QNAME_SHAPE_LAYOUT)) { - _items.add(CTShapeLayout.Factory.parse(obj.xmlText(), POIXMLDocumentPart.DEFAULT_XML_OPTIONS)); + _items.add(CTShapeLayout.Factory.parse(obj.xmlText(), DEFAULT_XML_OPTIONS)); } else if (qname.equals(QNAME_SHAPE_TYPE)) { - CTShapetype st = CTShapetype.Factory.parse(obj.xmlText(), POIXMLDocumentPart.DEFAULT_XML_OPTIONS); + CTShapetype st = CTShapetype.Factory.parse(obj.xmlText(), DEFAULT_XML_OPTIONS); _items.add(st); _shapeTypeId = st.getId(); } else if (qname.equals(QNAME_SHAPE)) { - CTShape shape = CTShape.Factory.parse(obj.xmlText(), POIXMLDocumentPart.DEFAULT_XML_OPTIONS); + CTShape shape = CTShape.Factory.parse(obj.xmlText(), DEFAULT_XML_OPTIONS); String id = shape.getId(); if(id != null) { Matcher m = ptrn_shapeId.matcher(id); @@ -130,7 +142,7 @@ public final class XSSFVMLDrawing extends POIXMLDocumentPart { } _items.add(shape); } else { - _items.add(XmlObject.Factory.parse(obj.xmlText(), POIXMLDocumentPart.DEFAULT_XML_OPTIONS)); + _items.add(XmlObject.Factory.parse(obj.xmlText(), DEFAULT_XML_OPTIONS)); } _qnames.add(qname); } @@ -160,15 +172,7 @@ public final class XSSFVMLDrawing extends POIXMLDocumentPart { } rootCursor.dispose(); - XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS); - xmlOptions.setSavePrettyPrint(); - HashMap map = new HashMap(); - map.put("urn:schemas-microsoft-com:vml", "v"); - map.put("urn:schemas-microsoft-com:office:office", "o"); - map.put("urn:schemas-microsoft-com:office:excel", "x"); - xmlOptions.setSaveSuggestedPrefixes(map); - - rootObject.save(out, xmlOptions); + rootObject.save(out, DEFAULT_XML_OPTIONS); } @Override diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java index dc2d8307ef..d0d1fda63f 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java @@ -17,6 +17,7 @@ package org.apache.poi.xssf.usermodel; +import static org.apache.poi.POIXMLTypeLoader.DEFAULT_XML_OPTIONS; import static org.apache.poi.xssf.usermodel.helpers.XSSFPaswordHelper.setPassword; import static org.apache.poi.xssf.usermodel.helpers.XSSFPaswordHelper.validatePassword; @@ -80,7 +81,6 @@ import org.apache.poi.xssf.usermodel.helpers.XSSFFormulaUtils; import org.apache.xmlbeans.XmlException; import org.apache.xmlbeans.XmlObject; import org.apache.xmlbeans.XmlOptions; -import org.openxmlformats.schemas.officeDocument.x2006.relationships.STRelationshipId; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBookView; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBookViews; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCalcPr; @@ -333,7 +333,7 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook { @SuppressWarnings("deprecation") // getXYZArray() array accessors are deprecated protected void onDocumentRead() throws IOException { try { - WorkbookDocument doc = WorkbookDocument.Factory.parse(getPackagePart().getInputStream(), POIXMLDocumentPart.DEFAULT_XML_OPTIONS); + WorkbookDocument doc = WorkbookDocument.Factory.parse(getPackagePart().getInputStream(), DEFAULT_XML_OPTIONS); this.workbook = doc.getWorkbook(); ThemesTable theme = null; @@ -1670,9 +1670,6 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook { XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS); xmlOptions.setSaveSyntheticDocumentElement(new QName(CTWorkbook.type.getName().getNamespaceURI(), "workbook")); - Map map = new HashMap(); - map.put(STRelationshipId.type.getName().getNamespaceURI(), "r"); - xmlOptions.setSaveSuggestedPrefixes(map); PackagePart part = getPackagePart(); OutputStream out = part.getOutputStream(); diff --git a/src/ooxml/java/org/apache/poi/xwpf/model/XWPFHeaderFooterPolicy.java b/src/ooxml/java/org/apache/poi/xwpf/model/XWPFHeaderFooterPolicy.java index 4f210ae425..28ba945792 100644 --- a/src/ooxml/java/org/apache/poi/xwpf/model/XWPFHeaderFooterPolicy.java +++ b/src/ooxml/java/org/apache/poi/xwpf/model/XWPFHeaderFooterPolicy.java @@ -16,12 +16,12 @@ ==================================================================== */ package org.apache.poi.xwpf.model; +import static org.apache.poi.POIXMLTypeLoader.DEFAULT_XML_OPTIONS; + import java.io.IOException; import java.io.OutputStream; -import java.util.HashMap; import java.util.Iterator; import java.util.List; -import java.util.Map; import org.apache.poi.POIXMLDocumentPart; import org.apache.poi.xwpf.usermodel.XWPFDocument; @@ -31,7 +31,6 @@ import org.apache.poi.xwpf.usermodel.XWPFHeader; import org.apache.poi.xwpf.usermodel.XWPFHeaderFooter; import org.apache.poi.xwpf.usermodel.XWPFParagraph; import org.apache.poi.xwpf.usermodel.XWPFRelation; -import org.apache.xmlbeans.XmlOptions; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBody; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTHdrFtr; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTHdrFtrRef; @@ -46,18 +45,18 @@ import org.openxmlformats.schemas.wordprocessingml.x2006.main.HdrDocument; import org.openxmlformats.schemas.wordprocessingml.x2006.main.STHdrFtr; import org.openxmlformats.schemas.wordprocessingml.x2006.main.STHdrFtr.Enum; -import schemasMicrosoftComOfficeOffice.CTLock; -import schemasMicrosoftComOfficeOffice.STConnectType; -import schemasMicrosoftComVml.CTFormulas; -import schemasMicrosoftComVml.CTGroup; -import schemasMicrosoftComVml.CTH; -import schemasMicrosoftComVml.CTHandles; -import schemasMicrosoftComVml.CTPath; -import schemasMicrosoftComVml.CTShape; -import schemasMicrosoftComVml.CTShapetype; -import schemasMicrosoftComVml.CTTextPath; -import schemasMicrosoftComVml.STExt; -import schemasMicrosoftComVml.STTrueFalse; +import com.microsoft.schemas.office.office.CTLock; +import com.microsoft.schemas.office.office.STConnectType; +import com.microsoft.schemas.vml.CTFormulas; +import com.microsoft.schemas.vml.CTGroup; +import com.microsoft.schemas.vml.CTH; +import com.microsoft.schemas.vml.CTHandles; +import com.microsoft.schemas.vml.CTPath; +import com.microsoft.schemas.vml.CTShape; +import com.microsoft.schemas.vml.CTShapetype; +import com.microsoft.schemas.vml.CTTextPath; +import com.microsoft.schemas.vml.STExt; +import com.microsoft.schemas.vml.STTrueFalse; /** * A .docx file can have no headers/footers, the same header/footer @@ -176,10 +175,8 @@ public class XWPFHeaderFooterPolicy { OutputStream outputStream = wrapper.getPackagePart().getOutputStream(); hdrDoc.setHdr(hdr); - XmlOptions xmlOptions = commit(wrapper); - assignHeader(wrapper, type); - hdrDoc.save(outputStream, xmlOptions); + hdrDoc.save(outputStream, DEFAULT_XML_OPTIONS); outputStream.close(); return wrapper; @@ -213,10 +210,8 @@ public class XWPFHeaderFooterPolicy { OutputStream outputStream = wrapper.getPackagePart().getOutputStream(); ftrDoc.setFtr(ftr); - XmlOptions xmlOptions = commit(wrapper); - assignFooter(wrapper, type); - ftrDoc.save(outputStream, xmlOptions); + ftrDoc.save(outputStream, DEFAULT_XML_OPTIONS); outputStream.close(); return wrapper; } @@ -299,22 +294,6 @@ public class XWPFHeaderFooterPolicy { } - private XmlOptions commit(XWPFHeaderFooter wrapper) { - XmlOptions xmlOptions = new XmlOptions(POIXMLDocumentPart.DEFAULT_XML_OPTIONS); - Map map = new HashMap(); - map.put("http://schemas.openxmlformats.org/officeDocument/2006/math", "m"); - map.put("urn:schemas-microsoft-com:office:office", "o"); - map.put("http://schemas.openxmlformats.org/officeDocument/2006/relationships", "r"); - map.put("urn:schemas-microsoft-com:vml", "v"); - map.put("http://schemas.openxmlformats.org/markup-compatibility/2006", "ve"); - map.put("http://schemas.openxmlformats.org/wordprocessingml/2006/main", "w"); - map.put("urn:schemas-microsoft-com:office:word", "w10"); - map.put("http://schemas.microsoft.com/office/word/2006/wordml", "wne"); - map.put("http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing", "wp"); - xmlOptions.setSaveSuggestedPrefixes(map); - return xmlOptions; - } - public XWPFHeader getFirstPageHeader() { return firstPageHeader; } diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java index da99997215..b22af706ca 100644 --- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java +++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java @@ -16,6 +16,8 @@ ==================================================================== */ package org.apache.poi.xwpf.usermodel; +import static org.apache.poi.POIXMLTypeLoader.DEFAULT_XML_OPTIONS; + import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; @@ -155,7 +157,7 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody { @Override protected void onDocumentRead() throws IOException { try { - DocumentDocument doc = DocumentDocument.Factory.parse(getPackagePart().getInputStream(), POIXMLDocumentPart.DEFAULT_XML_OPTIONS); + DocumentDocument doc = DocumentDocument.Factory.parse(getPackagePart().getInputStream(), DEFAULT_XML_OPTIONS); ctDocument = doc.getDocument(); initFootnotes(); @@ -205,7 +207,7 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody { header.onDocumentRead(); } else if (relation.equals(XWPFRelation.COMMENT.getRelation())) { // TODO Create according XWPFComment class, extending POIXMLDocumentPart - CommentsDocument cmntdoc = CommentsDocument.Factory.parse(p.getPackagePart().getInputStream(), POIXMLDocumentPart.DEFAULT_XML_OPTIONS); + CommentsDocument cmntdoc = CommentsDocument.Factory.parse(p.getPackagePart().getInputStream(), DEFAULT_XML_OPTIONS); for (CTComment ctcomment : cmntdoc.getComments().getCommentArray()) { comments.add(new XWPFComment(ctcomment, this)); } @@ -258,7 +260,7 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody { this.footnotes = (XWPFFootnotes) p; this.footnotes.onDocumentRead(); } else if (relation.equals(XWPFRelation.ENDNOTE.getRelation())) { - EndnotesDocument endnotesDocument = EndnotesDocument.Factory.parse(p.getPackagePart().getInputStream(), POIXMLDocumentPart.DEFAULT_XML_OPTIONS); + EndnotesDocument endnotesDocument = EndnotesDocument.Factory.parse(p.getPackagePart().getInputStream(), DEFAULT_XML_OPTIONS); for (CTFtnEdn ctFtnEdn : endnotesDocument.getEndnotes().getEndnoteArray()) { endnotes.put(ctFtnEdn.getId().intValue(), new XWPFFootnote(this, ctFtnEdn)); @@ -448,7 +450,7 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody { throw new IllegalStateException("Expecting one Styles document part, but found " + parts.length); } - StylesDocument sd = StylesDocument.Factory.parse(parts[0].getInputStream(), POIXMLDocumentPart.DEFAULT_XML_OPTIONS); + StylesDocument sd = StylesDocument.Factory.parse(parts[0].getInputStream(), DEFAULT_XML_OPTIONS); return sd.getStyles(); } @@ -704,17 +706,6 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody { protected void commit() throws IOException { XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS); xmlOptions.setSaveSyntheticDocumentElement(new QName(CTDocument1.type.getName().getNamespaceURI(), "document")); - Map map = new HashMap(); - map.put("http://schemas.openxmlformats.org/officeDocument/2006/math", "m"); - map.put("urn:schemas-microsoft-com:office:office", "o"); - map.put("http://schemas.openxmlformats.org/officeDocument/2006/relationships", "r"); - map.put("urn:schemas-microsoft-com:vml", "v"); - map.put("http://schemas.openxmlformats.org/markup-compatibility/2006", "ve"); - map.put("http://schemas.openxmlformats.org/wordprocessingml/2006/main", "w"); - map.put("urn:schemas-microsoft-com:office:word", "w10"); - map.put("http://schemas.microsoft.com/office/word/2006/wordml", "wne"); - map.put("http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing", "wp"); - xmlOptions.setSaveSuggestedPrefixes(map); PackagePart part = getPackagePart(); OutputStream out = part.getOutputStream(); diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFFooter.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFFooter.java index eaf28e319e..8268ff6505 100644 --- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFFooter.java +++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFFooter.java @@ -16,11 +16,11 @@ ==================================================================== */ package org.apache.poi.xwpf.usermodel; +import static org.apache.poi.POIXMLTypeLoader.DEFAULT_XML_OPTIONS; + import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import java.util.HashMap; -import java.util.Map; import javax.xml.namespace.QName; @@ -28,7 +28,6 @@ import org.apache.poi.POIXMLDocumentPart; import org.apache.poi.POIXMLException; import org.apache.poi.openxml4j.opc.PackagePart; import org.apache.poi.openxml4j.opc.PackageRelationship; -import org.apache.poi.util.DocumentHelper; import org.apache.xmlbeans.XmlCursor; import org.apache.xmlbeans.XmlObject; import org.apache.xmlbeans.XmlOptions; @@ -79,17 +78,6 @@ public class XWPFFooter extends XWPFHeaderFooter { protected void commit() throws IOException { XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS); xmlOptions.setSaveSyntheticDocumentElement(new QName(CTNumbering.type.getName().getNamespaceURI(), "ftr")); - Map map = new HashMap(); - map.put("http://schemas.openxmlformats.org/markup-compatibility/2006", "ve"); - map.put("urn:schemas-microsoft-com:office:office", "o"); - map.put("http://schemas.openxmlformats.org/officeDocument/2006/relationships", "r"); - map.put("http://schemas.openxmlformats.org/officeDocument/2006/math", "m"); - map.put("urn:schemas-microsoft-com:vml", "v"); - map.put("http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing", "wp"); - map.put("urn:schemas-microsoft-com:office:word", "w10"); - map.put("http://schemas.openxmlformats.org/wordprocessingml/2006/main", "w"); - map.put("http://schemas.microsoft.com/office/word/2006/wordml", "wne"); - xmlOptions.setSaveSuggestedPrefixes(map); PackagePart part = getPackagePart(); OutputStream out = part.getOutputStream(); super._getHdrFtr().save(out, xmlOptions); @@ -103,7 +91,7 @@ public class XWPFFooter extends XWPFHeaderFooter { InputStream is; try { is = getPackagePart().getInputStream(); - ftrDocument = FtrDocument.Factory.parse(is, POIXMLDocumentPart.DEFAULT_XML_OPTIONS); + ftrDocument = FtrDocument.Factory.parse(is, DEFAULT_XML_OPTIONS); headerFooter = ftrDocument.getFtr(); // parse the document with cursor and add // the XmlObject to its lists diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFFootnotes.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFFootnotes.java index ecdf71d791..c97ccd4507 100644 --- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFFootnotes.java +++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFFootnotes.java @@ -17,13 +17,13 @@ package org.apache.poi.xwpf.usermodel; +import static org.apache.poi.POIXMLTypeLoader.DEFAULT_XML_OPTIONS; + import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; import javax.xml.namespace.QName; @@ -32,11 +32,10 @@ import org.apache.poi.POIXMLException; import org.apache.poi.openxml4j.exceptions.OpenXML4JException; import org.apache.poi.openxml4j.opc.PackagePart; import org.apache.poi.openxml4j.opc.PackageRelationship; -import org.apache.poi.util.DocumentHelper; -import org.apache.xmlbeans.XmlException; -import org.apache.xmlbeans.XmlOptions; -import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTFootnotes; -import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTFtnEdn; +import org.apache.xmlbeans.XmlException; +import org.apache.xmlbeans.XmlOptions; +import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTFootnotes; +import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTFtnEdn; import org.openxmlformats.schemas.wordprocessingml.x2006.main.FootnotesDocument; /** @@ -72,7 +71,7 @@ public class XWPFFootnotes extends POIXMLDocumentPart { FootnotesDocument notesDoc; try { InputStream is = getPackagePart().getInputStream(); - notesDoc = FootnotesDocument.Factory.parse(is, POIXMLDocumentPart.DEFAULT_XML_OPTIONS); + notesDoc = FootnotesDocument.Factory.parse(is, DEFAULT_XML_OPTIONS); ctFootnotes = notesDoc.getFootnotes(); } catch (XmlException e) { throw new POIXMLException(); @@ -88,10 +87,6 @@ public class XWPFFootnotes extends POIXMLDocumentPart { protected void commit() throws IOException { XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS); xmlOptions.setSaveSyntheticDocumentElement(new QName(CTFootnotes.type.getName().getNamespaceURI(), "footnotes")); - Map map = new HashMap(); - map.put("http://schemas.openxmlformats.org/officeDocument/2006/relationships", "r"); - map.put("http://schemas.openxmlformats.org/wordprocessingml/2006/main", "w"); - xmlOptions.setSaveSuggestedPrefixes(map); PackagePart part = getPackagePart(); OutputStream out = part.getOutputStream(); ctFootnotes.save(out, xmlOptions); diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFHeader.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFHeader.java index ccba7a00da..0215727897 100644 --- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFHeader.java +++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFHeader.java @@ -16,11 +16,11 @@ ==================================================================== */ package org.apache.poi.xwpf.usermodel; +import static org.apache.poi.POIXMLTypeLoader.DEFAULT_XML_OPTIONS; + import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import java.util.HashMap; -import java.util.Map; import javax.xml.namespace.QName; @@ -28,7 +28,6 @@ import org.apache.poi.POIXMLDocumentPart; import org.apache.poi.POIXMLException; import org.apache.poi.openxml4j.opc.PackagePart; import org.apache.poi.openxml4j.opc.PackageRelationship; -import org.apache.poi.util.DocumentHelper; import org.apache.xmlbeans.XmlCursor; import org.apache.xmlbeans.XmlException; import org.apache.xmlbeans.XmlObject; @@ -77,17 +76,6 @@ public class XWPFHeader extends XWPFHeaderFooter { protected void commit() throws IOException { XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS); xmlOptions.setSaveSyntheticDocumentElement(new QName(CTNumbering.type.getName().getNamespaceURI(), "hdr")); - Map map = new HashMap(); - map.put("http://schemas.openxmlformats.org/markup-compatibility/2006", "ve"); - map.put("urn:schemas-microsoft-com:office:office", "o"); - map.put("http://schemas.openxmlformats.org/officeDocument/2006/relationships", "r"); - map.put("http://schemas.openxmlformats.org/officeDocument/2006/math", "m"); - map.put("urn:schemas-microsoft-com:vml", "v"); - map.put("http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing", "wp"); - map.put("urn:schemas-microsoft-com:office:word", "w10"); - map.put("http://schemas.openxmlformats.org/wordprocessingml/2006/main", "w"); - map.put("http://schemas.microsoft.com/office/word/2006/wordml", "wne"); - xmlOptions.setSaveSuggestedPrefixes(map); PackagePart part = getPackagePart(); OutputStream out = part.getOutputStream(); super._getHdrFtr().save(out, xmlOptions); @@ -106,7 +94,7 @@ public class XWPFHeader extends XWPFHeaderFooter { InputStream is; try { is = getPackagePart().getInputStream(); - hdrDocument = HdrDocument.Factory.parse(is, POIXMLDocumentPart.DEFAULT_XML_OPTIONS); + hdrDocument = HdrDocument.Factory.parse(is, DEFAULT_XML_OPTIONS); headerFooter = hdrDocument.getHdr(); // parse the document with cursor and add // the XmlObject to its lists diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFNumbering.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFNumbering.java index a2f03de09f..7059df9e27 100644 --- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFNumbering.java +++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFNumbering.java @@ -16,14 +16,14 @@ ==================================================================== */ package org.apache.poi.xwpf.usermodel; +import static org.apache.poi.POIXMLTypeLoader.DEFAULT_XML_OPTIONS; + import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.math.BigInteger; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; import javax.xml.namespace.QName; @@ -32,7 +32,6 @@ import org.apache.poi.POIXMLException; import org.apache.poi.openxml4j.exceptions.OpenXML4JException; import org.apache.poi.openxml4j.opc.PackagePart; import org.apache.poi.openxml4j.opc.PackageRelationship; -import org.apache.poi.util.DocumentHelper; import org.apache.xmlbeans.XmlException; import org.apache.xmlbeans.XmlOptions; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTAbstractNum; @@ -76,7 +75,7 @@ public class XWPFNumbering extends POIXMLDocumentPart { InputStream is; is = getPackagePart().getInputStream(); try { - numberingDoc = NumberingDocument.Factory.parse(is, POIXMLDocumentPart.DEFAULT_XML_OPTIONS); + numberingDoc = NumberingDocument.Factory.parse(is, DEFAULT_XML_OPTIONS); ctNumbering = numberingDoc.getNumbering(); //get any Nums for (CTNum ctNum : ctNumbering.getNumArray()) { @@ -98,17 +97,6 @@ public class XWPFNumbering extends POIXMLDocumentPart { protected void commit() throws IOException { XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS); xmlOptions.setSaveSyntheticDocumentElement(new QName(CTNumbering.type.getName().getNamespaceURI(), "numbering")); - Map map = new HashMap(); - map.put("http://schemas.openxmlformats.org/markup-compatibility/2006", "ve"); - map.put("urn:schemas-microsoft-com:office:office", "o"); - map.put("http://schemas.openxmlformats.org/officeDocument/2006/relationships", "r"); - map.put("http://schemas.openxmlformats.org/officeDocument/2006/math", "m"); - map.put("urn:schemas-microsoft-com:vml", "v"); - map.put("http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing", "wp"); - map.put("urn:schemas-microsoft-com:office:word", "w10"); - map.put("http://schemas.openxmlformats.org/wordprocessingml/2006/main", "w"); - map.put("http://schemas.microsoft.com/office/word/2006/wordml", "wne"); - xmlOptions.setSaveSuggestedPrefixes(map); PackagePart part = getPackagePart(); OutputStream out = part.getOutputStream(); ctNumbering.save(out, xmlOptions); diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java index 860aff25e0..99f63609e9 100644 --- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java +++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java @@ -16,6 +16,8 @@ ==================================================================== */ package org.apache.poi.xwpf.usermodel; +import static org.apache.poi.POIXMLTypeLoader.DEFAULT_XML_OPTIONS; + import java.io.IOException; import java.io.InputStream; import java.math.BigInteger; @@ -25,7 +27,6 @@ import java.util.List; import javax.xml.namespace.QName; -import org.apache.poi.POIXMLDocumentPart; import org.apache.poi.POIXMLException; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.util.Internal; @@ -177,7 +178,7 @@ public class XWPFRun implements ISDTContents, IRunElement, CharacterRun { if (pict instanceof XmlAnyTypeImpl) { // Pesky XmlBeans bug - see Bugzilla #49934 try { - pict = CTPicture.Factory.parse(pict.toString(), POIXMLDocumentPart.DEFAULT_XML_OPTIONS); + pict = CTPicture.Factory.parse(pict.toString(), DEFAULT_XML_OPTIONS); } catch (XmlException e) { throw new POIXMLException(e); } @@ -958,7 +959,7 @@ public class XWPFRun implements ISDTContents, IRunElement, CharacterRun { "" + "" + ""; - inline.set(XmlToken.Factory.parse(xml, POIXMLDocumentPart.DEFAULT_XML_OPTIONS)); + inline.set(XmlToken.Factory.parse(xml, DEFAULT_XML_OPTIONS)); // Setup the inline inline.setDistT(0); diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFSettings.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFSettings.java index 1dbc295875..66408c448f 100644 --- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFSettings.java +++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFSettings.java @@ -16,14 +16,14 @@ ==================================================================== */ package org.apache.poi.xwpf.usermodel; +import static org.apache.poi.POIXMLTypeLoader.DEFAULT_XML_OPTIONS; + import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.math.BigInteger; import java.security.SecureRandom; import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; import javax.xml.namespace.QName; @@ -33,7 +33,6 @@ import org.apache.poi.openxml4j.opc.PackagePart; import org.apache.poi.openxml4j.opc.PackageRelationship; import org.apache.poi.poifs.crypt.CryptoFunctions; import org.apache.poi.poifs.crypt.HashAlgorithm; -import org.apache.poi.util.DocumentHelper; import org.apache.xmlbeans.XmlOptions; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTDocProtect; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTOnOff; @@ -383,9 +382,6 @@ public class XWPFSettings extends POIXMLDocumentPart { XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS); xmlOptions.setSaveSyntheticDocumentElement(new QName(CTSettings.type.getName().getNamespaceURI(), "settings")); - Map map = new HashMap(); - map.put("http://schemas.openxmlformats.org/wordprocessingml/2006/main", "w"); - xmlOptions.setSaveSuggestedPrefixes(map); PackagePart part = getPackagePart(); OutputStream out = part.getOutputStream(); @@ -404,7 +400,7 @@ public class XWPFSettings extends POIXMLDocumentPart { private void readFrom(InputStream inputStream) { try { - ctSettings = SettingsDocument.Factory.parse(inputStream, POIXMLDocumentPart.DEFAULT_XML_OPTIONS).getSettings(); + ctSettings = SettingsDocument.Factory.parse(inputStream, DEFAULT_XML_OPTIONS).getSettings(); } catch (Exception e) { throw new RuntimeException(e); } diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFStyles.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFStyles.java index 3be62b6717..d9632926b2 100644 --- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFStyles.java +++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFStyles.java @@ -17,13 +17,13 @@ package org.apache.poi.xwpf.usermodel; +import static org.apache.poi.POIXMLTypeLoader.DEFAULT_XML_OPTIONS; + import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; import javax.xml.namespace.QName; @@ -32,17 +32,16 @@ import org.apache.poi.POIXMLException; import org.apache.poi.openxml4j.exceptions.OpenXML4JException; import org.apache.poi.openxml4j.opc.PackagePart; import org.apache.poi.openxml4j.opc.PackageRelationship; -import org.apache.poi.util.DocumentHelper; -import org.apache.xmlbeans.XmlException; -import org.apache.xmlbeans.XmlOptions; -import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTDocDefaults; -import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTFonts; -import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTLanguage; -import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPPrDefault; -import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRPr; -import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRPrDefault; -import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTStyle; -import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTStyles; +import org.apache.xmlbeans.XmlException; +import org.apache.xmlbeans.XmlOptions; +import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTDocDefaults; +import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTFonts; +import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTLanguage; +import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPPrDefault; +import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRPr; +import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRPrDefault; +import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTStyle; +import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTStyles; import org.openxmlformats.schemas.wordprocessingml.x2006.main.StylesDocument; /** @@ -83,7 +82,7 @@ public class XWPFStyles extends POIXMLDocumentPart { StylesDocument stylesDoc; try { InputStream is = getPackagePart().getInputStream(); - stylesDoc = StylesDocument.Factory.parse(is, POIXMLDocumentPart.DEFAULT_XML_OPTIONS); + stylesDoc = StylesDocument.Factory.parse(is, DEFAULT_XML_OPTIONS); setStyles(stylesDoc.getStyles()); latentStyles = new XWPFLatentStyles(ctStyles.getLatentStyles(), this); } catch (XmlException e) { @@ -99,10 +98,6 @@ public class XWPFStyles extends POIXMLDocumentPart { XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS); xmlOptions.setSaveSyntheticDocumentElement(new QName(CTStyles.type.getName().getNamespaceURI(), "styles")); - Map map = new HashMap(); - map.put("http://schemas.openxmlformats.org/officeDocument/2006/relationships", "r"); - map.put("http://schemas.openxmlformats.org/wordprocessingml/2006/main", "w"); - xmlOptions.setSaveSuggestedPrefixes(map); PackagePart part = getPackagePart(); OutputStream out = part.getOutputStream(); ctStyles.save(out, xmlOptions); diff --git a/src/ooxml/resources/org/apache/poi/schemas/ooxmlSchemas.xsdconfig b/src/ooxml/resources/org/apache/poi/schemas/ooxmlSchemas.xsdconfig new file mode 100644 index 0000000000..3121e451d7 --- /dev/null +++ b/src/ooxml/resources/org/apache/poi/schemas/ooxmlSchemas.xsdconfig @@ -0,0 +1,42 @@ + + + + + + com.microsoft.schemas.office.office + + + + com.microsoft.schemas.office.excel + + + + com.microsoft.schemas.office.word + + + + com.microsoft.schemas.office.powerpoint + + + + com.microsoft.schemas.vml + + + \ No newline at end of file diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFComment.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFComment.java index f3328d9e6c..0687c4b323 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFComment.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFComment.java @@ -49,7 +49,7 @@ import org.junit.Test; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComment; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRPrElt; -import schemasMicrosoftComVml.CTShape; +import com.microsoft.schemas.vml.CTShape; /** * @author Yegor Kozlov @@ -221,7 +221,7 @@ public final class TestXSSFComment extends BaseTestCellComment { .getSheetAt(0).getCommentsTable(true); XSSFVMLDrawing vml = ((SXSSFWorkbook) wb).getXSSFWorkbook() .getSheetAt(0).getVMLDrawing(true); - schemasMicrosoftComVml.CTShape vmlShape1 = vml.newCommentShape(); + CTShape vmlShape1 = vml.newCommentShape(); if (ca.isSet()) { String position = ca.getCol1() + ", 0, " + ca.getRow1() + ", 0, " + ca.getCol2() + ", 0, " + ca.getRow2() @@ -235,7 +235,7 @@ public final class TestXSSFComment extends BaseTestCellComment { shape1.setColumn(ca.getCol1()); shape1.setRow(ca.getRow1()); - schemasMicrosoftComVml.CTShape vmlShape2 = vml.newCommentShape(); + CTShape vmlShape2 = vml.newCommentShape(); if (ca.isSet()) { String position = ca.getCol1() + ", 0, " + ca.getRow1() + ", 0, " + ca.getCol2() + ", 0, " + ca.getRow2() diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFVMLDrawing.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFVMLDrawing.java index 5bb3acd0fb..3b3d88b66f 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFVMLDrawing.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFVMLDrawing.java @@ -16,23 +16,27 @@ ==================================================================== */ package org.apache.poi.xssf.usermodel; -import java.io.ByteArrayOutputStream; import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.InputStream; import java.math.BigInteger; import java.util.List; -import junit.framework.TestCase; - import org.apache.poi.POIDataSamples; import org.apache.xmlbeans.XmlObject; -import schemasMicrosoftComVml.*; -import schemasMicrosoftComOfficeOffice.CTShapeLayout; -import schemasMicrosoftComOfficeOffice.STConnectType; -import schemasMicrosoftComOfficeOffice.STInsetMode; -import schemasMicrosoftComOfficeExcel.CTClientData; -import schemasMicrosoftComOfficeExcel.STObjectType; +import com.microsoft.schemas.office.excel.CTClientData; +import com.microsoft.schemas.office.excel.STObjectType; +import com.microsoft.schemas.office.office.CTShapeLayout; +import com.microsoft.schemas.office.office.STConnectType; +import com.microsoft.schemas.office.office.STInsetMode; +import com.microsoft.schemas.vml.CTShadow; +import com.microsoft.schemas.vml.CTShape; +import com.microsoft.schemas.vml.CTShapetype; +import com.microsoft.schemas.vml.STExt; +import com.microsoft.schemas.vml.STTrueFalse; + +import junit.framework.TestCase; /** * @author Yegor Kozlov -- 2.39.5