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 18 /* $Id: FOEventHandler.java 1465599 2013-04-08 11:51:52Z vhennebert $ */ 19 20 package org.apache.fop.fo; 21 22 import org.xml.sax.SAXException; 23 24 import org.apache.fop.apps.FOUserAgent; 25 import org.apache.fop.apps.FormattingResults; 26 import org.apache.fop.fo.extensions.ExternalDocument; 27 import org.apache.fop.fo.flow.BasicLink; 28 import org.apache.fop.fo.flow.Block; 29 import org.apache.fop.fo.flow.BlockContainer; 30 import org.apache.fop.fo.flow.Character; 31 import org.apache.fop.fo.flow.ExternalGraphic; 32 import org.apache.fop.fo.flow.Footnote; 33 import org.apache.fop.fo.flow.FootnoteBody; 34 import org.apache.fop.fo.flow.Inline; 35 import org.apache.fop.fo.flow.InstreamForeignObject; 36 import org.apache.fop.fo.flow.Leader; 37 import org.apache.fop.fo.flow.ListBlock; 38 import org.apache.fop.fo.flow.ListItem; 39 import org.apache.fop.fo.flow.ListItemBody; 40 import org.apache.fop.fo.flow.ListItemLabel; 41 import org.apache.fop.fo.flow.PageNumber; 42 import org.apache.fop.fo.flow.PageNumberCitation; 43 import org.apache.fop.fo.flow.PageNumberCitationLast; 44 import org.apache.fop.fo.flow.RetrieveMarker; 45 import org.apache.fop.fo.flow.RetrieveTableMarker; 46 import org.apache.fop.fo.flow.Wrapper; 47 import org.apache.fop.fo.flow.table.Table; 48 import org.apache.fop.fo.flow.table.TableBody; 49 import org.apache.fop.fo.flow.table.TableCell; 50 import org.apache.fop.fo.flow.table.TableColumn; 51 import org.apache.fop.fo.flow.table.TableFooter; 52 import org.apache.fop.fo.flow.table.TableHeader; 53 import org.apache.fop.fo.flow.table.TableRow; 54 import org.apache.fop.fo.pagination.Flow; 55 import org.apache.fop.fo.pagination.PageSequence; 56 import org.apache.fop.fo.pagination.Root; 57 import org.apache.fop.fo.pagination.StaticContent; 58 import org.apache.fop.fonts.FontEventAdapter; 59 import org.apache.fop.fonts.FontInfo; 60 61 /** 62 * Abstract class defining what should be done with SAX events that map to 63 * XSL-FO input. The events are actually captured by fo/FOTreeBuilder, passed 64 * to the various fo Objects, which in turn, if needed, pass them to an instance 65 * of FOEventHandler. 66 * 67 * Sub-classes will generally fall into one of two categories: 68 * 1) a handler that actually builds an FO Tree from the events, or 2) a 69 * handler that builds a structured (as opposed to formatted) document, such 70 * as our MIF and RTF output targets. 71 */ 72 public abstract class FOEventHandler { 73 74 /** 75 * The FOUserAgent for this process 76 */ 77 protected FOUserAgent foUserAgent; 78 79 /** 80 * The Font information relevant for this document 81 */ 82 protected FontInfo fontInfo; 83 84 /** 85 * Main constructor 86 * @param foUserAgent the apps.FOUserAgent instance for this process 87 */ FOEventHandler(FOUserAgent foUserAgent)88 public FOEventHandler(FOUserAgent foUserAgent) { 89 this.foUserAgent = foUserAgent; 90 this.fontInfo = new FontInfo(); 91 this.fontInfo.setEventListener(new FontEventAdapter(foUserAgent.getEventBroadcaster())); 92 } 93 94 /** Constructor for sub-classes that do not need an {@link FOUserAgent} instance. */ FOEventHandler()95 protected FOEventHandler() { 96 } 97 98 /** 99 * Returns the User Agent object associated with this FOEventHandler. 100 * @return the User Agent object 101 */ getUserAgent()102 public FOUserAgent getUserAgent() { 103 return foUserAgent; 104 } 105 106 /** 107 * Retrieve the font information for this document 108 * @return the FontInfo instance for this document 109 */ getFontInfo()110 public FontInfo getFontInfo() { 111 return this.fontInfo; 112 } 113 114 /** 115 * This method is called to indicate the start of a new document run. 116 * @throws SAXException In case of a problem 117 */ startDocument()118 public void startDocument() throws SAXException { 119 } 120 121 /** 122 * This method is called to indicate the end of a document run. 123 * @throws SAXException In case of a problem 124 */ endDocument()125 public void endDocument() throws SAXException { 126 } 127 128 /** 129 * Called upon start of root element. 130 * @param root element 131 */ startRoot(Root root)132 public void startRoot(Root root) { 133 } 134 135 /** 136 * Called upon end of root element. 137 * @param root element 138 */ endRoot(Root root)139 public void endRoot(Root root) { 140 } 141 142 /** 143 * 144 * @param pageSeq PageSequence that is starting. 145 */ startPageSequence(PageSequence pageSeq)146 public void startPageSequence(PageSequence pageSeq) { 147 } 148 149 /** 150 * @param pageSeq PageSequence that is ending. 151 */ endPageSequence(PageSequence pageSeq)152 public void endPageSequence(PageSequence pageSeq) { 153 } 154 155 /** 156 * 157 * @param pagenum PageNumber that is starting. 158 */ startPageNumber(PageNumber pagenum)159 public void startPageNumber(PageNumber pagenum) { 160 } 161 162 /** 163 * 164 * @param pagenum PageNumber that is ending. 165 */ endPageNumber(PageNumber pagenum)166 public void endPageNumber(PageNumber pagenum) { 167 } 168 169 /** 170 * 171 * @param pageCite PageNumberCitation that is starting. 172 */ startPageNumberCitation(PageNumberCitation pageCite)173 public void startPageNumberCitation(PageNumberCitation pageCite) { 174 } 175 176 /** 177 * 178 * @param pageCite PageNumberCitation that is ending. 179 */ endPageNumberCitation(PageNumberCitation pageCite)180 public void endPageNumberCitation(PageNumberCitation pageCite) { 181 } 182 183 /** 184 * 185 * @param pageLast PageNumberCitationLast that is starting. 186 */ startPageNumberCitationLast(PageNumberCitationLast pageLast)187 public void startPageNumberCitationLast(PageNumberCitationLast pageLast) { 188 } 189 190 /** 191 * 192 * @param pageLast PageNumberCitationLast that is ending. 193 */ endPageNumberCitationLast(PageNumberCitationLast pageLast)194 public void endPageNumberCitationLast(PageNumberCitationLast pageLast) { 195 } 196 197 /** 198 * Process start of a Static. 199 * @param staticContent StaticContent that is starting 200 */ startStatic(StaticContent staticContent)201 public void startStatic(StaticContent staticContent) { 202 } 203 204 /** 205 * Process end of a Static. 206 * @param staticContent StaticContent that is ending 207 */ endStatic(StaticContent staticContent)208 public void endStatic(StaticContent staticContent) { 209 } 210 211 /** 212 * This method is called to indicate the start of a new fo:flow 213 * or fo:static-content. 214 * This method also handles fo:static-content tags, because the 215 * StaticContent class is derived from the Flow class. 216 * 217 * @param fl Flow that is starting. 218 */ startFlow(Flow fl)219 public void startFlow(Flow fl) { 220 } 221 222 /** 223 * 224 * @param fl Flow that is ending. 225 */ endFlow(Flow fl)226 public void endFlow(Flow fl) { 227 } 228 229 /** 230 * 231 * @param bl Block that is starting. 232 */ startBlock(Block bl)233 public void startBlock(Block bl) { 234 } 235 236 /** 237 * 238 * @param bl Block that is ending. 239 */ endBlock(Block bl)240 public void endBlock(Block bl) { 241 } 242 243 /** 244 * 245 * @param blc BlockContainer that is starting. 246 */ startBlockContainer(BlockContainer blc)247 public void startBlockContainer(BlockContainer blc) { 248 } 249 250 /** 251 * 252 * @param blc BlockContainer that is ending. 253 */ endBlockContainer(BlockContainer blc)254 public void endBlockContainer(BlockContainer blc) { 255 } 256 257 /** 258 * 259 * @param inl Inline that is starting. 260 */ startInline(Inline inl)261 public void startInline(Inline inl) { 262 } 263 264 /** 265 * 266 * @param inl Inline that is ending. 267 */ endInline(Inline inl)268 public void endInline(Inline inl) { 269 } 270 271 // Tables 272 /** 273 * 274 * @param tbl Table that is starting. 275 */ startTable(Table tbl)276 public void startTable(Table tbl) { 277 } 278 279 /** 280 * 281 * @param tbl Table that is ending. 282 */ endTable(Table tbl)283 public void endTable(Table tbl) { 284 } 285 286 /** 287 * 288 * @param tc TableColumn that is starting; 289 */ startColumn(TableColumn tc)290 public void startColumn(TableColumn tc) { 291 } 292 293 /** 294 * 295 * @param tc TableColumn that is ending; 296 */ endColumn(TableColumn tc)297 public void endColumn(TableColumn tc) { 298 } 299 300 /** 301 * 302 * @param header TableHeader that is starting; 303 */ startHeader(TableHeader header)304 public void startHeader(TableHeader header) { 305 } 306 307 /** 308 * 309 * @param header TableHeader that is ending. 310 */ endHeader(TableHeader header)311 public void endHeader(TableHeader header) { 312 } 313 314 /** 315 * 316 * @param footer TableFooter that is starting. 317 */ startFooter(TableFooter footer)318 public void startFooter(TableFooter footer) { 319 } 320 321 /** 322 * 323 * @param footer TableFooter that is ending. 324 */ endFooter(TableFooter footer)325 public void endFooter(TableFooter footer) { 326 } 327 328 /** 329 * 330 * @param body TableBody that is starting. 331 */ startBody(TableBody body)332 public void startBody(TableBody body) { 333 } 334 335 /** 336 * 337 * @param body TableBody that is ending. 338 */ endBody(TableBody body)339 public void endBody(TableBody body) { 340 } 341 342 /** 343 * 344 * @param tr TableRow that is starting. 345 */ startRow(TableRow tr)346 public void startRow(TableRow tr) { 347 } 348 349 /** 350 * 351 * @param tr TableRow that is ending. 352 */ endRow(TableRow tr)353 public void endRow(TableRow tr) { 354 } 355 356 /** 357 * 358 * @param tc TableCell that is starting. 359 */ startCell(TableCell tc)360 public void startCell(TableCell tc) { 361 } 362 363 /** 364 * 365 * @param tc TableCell that is ending. 366 */ endCell(TableCell tc)367 public void endCell(TableCell tc) { 368 } 369 370 371 // Lists 372 /** 373 * 374 * @param lb ListBlock that is starting. 375 */ startList(ListBlock lb)376 public void startList(ListBlock lb) { 377 } 378 379 /** 380 * 381 * @param lb ListBlock that is ending. 382 */ endList(ListBlock lb)383 public void endList(ListBlock lb) { 384 } 385 386 /** 387 * 388 * @param li ListItem that is starting. 389 */ startListItem(ListItem li)390 public void startListItem(ListItem li) { 391 } 392 393 /** 394 * 395 * @param li ListItem that is ending. 396 */ endListItem(ListItem li)397 public void endListItem(ListItem li) { 398 } 399 400 /** 401 * Process start of a ListLabel. 402 * @param listItemLabel ListItemLabel that is starting 403 */ startListLabel(ListItemLabel listItemLabel)404 public void startListLabel(ListItemLabel listItemLabel) { 405 } 406 407 /** 408 * Process end of a ListLabel. 409 * @param listItemLabel ListItemLabel that is ending 410 */ endListLabel(ListItemLabel listItemLabel)411 public void endListLabel(ListItemLabel listItemLabel) { 412 } 413 414 /** 415 * Process start of a ListBody. 416 * @param listItemBody ListItemBody that is starting 417 */ startListBody(ListItemBody listItemBody)418 public void startListBody(ListItemBody listItemBody) { 419 } 420 421 /** 422 * Process end of a ListBody. 423 * @param listItemBody ListItemBody that is ending 424 */ endListBody(ListItemBody listItemBody)425 public void endListBody(ListItemBody listItemBody) { 426 } 427 428 /** 429 * Process start of a Markup. 430 */ startMarkup()431 public void startMarkup() { 432 } 433 434 /** 435 * Process end of a Markup. 436 */ endMarkup()437 public void endMarkup() { 438 } 439 440 /** 441 * Process start of a Link. 442 * @param basicLink BasicLink that is starting 443 */ startLink(BasicLink basicLink)444 public void startLink(BasicLink basicLink) { 445 } 446 447 /** 448 * Process end of a Link. 449 * @param basicLink BasicLink that is ending 450 */ endLink(BasicLink basicLink)451 public void endLink(BasicLink basicLink) { 452 } 453 454 /** 455 * Process an ExternalGraphic. 456 * @param eg ExternalGraphic to process. 457 */ image(ExternalGraphic eg)458 public void image(ExternalGraphic eg) { 459 } 460 461 /** 462 * Process a pageRef. 463 */ pageRef()464 public void pageRef() { 465 } 466 467 /** 468 * Process the start of an InstreamForeignObject. 469 * @param ifo InstreamForeignObject that is starting 470 */ startInstreamForeignObject(InstreamForeignObject ifo)471 public void startInstreamForeignObject(InstreamForeignObject ifo) { 472 } 473 474 /** 475 * Process the end of an InstreamForeignObject. 476 * @param ifo InstreamForeignObject that is ending 477 */ endInstreamForeignObject(InstreamForeignObject ifo)478 public void endInstreamForeignObject(InstreamForeignObject ifo) { 479 } 480 481 /** 482 * Process the start of a footnote. 483 * @param footnote Footnote that is starting 484 */ startFootnote(Footnote footnote)485 public void startFootnote(Footnote footnote) { 486 } 487 488 /** 489 * Process the ending of a footnote. 490 * @param footnote Footnote that is ending 491 */ endFootnote(Footnote footnote)492 public void endFootnote(Footnote footnote) { 493 } 494 495 /** 496 * Process the start of a footnote body. 497 * @param body FootnoteBody that is starting 498 */ startFootnoteBody(FootnoteBody body)499 public void startFootnoteBody(FootnoteBody body) { 500 } 501 502 /** 503 * Process the ending of a footnote body. 504 * @param body FootnoteBody that is ending 505 */ endFootnoteBody(FootnoteBody body)506 public void endFootnoteBody(FootnoteBody body) { 507 } 508 509 /** 510 * Process the start of a Leader. 511 * @param l Leader that is starting 512 */ startLeader(Leader l)513 public void startLeader(Leader l) { 514 } 515 516 /** 517 * Process the end of a Leader. 518 * @param l Leader that is ending 519 */ endLeader(Leader l)520 public void endLeader(Leader l) { 521 } 522 523 /** 524 * Process the start of a wrapper. 525 * 526 * @param wrapper wrapper that is starting 527 */ startWrapper(Wrapper wrapper)528 public void startWrapper(Wrapper wrapper) { 529 } 530 531 /** 532 * Process the ending of a wrapper. 533 * 534 * @param wrapper wrapper that is ending 535 */ endWrapper(Wrapper wrapper)536 public void endWrapper(Wrapper wrapper) { 537 } 538 539 /** 540 * Process the start of a retrieve-marker. 541 * 542 * @param retrieveMarker the retrieve-marker that is starting 543 */ startRetrieveMarker(RetrieveMarker retrieveMarker)544 public void startRetrieveMarker(RetrieveMarker retrieveMarker) { 545 } 546 547 548 /** 549 * Process the ending of a retrieve-marker. 550 * 551 * @param retrieveMarker the retrieve-marker that is ending 552 */ endRetrieveMarker(RetrieveMarker retrieveMarker)553 public void endRetrieveMarker(RetrieveMarker retrieveMarker) { 554 } 555 556 /** 557 * Restore the state of this event handler as it was when the given fo:retrieve-marker 558 * element was processed. This method is called at marker retrieval time, so that 559 * events for the marker descendants are fired within the proper context. 560 * <p>The default implementation of this method does nothing.</p> 561 * 562 * @param retrieveMarker the fo:retrieve-marker element that is retrieving markers 563 */ restoreState(RetrieveMarker retrieveMarker)564 public void restoreState(RetrieveMarker retrieveMarker) { 565 } 566 567 /** 568 * Process the start of a retrieve-table-marker. 569 * 570 * @param retrieveTableMarker the retrieve-table-marker that is starting 571 */ startRetrieveTableMarker(RetrieveTableMarker retrieveTableMarker)572 public void startRetrieveTableMarker(RetrieveTableMarker retrieveTableMarker) { 573 } 574 575 /** 576 * Process the ending of a retrieve-table-marker. 577 * 578 * @param retrieveTableMarker the retrieve-table-marker that is ending 579 */ endRetrieveTableMarker(RetrieveTableMarker retrieveTableMarker)580 public void endRetrieveTableMarker(RetrieveTableMarker retrieveTableMarker) { 581 } 582 583 /** 584 * See {@link #restoreState(RetrieveMarker)}. 585 */ restoreState(RetrieveTableMarker retrieveTableMarker)586 public void restoreState(RetrieveTableMarker retrieveTableMarker) { 587 } 588 589 /** 590 * Process a Character. 591 * @param c Character to process. 592 */ character(Character c)593 public void character(Character c) { 594 } 595 596 /** 597 * Process character data. 598 * @param foText text to process 599 */ characters(FOText foText)600 public void characters(FOText foText) { 601 } 602 603 /** 604 * Process the start of the external-document extension. 605 * @param document the external-document node 606 */ startExternalDocument(ExternalDocument document)607 public void startExternalDocument(ExternalDocument document) { 608 } 609 610 /** 611 * Process the end of the external-document extension. 612 * @param document the external-document node 613 */ endExternalDocument(ExternalDocument document)614 public void endExternalDocument(ExternalDocument document) { 615 } 616 617 /** 618 * Get formatting results. 619 * @return the FormattingResults instance for this document 620 */ getResults()621 public FormattingResults getResults() { 622 return null; 623 } 624 625 } 626 627