Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

PDFRendererConfBuilder.java 4.7KB

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