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:
Dominik Stadler 2016-02-15 09:26:51 +00:00
parent 98da5af350
commit 677b19afbd
4 changed files with 46 additions and 0 deletions

View File

@ -919,6 +919,22 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody {
tables.set(pos, table); tables.set(pos, table);
ctDocument.getBody().setTblArray(pos, table.getCTTbl()); 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/> * Verifies that the documentProtection tag in settings.xml file <br/>

View File

@ -120,6 +120,29 @@ public class XWPFSettings extends POIXMLDocumentPart {
CTZoom zoom = ctSettings.getZoom(); CTZoom zoom = ctSettings.getZoom();
zoom.setPercent(BigInteger.valueOf(zoomPercent)); 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/> * Verifies the documentProtection tag inside settings.xml file <br/>

View File

@ -416,4 +416,11 @@ public final class TestXWPFDocument {
doc.close(); doc.close();
} }
@Test
public void testEnforcedWith() throws IOException {
XWPFDocument docx = XWPFTestDataSamples.openSampleDocument("EnforcedWith.docx");
assertTrue(docx.isEnforcedProtection());
docx.close();
}
} }

Binary file not shown.