From 16b90ce3423263d0bfc89a14cbdd9820b3e7db6d Mon Sep 17 00:00:00 2001 From: Dominik Stadler Date: Mon, 15 Feb 2016 09:26:51 +0000 Subject: [PATCH] GitHub PR 27: Add method to check for any protection in XWPFDocument, closes #27 git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1730471 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/xwpf/usermodel/XWPFDocument.java | 16 ++++++++++++ .../poi/xwpf/usermodel/XWPFSettings.java | 23 ++++++++++++++++++ .../poi/xwpf/usermodel/TestXWPFDocument.java | 7 ++++++ test-data/document/EnforcedWith.docx | Bin 0 -> 11321 bytes 4 files changed, 46 insertions(+) create mode 100644 test-data/document/EnforcedWith.docx 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 a7cf4dca08..82f545c031 100644 --- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java +++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java @@ -919,6 +919,22 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody { tables.set(pos, table); ctDocument.getBody().setTblArray(pos, table.getCTTbl()); } + + /** + * Verifies that the documentProtection tag in settings.xml file
+ * specifies that the protection is enforced (w:enforcement="1")
+ *
+ * sample snippet from settings.xml + *
+     *     <w:settings  ... >
+     *         <w:documentProtection w:edit="readOnly" w:enforcement="1"/>
+     * 
+ * + * @return true if documentProtection is enforced with option any + */ + public boolean isEnforcedProtection() { + return settings.isEnforcedWith(); + } /** * Verifies that the documentProtection tag in settings.xml file
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 fa4e6401f9..d9d29a3303 100644 --- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFSettings.java +++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFSettings.java @@ -120,6 +120,29 @@ public class XWPFSettings extends POIXMLDocumentPart { CTZoom zoom = ctSettings.getZoom(); zoom.setPercent(BigInteger.valueOf(zoomPercent)); } + + /** + * Verifies the documentProtection tag inside settings.xml file
+ * if the protection is enforced (w:enforcement="1")
+ *

+ *
+ * sample snippet from settings.xml + *

+     *     <w:settings  ... >
+     *         <w:documentProtection w:edit="readOnly" w:enforcement="1"/>
+     * 
+ * + * @return true if documentProtection is enforced with option any + */ + public boolean isEnforcedWith() { + CTDocProtect ctDocProtect = ctSettings.getDocumentProtection(); + + if (ctDocProtect == null) { + return false; + } + + return ctDocProtect.getEnforcement().equals(STOnOff.X_1); + } /** * Verifies the documentProtection tag inside settings.xml file
diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFDocument.java b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFDocument.java index 43d8cce0f9..afa0428b4a 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFDocument.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFDocument.java @@ -416,4 +416,11 @@ public final class TestXWPFDocument { doc.close(); } + + @Test + public void testEnforcedWith() throws IOException { + XWPFDocument docx = XWPFTestDataSamples.openSampleDocument("EnforcedWith.docx"); + assertTrue(docx.isEnforcedProtection()); + docx.close(); + } } diff --git a/test-data/document/EnforcedWith.docx b/test-data/document/EnforcedWith.docx new file mode 100644 index 0000000000000000000000000000000000000000..c50e358591f2b5bf7a1e5f2352d740bacf593926 GIT binary patch literal 11321 zcmeHt1y^0k67Ip>gNNYm?iSqLHE@979$XSMXmEGe;1Jwhg1Zx3gZn$lyt$Lf%zJ;} z-o4h|d$oME`}C>muKKzZWgsA50H6V|004j(u$ntzr40rE5J3R|7ywvs9T8g_Clebd z164OW6GuG;S8FSxY)EjbOaM5j|NpN4;u)xk9kS_ULKVA?yF-bpS2NnpE~Wtw6^N%- z-h;vM09SvE?rVN(#Q;}Q1B-&UA|YqJU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