aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache/fop/accessibility/StructureTreeBuildingFOEventHandler.java
blob: e3f94681018e99b750935dcdf5d086c0e376bcb6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/* $Id$ */

package org.apache.fop.accessibility;

import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMResult;
import javax.xml.transform.sax.SAXTransformerFactory;
import javax.xml.transform.sax.TransformerHandler;

import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;

import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.fo.DelegatingFOEventHandler;
import org.apache.fop.fo.FOEventHandler;
import org.apache.fop.fo.FONode;
import org.apache.fop.fo.extensions.ExtensionElementMapping;
import org.apache.fop.fo.extensions.ExternalDocument;
import org.apache.fop.fo.extensions.InternalElementMapping;
import org.apache.fop.fo.flow.AbstractGraphics;
import org.apache.fop.fo.flow.BasicLink;
import org.apache.fop.fo.flow.Block;
import org.apache.fop.fo.flow.BlockContainer;
import org.apache.fop.fo.flow.Character;
import org.apache.fop.fo.flow.ExternalGraphic;
import org.apache.fop.fo.flow.Footnote;
import org.apache.fop.fo.flow.FootnoteBody;
import org.apache.fop.fo.flow.Inline;
import org.apache.fop.fo.flow.InstreamForeignObject;
import org.apache.fop.fo.flow.Leader;
import org.apache.fop.fo.flow.ListBlock;
import org.apache.fop.fo.flow.ListItem;
import org.apache.fop.fo.flow.ListItemBody;
import org.apache.fop.fo.flow.ListItemLabel;
import org.apache.fop.fo.flow.PageNumber;
import org.apache.fop.fo.flow.PageNumberCitation;
import org.apache.fop.fo.flow.PageNumberCitationLast;
import org.apache.fop.fo.flow.Wrapper;
import org.apache.fop.fo.flow.table.Table;
import org.apache.fop.fo.flow.table.TableBody;
import org.apache.fop.fo.flow.table.TableCell;
import org.apache.fop.fo.flow.table.TableColumn;
import org.apache.fop.fo.flow.table.TableFooter;
import org.apache.fop.fo.flow.table.TableHeader;
import org.apache.fop.fo.flow.table.TableRow;
import org.apache.fop.fo.pagination.Flow;
import org.apache.fop.fo.pagination.PageSequence;
import org.apache.fop.fo.pagination.StaticContent;
import org.apache.fop.fo.properties.CommonAccessibilityHolder;
import org.apache.fop.util.XMLUtil;

/**
 * A class that builds the document's structure tree.
 */
public class StructureTreeBuildingFOEventHandler extends DelegatingFOEventHandler {

    private int idCounter;

    private final StructureTree structureTree;

    private TransformerHandler structureTreeDOMBuilder;

    private DOMResult result;

    /** Delegates to either {@link #actualStructureTreeBuilder} or {@link #eventSwallower}. */
    private FOEventHandler structureTreeBuilder;

    private FOEventHandler actualStructureTreeBuilder;

    /** The descendants of some elements like fo:leader must be ignored. */
    private final FOEventHandler eventSwallower;

    private final class StructureTreeBuilder extends FOEventHandler {

        public StructureTreeBuilder(FOUserAgent foUserAgent) {
            super(foUserAgent);
        }

        @Override
        public void startDocument() throws SAXException {
        }

        @Override
        public void endDocument() throws SAXException {
        }

        @Override
        public void startPageSequence(PageSequence pageSeq) {
            SAXTransformerFactory transformerFactory =
                    (SAXTransformerFactory) TransformerFactory.newInstance();
            try {
                structureTreeDOMBuilder = transformerFactory.newTransformerHandler();
            } catch (TransformerConfigurationException e) {
                throw new RuntimeException(e);
            }
            result = new DOMResult();
            structureTreeDOMBuilder.setResult(result);
            try {
                structureTreeDOMBuilder.startDocument();
            } catch (SAXException e) {
                throw new RuntimeException(e);
            }
            startElement(pageSeq);
        }

        @Override
        public void endPageSequence(PageSequence pageSeq) {
            endElement(pageSeq);
            try {
                structureTreeDOMBuilder.endDocument();
            } catch (SAXException e) {
                throw new RuntimeException(e);
            }
            structureTree.addPageSequenceStructure(
                    result.getNode().getFirstChild().getChildNodes());
        }

