You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PDFEncryptionParams.java 10.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. /* $Id$ */
  18. package org.apache.fop.pdf;
  19. /**
  20. * This class holds the parameters for PDF encryption.
  21. */
  22. public class PDFEncryptionParams {
  23. private String userPassword = ""; //May not be null
  24. private String ownerPassword = ""; //May not be null
  25. private boolean allowPrint = true;
  26. private boolean allowCopyContent = true;
  27. private boolean allowEditContent = true;
  28. private boolean allowEditAnnotations = true;
  29. private boolean allowFillInForms = true;
  30. private boolean allowAccessContent = true;
  31. private boolean allowAssembleDocument = true;
  32. private boolean allowPrintHq = true;
  33. private boolean encryptMetadata = true;
  34. private int encryptionLengthInBits = 128;
  35. /**
  36. * Creates a new instance.
  37. * @param userPassword the user password
  38. * @param ownerPassword the owner password
  39. * @param allowPrint true if printing is allowed
  40. * @param allowCopyContent true if copying content is allowed
  41. * @param allowEditContent true if editing content is allowed
  42. * @param allowEditAnnotations true if editing annotations is allowed
  43. */
  44. public PDFEncryptionParams(String userPassword, String ownerPassword,
  45. boolean allowPrint,
  46. boolean allowCopyContent,
  47. boolean allowEditContent,
  48. boolean allowEditAnnotations,
  49. boolean encryptMetadata) {
  50. setUserPassword(userPassword);
  51. setOwnerPassword(ownerPassword);
  52. setAllowPrint(allowPrint);
  53. setAllowCopyContent(allowCopyContent);
  54. setAllowEditContent(allowEditContent);
  55. setAllowEditAnnotations(allowEditAnnotations);
  56. this.encryptMetadata = encryptMetadata;
  57. }
  58. /**
  59. * Default constructor initializing to default values.
  60. */
  61. public PDFEncryptionParams() {
  62. //nop
  63. }
  64. /**
  65. * Creates a copy of the given encryption parameters.
  66. *
  67. * @param source source encryption parameters
  68. */
  69. public PDFEncryptionParams(PDFEncryptionParams source) {
  70. setUserPassword(source.getUserPassword());
  71. setOwnerPassword(source.getOwnerPassword());
  72. setAllowPrint(source.isAllowPrint());
  73. setAllowCopyContent(source.isAllowCopyContent());
  74. setAllowEditContent(source.isAllowEditContent());
  75. setAllowEditAnnotations(source.isAllowEditAnnotations());
  76. setAllowAssembleDocument(source.isAllowAssembleDocument());
  77. setAllowAccessContent(source.isAllowAccessContent());
  78. setAllowFillInForms(source.isAllowFillInForms());
  79. setAllowPrintHq(source.isAllowPrintHq());
  80. setEncryptionLengthInBits(source.getEncryptionLengthInBits());
  81. encryptMetadata = source.encryptMetadata();
  82. }
  83. /**
  84. * Indicates whether copying content is allowed.
  85. * @return true if copying is allowed
  86. */
  87. public boolean isAllowCopyContent() {
  88. return allowCopyContent;
  89. }
  90. /**
  91. * Indicates whether editing annotations is allowed.
  92. * @return true is editing annotations is allowed
  93. */
  94. public boolean isAllowEditAnnotations() {
  95. return allowEditAnnotations;
  96. }
  97. /**
  98. * Indicates whether editing content is allowed.
  99. * @return true if editing content is allowed
  100. */
  101. public boolean isAllowEditContent() {
  102. return allowEditContent;
  103. }
  104. /**
  105. * Indicates whether printing is allowed.
  106. * @return true if printing is allowed
  107. */
  108. public boolean isAllowPrint() {
  109. return allowPrint;
  110. }
  111. /**
  112. * Indicates whether revision 3 filling in forms is allowed.
  113. * @return true if revision 3 filling in forms is allowed
  114. */
  115. public boolean isAllowFillInForms() {
  116. return allowFillInForms;
  117. }
  118. /**
  119. * Indicates whether revision 3 extracting text and graphics is allowed.
  120. * @return true if revision 3 extracting text and graphics is allowed
  121. */
  122. public boolean isAllowAccessContent() {
  123. return allowAccessContent;
  124. }
  125. /**
  126. * Indicates whether revision 3 assembling document is allowed.
  127. * @return true if revision 3 assembling document is allowed
  128. */
  129. public boolean isAllowAssembleDocument() {
  130. return allowAssembleDocument;
  131. }
  132. /**
  133. * Indicates whether revision 3 printing to high quality is allowed.
  134. * @return true if revision 3 printing to high quality is allowed
  135. */
  136. public boolean isAllowPrintHq() {
  137. return allowPrintHq;
  138. }
  139. /**
  140. * Indicates whether Metadata should be encrypted.
  141. * @return true or false
  142. */
  143. public boolean encryptMetadata() {
  144. return encryptMetadata;
  145. }
  146. /**
  147. * Returns the owner password.
  148. * @return the owner password, an empty string if no password applies
  149. */
  150. public String getOwnerPassword() {
  151. return ownerPassword;
  152. }
  153. /**
  154. * Returns the user password.
  155. * @return the user password, an empty string if no password applies
  156. */
  157. public String getUserPassword() {
  158. return userPassword;
  159. }
  160. /**
  161. * Sets the permission for copying content.
  162. * @param allowCopyContent true if copying content is allowed
  163. */
  164. public void setAllowCopyContent(boolean allowCopyContent) {
  165. this.allowCopyContent = allowCopyContent;
  166. }
  167. /**
  168. * Sets the permission for editing annotations.
  169. * @param allowEditAnnotations true if editing annotations is allowed
  170. */
  171. public void setAllowEditAnnotations(boolean allowEditAnnotations) {
  172. this.allowEditAnnotations = allowEditAnnotations;
  173. }
  174. /**
  175. * Sets the permission for editing content.
  176. * @param allowEditContent true if editing annotations is allowed
  177. */
  178. public void setAllowEditContent(boolean allowEditContent) {
  179. this.allowEditContent = allowEditContent;
  180. }
  181. /**
  182. * Sets the permission for printing.
  183. * @param allowPrint true if printing is allowed
  184. */
  185. public void setAllowPrint(boolean allowPrint) {
  186. this.allowPrint = allowPrint;
  187. }
  188. /**
  189. * Sets whether revision 3 filling in forms is allowed.
  190. * @param allowFillInForms true if revision 3 filling in forms is allowed.
  191. */
  192. public void setAllowFillInForms(boolean allowFillInForms) {
  193. this.allowFillInForms = allowFillInForms;
  194. }
  195. /**
  196. * Sets whether revision 3 extracting text and graphics is allowed.
  197. * @param allowAccessContent true if revision 3 extracting text and graphics is allowed
  198. */
  199. public void setAllowAccessContent(boolean allowAccessContent) {
  200. this.allowAccessContent = allowAccessContent;
  201. }
  202. /**
  203. * Sets whether revision 3 assembling document is allowed.
  204. * @param allowAssembleDocument true if revision 3 assembling document is allowed
  205. */
  206. public void setAllowAssembleDocument(boolean allowAssembleDocument) {
  207. this.allowAssembleDocument = allowAssembleDocument;
  208. }
  209. /**
  210. * Sets whether revision 3 printing to high quality is allowed.
  211. * @param allowPrintHq true if revision 3 printing to high quality is allowed
  212. */
  213. public void setAllowPrintHq(boolean allowPrintHq) {
  214. this.allowPrintHq = allowPrintHq;
  215. }
  216. /**
  217. * Whether the Metadata should be encrypted or not; default is true;
  218. * @param encryptMetadata true or false
  219. */
  220. public void setEncryptMetadata(boolean encryptMetadata) {
  221. this.encryptMetadata = encryptMetadata;
  222. }
  223. /**
  224. * Sets the owner password.
  225. * @param ownerPassword The owner password to set, null or an empty String
  226. * if no password is applicable
  227. */
  228. public void setOwnerPassword(String ownerPassword) {
  229. if (ownerPassword == null) {
  230. this.ownerPassword = "";
  231. } else {
  232. this.ownerPassword = ownerPassword;
  233. }
  234. }
  235. /**
  236. * Sets the user password.
  237. * @param userPassword The user password to set, null or an empty String
  238. * if no password is applicable
  239. */
  240. public void setUserPassword(String userPassword) {
  241. if (userPassword == null) {
  242. this.userPassword = "";
  243. } else {
  244. this.userPassword = userPassword;
  245. }
  246. }
  247. /**
  248. * Returns the encryption length.
  249. * @return the encryption length
  250. */
  251. public int getEncryptionLengthInBits() {
  252. return encryptionLengthInBits;
  253. }
  254. /**
  255. * Sets the encryption length.
  256. *
  257. * @param encryptionLength the encryption length
  258. */
  259. public void setEncryptionLengthInBits(int encryptionLength) {
  260. this.encryptionLengthInBits = encryptionLength;
  261. }
  262. public String toString() {
  263. return "userPassword = " + userPassword + "\n"
  264. + "ownerPassword = " + ownerPassword + "\n"
  265. + "allowPrint = " + allowPrint + "\n"
  266. + "allowCopyContent = " + allowCopyContent + "\n"
  267. + "allowEditContent = " + allowEditContent + "\n"
  268. + "allowEditAnnotations = " + allowEditAnnotations + "\n"
  269. + "allowFillInForms = " + allowFillInForms + "\n"
  270. + "allowAccessContent = " + allowAccessContent + "\n"
  271. + "allowAssembleDocument = " + allowAssembleDocument + "\n"
  272. + "allowPrintHq = " + allowPrintHq + "\n"
  273. + "encryptMetadata = " + encryptMetadata;
  274. }
  275. }