public class DocumentSecurity
extends java.lang.Object
BuiltInDocumentProperties.getSecurity() / BuiltInDocumentProperties.setSecurity(int) property. Specifies the security level of a document as a numeric value.
Examples:
Shows how to use document properties to display the security level of a document.
Document doc = new Document();
Assert.assertEquals(DocumentSecurity.NONE, doc.getBuiltInDocumentProperties().getSecurity());
// If we configure a document to be read-only, it will display this status using the "Security" built-in property.
doc.getWriteProtection().setReadOnlyRecommended(true);
doc.save(getArtifactsDir() + "DocumentProperties.Security.ReadOnlyRecommended.docx");
Assert.assertEquals(DocumentSecurity.READ_ONLY_RECOMMENDED,
new Document(getArtifactsDir() + "DocumentProperties.Security.ReadOnlyRecommended.docx").getBuiltInDocumentProperties().getSecurity());
// Write-protect a document, and then verify its security level.
doc = new Document();
Assert.assertFalse(doc.getWriteProtection().isWriteProtected());
doc.getWriteProtection().setPassword("MyPassword");
Assert.assertTrue(doc.getWriteProtection().validatePassword("MyPassword"));
Assert.assertTrue(doc.getWriteProtection().isWriteProtected());
doc.save(getArtifactsDir() + "DocumentProperties.Security.ReadOnlyEnforced.docx");
Assert.assertEquals(DocumentSecurity.READ_ONLY_ENFORCED,
new Document(getArtifactsDir() + "DocumentProperties.Security.ReadOnlyEnforced.docx").getBuiltInDocumentProperties().getSecurity());
// "Security" is a descriptive property. We can edit its value manually.
doc = new Document();
doc.protect(ProtectionType.ALLOW_ONLY_COMMENTS, "MyPassword");
doc.getBuiltInDocumentProperties().setSecurity(DocumentSecurity.READ_ONLY_EXCEPT_ANNOTATIONS);
doc.save(getArtifactsDir() + "DocumentProperties.Security.ReadOnlyExceptAnnotations.docx");
Assert.assertEquals(DocumentSecurity.READ_ONLY_EXCEPT_ANNOTATIONS,
new Document(getArtifactsDir() + "DocumentProperties.Security.ReadOnlyExceptAnnotations.docx").getBuiltInDocumentProperties().getSecurity());
| Modifier and Type | Field and Description |
|---|---|
static int |
length |
static int |
NONE
There are no security states specified by the property.
|
static int |
PASSWORD_PROTECTED
The document is password protected.
|
static int |
READ_ONLY_ENFORCED
The document to always be opened read-only.
|
static int |
READ_ONLY_EXCEPT_ANNOTATIONS
The document to always be opened read-only except for annotations.
|
static int |
READ_ONLY_RECOMMENDED
The document to be opened read-only if possible, but the setting can be overridden.
|
| Modifier and Type | Method and Description |
|---|---|
static int |
fromName(java.lang.String documentSecurityName) |
static int |
fromNames(java.util.Set documentSecurityNames) |
static java.lang.String |
getName(int documentSecurity) |
static java.util.Set |
getNames(int documentSecurity) |
static int[] |
getValues() |
static java.lang.String |
toString(int documentSecurity) |
static java.lang.String |
toStringSet(int attr) |
public static int NONE
public static int PASSWORD_PROTECTED
public static int READ_ONLY_RECOMMENDED
public static int READ_ONLY_ENFORCED
public static int READ_ONLY_EXCEPT_ANNOTATIONS
public static int length
public static java.lang.String getName(int documentSecurity)
public static java.util.Set getNames(int documentSecurity)
public static java.lang.String toString(int documentSecurity)
public static java.lang.String toStringSet(int attr)
public static int fromName(java.lang.String documentSecurityName)
public static int fromNames(java.util.Set documentSecurityNames)
public static int[] getValues()