Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

PDFEncryptionParams.java 9.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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 int encryptionLengthInBits = 40;
  34. /**
  35. * Creates a new instance.
  36. * @param userPassword the user password
  37. * @param ownerPassword the owner password
  38. * @param allowPrint true if printing is allowed
  39. * @param allowCopyContent true if copying content is allowed
  40. * @param allowEditContent true if editing content is allowed
  41. * @param allowEditAnnotations true if editing annotations is allowed
  42. */
  43. public PDFEncryptionParams(String userPassword, String ownerPassword,
  44. boolean allowPrint,
  45. boolean allowCopyContent,
  46. boolean allowEditContent,
  47. boolean allowEditAnnotations) {
  48. setUserPassword(userPassword);
  49. setOwnerPassword(ownerPassword);
  50. setAllowPrint(allowPrint);
  51. setAllowCopyContent(allowCopyContent);
  52. setAllowEditContent(allowEditContent);
  53. setAllowEditAnnotations(allowEditAnnotations);
  54. }
  55. /**
  56. * Default constructor initializing to default values.
  57. */
  58. public PDFEncryptionParams() {
  59. //nop
  60. }
  61. /**
  62. * Creates a copy of the given encryption parameters.
  63. *
  64. * @param source source encryption parameters
  65. */
  66. public PDFEncryptionParams(PDFEncryptionParams source) {
  67. setUserPassword(source.getUserPassword());
  68. setOwnerPassword(source.getOwnerPassword());
  69. setAllowPrint(source.isAllowPrint());
  70. setAllowCopyContent(source.isAllowCopyContent());
  71. setAllowEditContent(source.isAllowEditContent());
  72. setAllowEditAnnotations(source.isAllowEditAnnotations());
  73. setAllowAssembleDocument(source.isAllowAssembleDocument());
  74. setAllowAccessContent(source.isAllowAccessContent());
  75. setAllowFillInForms(source.isAllowFillInForms());
  76. setAllowPrintHq(source.isAllowPrintHq());
  77. setEncryptionLengthInBits(source.getEncryptionLengthInBits());
  78. }
  79. /**
  80. * Indicates whether copying content is allowed.
  81. * @return true if copying is allowed
  82. */
  83. public boolean isAllowCopyContent() {
  84. return allowCopyContent;
  85. }
  86. /**
  87. * Indicates whether editing annotations is allowed.
  88. * @return true is editing annotations is allowed
  89. */
  90. public boolean isAllowEditAnnotations() {
  91. return allowEditAnnotations;
  92. }
  93. /**
  94. * Indicates whether editing content is allowed.
  95. * @return true if editing content is allowed
  96. */
  97. public boolean isAllowEditContent() {
  98. return allowEditContent;
  99. }
  100. /**
  101. * Indicates whether printing is allowed.
  102. * @return true if printing is allowed
  103. */
  104. public boolean isAllowPrint() {
  105. return allowPrint;
  106. }
  107. /**
  108. * Indicates whether revision 3 filling in forms is allowed.
  109. * @return true if revision 3 filling in forms is allowed
  110. */
  111. public boolean isAllowFillInForms() {
  112. return allowFillInForms;
  113. }
  114. /**
  115. * Indicates whether revision 3 extracting text and graphics is allowed.
  116. * @return true if revision 3 extracting text and graphics is allowed
  117. */
  118. public boolean isAllowAccessContent() {
  119. return allowAccessContent;
  120. }
  121. /**
  122. * Indicates whether revision 3 assembling document is allowed.
  123. * @return true if revision 3 assembling document is allowed
  124. */
  125. public boolean isAllowAssembleDocument() {
  126. return allowAssembleDocument;
  127. }
  128. /**
  129. * Indicates whether revision 3 printing to high quality is allowed.
  130. * @return true if revision 3 printing to high quality is allowed
  131. */
  132. public boolean isAllowPrintHq() {
  133. return allowPrintHq;
  134. }
  135. /**
  136. * Returns the owner password.
  137. * @return the owner password, an empty string if no password applies
  138. */
  139. public String getOwnerPassword() {
  140. return ownerPassword;
  141. }
  142. /**
  143. * Returns the user password.
  144. * @return the user password, an empty string if no password applies
  145. */
  146. public String getUserPassword() {
  147. return userPassword;
  148. }
  149. /**
  150. * Sets the permission for copying content.
  151. * @param allowCopyContent true if copying content is allowed
  152. */
  153. public void setAllowCopyContent(boolean allowCopyContent) {
  154. this.allowCopyContent = allowCopyContent;
  155. }
  156. /**
  157. * Sets the permission for editing annotations.
  158. * @param allowEditAnnotations true if editing annotations is allowed
  159. */
  160. public void setAllowEditAnnotations(boolean allowEditAnnotations) {
  161. this.allowEditAnnotations = allowEditAnnotations;
  162. }
  163. /**
  164. * Sets the permission for editing content.
  165. * @param allowEditContent true if editing annotations is allowed
  166. */
  167. public void setAllowEditContent(boolean allowEditContent) {
  168. this.allowEditContent = allowEditContent;
  169. }
  170. /**
  171. * Sets the permission for printing.
  172. * @param allowPrint true if printing is allowed
  173. */
  174. public void setAllowPrint(boolean allowPrint) {
  175. this.allowPrint = allowPrint;
  176. }
  177. /**
  178. * Sets whether revision 3 filling in forms is allowed.
  179. * @param allowFillInForms true if revision 3 filling in forms is allowed.
  180. */
  181. public void setAllowFillInForms(boolean allowFillInForms) {
  182. this.allowFillInForms = allowFillInForms;
  183. }
  184. /**
  185. * Sets whether revision 3 extracting text and graphics is allowed.
  186. * @param allowAccessContent true if revision 3 extracting text and graphics is allowed
  187. */
  188. public void setAllowAccessContent(boolean allowAccessContent) {
  189. this.allowAccessContent = allowAccessContent;
  190. }
  191. /**
  192. * Sets whether revision 3 assembling document is allowed.
  193. * @param allowAssembleDocument true if revision 3 assembling document is allowed
  194. */
  195. public void setAllowAssembleDocument(boolean allowAssembleDocument) {
  196. this.allowAssembleDocument = allowAssembleDocument;
  197. }
  198. /**
  199. * Sets whether revision 3 printing to high quality is allowed.
  200. * @param allowPrintHq true if revision 3 printing to high quality is allowed
  201. */
  202. public void setAllowPrintHq(boolean allowPrintHq) {
  203. this.allowPrintHq = allowPrintHq;
  204. }
  205. /**
  206. * Sets the owner password.
  207. * @param ownerPassword The owner password to set, null or an empty String
  208. * if no password is applicable
  209. */
  210. public void setOwnerPassword(String ownerPassword) {
  211. if (ownerPassword == null) {
  212. this.ownerPassword = "";
  213. } else {
  214. this.ownerPassword = ownerPassword;
  215. }
  216. }
  217. /**
  218. * Sets the user password.
  219. * @param userPassword The user password to set, null or an empty String
  220. * if no password is applicable
  221. */
  222. public void setUserPassword(String userPassword) {
  223. if (userPassword == null) {
  224. this.userPassword = "";
  225. } else {
  226. this.userPassword = userPassword;
  227. }
  228. }
  229. /**
  230. * Returns the encryption length.
  231. * @return the encryption length
  232. */
  233. public int getEncryptionLengthInBits() {
  234. return encryptionLengthInBits;
  235. }
  236. /**
  237. * Sets the encryption length.
  238. *
  239. * @param encryptionLength the encryption length
  240. */
  241. public void setEncryptionLengthInBits(int encryptionLength) {
  242. this.encryptionLengthInBits = encryptionLength;
  243. }
  244. public String toString() {
  245. return "userPassword = " + userPassword + "\n"
  246. + "ownerPassword = " + ownerPassword + "\n"
  247. + "allowPrint = " + allowPrint + "\n"
  248. + "allowCopyContent = " + allowCopyContent + "\n"
  249. + "allowEditContent = " + allowEditContent + "\n"
  250. + "allowEditAnnotations = " + allowEditAnnotations + "\n"
  251. + "allowFillInForms = " + allowFillInForms + "\n"
  252. + "allowAccessContent = " + allowAccessContent + "\n"
  253. + "allowAssembleDocument = " + allowAssembleDocument + "\n"
  254. + "allowPrintHq = " + allowPrintHq;
  255. }
  256. }