You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ce...@apache.org on 2016/02/15 10:26:51 UTC
svn commit: r1730471 - in /poi/trunk:
src/ooxml/java/org/apache/poi/xwpf/usermodel/
src/ooxml/testcases/org/apache/poi/xwpf/usermodel/ test-data/document/
Author: centic
Date: Mon Feb 15 09:26:51 2016
New Revision: 1730471
URL: http://svn.apache.org/viewvc?rev=1730471&view=rev
Log:
GitHub PR 27: Add method to check for any protection in XWPFDocument, closes #27
Added:
poi/trunk/test-data/document/EnforcedWith.docx (with props)
Modified:
poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java
poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFSettings.java
poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFDocument.java
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java?rev=1730471&r1=1730470&r2=1730471&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java Mon Feb 15 09:26:51 2016
@@ -919,6 +919,22 @@ public class XWPFDocument extends POIXML
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>
+ * <w:settings ... >
+ * <w:documentProtection w:edit="readOnly" w:enforcement="1"/>
+ * </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/>
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFSettings.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFSettings.java?rev=1730471&r1=1730470&r2=1730471&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFSettings.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFSettings.java Mon Feb 15 09:26:51 2016
@@ -120,6 +120,29 @@ public class XWPFSettings extends POIXML
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>
+ * <w:settings ... >
+ * <w:documentProtection w:edit="readOnly" w:enforcement="1"/>
+ * </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/>
Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFDocument.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFDocument.java?rev=1730471&r1=1730470&r2=1730471&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFDocument.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFDocument.java Mon Feb 15 09:26:51 2016
@@ -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();
+ }
}
Added: poi/trunk/test-data/document/EnforcedWith.docx
URL: http://svn.apache.org/viewvc/poi/trunk/test-data/document/EnforcedWith.docx?rev=1730471&view=auto
==============================================================================
Binary file - no diff available.
Propchange: poi/trunk/test-data/document/EnforcedWith.docx
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org