        @Override
        public void startPageNumber(PageNumber pagenum) {
            startElementWithID(pagenum);
        }

        @Override
        public void endPageNumber(PageNumber pagenum) {
            endElement(pagenum);
        }

        @Override
        public void startPageNumberCitation(PageNumberCitation pageCite) {
            startElementWithID(pageCite);
        }

        @Override
        public void endPageNumberCitation(PageNumberCitation pageCite) {
            endElement(pageCite);
        }

        @Override
        public void startPageNumberCitationLast(PageNumberCitationLast pageLast) {
            startElementWithID(pageLast);
        }

        @Override
        public void endPageNumberCitationLast(PageNumberCitationLast pageLast) {
            endElement(pageLast);
        }

        @Override
        public void startFlow(Flow fl) {
            startElement(fl);
        }

        @Override
        public void endFlow(Flow fl) {
            endElement(fl);
        }

        @Override
        public void startBlock(Block bl) {
            startElementWithID(bl);
        }

        @Override
        public void endBlock(Block bl) {
            endElement(bl);
        }

        @Override
        public void startBlockContainer(BlockContainer blc) {
            startElement(blc);
        }

        @Override
        public void endBlockContainer(BlockContainer blc) {
            endElement(blc);
        }

        @Override
        public void startInline(Inline inl) {
            startElementWithID(inl);
        }

        @Override
        public void endInline(Inline inl) {
            endElement(inl);
        }

        @Override
        public void startTable(Table tbl) {
            startElementWithID(tbl);
        }

        @Override
        public void endTable(Table tbl) {
            endElement(tbl);
        }

        @Override
        public void startHeader(TableHeader header) {
            startElementWithID(header);
        }

        @Override
        public void endHeader(TableHeader header) {
            endElement(header);
        }

        @Override
        public void startFooter(TableFooter footer) {
            startElementWithID(footer);
        }

        @Override
        public void endFooter(TableFooter footer) {
            endElement(footer);
        }

        @Override
        public void startBody(TableBody body) {
            startElementWithID(body);
        }

        @Override
        public void endBody(TableBody body) {
            endElement(body);
        }

        @Override
        public void startRow(TableRow tr) {
            startElementWithID(tr);
        }

        @Override
        public void endRow(TableRow tr) {
            endElement(tr);
        }

        @Override
        public void startCell(TableCell tc) {
            AttributesImpl attributes = new AttributesImpl();
            int colSpan = tc.getNumberColumnsSpanned();
            if (colSpan > 1) {
                addNoNamespaceAttribute(attributes, "number-columns-spanned",
                        Integer.toString(colSpan));
            }
            startElementWithID(tc, attributes);
        }

        @Override
        public void endCell(TableCell tc) {
            endElement(tc);
        }

        @Override
        public void startList(ListBlock lb) {
            startElement(lb);
        }

        @Override
        public void endList(ListBlock lb) {
            endElement(lb);
        }

        @Override
        public void startListItem(ListItem li) {
            startElement(li);
        }

        @Override
        public void endListItem(ListItem li) {
            endElement(li);
        }

        @Override
        public void startListLabel(ListItemLabel listItemLabel) {
            startElement(listItemLabel);
        }

        @Override
        public void endListLabel(ListItemLabel listItemLabel) {
            endElement(listItemLabel);
        }

        @Override
        public void startListBody(ListItemBody listItemBody) {
            startElement(listItemBody);
        }

        @Override
        public void endListBody(ListItemBody listItemBody) {
            endElement(listItemBody);
        }

        @Override
        public void startStatic(StaticContent staticContent) {
            startElement(staticContent);
        }

        @Override
        public void endStatic(StaticContent statisContent) {
            endElement(statisContent);
        }

        @Override
        public void startLink(BasicLink basicLink) {
            startElementWithID(basicLink);
        }

        @Override
        public void endLink(BasicLink basicLink) {
            endElement(basicLink);
        }

        @Override
        public void image(ExternalGraphic eg) {
            startElementWithIDAndAltText(eg);
            endElement(eg);
        }

        @Override
        public void startInstreamForeignObject(InstreamForeignObject ifo) {
            startElementWithIDAndAltText(ifo);
        }

        @Override
        public void endInstreamForeignObject(InstreamForeignObject ifo) {
            endElement(ifo);
        }

        @Override
        public void startFootnote(Footnote footnote) {
            startElement(footnote);
        }

        @Override
        public void endFootnote(Footnote footnote) {
            endElement(footnote);
        }

