aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDominik Stadler <centic@apache.org>2016-02-15 09:26:51 +0000
committerDominik Stadler <centic@apache.org>2016-02-15 09:26:51 +0000
commit16b90ce3423263d0bfc89a14cbdd9820b3e7db6d (patch)
treeb2cf77d3f17bf66528595580d358a9ec355f0a5d
parente156c3d6910752dfa6fd10250038da1c08c58530 (diff)
downloadpoi-16b90ce3423263d0bfc89a14cbdd9820b3e7db6d.tar.gz
poi-16b90ce3423263d0bfc89a14cbdd9820b3e7db6d.zip
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
-rw-r--r--src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java16
-rw-r--r--src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFSettings.java23
-rw-r--r--src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFDocument.java7
-rw-r--r--test-data/document/EnforcedWith.docxbin0 -> 11321 bytes
4 files changed, 46 insertions, 0 deletions
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 <br/>
+ * specifies that the protection is enforced (w:enforcement="1") <br/>
+ * <br/>
+ * sample snippet from settings.xml
+ * <pre>
+ * &lt;w:settings ... &gt;
+ * &lt;w:documentProtection w:edit=&quot;readOnly&quot; w:enforcement=&quot;1&quot;/&gt;
+ * </pre>
+ *
+ * @return true if documentProtection is enforced with option any
+ */
+ public boolean isEnforcedProtection() {
+ return settings.isEnforcedWith();
+ }
/**
* Verifies that the documentProtection tag in settings.xml file <br/>
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 <br/>
+ * if the protection is enforced (w:enforcement="1") <br/>
+ * <p/>
+ * <br/>
+ * sample snippet from settings.xml
+ * <pre>
+ * &lt;w:settings ... &gt;
+ * &lt;w:documentProtection w:edit=&quot;readOnly&quot; w:enforcement=&quot;1&quot;/&gt;
+ * </pre>
+ *
+ * @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 <br/>
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 0000000000..c50e358591
--- /dev/null
+++ b/test-data/document/EnforcedWith.docx
Binary files differ