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
|
/*
* 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.render.intermediate;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.geom.AffineTransform;
import java.util.Map;
import java.util.Set;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.sax.SAXResult;
import javax.xml.transform.sax.SAXTransformerFactory;
import org.w3c.dom.DOMImplementation;
import org.w3c.dom.Document;
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
import org.xml.sax.helpers.DefaultHandler;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.xmlgraphics.util.QName;
import org.apache.fop.accessibility.StructureTreeBuilder;
import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.fo.ElementMapping;
import org.apache.fop.fo.ElementMappingRegistry;
import org.apache.fop.fo.expr.PropertyException;
import org.apache.fop.render.intermediate.extensions.DocumentNavigationExtensionConstants;
import org.apache.fop.render.intermediate.extensions.DocumentNavigationHandler;
import org.apache.fop.traits.BorderProps;
import org.apache.fop.traits.RuleStyle;
import org.apache.fop.util.ColorUtil;
import org.apache.fop.util.ContentHandlerFactory;
import org.apache.fop.util.ContentHandlerFactoryRegistry;
import org.apache.fop.util.DOMBuilderContentHandlerFactory;
import org.apache.fop.util.DefaultErrorListener;
import org.apache.fop.util.DelegatingContentHandler;
import org.apache.fop.util.XMLUtil;
/**
* This is a parser for the intermediate format XML which converts the intermediate file into
* {@link IFPainter} events.
*/
public class IFParser implements IFConstants {
/** Logger instance */
protected static Log log = LogFactory.getLog(IFParser.class);
private static SAXTransformerFactory tFactory
= (SAXTransformerFactory)SAXTransformerFactory.newInstance();
private static Set handledNamespaces = new java.util.HashSet();
static {
handledNamespaces.add(XMLNS_NAMESPACE_URI);
handledNamespaces.add(XML_NAMESPACE);
handledNamespaces.add(NAMESPACE);
handledNamespaces.add(XLINK_NAMESPACE);
}
/**
* Parses an intermediate file and paints it.
* @param src the Source instance pointing to the intermediate file
* @param documentHandler the intermediate format document handler used to process the IF events
* @param userAgent the user agent
* @throws TransformerException if an error occurs while parsing the area tree XML
* @throws IFException if an IF-related error occurs inside the target document handler
*/
public void parse(Source src, IFDocumentHandler documentHandler, FOUserAgent userAgent)
throws TransformerException, IFException {
try {
Transformer transformer = tFactory.newTransformer();
transformer.setErrorListener(new DefaultErrorListener(log));
SAXResult res = new SAXResult(getContentHandler(documentHandler, userAgent));
transformer.transform(src, res);
} catch (TransformerException te) {
//Unpack original IFException if applicable
if (te.getCause() instanceof SAXException) {
SAXException se = (SAXException)te.getCause();
if (se.getCause() instanceof IFException) {
throw (IFException)se.getCause();
}
} else if (te.getCause() instanceof IFException) {
throw (IFException)te.getCause();
}
throw te;
}
}
/**
* Creates a new ContentHandler instance that you can send the area tree XML to. The parsed
* pages are added to the AreaTreeModel instance you pass in as a parameter.
* @param documentHandler the intermediate format document handler used to process the IF events
* @param userAgent the user agent
* @return the ContentHandler instance to receive the SAX stream from the area tree XML
*/
public ContentHandler getContentHandler(IFDocumentHandler documentHandler,
FOUserAgent userAgent) {
ElementMappingRegistry elementMappingRegistry
= userAgent.getFactory().getElementMappingRegistry();
return new Handler(documentHandler, userAgent, elementMappingRegistry);
}
private static class Handler extends DefaultHandler {
private Map elementHandlers = new java.util.HashMap();
private IFDocumentHandler documentHandler;
private IFPainter painter;
private FOUserAgent userAgent;
private ElementMappingRegistry elementMappingRegistry;
private Attributes lastAttributes;
private StringBuffer content = new StringBuffer();
private boolean ignoreCharacters = true;
//private Stack delegateStack = new Stack();
private int delegateDepth;
private ContentHandler delegate;
private boolean inForeignObject;
private Document foreignObject;
private ContentHandler navParser;
private StructureTreeBuilder structureTreeBuilder;
private ContentHandler structureTreeBuilderWrapper;
private final class StructureTreeBuilderWrapper extends DelegatingContentHandler {
private Attributes pageSequenceAttributes;
private StructureTreeBuilderWrapper(Attributes pageSequenceAttributes)
throws SAXException {
super(structureTreeBuilder.getHandlerForNextPageSequence());
this.pageSequenceAttributes = new AttributesImpl(pageSequenceAttributes);
}
public void endDocument() throws SAXException {
super.endDocument();
startIFElement(EL_PAGE_SEQUENCE, pageSequenceAttributes);
}
}
public Handler(IFDocumentHandler documentHandler, FOUserAgent userAgent,
ElementMappingRegistry elementMappingRegistry) {
this.documentHandler = documentHandler;
this.userAgent = userAgent;
this.elementMappingRegistry = elementMappingRegistry;
elementHandlers.put(EL_DOCUMENT, new DocumentHandler());
elementHandlers.put(EL_HEADER, new DocumentHeaderHandler());
elementHandlers.put(EL_TRAILER, new DocumentTrailerHandler());
elementHandlers.put(EL_PAGE_SEQUENCE, new PageSequenceHandler());
elementHandlers.put(EL_PAGE, new PageHandler());
elementHandlers.put(EL_PAGE_HEADER, new PageHeaderHandler());
elementHandlers.put(EL_PAGE_CONTENT, new PageContentHandler());
elementHandlers.put(EL_PAGE_TRAILER, new PageTrailerHandler());
//Page content
elementHandlers.put(EL_VIEWPORT, new ViewportHandler());
elementHandlers.put(EL_GROUP, new GroupHandler());
elementHandlers.put(EL_FONT, new FontHandler());
elementHandlers.put(EL_TEXT, new TextHandler());
elementHandlers.put(EL_CLIP_RECT, new ClipRectHandler());
elementHandlers.put(EL_RECT, new RectHandler());
elementHandlers.put(EL_LINE, new LineHandler());
elementHandlers.put(EL_BORDER_RECT, new BorderRectHandler());
elementHandlers.put(EL_IMAGE, new ImageHandler());
if (userAgent.isAccessibilityEnabled()) {
structureTreeBuilder = new StructureTreeBuilder(tFactory);
userAgent.setStructureTree(structureTreeBuilder.getStructureTree());
}
}
private void establishForeignAttributes(Map foreignAttributes) {
documentHandler.getContext().setForeignAttributes(foreignAttributes);
}
private void resetForeignAttributes() {
documentHandler.getContext().resetForeignAttributes();
}
private void establishStructurePointer(String ptr) {
documentHandler.getContext().setStructurePointer(ptr);
}
private void resetStructurePointer() {
documentHandler.getContext().resetStructurePointer();
}
/** {@inheritDoc} */
public void startElement(String uri, String localName, String qName, Attributes attributes)
throws SAXException {
if (delegate != null) {
delegateDepth++;
delegate.startElement(uri, localName, qName, attributes);
} else {
boolean handled = true;
if (NAMESPACE.equals(uri)) {
if (localName.equals(EL_PAGE_SEQUENCE) && userAgent.isAccessibilityEnabled()) {
structureTreeBuilderWrapper = new StructureTreeBuilderWrapper(attributes);
} else if (localName.equals(EL_STRUCTURE_TREE)) {
if (userAgent.isAccessibilityEnabled()) {
delegate = structureTreeBuilderWrapper;
} else {
/* Delegate to a handler that does nothing */
delegate = new DefaultHandler();
}
delegateDepth++;
delegate.startDocument();
delegate.startElement(uri, localName, qName, attributes);
} else {
handled = startIFElement(localName, attributes);
}
} else if (DocumentNavigationExtensionConstants.NAMESPACE.equals(uri)) {
if (this.navParser == null) {
this.navParser = new DocumentNavigationHandler(
this.documentHandler.getDocumentNavigationHandler());
}
delegate = this.navParser;
delegateDepth++;
delegate.startDocument();
delegate.startElement(uri, localName, qName, attributes);
} else {
ContentHandlerFactoryRegistry registry
= userAgent.getFactory().getContentHandlerFactoryRegistry();
ContentHandlerFactory factory = registry.getFactory(uri);
if (factory == null) {
DOMImplementation domImplementation
= elementMappingRegistry.getDOMImplementationForNamespace(uri);
if (domImplementation == null) {
domImplementation = ElementMapping.getDefaultDOMImplementation();
/*
throw new SAXException("No DOMImplementation could be"
+ " identified to handle namespace: " + uri);
*/
}
factory = new DOMBuilderContentHandlerFactory(uri, domImplementation);
}
delegate = factory.createContentHandler();
delegateDepth++;
delegate.startDocument();
delegate.startElement(uri, localName, qName, attributes);
}
if (!handled) {
if (uri == null || uri.length() == 0) {
throw new SAXException("Unhandled element " + localName
+ " in namespace: " + uri);
} else {
log.warn("Unhandled element " + localName
+ " in namespace: " + uri);
}
}
}
}
private boolean startIFElement(String localName, Attributes attributes)
throws SAXException {
lastAttributes = new AttributesImpl(attributes);
ElementHandler elementHandler = (ElementHandler)elementHandlers.get(localName);
content.setLength(0);
ignoreCharacters = true;
if (elementHandler != null) {
ignoreCharacters = elementHandler.ignoreCharacters();
try {
elementHandler.startElement(attributes);
} catch (IFException ife) {
handleIFException(ife);
}
return true;
} else {
return false;
}
}
private void handleIFException(IFException ife) throws SAXException {
if (ife.getCause() instanceof SAXException) {
//unwrap
throw (SAXException)ife.getCause();
} else {
//wrap
throw new SAXException(ife);
}
}
/** {@inheritDoc} */
public void endElement(String uri, String localName, String qName) throws SAXException {
if (delegate != null) {
delegate.endElement(uri, localName, qName);
delegateDepth--;
if (delegateDepth == 0) {
delegate.endDocument();
if (delegate instanceof ContentHandlerFactory.ObjectSource) {
Object obj = ((ContentHandlerFactory.ObjectSource)delegate).getObject();
if (inForeignObject) {
this.foreignObject = (Document)obj;
} else {
handleExternallyGeneratedObject(obj);
}
}
delegate = null; //Sub-document is processed, return to normal processing
}
} else {
if (NAMESPACE.equals(uri)) {
ElementHandler elementHandler = (ElementHandler)elementHandlers.get(localName);
if (elementHandler != null) {
try {
elementHandler.endElement();
} catch (IFException ife) {
handleIFException(ife);
}
content.setLength(0);
}
ignoreCharacters = true;
} else {
if (log.isTraceEnabled()) {
log.trace("Ignoring " + localName + " in namespace: " + uri);
}
}
}
}
// ============== Element handlers for the intermediate format =============
private static interface ElementHandler {
void startElement(Attributes attributes) throws IFException, SAXException;
void endElement() throws IFException;
boolean ignoreCharacters();
}
private abstract class AbstractElementHandler implements ElementHandler {
public void startElement(Attributes attributes) throws IFException, SAXException {
//nop
}
public void endElement() throws IFException {
//nop
}
public boolean ignoreCharacters() {
return true;
}
}
private class DocumentHandler extends AbstractElementHandler {
public void startElement(Attributes attributes) throws IFException {
documentHandler.startDocument();
}
public void endElement() throws IFException {
documentHandler.endDocument();
}
}
private class DocumentHeaderHandler extends AbstractElementHandler {
public void startElement(Attributes attributes) throws IFException {
documentHandler.startDocumentHeader();
}
public void endElement() throws IFException {
documentHandler.endDocumentHeader();
}
}
private class DocumentTrailerHandler extends AbstractElementHandler {
public void startElement(Attributes attributes) throws IFException {
documentHandler.startDocumentTrailer();
}
public void endElement() throws IFException {
documentHandler.endDocumentTrailer();
}
}
private class PageSequenceHandler extends AbstractElementHandler {
public void startElement(Attributes attributes) throws IFException {
String id = attributes.getValue("id");
String xmllang = attributes.getValue(XML_NAMESPACE, "lang");
if (xmllang != null) {
documentHandler.getContext().setLanguage(
XMLUtil.convertRFC3066ToLocale(xmllang));
}
Map foreignAttributes = getForeignAttributes(lastAttributes);
establishForeignAttributes(foreignAttributes);
documentHandler.startPageSequence(id);
resetForeignAttributes();
}
public void endElement() throws IFException {
documentHandler.endPageSequence();
documentHandler.getContext().setLanguage(null);
}
}
private class PageHandler extends AbstractElementHandler {
public void startElement(Attributes attributes) throws IFException {
int index = Integer.parseInt(attributes.getValue("index"));
String name = attributes.getValue("name");
String pageMasterName = attributes.getValue("page-master-name");
int width = Integer.parseInt(attributes.getValue("width"));
int height = Integer.parseInt(attributes.getValue("height"));
Map foreignAttributes = getForeignAttributes(lastAttributes);
establishForeignAttributes(foreignAttributes);
documentHandler.startPage(index, name, pageMasterName,
new Dimension(width, height));
resetForeignAttributes();
}
public void endElement() throws IFException {
documentHandler.endPage();
}
}
private class PageHeaderHandler extends AbstractElementHandler {
public void startElement(Attributes attributes) throws IFException {
documentHandler.startPageHeader();
}
public void endElement() throws IFException {
documentHandler.endPageHeader();
}
}
private class PageContentHandler extends AbstractElementHandler {
public void startElement(Attributes attributes) throws IFException {
painter = documentHandler.startPageContent();
}
public void endElement() throws IFException {
painter = null;
documentHandler.endPageContent();
}
}
private class PageTrailerHandler extends AbstractElementHandler {
public void startElement(Attributes attributes) throws IFException {
documentHandler.startPageTrailer();
}
public void endElement() throws IFException {
documentHandler.endPageTrailer();
}
}
private class ViewportHandler extends AbstractElementHandler {
public void startElement(Attributes attributes) throws IFException {
String transform = attributes.getValue("transform");
AffineTransform[] transforms
= AffineTransformArrayParser.createAffineTransform(transform);
int width = Integer.parseInt(attributes.getValue("width"));
int height = Integer.parseInt(attributes.getValue("height"));
Rectangle clipRect = XMLUtil.getAttributeAsRectangle(attributes, "clip-rect");
painter.startViewport(transforms, new Dimension(width, height), clipRect);
}
public void endElement() throws IFException {
painter.endViewport();
}
}
private class GroupHandler extends AbstractElementHandler {
public void startElement(Attributes attributes) throws IFException {
String transform = attributes.getValue("transform");
AffineTransform[] transforms
= AffineTransformArrayParser.createAffineTransform(transform);
painter.startGroup(transforms);
}
public void endElement() throws IFException {
painter.endGroup();
}
}
private class FontHandler extends AbstractElementHandler {
public void startElement(Attributes attributes) throws IFException {
String family = attributes.getValue("family");
String style = attributes.getValue("style");
Integer weight = XMLUtil.getAttributeAsInteger(attributes, "weight");
String variant = attributes.getValue("variant");
Integer size = XMLUtil.getAttributeAsInteger(attributes, "size");
Color color;
try {
color = getAttributeAsColor(attributes, "color");
} catch (PropertyException pe) {
throw new IFException("Error parsing the color attribute", pe);
}
painter.setFont(family, style, weight, variant, size, color);
}
}
private class TextHandler extends AbstractElementHandler {
public void endElement() throws IFException {
int x = Integer.parseInt(lastAttributes.getValue("x"));
int y = Integer.parseInt(lastAttributes.getValue("y"));
String s = lastAttributes.getValue("letter-spacing");
int letterSpacing = (s != null ? Integer.parseInt(s) : 0);
s = lastAttributes.getValue("word-spacing");
int wordSpacing = (s != null ? Integer.parseInt(s) : 0);
int[] dx = XMLUtil.getAttributeAsIntArray(lastAttributes, "dx");
setAccessibilityPointer(lastAttributes);
painter.drawText(x, y, letterSpacing, wordSpacing, dx, content.toString());
resetStructurePointer();
}
public boolean ignoreCharacters() {
return false;
}
}
private class ClipRectHandler extends AbstractElementHandler {
public void startElement(Attributes attributes) throws IFException {
int x = Integer.parseInt(attributes.getValue("x"));
int y = Integer.parseInt(attributes.getValue("y"));
int width = Integer.parseInt(attributes.getValue("width"));
int height = Integer.parseInt(attributes.getValue("height"));
painter.clipRect(new Rectangle(x, y, width, height));
}
}
private class RectHandler extends AbstractElementHandler {
public void startElement(Attributes attributes) throws IFException {
int x = Integer.parseInt(attributes.getValue("x"));
int y = Integer.parseInt(attributes.getValue("y"));
int width = Integer.parseInt(attributes.getValue("width"));
int height = Integer.parseInt(attributes.getValue("height"));
Color fillColor;
try {
fillColor = getAttributeAsColor(attributes, "fill");
} catch (PropertyException pe) {
throw new IFException("Error parsing the fill attribute", pe);
}
painter.fillRect(new Rectangle(x, y, width, height), fillColor);
}
}
private class LineHandler extends AbstractElementHandler {
public void startElement(Attributes attributes) throws IFException {
int x1 = Integer.parseInt(attributes.getValue("x1"));
int y1 = Integer.parseInt(attributes.getValue("y1"));
int x2 = Integer.parseInt(attributes.getValue("x2"));
int y2 = Integer.parseInt(attributes.getValue("y2"));
int width = Integer.parseInt(attributes.getValue("stroke-width"));
Color color;
try {
color = getAttributeAsColor(attributes, "color");
} catch (PropertyException pe) {
throw new IFException("Error parsing the fill attribute", pe);
}
RuleStyle style = RuleStyle.valueOf(attributes.getValue("style"));
painter.drawLine(new Point(x1, y1), new Point(x2, y2), width, color, style);
}
}
private static final String[] SIDES = new String[] {"before", "after", "start", "end"};
private class BorderRectHandler extends AbstractElementHandler {
public void startElement(Attributes attributes) throws IFException {
int x = Integer.parseInt(attributes.getValue("x"));
int y = Integer.parseInt(attributes.getValue("y"));
int width = Integer.parseInt(attributes.getValue("width"));
int height = Integer.parseInt(attributes.getValue("height"));
BorderProps[] borders = new BorderProps[4];
for (int i = 0; i < 4; i++) {
String b = attributes.getValue(SIDES[i]);
if (b != null) {
borders[i] = BorderProps.valueOf(userAgent, b);
}
}
painter.drawBorderRect(new Rectangle(x, y, width, height),
borders[0], borders[1], borders[2], borders[3]);
}
}
private class ImageHandler extends AbstractElementHandler {
public void startElement(Attributes attributes) throws IFException {
inForeignObject = true;
}
public void endElement() throws IFException {
int x = Integer.parseInt(lastAttributes.getValue("x"));
int y = Integer.parseInt(lastAttributes.getValue("y"));
int width = Integer.parseInt(lastAttributes.getValue("width"));
int height = Integer.parseInt(lastAttributes.getValue("height"));
Map foreignAttributes = getForeignAttributes(lastAttributes);
establishForeignAttributes(foreignAttributes);
setAccessibilityPointer(lastAttributes);
if (foreignObject != null) {
painter.drawImage(foreignObject,
new Rectangle(x, y, width, height));
foreignObject = null;
} else {
String uri = lastAttributes.getValue(
XLINK_HREF.getNamespaceURI(), XLINK_HREF.getLocalName());
if (uri == null) {
throw new IFException("xlink:href is missing on image", null);
}
painter.drawImage(uri, new Rectangle(x, y, width, height));
}
resetForeignAttributes();
resetStructurePointer();
inForeignObject = false;
}
public boolean ignoreCharacters() {
return false;
}
}
// ====================================================================
/**
* Handles objects created by "sub-parsers" that implement the ObjectSource interface.
* An example of object handled here are ExtensionAttachments.
* @param obj the Object to be handled.
* @throws SAXException if an error occurs while handling the extension object
*/
protected void handleExternallyGeneratedObject(Object obj) throws SAXException {
try {
documentHandler.handleExtensionObject(obj);
} catch (IFException ife) {
handleIFException(ife);
}
}
private Color getAttributeAsColor(Attributes attributes, String name)
throws PropertyException {
String s = attributes.getValue(name);
if (s == null) {
return null;
} else {
return ColorUtil.parseColorString(userAgent, s);
}
}
private static Map getForeignAttributes(Attributes atts) {
Map foreignAttributes = null;
for (int i = 0, c = atts.getLength(); i < c; i++) {
String ns = atts.getURI(i);
if (ns.length() > 0) {
if (handledNamespaces.contains(ns)) {
continue;
}
if (foreignAttributes == null) {
foreignAttributes = new java.util.HashMap();
}
QName qname = new QName(ns, atts.getQName(i));
foreignAttributes.put(qname, atts.getValue(i));
}
}
return foreignAttributes;
}
private void setAccessibilityPointer(Attributes attributes) {
String ptr = attributes.getValue("ptr");
if (ptr != null && ptr.length() > 0) {
establishStructurePointer(ptr);
}
}
/** {@inheritDoc} */
public void characters(char[] ch, int start, int length) throws SAXException {
if (delegate != null) {
delegate.characters(ch, start, length);
} else if (!ignoreCharacters) {
this.content.append(ch, start, length);
}
}
}
}
|