        @Override
        public void startFootnoteBody(FootnoteBody body) {
            startElement(body);
        }

        @Override
        public void endFootnoteBody(FootnoteBody body) {
            endElement(body);
        }

        @Override
        public void startWrapper(Wrapper wrapper) {
            startElement(wrapper);
        }

        @Override
        public void endWrapper(Wrapper wrapper) {
            endElement(wrapper);
        }

        @Override
        public void character(Character c) {
            startElementWithID(c);
            endElement(c);
        }

        private void startElement(FONode node) {
            startElement(node, new AttributesImpl());
        }

        private void startElementWithID(FONode node) {
            startElementWithID(node, new AttributesImpl());
        }

        private void startElementWithIDAndAltText(AbstractGraphics node) {
            AttributesImpl attributes = new AttributesImpl();
            addAttribute(attributes, ExtensionElementMapping.URI, "alt-text",
                    ExtensionElementMapping.STANDARD_PREFIX, node.getAltText());
            startElementWithID(node, attributes);
        }

        private void startElementWithID(FONode node, AttributesImpl attributes) {
            String id = Integer.toHexString(idCounter++);
            node.setPtr(id);
            addAttribute(attributes,
                    InternalElementMapping.URI, "ptr", InternalElementMapping.STANDARD_PREFIX, id);
            startElement(node, attributes);
        }

        private void startElement(FONode node, AttributesImpl attributes) {
            String localName = node.getLocalName();
            if (node instanceof CommonAccessibilityHolder) {
                addRole((CommonAccessibilityHolder) node, attributes);
            }
            try {
                structureTreeDOMBuilder.startElement(node.getNamespaceURI(), localName,
                        node.getNormalNamespacePrefix() + ":" + localName,
                        attributes);
            } catch (SAXException e) {
                throw new RuntimeException(e);
            }
        }

        private void addNoNamespaceAttribute(AttributesImpl attributes, String name, String value) {
            attributes.addAttribute("", name, name, XMLUtil.CDATA, value);
        }

        private void addAttribute(AttributesImpl attributes,
                String namespace, String localName, String prefix, String value) {
            assert namespace.length() > 0 && prefix.length() > 0;
            String qualifiedName = prefix + ":" + localName;
            attributes.addAttribute(namespace, localName, qualifiedName, XMLUtil.CDATA, value);
        }

        private void addRole(CommonAccessibilityHolder node, AttributesImpl attributes) {
            String role = node.getCommonAccessibility().getRole();
            if (role != null) {
                addNoNamespaceAttribute(attributes, "role", role);
            }
        }

        private void endElement(FONode node) {
            String localName = node.getLocalName();
            try {
                structureTreeDOMBuilder.endElement(node.getNamespaceURI(), localName,
                        node.getNormalNamespacePrefix() + ":" + localName);
            } catch (SAXException e) {
                throw new RuntimeException(e);
            }
        }

    }

    /**
     * Creates a new instance.
     *
     * @param structureTree the object that will hold the structure tree
     * @param delegate the FO event handler that must be wrapped by this instance
     */
    public StructureTreeBuildingFOEventHandler(StructureTree structureTree,
            FOEventHandler delegate) {
        super(delegate);
        this.structureTree = structureTree;
        this.actualStructureTreeBuilder = new StructureTreeBuilder(foUserAgent);
        this.structureTreeBuilder = actualStructureTreeBuilder;
        this.eventSwallower = new FOEventHandler(foUserAgent) { };
    }

    @Override
    public void startDocument() throws SAXException {
        structureTreeBuilder.startDocument();
        super.startDocument();
    }

    @Override
    public void endDocument() throws SAXException {
        structureTreeBuilder.endDocument();
        super.endDocument();
    }

    @Override
    public void startPageSequence(PageSequence pageSeq) {
        structureTreeBuilder.startPageSequence(pageSeq);
        super.startPageSequence(pageSeq);
    }

    @Override
    public void endPageSequence(PageSequence pageSeq) {
        structureTreeBuilder.endPageSequence(pageSeq);
        super.endPageSequence(pageSeq);
    }

    @Override
    public void startPageNumber(PageNumber pagenum) {
        structureTreeBuilder.startPageNumber(pagenum);
        super.startPageNumber(pagenum);
    }

    @Override
    public void endPageNumber(PageNumber pagenum) {
        structureTreeBuilder.endPageNumber(pagenum);
        super.endPageNumber(pagenum);
    }

