mirror of https://github.com/apache/poi.git
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:
parent
37d2d474dc
commit
0ce6ceb3ea
|
@ -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?
|
||||
*/
|
||||
|
|
|
@ -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.
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue