Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

IFContext.java 7.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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.render.intermediate;
  19. import java.util.Collections;
  20. import java.util.Locale;
  21. import java.util.Map;
  22. import org.apache.xmlgraphics.util.QName;
  23. import org.apache.fop.accessibility.StructureTreeElement;
  24. import org.apache.fop.apps.FOUserAgent;
  25. /**
  26. * This class provides a context object that is valid for a single processing run to create
  27. * an output file using the intermediate format. It allows access to the user agent and other
  28. * context information, such as foreign attributes for certain elements in the intermediate
  29. * format.
  30. * <p>
  31. * Foreign attributes are usually specific to a particular output format implementation. Most
  32. * implementations will just ignore all foreign attributes for most elements. That's why the
  33. * main IF interfaces are not burdened with this.
  34. */
  35. public class IFContext implements PageIndexContext {
  36. private FOUserAgent userAgent;
  37. /** foreign attributes: Map<QName, Object> */
  38. private Map foreignAttributes = Collections.EMPTY_MAP;
  39. private Locale language;
  40. private StructureTreeElement structureTreeElement;
  41. private String id = "";
  42. private String location;
  43. private boolean hyphenated;
  44. private int pageIndex = -1;
  45. private int pageNumber = -1;
  46. /**
  47. * Main constructor.
  48. * @param ua the user agent
  49. */
  50. public IFContext(FOUserAgent ua) {
  51. setUserAgent(ua);
  52. }
  53. /**
  54. * Set the user agent.
  55. * @param ua the user agent
  56. */
  57. public void setUserAgent(FOUserAgent ua) {
  58. if (this.userAgent != null) {
  59. throw new IllegalStateException("The user agent was already set");
  60. }
  61. this.userAgent = ua;
  62. }
  63. /**
  64. * Returns the associated user agent.
  65. * @return the user agent
  66. */
  67. public FOUserAgent getUserAgent() {
  68. return this.userAgent;
  69. }
  70. /**
  71. * Returns the currently applicable foreign attributes.
  72. * @return a Map&lt;QName, Object&gt;
  73. */
  74. public Map getForeignAttributes() {
  75. return this.foreignAttributes;
  76. }
  77. /**
  78. * Returns a foreign attribute.
  79. * @param qName the qualified name of the foreign attribute
  80. * @return the value of the foreign attribute or null if the attribute isn't specified
  81. */
  82. public Object getForeignAttribute(QName qName) {
  83. return this.foreignAttributes.get(qName);
  84. }
  85. /**
  86. * Sets the currently applicable foreign attributes.
  87. * @param foreignAttributes a Map&lt;QName, Object&gt; or null to reset
  88. */
  89. public void setForeignAttributes(Map foreignAttributes) {
  90. if (foreignAttributes != null) {
  91. this.foreignAttributes = foreignAttributes;
  92. } else {
  93. //Make sure there is always at least an empty map so we don't have to check
  94. //in the implementation code
  95. this.foreignAttributes = Collections.EMPTY_MAP;
  96. }
  97. }
  98. /**
  99. * Resets the foreign attributes to "no foreign attributes".
  100. */
  101. public void resetForeignAttributes() {
  102. setForeignAttributes(null);
  103. }
  104. /**
  105. * Sets the currently applicable language.
  106. * @param lang the language
  107. */
  108. public void setLanguage(Locale lang) {
  109. this.language = lang;
  110. }
  111. /**
  112. * Returns the currently applicable language.
  113. * @return the language (or null if the language is undefined)
  114. */
  115. public Locale getLanguage() {
  116. return this.language;
  117. }
  118. /**
  119. * Sets the structure tree element to which the subsequently painted marks
  120. * will correspond. This method is used when accessibility features are
  121. * enabled.
  122. *
  123. * @param structureTreeElement the structure tree element
  124. */
  125. public void setStructureTreeElement(StructureTreeElement structureTreeElement) {
  126. this.structureTreeElement = structureTreeElement;
  127. }
  128. /**
  129. * Resets the current structure tree element.
  130. * @see #setStructureTreeElement(StructureTreeElement)
  131. */
  132. public void resetStructureTreeElement() {
  133. setStructureTreeElement(null);
  134. }
  135. /**
  136. * Returns the current structure tree element.
  137. * @return the structure tree element (or null if no element is active)
  138. * @see #setStructureTreeElement(StructureTreeElement)
  139. */
  140. public StructureTreeElement getStructureTreeElement() {
  141. return this.structureTreeElement;
  142. }
  143. /**
  144. * Sets the ID of the object enclosing the content that will follow.
  145. *
  146. * @param id the ID of the nearest ancestor object for which the id property was set
  147. */
  148. void setID(String id) {
  149. assert id != null;
  150. this.id = id;
  151. }
  152. /**
  153. * Returns the ID of the object enclosing the current content.
  154. *
  155. * @return the ID of the nearest ancestor object for which the id property was set
  156. */
  157. String getID() {
  158. return id;
  159. }
  160. /**
  161. * Sets the location of the object enclosing the current content.
  162. *
  163. * location the line and column location of the object in the source FO file
  164. */
  165. public void setLocation(String location) {
  166. this.location = location;
  167. }
  168. /**
  169. * Returns the location of the object enclosing the current content.
  170. *
  171. * @return the line and column location of the object in the source FO file,
  172. * {@code null} if that information is not available
  173. */
  174. public String getLocation() {
  175. return location;
  176. }
  177. /**
  178. * Records that the last text in the currently processed text area is hyphenated.
  179. */
  180. public void setHyphenated(boolean hyphenated) {
  181. this.hyphenated = hyphenated;
  182. }
  183. /**
  184. * Returns {@code true} if the last text in the currently processed text area is hyphenated.
  185. */
  186. public boolean isHyphenated() {
  187. return hyphenated;
  188. }
  189. /**
  190. * Record current page index.
  191. * @param pageIndex a zero based page index or -1 (no page)
  192. */
  193. public void setPageIndex(int pageIndex) {
  194. this.pageIndex = pageIndex;
  195. }
  196. /**
  197. * Obtain current page index.
  198. * @return a zero based page index or -1 (no page)
  199. */
  200. public int getPageIndex() {
  201. return this.pageIndex;
  202. }
  203. public int getPageNumber() {
  204. return pageNumber;
  205. }
  206. public void setPageNumber(int pageNumber) {
  207. this.pageNumber = pageNumber;
  208. }
  209. }