    @Override
    public void startPageNumberCitation(PageNumberCitation pageCite) {
        structureTreeBuilder.startPageNumberCitation(pageCite);
        super.startPageNumberCitation(pageCite);
    }

    @Override
    public void endPageNumberCitation(PageNumberCitation pageCite) {
        structureTreeBuilder.endPageNumberCitation(pageCite);
        super.endPageNumberCitation(pageCite);
    }

    @Override
    public void startPageNumberCitationLast(PageNumberCitationLast pageLast) {
        structureTreeBuilder.startPageNumberCitationLast(pageLast);
        super.startPageNumberCitationLast(pageLast);
    }

    @Override
    public void endPageNumberCitationLast(PageNumberCitationLast pageLast) {
        structureTreeBuilder.endPageNumberCitationLast(pageLast);
        super.endPageNumberCitationLast(pageLast);
    }

    @Override
    public void startFlow(Flow fl) {
        structureTreeBuilder.startFlow(fl);
        super.startFlow(fl);
    }

    @Override
    public void endFlow(Flow fl) {
        structureTreeBuilder.endFlow(fl);
        super.endFlow(fl);
    }

    @Override
    public void startBlock(Block bl) {
        structureTreeBuilder.startBlock(bl);
        super.startBlock(bl);
    }

    @Override
    public void endBlock(Block bl) {
        structureTreeBuilder.endBlock(bl);
        super.endBlock(bl);
    }

    @Override
    public void startBlockContainer(BlockContainer blc) {
        structureTreeBuilder.startBlockContainer(blc);
        super.startBlockContainer(blc);
    }

    @Override
    public void endBlockContainer(BlockContainer blc) {
        structureTreeBuilder.endBlockContainer(blc);
        super.endBlockContainer(blc);
    }

    @Override
    public void startInline(Inline inl) {
        structureTreeBuilder.startInline(inl);
        super.startInline(inl);
    }

    @Override
    public void endInline(Inline inl) {
        structureTreeBuilder.endInline(inl);
        super.endInline(inl);
    }

    @Override
    public void startTable(Table tbl) {
        structureTreeBuilder.startTable(tbl);
        super.startTable(tbl);
    }

    @Override
    public void endTable(Table tbl) {
        structureTreeBuilder.endTable(tbl);
        super.endTable(tbl);
    }

    @Override
    public void startColumn(TableColumn tc) {
        structureTreeBuilder.startColumn(tc);
        super.startColumn(tc);
    }

    @Override
    public void endColumn(TableColumn tc) {
        structureTreeBuilder.endColumn(tc);
        super.endColumn(tc);
    }

    @Override
    public void startHeader(TableHeader header) {
        structureTreeBuilder.startHeader(header);
        super.startHeader(header);
    }

    @Override
    public void endHeader(TableHeader header) {
        structureTreeBuilder.endHeader(header);
        super.endHeader(header);
    }

    @Override
    public void startFooter(TableFooter footer) {
        structureTreeBuilder.startFooter(footer);
        super.startFooter(footer);
    }

    @Override
    public void endFooter(TableFooter footer) {
        structureTreeBuilder.endFooter(footer);
        super.endFooter(footer);
    }

    @Override
    public void startBody(TableBody body) {
        structureTreeBuilder.startBody(body);
        super.startBody(body);
    }

    @Override
    public void endBody(TableBody body) {
        structureTreeBuilder.endBody(body);
        super.endBody(body);
    }

    @Override
    public void startRow(TableRow tr) {
        structureTreeBuilder.startRow(tr);
        super.startRow(tr);
    }

    @Override
    public void endRow(TableRow tr) {
        structureTreeBuilder.endRow(tr);
        super.endRow(tr);
    }

    @Override
    public void startCell(TableCell tc) {
        structureTreeBuilder.startCell(tc);
        super.startCell(tc);
    }

    @Override
    public void endCell(TableCell tc) {
        structureTreeBuilder.endCell(tc);
        super.endCell(tc);
    }

    @Override
    public void startList(ListBlock lb) {
        structureTreeBuilder.startList(lb);
        super.startList(lb);
    }

    @Override
    public void endList(ListBlock lb) {
        structureTreeBuilder.endList(lb);
        super.endList(lb);
    }

    @Override
    public void startListItem(ListItem li) {
        structureTreeBuilder.startListItem(li);
        super.startListItem(li);
    }

