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.

PDFRendererConfBuilder.java 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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.apps;
  19. import org.w3c.dom.Element;
  20. import org.apache.fop.apps.FopConfBuilder.RendererConfBuilder;
  21. import org.apache.fop.render.RendererConfigOption;
  22. import org.apache.fop.render.pdf.PDFEncryptionOption;
  23. import static org.apache.fop.render.pdf.PDFEncryptionOption.ENCRYPTION_LENGTH;
  24. import static org.apache.fop.render.pdf.PDFEncryptionOption.ENCRYPTION_PARAMS;
  25. import static org.apache.fop.render.pdf.PDFEncryptionOption.OWNER_PASSWORD;
  26. import static org.apache.fop.render.pdf.PDFEncryptionOption.USER_PASSWORD;
  27. import static org.apache.fop.render.pdf.PDFRendererOption.DISABLE_SRGB_COLORSPACE;
  28. import static org.apache.fop.render.pdf.PDFRendererOption.FILTER_LIST;
  29. import static org.apache.fop.render.pdf.PDFRendererOption.OUTPUT_PROFILE;
  30. import static org.apache.fop.render.pdf.PDFRendererOption.PDF_A_MODE;
  31. import static org.apache.fop.render.pdf.PDFRendererOption.PDF_X_MODE;
  32. import static org.apache.fop.render.pdf.PDFRendererOption.VERSION;
  33. /**
  34. * A config builder specific to a particular renderer for specific MIME type.
  35. */
  36. public final class PDFRendererConfBuilder extends RendererConfBuilder {
  37. private EncryptionParamsBuilder accessConf;
  38. public PDFRendererConfBuilder() {
  39. super(MimeConstants.MIME_PDF);
  40. }
  41. public EncryptionParamsBuilder startEncryptionParams() {
  42. accessConf = new EncryptionParamsBuilder();
  43. return accessConf;
  44. }
  45. public PDFRendererConfBuilder endEncryptionParams() {
  46. accessConf = null;
  47. return this;
  48. }
  49. public PDFRendererConfBuilder createFilterList(String type, String... filters) {
  50. Element filterListEl = createElement(FILTER_LIST.getName());
  51. if (type != null) {
  52. filterListEl.setAttribute("type", type);
  53. }
  54. for (String filter : filters) {
  55. createTextElement("value", filter, filterListEl);
  56. }
  57. return this;
  58. }
  59. public PDFRendererConfBuilder setPDFAMode(String value) {
  60. createTextElement(PDF_A_MODE, value);
  61. return this;
  62. }
  63. public PDFRendererConfBuilder setPDFXMode(String value) {
  64. createTextElement(PDF_X_MODE, value);
  65. return this;
  66. }
  67. public PDFRendererConfBuilder setPDFVersion(String version) {
  68. createTextElement(VERSION, version);
  69. return this;
  70. }
  71. public PDFRendererConfBuilder setOutputProfile(String profile) {
  72. createTextElement(OUTPUT_PROFILE, profile);
  73. return this;
  74. }
  75. public PDFRendererConfBuilder disableSRGBColorSpace(boolean disable) {
  76. createTextElement(DISABLE_SRGB_COLORSPACE, String.valueOf(disable));
  77. return this;
  78. }
  79. public final class EncryptionParamsBuilder {
  80. private final Element el;
  81. private EncryptionParamsBuilder() {
  82. el = createElement(ENCRYPTION_PARAMS);
  83. }
  84. public EncryptionParamsBuilder setEncryptionLength(int length) {
  85. createTextElement(ENCRYPTION_LENGTH, String.valueOf(length));
  86. return this;
  87. }
  88. public EncryptionParamsBuilder setUserPassword(String password) {
  89. createTextElement(USER_PASSWORD, password);
  90. return this;
  91. }
  92. public EncryptionParamsBuilder setOwnerPassword(String password) {
  93. createTextElement(OWNER_PASSWORD, password);
  94. return this;
  95. }
  96. public EncryptionParamsBuilder setAllowParam(PDFEncryptionOption option) {
  97. el.appendChild(createElement(option.getName()));
  98. return this;
  99. }
  100. public PDFRendererConfBuilder endEncryptionParams() {
  101. return PDFRendererConfBuilder.this.endEncryptionParams();
  102. }
  103. private void createTextElement(RendererConfigOption name, String value) {
  104. PDFRendererConfBuilder.this.createTextElement(name.getName(), value, el);
  105. }
  106. }
  107. }