]> source.dussan.org Git - poi.git/commitdiff
add method to test for strict ooxml format
authorPJ Fanning <fanningpj@apache.org>
Mon, 15 Feb 2021 21:05:57 +0000 (21:05 +0000)
committerPJ Fanning <fanningpj@apache.org>
Mon, 15 Feb 2021 21:05:57 +0000 (21:05 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1886545 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java
src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java

index 203d5c18f2155a89998e8666595b205e54312922..ffd764918bd2efc9bd86922fded491e78d612a1f 100644 (file)
@@ -1664,6 +1664,16 @@ public abstract class OPCPackage implements RelationshipSource, Closeable {
         return partList.getUnusedPartIndex(nameTemplate);
     }
 
+       /**
+        * @return true if the package is in Strict OOXML format
+        * @since POI 5.0.1
+        */
+    public boolean isStrictOoxmlFormat() {
+               PackageRelationshipCollection coreDocRelationships = getRelationshipsByType(
+                               PackageRelationshipTypes.STRICT_CORE_DOCUMENT);
+               return coreDocRelationships.size() > 0;
+       }
+
        /**
         * Has close been called already?
         */
index 07e9a17d21691b27b2f4ff29fd48d24408cf7661..0d8b8360c89fe1cfe1c85c2d54698f35a2380d4a 100644 (file)
@@ -103,6 +103,20 @@ public final class TestPackage {
        private static final String CONTENT_EXT_PROPS = "application/vnd.openxmlformats-officedocument.extended-properties+xml";
        private static final POIDataSamples xlsSamples = POIDataSamples.getSpreadSheetInstance();
 
+       @Test
+       void isStrictOoxmlFormat() throws IOException, InvalidFormatException {
+               try (OPCPackage p = OPCPackage.open(getSampleFileName("TestPackageCommon.docx"), PackageAccess.READ)) {
+                       assertFalse(p.isStrictOoxmlFormat());
+               }
+               try (OPCPackage p = OPCPackage.open(xlsSamples.getFile("sample.xlsx"), PackageAccess.READ)) {
+                       assertFalse(p.isStrictOoxmlFormat());
+               }
+               try (OPCPackage p = OPCPackage.open(xlsSamples.getFile("sample.strict.xlsx"), PackageAccess.READ)) {
+                       assertTrue(p.isStrictOoxmlFormat());
+               }
+       }
+
+
        /**
         * Test that just opening and closing the file doesn't alter the document.
         */