add method to test for strict ooxml format

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1886545 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
PJ Fanning 2021-02-15 21:05:57 +00:00
parent 37d2d474dc
commit 0ce6ceb3ea
2 changed files with 24 additions and 0 deletions

View 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?
*/

View 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.
*/