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.

FOInputHandler.java 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  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.fo;
  18. // Java
  19. import java.util.HashSet;
  20. import java.util.Set;
  21. import org.xml.sax.SAXException;
  22. // Apache
  23. import org.apache.fop.apps.FOUserAgent;
  24. import org.apache.fop.apps.FOPException;
  25. import org.apache.fop.area.AreaTree;
  26. import org.apache.fop.fo.flow.BasicLink;
  27. import org.apache.fop.fo.flow.Block;
  28. import org.apache.fop.fo.flow.ExternalGraphic;
  29. import org.apache.fop.fo.flow.Footnote;
  30. import org.apache.fop.fo.flow.FootnoteBody;
  31. import org.apache.fop.fo.flow.Inline;
  32. import org.apache.fop.fo.flow.InstreamForeignObject;
  33. import org.apache.fop.fo.flow.Leader;
  34. import org.apache.fop.fo.flow.ListBlock;
  35. import org.apache.fop.fo.flow.ListItem;
  36. import org.apache.fop.fo.flow.PageNumber;
  37. import org.apache.fop.fo.flow.Table;
  38. import org.apache.fop.fo.flow.TableColumn;
  39. import org.apache.fop.fo.flow.TableBody;
  40. import org.apache.fop.fo.flow.TableCell;
  41. import org.apache.fop.fo.flow.TableRow;
  42. import org.apache.fop.fo.pagination.Flow;
  43. import org.apache.fop.fo.pagination.PageSequence;
  44. import org.apache.fop.fonts.FontInfo;
  45. import org.apache.commons.logging.Log;
  46. import org.apache.commons.logging.LogFactory;
  47. /**
  48. * Abstract class defining what should be done with SAX events that map to
  49. * XSL-FO input. The events are actually captured by fo/FOTreeBuilder, passed
  50. * to the various fo Objects, which in turn, if needed, pass them to an instance
  51. * of FOInputHandler.
  52. *
  53. * Sub-classes will generally fall into one of two categories:
  54. * 1) a handler that actually builds an FO Tree from the events, or 2) a
  55. * handler that builds a structured (as opposed to formatted) document, such
  56. * as our MIF and RTF output targets.
  57. */
  58. public abstract class FOInputHandler {
  59. /**
  60. * The FOUserAgent for this process
  61. */
  62. protected FOUserAgent foUserAgent;
  63. /**
  64. * The Font information relevant for this document
  65. */
  66. protected FontInfo fontInfo;
  67. /** Logger for FOInputHandler-related messages **/
  68. protected static Log logger = LogFactory.getLog(FOInputHandler.class);
  69. /**
  70. * The current set of id's in the FO tree.
  71. * This is used so we know if the FO tree contains duplicates.
  72. */
  73. private Set idReferences = new HashSet();
  74. /**
  75. * Main constructor
  76. * @param FOUserAgent the apps.FOUserAgent instance for this process
  77. */
  78. public FOInputHandler(FOUserAgent foUserAgent) {
  79. this.foUserAgent = foUserAgent;
  80. this.fontInfo = new FontInfo();
  81. }
  82. /**
  83. * Retuns the set of ID references.
  84. * @return the ID references
  85. */
  86. public Set getIDReferences() {
  87. return idReferences;
  88. }
  89. /**
  90. * Returns the Commons-Logging instance for this class
  91. * @return The Commons-Logging instance
  92. */
  93. protected Log getLogger(Log logger) {
  94. return logger;
  95. }
  96. /**
  97. * Returns the User Agent object associated with this FOInputHandler.
  98. * @return the User Agent object
  99. */
  100. public FOUserAgent getUserAgent() {
  101. return foUserAgent;
  102. }
  103. /**
  104. * Retrieve the font information for this document
  105. * @return the FontInfo instance for this document
  106. */
  107. public FontInfo getFontInfo() {
  108. return this.fontInfo;
  109. }
  110. /**
  111. * This method is called to indicate the start of a new document run.
  112. * @throws SAXException In case of a problem
  113. */
  114. public abstract void startDocument() throws SAXException;
  115. /**
  116. * This method is called to indicate the end of a document run.
  117. * @throws SAXException In case of a problem
  118. */
  119. public abstract void endDocument() throws SAXException;
  120. /**
  121. *
  122. * @param pageSeq PageSequence that is starting.
  123. */
  124. public abstract void startPageSequence(PageSequence pageSeq);
  125. /**
  126. *
  127. * @param pageSeq PageSequence that is ending.
  128. * @throws FOPException For errors encountered.
  129. */
  130. public abstract void endPageSequence(PageSequence pageSeq) throws FOPException;
  131. /**
  132. *
  133. * @param pagenum PageNumber that is starting.
  134. */
  135. public abstract void startPageNumber(PageNumber pagenum);
  136. /**
  137. *
  138. * @param pagenum PageNumber that is ending.
  139. */
  140. public abstract void endPageNumber(PageNumber pagenum);
  141. /**
  142. * This method is called to indicate the start of a new fo:flow or fo:static-content.
  143. * This method also handles fo:static-content tags, because the StaticContent class
  144. * is derived from the Flow class.
  145. *
  146. * @param fl Flow that is starting.
  147. */
  148. public abstract void startFlow(Flow fl);
  149. /**
  150. *
  151. * @param fl Flow that is ending.
  152. */
  153. public abstract void endFlow(Flow fl);
  154. /**
  155. *
  156. * @param bl Block that is starting.
  157. */
  158. public abstract void startBlock(Block bl);
  159. /**
  160. *
  161. * @param bl Block that is ending.
  162. */
  163. public abstract void endBlock(Block bl);
  164. /**
  165. *
  166. * @param inl Inline that is starting.
  167. */
  168. public abstract void startInline(Inline inl);
  169. /**
  170. *
  171. * @param inl Inline that is ending.
  172. */
  173. public abstract void endInline(Inline inl);
  174. // Tables
  175. /**
  176. *
  177. * @param tbl Table that is starting.
  178. */
  179. public abstract void startTable(Table tbl);
  180. /**
  181. *
  182. * @param tbl Table that is ending.
  183. */
  184. public abstract void endTable(Table tbl);
  185. /**
  186. *
  187. * @param tc TableColumn that is starting;
  188. */
  189. public abstract void startColumn(TableColumn tc);
  190. /**
  191. *
  192. * @param tc TableColumn that is ending;
  193. */
  194. public abstract void endColumn(TableColumn tc);
  195. /**
  196. *
  197. * @param th TableBody that is starting;
  198. */
  199. public abstract void startHeader(TableBody th);
  200. /**
  201. *
  202. * @param th TableBody that is ending.
  203. */
  204. public abstract void endHeader(TableBody th);
  205. /**
  206. *
  207. * @param tf TableFooter that is starting.
  208. */
  209. public abstract void startFooter(TableBody tf);
  210. /**
  211. *
  212. * @param tf TableFooter that is ending.
  213. */
  214. public abstract void endFooter(TableBody tf);
  215. /**
  216. *
  217. * @param tb TableBody that is starting.
  218. */
  219. public abstract void startBody(TableBody tb);
  220. /**
  221. *
  222. * @param tb TableBody that is ending.
  223. */
  224. public abstract void endBody(TableBody tb);
  225. /**
  226. *
  227. * @param tr TableRow that is starting.
  228. */
  229. public abstract void startRow(TableRow tr);
  230. /**
  231. *
  232. * @param tr TableRow that is ending.
  233. */
  234. public abstract void endRow(TableRow tr);
  235. /**
  236. *
  237. * @param tc TableCell that is starting.
  238. */
  239. public abstract void startCell(TableCell tc);
  240. /**
  241. *
  242. * @param tc TableCell that is ending.
  243. */
  244. public abstract void endCell(TableCell tc);
  245. // Lists
  246. /**
  247. *
  248. * @param lb ListBlock that is starting.
  249. */
  250. public abstract void startList(ListBlock lb);
  251. /**
  252. *
  253. * @param lb ListBlock that is ending.
  254. */
  255. public abstract void endList(ListBlock lb);
  256. /**
  257. *
  258. * @param li ListItem that is starting.
  259. */
  260. public abstract void startListItem(ListItem li);
  261. /**
  262. *
  263. * @param li ListItem that is ending.
  264. */
  265. public abstract void endListItem(ListItem li);
  266. /**
  267. * Process start of a ListLabel.
  268. */
  269. public abstract void startListLabel();
  270. /**
  271. * Process end of a ListLabel.
  272. */
  273. public abstract void endListLabel();
  274. /**
  275. * Process start of a ListBody.
  276. */
  277. public abstract void startListBody();
  278. /**
  279. * Process end of a ListBody.
  280. */
  281. public abstract void endListBody();
  282. // Static Regions
  283. /**
  284. * Process start of a Static.
  285. */
  286. public abstract void startStatic();
  287. /**
  288. * Process end of a Static.
  289. */
  290. public abstract void endStatic();
  291. /**
  292. * Process start of a Markup.
  293. */
  294. public abstract void startMarkup();
  295. /**
  296. * Process end of a Markup.
  297. */
  298. public abstract void endMarkup();
  299. /**
  300. * Process start of a Link.
  301. * @param basicLink BasicLink that is ending
  302. */
  303. public abstract void startLink(BasicLink basicLink);
  304. /**
  305. * Process end of a Link.
  306. */
  307. public abstract void endLink();
  308. /**
  309. * Process an ExternalGraphic.
  310. * @param eg ExternalGraphic to process.
  311. */
  312. public abstract void image(ExternalGraphic eg);
  313. /**
  314. * Process a pageRef.
  315. */
  316. public abstract void pageRef();
  317. /**
  318. * Process an InstreamForeignObject.
  319. * @param ifo InstreamForeignObject to process.
  320. */
  321. public abstract void foreignObject(InstreamForeignObject ifo);
  322. /**
  323. * Process the start of a footnote.
  324. * @param footnote Footnote that is starting
  325. */
  326. public abstract void startFootnote(Footnote footnote);
  327. /**
  328. * Process the ending of a footnote.
  329. * @param footnote Footnote that is ending
  330. */
  331. public abstract void endFootnote(Footnote footnote);
  332. /**
  333. * Process the start of a footnote body.
  334. * @param body FootnoteBody that is starting
  335. */
  336. public abstract void startFootnoteBody(FootnoteBody body);
  337. /**
  338. * Process the ending of a footnote body.
  339. * @param body FootnoteBody that is ending
  340. */
  341. public abstract void endFootnoteBody(FootnoteBody body);
  342. /**
  343. * Process a Leader.
  344. * @param l Leader to process.
  345. */
  346. public abstract void leader(Leader l);
  347. /**
  348. * Process character data.
  349. * @param data Array of characters to process.
  350. * @param start Offset for characters to process.
  351. * @param length Portion of array to process.
  352. */
  353. public abstract void characters(char data[], int start, int length);
  354. }