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.

FO2StructureTreeConverter.java 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859
  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.accessibility.fo;
  19. import java.util.HashMap;
  20. import java.util.Map;
  21. import java.util.Stack;
  22. import org.xml.sax.SAXException;
  23. import org.apache.fop.accessibility.Accessibility;
  24. import org.apache.fop.accessibility.StructureTreeEventHandler;
  25. import org.apache.fop.fo.DelegatingFOEventHandler;
  26. import org.apache.fop.fo.FOEventHandler;
  27. import org.apache.fop.fo.FOText;
  28. import org.apache.fop.fo.extensions.ExternalDocument;
  29. import org.apache.fop.fo.flow.AbstractRetrieveMarker;
  30. import org.apache.fop.fo.flow.BasicLink;
  31. import org.apache.fop.fo.flow.Block;
  32. import org.apache.fop.fo.flow.BlockContainer;
  33. import org.apache.fop.fo.flow.Character;
  34. import org.apache.fop.fo.flow.ExternalGraphic;
  35. import org.apache.fop.fo.flow.Footnote;
  36. import org.apache.fop.fo.flow.FootnoteBody;
  37. import org.apache.fop.fo.flow.Inline;
  38. import org.apache.fop.fo.flow.InstreamForeignObject;
  39. import org.apache.fop.fo.flow.Leader;
  40. import org.apache.fop.fo.flow.ListBlock;
  41. import org.apache.fop.fo.flow.ListItem;
  42. import org.apache.fop.fo.flow.ListItemBody;
  43. import org.apache.fop.fo.flow.ListItemLabel;
  44. import org.apache.fop.fo.flow.PageNumber;
  45. import org.apache.fop.fo.flow.PageNumberCitation;
  46. import org.apache.fop.fo.flow.PageNumberCitationLast;
  47. import org.apache.fop.fo.flow.RetrieveMarker;
  48. import org.apache.fop.fo.flow.RetrieveTableMarker;
  49. import org.apache.fop.fo.flow.Wrapper;
  50. import org.apache.fop.fo.flow.table.Table;
  51. import org.apache.fop.fo.flow.table.TableBody;
  52. import org.apache.fop.fo.flow.table.TableCell;
  53. import org.apache.fop.fo.flow.table.TableColumn;
  54. import org.apache.fop.fo.flow.table.TableFooter;
  55. import org.apache.fop.fo.flow.table.TableHeader;
  56. import org.apache.fop.fo.flow.table.TableRow;
  57. import org.apache.fop.fo.pagination.Flow;
  58. import org.apache.fop.fo.pagination.PageSequence;
  59. import org.apache.fop.fo.pagination.Root;
  60. import org.apache.fop.fo.pagination.StaticContent;
  61. import org.apache.fop.fo.properties.CommonAccessibility;
  62. import org.apache.fop.fo.properties.CommonAccessibilityHolder;
  63. /**
  64. * Allows to create the structure tree of an FO document, by converting FO
  65. * events into appropriate structure tree events.
  66. */
  67. public class FO2StructureTreeConverter extends DelegatingFOEventHandler {
  68. /** The top of the {@link converters} stack. */
  69. protected FOEventHandler converter;
  70. private Stack<FOEventHandler> converters = new Stack<FOEventHandler>();
  71. private final StructureTreeEventTrigger structureTreeEventTrigger;
  72. /** The descendants of some elements like fo:leader must be ignored. */
  73. private final FOEventHandler eventSwallower = new FOEventHandler() {
  74. };
  75. private final Map<AbstractRetrieveMarker, State> states = new HashMap<AbstractRetrieveMarker, State>();
  76. private static final class State {
  77. private final FOEventHandler converter;
  78. private final Stack<FOEventHandler> converters;
  79. @SuppressWarnings("unchecked")
  80. State(FO2StructureTreeConverter o) {
  81. this.converter = o.converter;
  82. this.converters = (Stack<FOEventHandler>) o.converters.clone();
  83. }
  84. }
  85. private Event root = new Event((Event) null);
  86. private Event currentNode = root;
  87. private void startContent(Event event, boolean hasContent) {
  88. if (getUserAgent().isKeepEmptyTags()) {
  89. event.run();
  90. } else {
  91. Event node = new Event(currentNode);
  92. event.hasContent = hasContent;
  93. node.add(event);
  94. currentNode.add(node);
  95. currentNode = node;
  96. }
  97. }
  98. private void content(Event event, boolean hasContent) {
  99. if (getUserAgent().isKeepEmptyTags()) {
  100. event.run();
  101. } else {
  102. currentNode.add(event);
  103. event.hasContent = hasContent;
  104. }
  105. }
  106. private void endContent(Event event) {
  107. if (getUserAgent().isKeepEmptyTags()) {
  108. event.run();
  109. } else {
  110. currentNode.add(event);
  111. currentNode = currentNode.parent;
  112. if (currentNode == root) {
  113. root.run();
  114. }
  115. }
  116. }
  117. /**
  118. * Creates a new instance.
  119. *
  120. * @param structureTreeEventHandler the object that will hold the structure tree
  121. * @param delegate the FO event handler that must be wrapped by this instance
  122. */
  123. public FO2StructureTreeConverter(StructureTreeEventHandler structureTreeEventHandler,
  124. FOEventHandler delegate) {
  125. super(delegate);
  126. this.structureTreeEventTrigger = new StructureTreeEventTrigger(structureTreeEventHandler);
  127. this.converter = structureTreeEventTrigger;
  128. }
  129. @Override
  130. public void startDocument() throws SAXException {
  131. converter.startDocument();
  132. super.startDocument();
  133. }
  134. @Override
  135. public void endDocument() throws SAXException {
  136. converter.endDocument();
  137. super.endDocument();
  138. }
  139. @Override
  140. public void startRoot(Root root) {
  141. converter.startRoot(root);
  142. super.startRoot(root);
  143. }
  144. @Override
  145. public void endRoot(Root root) {
  146. converter.endRoot(root);
  147. super.endRoot(root);
  148. }
  149. @Override
  150. public void startPageSequence(PageSequence pageSeq) {
  151. converter.startPageSequence(pageSeq);
  152. super.startPageSequence(pageSeq);
  153. }
  154. @Override
  155. public void endPageSequence(PageSequence pageSeq) {
  156. converter.endPageSequence(pageSeq);
  157. super.endPageSequence(pageSeq);
  158. }
  159. @Override
  160. public void startPageNumber(final PageNumber pagenum) {
  161. startContent(new Event(this) {
  162. public void run() {
  163. eventHandler.startPageNumber(pagenum);
  164. }
  165. }, true);
  166. super.startPageNumber(pagenum);
  167. }
  168. @Override
  169. public void endPageNumber(final PageNumber pagenum) {
  170. endContent(new Event(this) {
  171. public void run() {
  172. eventHandler.endPageNumber(pagenum);
  173. }
  174. });
  175. super.endPageNumber(pagenum);
  176. }
  177. @Override
  178. public void startPageNumberCitation(final PageNumberCitation pageCite) {
  179. startContent(new Event(this) {
  180. public void run() {
  181. eventHandler.startPageNumberCitation(pageCite);
  182. }
  183. }, true);
  184. super.startPageNumberCitation(pageCite);
  185. }
  186. @Override
  187. public void endPageNumberCitation(final PageNumberCitation pageCite) {
  188. endContent(new Event(this) {
  189. public void run() {
  190. eventHandler.endPageNumberCitation(pageCite);
  191. }
  192. });
  193. super.endPageNumberCitation(pageCite);
  194. }
  195. @Override
  196. public void startPageNumberCitationLast(final PageNumberCitationLast pageLast) {
  197. startContent(new Event(this) {
  198. public void run() {
  199. eventHandler.startPageNumberCitationLast(pageLast);
  200. }
  201. }, true);
  202. super.startPageNumberCitationLast(pageLast);
  203. }
  204. @Override
  205. public void endPageNumberCitationLast(final PageNumberCitationLast pageLast) {
  206. endContent(new Event(this) {
  207. public void run() {
  208. eventHandler.endPageNumberCitationLast(pageLast);
  209. }
  210. });
  211. super.endPageNumberCitationLast(pageLast);
  212. }
  213. @Override
  214. public void startStatic(final StaticContent staticContent) {
  215. handleStartArtifact(staticContent);
  216. startContent(new Event(this) {
  217. public void run() {
  218. eventHandler.startStatic(staticContent);
  219. }
  220. }, true);
  221. super.startStatic(staticContent);
  222. }
  223. @Override
  224. public void endStatic(final StaticContent staticContent) {
  225. endContent(new Event(this) {
  226. public void run() {
  227. eventHandler.endStatic(staticContent);
  228. }
  229. });
  230. handleEndArtifact(staticContent);
  231. super.endStatic(staticContent);
  232. }
  233. @Override
  234. public void startFlow(Flow fl) {
  235. converter.startFlow(fl);
  236. super.startFlow(fl);
  237. }
  238. @Override
  239. public void endFlow(Flow fl) {
  240. converter.endFlow(fl);
  241. super.endFlow(fl);
  242. }
  243. @Override
  244. public void startBlock(final Block bl) {
  245. startContent(new Event(this) {
  246. public void run() {
  247. eventHandler.startBlock(bl);
  248. }
  249. }, false);
  250. super.startBlock(bl);
  251. }
  252. @Override
  253. public void endBlock(final Block bl) {
  254. endContent(new Event(this) {
  255. public void run() {
  256. eventHandler.endBlock(bl);
  257. }
  258. });
  259. super.endBlock(bl);
  260. }
  261. @Override
  262. public void startBlockContainer(final BlockContainer blc) {
  263. startContent(new Event(this) {
  264. public void run() {
  265. eventHandler.startBlockContainer(blc);
  266. }
  267. }, false);
  268. super.startBlockContainer(blc);
  269. }
  270. @Override
  271. public void endBlockContainer(final BlockContainer blc) {
  272. endContent(new Event(this) {
  273. public void run() {
  274. eventHandler.endBlockContainer(blc);
  275. }
  276. });
  277. super.endBlockContainer(blc);
  278. }
  279. @Override
  280. public void startInline(final Inline inl) {
  281. startContent(new Event(this) {
  282. public void run() {
  283. eventHandler.startInline(inl);
  284. }
  285. }, true);
  286. super.startInline(inl);
  287. }
  288. @Override
  289. public void endInline(final Inline inl) {
  290. endContent(new Event(this) {
  291. public void run() {
  292. eventHandler.endInline(inl);
  293. }
  294. });
  295. super.endInline(inl);
  296. }
  297. @Override
  298. public void startTable(final Table tbl) {
  299. startContent(new Event(this) {
  300. public void run() {
  301. eventHandler.startTable(tbl);
  302. }
  303. }, true);
  304. super.startTable(tbl);
  305. }
  306. @Override
  307. public void endTable(final Table tbl) {
  308. endContent(new Event(this) {
  309. public void run() {
  310. eventHandler.endTable(tbl);
  311. }
  312. });
  313. super.endTable(tbl);
  314. }
  315. @Override
  316. public void startColumn(final TableColumn tc) {
  317. startContent(new Event(this) {
  318. public void run() {
  319. eventHandler.startColumn(tc);
  320. }
  321. }, true);
  322. super.startColumn(tc);
  323. }
  324. @Override
  325. public void endColumn(final TableColumn tc) {
  326. endContent(new Event(this) {
  327. public void run() {
  328. eventHandler.endColumn(tc);
  329. }
  330. });
  331. super.endColumn(tc);
  332. }
  333. @Override
  334. public void startHeader(final TableHeader header) {
  335. startContent(new Event(this) {
  336. public void run() {
  337. eventHandler.startHeader(header);
  338. }
  339. }, true);
  340. super.startHeader(header);
  341. }
  342. @Override
  343. public void endHeader(final TableHeader header) {
  344. endContent(new Event(this) {
  345. public void run() {
  346. eventHandler.endHeader(header);
  347. }
  348. });
  349. super.endHeader(header);
  350. }
  351. @Override
  352. public void startFooter(final TableFooter footer) {
  353. startContent(new Event(this) {
  354. public void run() {
  355. eventHandler.startFooter(footer);
  356. }
  357. }, true);
  358. super.startFooter(footer);
  359. }
  360. @Override
  361. public void endFooter(final TableFooter footer) {
  362. endContent(new Event(this) {
  363. public void run() {
  364. eventHandler.endFooter(footer);
  365. }
  366. });
  367. super.endFooter(footer);
  368. }
  369. @Override
  370. public void startBody(final TableBody body) {
  371. startContent(new Event(this) {
  372. public void run() {
  373. eventHandler.startBody(body);
  374. }
  375. }, true);
  376. super.startBody(body);
  377. }
  378. @Override
  379. public void endBody(final TableBody body) {
  380. endContent(new Event(this) {
  381. public void run() {
  382. eventHandler.endBody(body);
  383. }
  384. });
  385. super.endBody(body);
  386. }
  387. @Override
  388. public void startRow(final TableRow tr) {
  389. startContent(new Event(this) {
  390. public void run() {
  391. eventHandler.startRow(tr);
  392. }
  393. }, true);
  394. super.startRow(tr);
  395. }
  396. @Override
  397. public void endRow(final TableRow tr) {
  398. endContent(new Event(this) {
  399. public void run() {
  400. eventHandler.endRow(tr);
  401. }
  402. });
  403. super.endRow(tr);
  404. }
  405. @Override
  406. public void startCell(final TableCell tc) {
  407. startContent(new Event(this) {
  408. public void run() {
  409. eventHandler.startCell(tc);
  410. }
  411. }, true);
  412. super.startCell(tc);
  413. }
  414. @Override
  415. public void endCell(final TableCell tc) {
  416. endContent(new Event(this) {
  417. public void run() {
  418. eventHandler.endCell(tc);
  419. }
  420. });
  421. super.endCell(tc);
  422. }
  423. @Override
  424. public void startList(final ListBlock lb) {
  425. startContent(new Event(this) {
  426. public void run() {
  427. eventHandler.startList(lb);
  428. }
  429. }, true);
  430. super.startList(lb);
  431. }
  432. @Override
  433. public void endList(final ListBlock lb) {
  434. endContent(new Event(this) {
  435. public void run() {
  436. eventHandler.endList(lb);
  437. }
  438. });
  439. super.endList(lb);
  440. }
  441. @Override
  442. public void startListItem(final ListItem li) {
  443. startContent(new Event(this) {
  444. public void run() {
  445. eventHandler.startListItem(li);
  446. }
  447. }, true);
  448. super.startListItem(li);
  449. }
  450. @Override
  451. public void endListItem(final ListItem li) {
  452. endContent(new Event(this) {
  453. public void run() {
  454. eventHandler.endListItem(li);
  455. }
  456. });
  457. super.endListItem(li);
  458. }
  459. @Override
  460. public void startListLabel(final ListItemLabel listItemLabel) {
  461. startContent(new Event(this) {
  462. public void run() {
  463. eventHandler.startListLabel(listItemLabel);
  464. }
  465. }, true);
  466. super.startListLabel(listItemLabel);
  467. }
  468. @Override
  469. public void endListLabel(final ListItemLabel listItemLabel) {
  470. endContent(new Event(this) {
  471. public void run() {
  472. eventHandler.endListLabel(listItemLabel);
  473. }
  474. });
  475. super.endListLabel(listItemLabel);
  476. }
  477. @Override
  478. public void startListBody(final ListItemBody listItemBody) {
  479. startContent(new Event(this) {
  480. public void run() {
  481. eventHandler.startListBody(listItemBody);
  482. }
  483. }, true);
  484. super.startListBody(listItemBody);
  485. }
  486. @Override
  487. public void endListBody(final ListItemBody listItemBody) {
  488. endContent(new Event(this) {
  489. public void run() {
  490. eventHandler.endListBody(listItemBody);
  491. }
  492. });
  493. super.endListBody(listItemBody);
  494. }
  495. @Override
  496. public void startMarkup() {
  497. startContent(new Event(this) {
  498. public void run() {
  499. eventHandler.startMarkup();
  500. }
  501. }, true);
  502. super.startMarkup();
  503. }
  504. @Override
  505. public void endMarkup() {
  506. endContent(new Event(this) {
  507. public void run() {
  508. eventHandler.endMarkup();
  509. }
  510. });
  511. super.endMarkup();
  512. }
  513. @Override
  514. public void startLink(final BasicLink basicLink) {
  515. startContent(new Event(this) {
  516. public void run() {
  517. eventHandler.startLink(basicLink);
  518. }
  519. }, true);
  520. super.startLink(basicLink);
  521. }
  522. @Override
  523. public void endLink(final BasicLink basicLink) {
  524. endContent(new Event(this) {
  525. public void run() {
  526. eventHandler.endLink(basicLink);
  527. }
  528. });
  529. super.endLink(basicLink);
  530. }
  531. @Override
  532. public void image(final ExternalGraphic eg) {
  533. content(new Event(this) {
  534. public void run() {
  535. eventHandler.image(eg);
  536. }
  537. }, true);
  538. super.image(eg);
  539. }
  540. @Override
  541. public void pageRef() {
  542. content(new Event(this) {
  543. public void run() {
  544. eventHandler.pageRef();
  545. }
  546. }, true);
  547. super.pageRef();
  548. }
  549. @Override
  550. public void startInstreamForeignObject(final InstreamForeignObject ifo) {
  551. startContent(new Event(this) {
  552. public void run() {
  553. eventHandler.startInstreamForeignObject(ifo);
  554. }
  555. }, true);
  556. super.startInstreamForeignObject(ifo);
  557. }
  558. @Override
  559. public void endInstreamForeignObject(final InstreamForeignObject ifo) {
  560. endContent(new Event(this) {
  561. public void run() {
  562. eventHandler.endInstreamForeignObject(ifo);
  563. }
  564. });
  565. super.endInstreamForeignObject(ifo);
  566. }
  567. @Override
  568. public void startFootnote(final Footnote footnote) {
  569. startContent(new Event(this) {
  570. public void run() {
  571. eventHandler.startFootnote(footnote);
  572. }
  573. }, true);
  574. super.startFootnote(footnote);
  575. }
  576. @Override
  577. public void endFootnote(final Footnote footnote) {
  578. endContent(new Event(this) {
  579. public void run() {
  580. eventHandler.endFootnote(footnote);
  581. }
  582. });
  583. super.endFootnote(footnote);
  584. }
  585. @Override
  586. public void startFootnoteBody(final FootnoteBody body) {
  587. startContent(new Event(this) {
  588. public void run() {
  589. eventHandler.startFootnoteBody(body);
  590. }
  591. }, true);
  592. super.startFootnoteBody(body);
  593. }
  594. @Override
  595. public void endFootnoteBody(final FootnoteBody body) {
  596. endContent(new Event(this) {
  597. public void run() {
  598. eventHandler.endFootnoteBody(body);
  599. }
  600. });
  601. super.endFootnoteBody(body);
  602. }
  603. @Override
  604. public void startLeader(final Leader l) {
  605. converters.push(converter);
  606. converter = eventSwallower;
  607. startContent(new Event(this) {
  608. public void run() {
  609. eventHandler.startLeader(l);
  610. }
  611. }, true);
  612. super.startLeader(l);
  613. }
  614. @Override
  615. public void endLeader(final Leader l) {
  616. endContent(new Event(this) {
  617. public void run() {
  618. eventHandler.endLeader(l);
  619. }
  620. });
  621. converter = converters.pop();
  622. super.endLeader(l);
  623. }
  624. @Override
  625. public void startWrapper(final Wrapper wrapper) {
  626. handleStartArtifact(wrapper);
  627. startContent(new Event(this) {
  628. public void run() {
  629. eventHandler.startWrapper(wrapper);
  630. }
  631. }, true);
  632. super.startWrapper(wrapper);
  633. }
  634. @Override
  635. public void endWrapper(final Wrapper wrapper) {
  636. endContent(new Event(this) {
  637. public void run() {
  638. eventHandler.endWrapper(wrapper);
  639. }
  640. });
  641. handleEndArtifact(wrapper);
  642. super.endWrapper(wrapper);
  643. }
  644. @Override
  645. public void startRetrieveMarker(final RetrieveMarker retrieveMarker) {
  646. startContent(new Event(this) {
  647. public void run() {
  648. eventHandler.startRetrieveMarker(retrieveMarker);
  649. }
  650. }, true);
  651. saveState(retrieveMarker);
  652. super.startRetrieveMarker(retrieveMarker);
  653. }
  654. private void saveState(AbstractRetrieveMarker retrieveMarker) {
  655. states.put(retrieveMarker, new State(this));
  656. }
  657. @Override
  658. public void endRetrieveMarker(final RetrieveMarker retrieveMarker) {
  659. endContent(new Event(this) {
  660. public void run() {
  661. eventHandler.endRetrieveMarker(retrieveMarker);
  662. }
  663. });
  664. super.endRetrieveMarker(retrieveMarker);
  665. }
  666. @Override
  667. public void restoreState(final RetrieveMarker retrieveMarker) {
  668. restoreRetrieveMarkerState(retrieveMarker);
  669. content(new Event(this) {
  670. public void run() {
  671. eventHandler.restoreState(retrieveMarker);
  672. }
  673. }, true);
  674. super.restoreState(retrieveMarker);
  675. }
  676. @SuppressWarnings("unchecked")
  677. private void restoreRetrieveMarkerState(AbstractRetrieveMarker retrieveMarker) {
  678. State state = states.get(retrieveMarker);
  679. this.converter = state.converter;
  680. this.converters = (Stack<FOEventHandler>) state.converters.clone();
  681. }
  682. @Override
  683. public void startRetrieveTableMarker(final RetrieveTableMarker retrieveTableMarker) {
  684. startContent(new Event(this) {
  685. public void run() {
  686. eventHandler.startRetrieveTableMarker(retrieveTableMarker);
  687. }
  688. }, true);
  689. saveState(retrieveTableMarker);
  690. super.startRetrieveTableMarker(retrieveTableMarker);
  691. }
  692. @Override
  693. public void endRetrieveTableMarker(final RetrieveTableMarker retrieveTableMarker) {
  694. endContent(new Event(this) {
  695. public void run() {
  696. eventHandler.endRetrieveTableMarker(retrieveTableMarker);
  697. }
  698. });
  699. super.endRetrieveTableMarker(retrieveTableMarker);
  700. }
  701. @Override
  702. public void restoreState(final RetrieveTableMarker retrieveTableMarker) {
  703. restoreRetrieveMarkerState(retrieveTableMarker);
  704. currentNode.add(new Event(this) {
  705. public void run() {
  706. eventHandler.restoreState(retrieveTableMarker);
  707. }
  708. });
  709. super.restoreState(retrieveTableMarker);
  710. }
  711. @Override
  712. public void character(final Character c) {
  713. content(new Event(this) {
  714. public void run() {
  715. eventHandler.character(c);
  716. }
  717. }, true);
  718. super.character(c);
  719. }
  720. @Override
  721. public void characters(final FOText foText) {
  722. content(new Event(this) {
  723. public void run() {
  724. eventHandler.characters(foText);
  725. }
  726. }, foText.length() > 0);
  727. super.characters(foText);
  728. }
  729. @Override
  730. public void startExternalDocument(final ExternalDocument document) {
  731. startContent(new Event(this) {
  732. public void run() {
  733. eventHandler.startExternalDocument(document);
  734. }
  735. }, true);
  736. super.startExternalDocument(document);
  737. }
  738. @Override
  739. public void endExternalDocument(final ExternalDocument document) {
  740. endContent(new Event(this) {
  741. public void run() {
  742. eventHandler.endExternalDocument(document);
  743. }
  744. });
  745. super.endExternalDocument(document);
  746. }
  747. private void handleStartArtifact(CommonAccessibilityHolder fobj) {
  748. if (isArtifact(fobj)) {
  749. converters.push(converter);
  750. converter = eventSwallower;
  751. }
  752. }
  753. private void handleEndArtifact(CommonAccessibilityHolder fobj) {
  754. if (isArtifact(fobj)) {
  755. converter = converters.pop();
  756. }
  757. }
  758. private boolean isArtifact(CommonAccessibilityHolder fobj) {
  759. CommonAccessibility accessibility = fobj.getCommonAccessibility();
  760. return Accessibility.ROLE_ARTIFACT.equalsIgnoreCase(accessibility.getRole());
  761. }
  762. }