Class ProtectDocument

java.lang.Object
org.docx4j.openpackaging.packages.ProtectionSettings
org.docx4j.openpackaging.packages.ProtectDocument

public class ProtectDocument extends ProtectionSettings
  • Field Details

    • log

      protected static org.slf4j.Logger log
  • Constructor Details

  • Method Details

    • getPkg

      private WordprocessingMLPackage getPkg()
    • restrictFormatting

      public void restrictFormatting(List<String> allowedStyleNames, boolean removedNotAllowedFormatting, boolean autoFormatOverride, boolean styleLockTheme, boolean styleLockQFSet) throws Docx4JException
      Restrict allowed formatting to specified styles, no password.
      Parameters:
      allowedStyleNames -
      removedNotAllowedFormatting - whether existing usages of styles which aren't allowed are removed
      autoFormatOverride -
      styleLockTheme -
      styleLockQFSet -
      Throws:
      Docx4JException
      Since:
      3.3.0
    • restrictFormatting

      public void restrictFormatting(List<String> allowedStyleNames, boolean removedNotAllowedFormatting, boolean autoFormatOverride, boolean styleLockTheme, boolean styleLockQFSet, String password) throws Docx4JException
      Restrict allowed formatting to specified styles, password protected. Defaults to sha1.
      Parameters:
      allowedStyleNames -
      removedNotAllowedFormatting - whether existing usages of styles which aren't allowed are removed
      autoFormatOverride -
      styleLockTheme -
      styleLockQFSet -
      password -
      Throws:
      Docx4JException
      Since:
      3.3.0
    • restrictFormatting

      public void restrictFormatting(List<String> allowedStyleNames, boolean removedNotAllowedFormatting, boolean autoFormatOverride, boolean styleLockTheme, boolean styleLockQFSet, String password, HashAlgorithm hashAlgo) throws Docx4JException
      Restrict allowed formatting to specified styles. Specify password and HashAlgorithm
      Parameters:
      allowedStyleNames -
      removedNotAllowedFormatting - whether existing usages of styles which aren't allowed are removed
      autoFormatOverride -
      styleLockTheme -
      styleLockQFSet -
      password -
      hashAlgo -
      Throws:
      Docx4JException
      Since:
      3.3.0
    • isRestrictEditingWith

      public 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)
      Returns:
      true if documentProtection is enforced with option readOnly
      Since:
      3.3.0
    • restrictEditing

      public 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.xml
           <w:settings  ... >
               <w:documentProtection w:edit="[passed editValue]" w:enforcement="1"/>
       
      Since:
      3.3.0
    • restrictEditing

      public void restrictEditing(STDocProtect editValue, String password)
      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 type
      password - the plaintext password, if null no password will be applied
      hashAlgo - 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, String password, HashAlgorithm hashAlgo)
      Enforces the protection with the option specified by passed editValue, password, and HashAlgorithm for the password.
      Parameters:
      editValue - the protection type
      password - the plaintext password, if null no password will be applied
      hashAlgo - 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(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