Class ProtectDocument
java.lang.Object
org.docx4j.openpackaging.packages.ProtectionSettings
org.docx4j.openpackaging.packages.ProtectDocument
public class ProtectDocument extends ProtectionSettings
- Author:
- jharrop
-
Field Summary
Fields Modifier and Type Field Description protected static org.slf4j.Logger
log
-
Constructor Summary
Constructors Constructor Description ProtectDocument(WordprocessingMLPackage pkg)
-
Method Summary
Modifier and Type Method Description boolean
isRestrictEditingWith(STDocProtect editValue)
Verifies the documentProtection tag inside settings.xml file if the protection is enforced (w:enforcement="1") and if the kind of protection equals to passed (STDocProtect.Enum editValue)void
removeEnforcement()
Removes protection enforcement.
In the documentProtection tag inside settings.xml file
it sets the value of enforcement to "0" (w:enforcement="0")void
restrictEditing(STDocProtect editValue)
Enforces the protection with the option specified by passed editValue.
In the documentProtection tag inside settings.xml file
it sets the value of enforcement to "1" (w:enforcement="1")
and the value of edit to the passed editValue (w:edit="[passed editValue]")
sample snippet from settings.xmlvoid
restrictEditing(STDocProtect editValue, java.lang.String password)
Enforces the protection with the option specified by passed editValue and password, using rsaFull (sha1) (like Word 2010).void
restrictEditing(STDocProtect editValue, java.lang.String password, HashAlgorithm hashAlgo)
Enforces the protection with the option specified by passed editValue, password, and HashAlgorithm for the password.void
restrictFormatting(java.util.List<java.lang.String> allowedStyleNames, boolean removedNotAllowedFormatting, boolean autoFormatOverride, boolean styleLockTheme, boolean styleLockQFSet)
Restrict allowed formatting to specified styles, no password.void
restrictFormatting(java.util.List<java.lang.String> allowedStyleNames, boolean removedNotAllowedFormatting, boolean autoFormatOverride, boolean styleLockTheme, boolean styleLockQFSet, java.lang.String password)
Restrict allowed formatting to specified styles, password protected.void
restrictFormatting(java.util.List<java.lang.String> allowedStyleNames, boolean removedNotAllowedFormatting, boolean autoFormatOverride, boolean styleLockTheme, boolean styleLockQFSet, java.lang.String password, HashAlgorithm hashAlgo)
Restrict allowed formatting to specified styles.boolean
validateProtectionPassword(java.lang.String password)
Validates the existing passwordMethods inherited from class org.docx4j.openpackaging.packages.ProtectionSettings
getMarkAsFinal, getSignatureHelper, setDocSecurity, setMarkAsFinal
-
Field Details
-
log
protected static org.slf4j.Logger log
-
-
Constructor Details
-
Method Details
-
restrictFormatting
public void restrictFormatting(java.util.List<java.lang.String> allowedStyleNames, boolean removedNotAllowedFormatting, boolean autoFormatOverride, boolean styleLockTheme, boolean styleLockQFSet) throws Docx4JExceptionRestrict allowed formatting to specified styles, no password.- Parameters:
allowedStyleNames
-removedNotAllowedFormatting
- whether existing usages of styles which aren't allowed are removedautoFormatOverride
-styleLockTheme
-styleLockQFSet
-- Throws:
Docx4JException
- Since:
- 3.3.0
-
restrictFormatting
public void restrictFormatting(java.util.List<java.lang.String> allowedStyleNames, boolean removedNotAllowedFormatting, boolean autoFormatOverride, boolean styleLockTheme, boolean styleLockQFSet, java.lang.String password) throws Docx4JExceptionRestrict allowed formatting to specified styles, password protected. Defaults to sha1.- Parameters:
allowedStyleNames
-removedNotAllowedFormatting
- whether existing usages of styles which aren't allowed are removedautoFormatOverride
-styleLockTheme
-styleLockQFSet
-password
-- Throws:
Docx4JException
- Since:
- 3.3.0
-
restrictFormatting
public void restrictFormatting(java.util.List<java.lang.String> allowedStyleNames, boolean removedNotAllowedFormatting, boolean autoFormatOverride, boolean styleLockTheme, boolean styleLockQFSet, java.lang.String password, HashAlgorithm hashAlgo) throws Docx4JExceptionRestrict allowed formatting to specified styles. Specify password and HashAlgorithm- Parameters:
allowedStyleNames
-removedNotAllowedFormatting
- whether existing usages of styles which aren't allowed are removedautoFormatOverride
-styleLockTheme
-styleLockQFSet
-password
-hashAlgo
-- Throws:
Docx4JException
- Since:
- 3.3.0
-
isRestrictEditingWith
Verifies the documentProtection tag inside settings.xml file if the protection is enforced (w:enforcement="1") and if the kind of protection equals to passed (STDocProtect.Enum editValue)- Returns:
- true if documentProtection is enforced with option readOnly
- Since:
- 3.3.0
-
restrictEditing
Enforces the protection with the option specified by passed editValue.
In the documentProtection tag inside settings.xml file
it sets the value of enforcement to "1" (w:enforcement="1")
and the value of edit to the passed editValue (w:edit="[passed editValue]")
sample snippet from settings.xml<w:settings ... > <w:documentProtection w:edit="[passed editValue]" w:enforcement="1"/>
- Since:
- 3.3.0
-
restrictEditing
Enforces the protection with the option specified by passed editValue and password, using rsaFull (sha1) (like Word 2010). WARNING: this functionality may give a false sense of security, since it only affects the behaviour of Word's user interface. A mischevious user could still edit the document in some other program, and subsequent users would *not* be warned it has been tampered with.- Parameters:
editValue
- the protection typepassword
- the plaintext password, if null no password will be appliedhashAlgo
- the hash algorithm - only md2, m5, sha1, sha256, sha384 and sha512 are supported. if null, it will default default to sha512 (like Word 2013)- Since:
- 3.3.0
-
restrictEditing
public void restrictEditing(STDocProtect editValue, java.lang.String password, HashAlgorithm hashAlgo)Enforces the protection with the option specified by passed editValue, password, and HashAlgorithm for the password.- Parameters:
editValue
- the protection typepassword
- the plaintext password, if null no password will be appliedhashAlgo
- the hash algorithm - only md2, m5, sha1, sha256, sha384 and sha512 are supported. if null, it will default default to sha512 (like Word 2013)- Since:
- 3.3.0
-
validateProtectionPassword
public boolean validateProtectionPassword(java.lang.String password)Validates the existing password- Parameters:
password
-- Returns:
- true, only if password was set and equals, false otherwise
- Since:
- 3.3.0
-
removeEnforcement
public void removeEnforcement()Removes protection enforcement.
In the documentProtection tag inside settings.xml file
it sets the value of enforcement to "0" (w:enforcement="0")- Since:
- 3.3.0
-