    @Override
    public void endListItem(ListItem li) {
        structureTreeBuilder.endListItem(li);
        super.endListItem(li);
    }

    @Override
    public void startListLabel(ListItemLabel listItemLabel) {
        structureTreeBuilder.startListLabel(listItemLabel);
        super.startListLabel(listItemLabel);
    }

    @Override
    public void endListLabel(ListItemLabel listItemLabel) {
        structureTreeBuilder.endListLabel(listItemLabel);
        super.endListLabel(listItemLabel);
    }

    @Override
    public void startListBody(ListItemBody listItemBody) {
        structureTreeBuilder.startListBody(listItemBody);
        super.startListBody(listItemBody);
    }

    @Override
    public void endListBody(ListItemBody listItemBody) {
        structureTreeBuilder.endListBody(listItemBody);
        super.endListBody(listItemBody);
    }

    @Override
    public void startStatic(StaticContent staticContent) {
        structureTreeBuilder.startStatic(staticContent);
        super.startStatic(staticContent);
    }

    @Override
    public void endStatic(StaticContent statisContent) {
        structureTreeBuilder.endStatic(statisContent);
        super.endStatic(statisContent);
    }

    @Override
    public void startMarkup() {
        structureTreeBuilder.startMarkup();
        super.startMarkup();
    }

    @Override
    public void endMarkup() {
        structureTreeBuilder.endMarkup();
        super.endMarkup();
    }

    @Override
    public void startLink(BasicLink basicLink) {
        structureTreeBuilder.startLink(basicLink);
        super.startLink(basicLink);
    }

    @Override
    public void endLink(BasicLink basicLink) {
        structureTreeBuilder.endLink(basicLink);
        super.endLink(basicLink);
    }

    @Override
    public void image(ExternalGraphic eg) {
        structureTreeBuilder.image(eg);
        super.image(eg);
    }

    @Override
    public void pageRef() {
        structureTreeBuilder.pageRef();
        super.pageRef();
    }

    @Override
    public void startInstreamForeignObject(InstreamForeignObject ifo) {
        structureTreeBuilder.startInstreamForeignObject(ifo);
        super.startInstreamForeignObject(ifo);
    }

    @Override
    public void endInstreamForeignObject(InstreamForeignObject ifo) {
        structureTreeBuilder.endInstreamForeignObject(ifo);
        super.endInstreamForeignObject(ifo);
    }

    @Override
    public void startFootnote(Footnote footnote) {
        structureTreeBuilder.startFootnote(footnote);
        super.startFootnote(footnote);
    }

    @Override
    public void endFootnote(Footnote footnote) {
        structureTreeBuilder.endFootnote(footnote);
        super.endFootnote(footnote);
    }

    @Override
    public void startFootnoteBody(FootnoteBody body) {
        structureTreeBuilder.startFootnoteBody(body);
        super.startFootnoteBody(body);
    }

    @Override
    public void endFootnoteBody(FootnoteBody body) {
        structureTreeBuilder.endFootnoteBody(body);
        super.endFootnoteBody(body);
    }

    @Override
    public void startLeader(Leader l) {
        structureTreeBuilder = eventSwallower;
        structureTreeBuilder.startLeader(l);
        super.startLeader(l);
    }

    @Override
    public void endLeader(Leader l) {
        structureTreeBuilder.endLeader(l);
        structureTreeBuilder = actualStructureTreeBuilder;
        super.endLeader(l);
    }

    @Override
    public void startWrapper(Wrapper wrapper) {
        structureTreeBuilder.startWrapper(wrapper);
        super.startWrapper(wrapper);
    }

    @Override
    public void endWrapper(Wrapper wrapper) {
        structureTreeBuilder.endWrapper(wrapper);
        super.endWrapper(wrapper);
    }

    @Override
    public void character(Character c) {
        structureTreeBuilder.character(c);
        super.character(c);
    }

    @Override
    public void characters(char[] data, int start, int length) {
        structureTreeBuilder.characters(data, start, length);
        super.characters(data, start, length);
    }

    @Override
    public void startExternalDocument(ExternalDocument document) {
        structureTreeBuilder.startExternalDocument(document);
        super.startExternalDocument(document);
    }

    @Override
    public void endExternalDocument(ExternalDocument document) {
        structureTreeBuilder.endExternalDocument(document);
        super.endExternalDocument(document);
    }

}