mirror of https://github.com/apache/poi.git
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
This commit is contained in:
parent
e156c3d691
commit
16b90ce342
|
@ -923,6 +923,22 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody {
|
|||
/**
|
||||
* 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/>
|
||||
* specifies that the protection is enforced (w:enforcement="1") <br/>
|
||||
* and that the kind of protection is readOnly (w:edit="readOnly")<br/>
|
||||
* <br/>
|
||||
* sample snippet from settings.xml
|
||||
|
|
|
@ -124,6 +124,29 @@ public class XWPFSettings extends POIXMLDocumentPart {
|
|||
/**
|
||||
* 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/>
|
||||
* if the protection is enforced (w:enforcement="1") <br/>
|
||||
* and if the kind of protection equals to passed (STDocProtect.Enum editValue) <br/>
|
||||
* <p/>
|
||||
* <br/>
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue