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.

FOEventHandler.java 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578
  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.fo;
  19. import java.util.HashSet;
  20. import java.util.Set;
  21. import org.xml.sax.SAXException;
  22. import org.apache.fop.apps.FOUserAgent;
  23. import org.apache.fop.fo.extensions.ExternalDocument;
  24. import org.apache.fop.fo.flow.BasicLink;
  25. import org.apache.fop.fo.flow.Block;
  26. import org.apache.fop.fo.flow.BlockContainer;
  27. import org.apache.fop.fo.flow.Character;
  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.PageNumberCitation;
  38. import org.apache.fop.fo.flow.PageNumberCitationLast;
  39. import org.apache.fop.fo.flow.table.Table;
  40. import org.apache.fop.fo.flow.table.TableBody;
  41. import org.apache.fop.fo.flow.table.TableCell;
  42. import org.apache.fop.fo.flow.table.TableColumn;
  43. import org.apache.fop.fo.flow.table.TableRow;
  44. import org.apache.fop.fo.pagination.Flow;
  45. import org.apache.fop.fo.pagination.PageSequence;
  46. import org.apache.fop.fonts.FontEventAdapter;
  47. import org.apache.fop.fonts.FontInfo;
  48. /**
  49. * Abstract class defining what should be done with SAX events that map to
  50. * XSL-FO input. The events are actually captured by fo/FOTreeBuilder, passed
  51. * to the various fo Objects, which in turn, if needed, pass them to an instance
  52. * of FOEventHandler.
  53. *
  54. * Sub-classes will generally fall into one of two categories:
  55. * 1) a handler that actually builds an FO Tree from the events, or 2) a
  56. * handler that builds a structured (as opposed to formatted) document, such
  57. * as our MIF and RTF output targets.
  58. */
  59. public abstract class FOEventHandler {
  60. /**
  61. * The FOUserAgent for this process
  62. */
  63. protected FOUserAgent foUserAgent;
  64. /**
  65. * The Font information relevant for this document
  66. */
  67. protected FontInfo fontInfo;
  68. /**
  69. * The current set of id's in the FO tree.
  70. * This is used so we know if the FO tree contains duplicates.
  71. */
  72. private Set idReferences = new HashSet();
  73. /**
  74. * The property list maker.
  75. */
  76. protected PropertyListMaker propertyListMaker;
  77. /**
  78. * The XMLWhitespaceHandler for this tree
  79. */
  80. protected XMLWhiteSpaceHandler whiteSpaceHandler = new XMLWhiteSpaceHandler();
  81. /**
  82. * Indicates whether processing descendants of a marker
  83. */
  84. private boolean inMarker = false;
  85. /**
  86. * Main constructor
  87. * @param foUserAgent the apps.FOUserAgent instance for this process
  88. */
  89. public FOEventHandler(FOUserAgent foUserAgent) {
  90. this.foUserAgent = foUserAgent;
  91. this.fontInfo = new FontInfo();
  92. this.fontInfo.setEventListener(new FontEventAdapter(foUserAgent.getEventBroadcaster()));
  93. }
  94. /**
  95. * Retuns the set of ID references.
  96. * @return the ID references
  97. */
  98. public Set getIDReferences() {
  99. return idReferences;
  100. }
  101. /**
  102. * Returns the User Agent object associated with this FOEventHandler.
  103. * @return the User Agent object
  104. */
  105. public FOUserAgent getUserAgent() {
  106. return foUserAgent;
  107. }
  108. /**
  109. * Retrieve the font information for this document
  110. * @return the FontInfo instance for this document
  111. */
  112. public FontInfo getFontInfo() {
  113. return this.fontInfo;
  114. }
  115. /**
  116. * Return the propertyListMaker.
  117. */
  118. public PropertyListMaker getPropertyListMaker() {
  119. return propertyListMaker;
  120. }
  121. /**
  122. * Set a new propertyListMaker.
  123. */
  124. public void setPropertyListMaker(PropertyListMaker propertyListMaker) {
  125. this.propertyListMaker = propertyListMaker;
  126. }
  127. /**
  128. * Return the XMLWhiteSpaceHandler
  129. * @return the whiteSpaceHandler
  130. */
  131. public XMLWhiteSpaceHandler getXMLWhiteSpaceHandler() {
  132. return whiteSpaceHandler;
  133. }
  134. /**
  135. * Switch to or from marker context
  136. * (used by FOTreeBuilder when processing
  137. * a marker)
  138. *
  139. */
  140. protected void switchMarkerContext(boolean inMarker) {
  141. this.inMarker = inMarker;
  142. }
  143. /**
  144. * Check whether in marker context
  145. */
  146. protected boolean inMarker() {
  147. return this.inMarker;
  148. }
  149. /**
  150. * This method is called to indicate the start of a new document run.
  151. * @throws SAXException In case of a problem
  152. */
  153. public void startDocument() throws SAXException {
  154. }
  155. /**
  156. * This method is called to indicate the end of a document run.
  157. * @throws SAXException In case of a problem
  158. */
  159. public void endDocument() throws SAXException {
  160. }
  161. /**
  162. *
  163. * @param pageSeq PageSequence that is starting.
  164. */
  165. public void startPageSequence(PageSequence pageSeq) {
  166. }
  167. /**
  168. * @param pageSeq PageSequence that is ending.
  169. */
  170. public void endPageSequence(PageSequence pageSeq) {
  171. }
  172. /**
  173. *
  174. * @param pagenum PageNumber that is starting.
  175. */
  176. public void startPageNumber(PageNumber pagenum) {
  177. }
  178. /**
  179. *
  180. * @param pagenum PageNumber that is ending.
  181. */
  182. public void endPageNumber(PageNumber pagenum) {
  183. }
  184. /**
  185. *
  186. * @param pageCite PageNumberCitation that is starting.
  187. */
  188. public void startPageNumberCitation(PageNumberCitation pageCite) {
  189. }
  190. /**
  191. *
  192. * @param pageCite PageNumberCitation that is ending.
  193. */
  194. public void endPageNumberCitation(PageNumberCitation pageCite) {
  195. }
  196. /**
  197. *
  198. * @param pageLast PageNumberCitationLast that is starting.
  199. */
  200. public void startPageNumberCitationLast(PageNumberCitationLast pageLast) {
  201. }
  202. /**
  203. *
  204. * @param pageLast PageNumberCitationLast that is ending.
  205. */
  206. public void endPageNumberCitationLast(PageNumberCitationLast pageLast) {
  207. }
  208. /**
  209. * This method is called to indicate the start of a new fo:flow
  210. * or fo:static-content.
  211. * This method also handles fo:static-content tags, because the
  212. * StaticContent class is derived from the Flow class.
  213. *
  214. * @param fl Flow that is starting.
  215. */
  216. public void startFlow(Flow fl) {
  217. }
  218. /**
  219. *
  220. * @param fl Flow that is ending.
  221. */
  222. public void endFlow(Flow fl) {
  223. }
  224. /**
  225. *
  226. * @param bl Block that is starting.
  227. */
  228. public void startBlock(Block bl) {
  229. }
  230. /**
  231. *
  232. * @param bl Block that is ending.
  233. */
  234. public void endBlock(Block bl) {
  235. }
  236. /**
  237. *
  238. * @param blc BlockContainer that is starting.
  239. */
  240. public void startBlockContainer(BlockContainer blc) {
  241. }
  242. /**
  243. *
  244. * @param blc BlockContainer that is ending.
  245. */
  246. public void endBlockContainer(BlockContainer blc) {
  247. }
  248. /**
  249. *
  250. * @param inl Inline that is starting.
  251. */
  252. public void startInline(Inline inl) {
  253. }
  254. /**
  255. *
  256. * @param inl Inline that is ending.
  257. */
  258. public void endInline(Inline inl) {
  259. }
  260. // Tables
  261. /**
  262. *
  263. * @param tbl Table that is starting.
  264. */
  265. public void startTable(Table tbl) {
  266. }
  267. /**
  268. *
  269. * @param tbl Table that is ending.
  270. */
  271. public void endTable(Table tbl) {
  272. }
  273. /**
  274. *
  275. * @param tc TableColumn that is starting;
  276. */
  277. public void startColumn(TableColumn tc) {
  278. }
  279. /**
  280. *
  281. * @param tc TableColumn that is ending;
  282. */
  283. public void endColumn(TableColumn tc) {
  284. }
  285. /**
  286. *
  287. * @param th TableBody that is starting;
  288. */
  289. public void startHeader(TableBody th) {
  290. }
  291. /**
  292. *
  293. * @param th TableBody that is ending.
  294. */
  295. public void endHeader(TableBody th) {
  296. }
  297. /**
  298. *
  299. * @param tf TableFooter that is starting.
  300. */
  301. public void startFooter(TableBody tf) {
  302. }
  303. /**
  304. *
  305. * @param tf TableFooter that is ending.
  306. */
  307. public void endFooter(TableBody tf) {
  308. }
  309. /**
  310. *
  311. * @param tb TableBody that is starting.
  312. */
  313. public void startBody(TableBody tb) {
  314. }
  315. /**
  316. *
  317. * @param tb TableBody that is ending.
  318. */
  319. public void endBody(TableBody tb) {
  320. }
  321. /**
  322. *
  323. * @param tr TableRow that is starting.
  324. */
  325. public void startRow(TableRow tr) {
  326. }
  327. /**
  328. *
  329. * @param tr TableRow that is ending.
  330. */
  331. public void endRow(TableRow tr) {
  332. }
  333. /**
  334. *
  335. * @param tc TableCell that is starting.
  336. */
  337. public void startCell(TableCell tc) {
  338. }
  339. /**
  340. *
  341. * @param tc TableCell that is ending.
  342. */
  343. public void endCell(TableCell tc) {
  344. }
  345. // Lists
  346. /**
  347. *
  348. * @param lb ListBlock that is starting.
  349. */
  350. public void startList(ListBlock lb) {
  351. }
  352. /**
  353. *
  354. * @param lb ListBlock that is ending.
  355. */
  356. public void endList(ListBlock lb) {
  357. }
  358. /**
  359. *
  360. * @param li ListItem that is starting.
  361. */
  362. public void startListItem(ListItem li) {
  363. }
  364. /**
  365. *
  366. * @param li ListItem that is ending.
  367. */
  368. public void endListItem(ListItem li) {
  369. }
  370. /**
  371. * Process start of a ListLabel.
  372. */
  373. public void startListLabel() {
  374. }
  375. /**
  376. * Process end of a ListLabel.
  377. */
  378. public void endListLabel() {
  379. }
  380. /**
  381. * Process start of a ListBody.
  382. */
  383. public void startListBody() {
  384. }
  385. /**
  386. * Process end of a ListBody.
  387. */
  388. public void endListBody() {
  389. }
  390. // Static Regions
  391. /**
  392. * Process start of a Static.
  393. */
  394. public void startStatic() {
  395. }
  396. /**
  397. * Process end of a Static.
  398. */
  399. public void endStatic() {
  400. }
  401. /**
  402. * Process start of a Markup.
  403. */
  404. public void startMarkup() {
  405. }
  406. /**
  407. * Process end of a Markup.
  408. */
  409. public void endMarkup() {
  410. }
  411. /**
  412. * Process start of a Link.
  413. * @param basicLink BasicLink that is ending
  414. */
  415. public void startLink(BasicLink basicLink) {
  416. }
  417. /**
  418. * Process end of a Link.
  419. */
  420. public void endLink() {
  421. }
  422. /**
  423. * Process an ExternalGraphic.
  424. * @param eg ExternalGraphic to process.
  425. */
  426. public void image(ExternalGraphic eg) {
  427. }
  428. /**
  429. * Process a pageRef.
  430. */
  431. public void pageRef() {
  432. }
  433. /**
  434. * Process an InstreamForeignObject.
  435. * @param ifo InstreamForeignObject to process.
  436. */
  437. public void foreignObject(InstreamForeignObject ifo) {
  438. }
  439. /**
  440. * Process the start of a footnote.
  441. * @param footnote Footnote that is starting
  442. */
  443. public void startFootnote(Footnote footnote) {
  444. }
  445. /**
  446. * Process the ending of a footnote.
  447. * @param footnote Footnote that is ending
  448. */
  449. public void endFootnote(Footnote footnote) {
  450. }
  451. /**
  452. * Process the start of a footnote body.
  453. * @param body FootnoteBody that is starting
  454. */
  455. public void startFootnoteBody(FootnoteBody body) {
  456. }
  457. /**
  458. * Process the ending of a footnote body.
  459. * @param body FootnoteBody that is ending
  460. */
  461. public void endFootnoteBody(FootnoteBody body) {
  462. }
  463. /**
  464. * Process a Leader.
  465. * @param l Leader to process.
  466. */
  467. public void leader(Leader l) {
  468. }
  469. /**
  470. * Process a Character.
  471. * @param c Character to process.
  472. */
  473. public void character(Character c) {
  474. }
  475. /**
  476. * Process character data.
  477. * @param data Array of characters to process.
  478. * @param start Offset for characters to process.
  479. * @param length Portion of array to process.
  480. */
  481. public void characters(char data[], int start, int length) {
  482. }
  483. /**
  484. * Process the start of the external-document extension.
  485. * @param document the external-document node
  486. */
  487. public void startExternalDocument(ExternalDocument document) {
  488. }
  489. /**
  490. * Process the end of the external-document extension.
  491. * @param document the external-document node
  492. */
  493. public void endExternalDocument(ExternalDocument document) {
  494. }
  495. }