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.

FOUserAgent.java 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /*
  2. * Copyright 1999-2004 The Apache Software Foundation.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /* $Id$ */
  17. package org.apache.fop.apps;
  18. // Java
  19. import java.util.Map;
  20. import java.io.IOException;
  21. import java.io.InputStream;
  22. // Avalon
  23. import org.apache.avalon.framework.logger.LogEnabled;
  24. import org.apache.avalon.framework.logger.Logger;
  25. // FOP
  26. import org.apache.fop.pdf.PDFEncryptionParams;
  27. /**
  28. * The User Agent for fo.
  29. * This user agent is used by the processing to obtain user configurable
  30. * options.
  31. * <p>
  32. * Renderer specific extensions (that do not produce normal areas on
  33. * the output) will be done like so:
  34. * <br>
  35. * The extension will create an area, custom if necessary
  36. * <br>
  37. * this area will be added to the user agent with a key
  38. * <br>
  39. * the renderer will know keys for particular extensions
  40. * <br>
  41. * eg. bookmarks will be held in a special hierarchical area representing
  42. * the title and bookmark structure
  43. * <br>
  44. * These areas may contain resolveable areas that will be processed
  45. * with other resolveable areas
  46. */
  47. public class FOUserAgent implements LogEnabled {
  48. private Logger log;
  49. /** Map containing various default values */
  50. public Map defaults = new java.util.HashMap();
  51. /** Map containing XML handlers for various document types */
  52. public Map handlers = new java.util.HashMap();
  53. private String baseURL;
  54. private PDFEncryptionParams pdfEncryptionParams;
  55. private float px2mm = 0.35277777777777777778f; //72dpi (=25.4/dpi)
  56. /**
  57. * Sets the logger.
  58. * @param log Logger to use
  59. * @see org.apache.avalon.framework.logger.LogEnabled#enableLogging(Logger)
  60. */
  61. public void enableLogging(Logger log) {
  62. this.log = log;
  63. }
  64. /**
  65. * Returns the logger to use.
  66. * @see org.apache.avalon.framework.logger.AbstractLogEnabled#getLogger()
  67. * (todo) This breaks IoC/SoC. Should be improved.
  68. */
  69. public Logger getLogger() {
  70. return this.log;
  71. }
  72. /**
  73. * Sets the base URL.
  74. * @param baseURL base URL
  75. */
  76. public void setBaseURL(String baseURL) {
  77. this.baseURL = baseURL;
  78. }
  79. /**
  80. * Returns the base URL.
  81. * @return the base URL
  82. */
  83. public String getBaseURL() {
  84. if ((this.baseURL == null) || (this.baseURL.trim().equals(""))) {
  85. return "file:.";
  86. } else {
  87. return this.baseURL;
  88. }
  89. }
  90. /**
  91. * Returns the parameters for PDF encryption.
  92. * @return the PDF encryption parameters, null if not applicable
  93. */
  94. public PDFEncryptionParams getPDFEncryptionParams() {
  95. return pdfEncryptionParams;
  96. }
  97. /**
  98. * Sets the parameters for PDF encryption.
  99. * @param pdfEncryptionParams the PDF encryption parameters, null to
  100. * disable PDF encryption
  101. */
  102. public void setPDFEncryptionParams(PDFEncryptionParams pdfEncryptionParams) {
  103. this.pdfEncryptionParams = pdfEncryptionParams;
  104. }
  105. /**
  106. * Get an input stream for a reference.
  107. * Temporary solution until API better.
  108. * @param uri URI to access
  109. * @return InputStream for accessing the resource.
  110. * @throws IOException in case of an I/O problem
  111. */
  112. public InputStream getStream(String uri) throws IOException {
  113. return null;
  114. }
  115. /**
  116. * Returns the conversion factor from pixel units to millimeters. This
  117. * depends on the desired reolution.
  118. * @return float conversion factor
  119. */
  120. public float getPixelUnitToMillimeter() {
  121. return this.px2mm;
  122. }
  123. /**
  124. * Sets the resolution in dpi.
  125. * @param dpi resolution in dpi
  126. */
  127. public void setResolution(int dpi) {
  128. this.px2mm = (float)(25.4 / dpi);
  129. }
  130. /**
  131. * If to create hot links to footnotes and before floats.
  132. * @return True if hot links dhould be created
  133. */
  134. public boolean linkToFootnotes() {
  135. return true;
  136. }
  137. }