1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| package org.dom4j.io; |
11 |
| |
12 |
| import java.lang.reflect.Method; |
13 |
| import java.util.ArrayList; |
14 |
| import java.util.HashMap; |
15 |
| import java.util.List; |
16 |
| import java.util.Map; |
17 |
| |
18 |
| import org.dom4j.Branch; |
19 |
| import org.dom4j.Document; |
20 |
| import org.dom4j.DocumentFactory; |
21 |
| import org.dom4j.DocumentType; |
22 |
| import org.dom4j.Element; |
23 |
| import org.dom4j.ElementHandler; |
24 |
| import org.dom4j.Namespace; |
25 |
| import org.dom4j.QName; |
26 |
| import org.dom4j.dtd.AttributeDecl; |
27 |
| import org.dom4j.dtd.ElementDecl; |
28 |
| import org.dom4j.dtd.ExternalEntityDecl; |
29 |
| import org.dom4j.dtd.InternalEntityDecl; |
30 |
| import org.dom4j.tree.AbstractElement; |
31 |
| import org.dom4j.tree.NamespaceStack; |
32 |
| import org.xml.sax.Attributes; |
33 |
| import org.xml.sax.DTDHandler; |
34 |
| import org.xml.sax.EntityResolver; |
35 |
| import org.xml.sax.InputSource; |
36 |
| import org.xml.sax.Locator; |
37 |
| import org.xml.sax.SAXException; |
38 |
| import org.xml.sax.SAXParseException; |
39 |
| import org.xml.sax.ext.DeclHandler; |
40 |
| import org.xml.sax.ext.LexicalHandler; |
41 |
| import org.xml.sax.helpers.DefaultHandler; |
42 |
| |
43 |
| |
44 |
| |
45 |
| |
46 |
| |
47 |
| |
48 |
| public class SAXContentHandler extends DefaultHandler implements LexicalHandler, DeclHandler, DTDHandler { |
49 |
| |
50 |
| |
51 |
| private DocumentFactory documentFactory; |
52 |
| |
53 |
| |
54 |
| private Document document; |
55 |
| |
56 |
| |
57 |
| private ElementStack elementStack; |
58 |
| |
59 |
| |
60 |
| private NamespaceStack namespaceStack; |
61 |
| |
62 |
| |
63 |
| private ElementHandler elementHandler; |
64 |
| |
65 |
| |
66 |
| private Locator locator; |
67 |
| |
68 |
| |
69 |
| private String entity; |
70 |
| |
71 |
| |
72 |
| private boolean insideDTDSection; |
73 |
| |
74 |
| |
75 |
| private boolean insideCDATASection; |
76 |
| |
77 |
| |
78 |
| private StringBuffer cdataText; |
79 |
| |
80 |
| |
81 |
| private Map availableNamespaceMap = new HashMap(); |
82 |
| |
83 |
| |
84 |
| private List declaredNamespaceList = new ArrayList(); |
85 |
| |
86 |
| |
87 |
| private List internalDTDDeclarations; |
88 |
| |
89 |
| |
90 |
| private List externalDTDDeclarations; |
91 |
| |
92 |
| |
93 |
| private int declaredNamespaceIndex; |
94 |
| |
95 |
| |
96 |
| private EntityResolver entityResolver; |
97 |
| |
98 |
| private InputSource inputSource; |
99 |
| |
100 |
| |
101 |
| private Element currentElement; |
102 |
| |
103 |
| |
104 |
| private boolean includeInternalDTDDeclarations = false; |
105 |
| |
106 |
| |
107 |
| private boolean includeExternalDTDDeclarations = false; |
108 |
| |
109 |
| |
110 |
| private int entityLevel; |
111 |
| |
112 |
| |
113 |
| private boolean internalDTDsubset = false; |
114 |
| |
115 |
| |
116 |
| private boolean mergeAdjacentText = false; |
117 |
| |
118 |
| |
119 |
| private boolean textInTextBuffer = false; |
120 |
| |
121 |
| |
122 |
| private boolean ignoreComments = false; |
123 |
| |
124 |
| |
125 |
| private StringBuffer textBuffer; |
126 |
| |
127 |
| |
128 |
| private boolean stripWhitespaceText = false; |
129 |
| |
130 |
| |
131 |
38
| public SAXContentHandler() {
|
132 |
38
| this(DocumentFactory.getInstance());
|
133 |
| } |
134 |
| |
135 |
38
| public SAXContentHandler(DocumentFactory documentFactory) {
|
136 |
38
| this(documentFactory, null);
|
137 |
| } |
138 |
| |
139 |
11598
| public SAXContentHandler(DocumentFactory documentFactory, ElementHandler elementHandler) {
|
140 |
11598
| this(documentFactory, elementHandler, null);
|
141 |
11598
| this.elementStack = createElementStack();
|
142 |
| } |
143 |
| |
144 |
11598
| public SAXContentHandler(DocumentFactory documentFactory, ElementHandler elementHandler, ElementStack elementStack) {
|
145 |
11598
| this.documentFactory = documentFactory;
|
146 |
11598
| this.elementHandler = elementHandler;
|
147 |
11598
| this.elementStack = elementStack;
|
148 |
11598
| this.namespaceStack = new NamespaceStack(documentFactory);
|
149 |
| } |
150 |
| |
151 |
| |
152 |
| |
153 |
23316
| public Document getDocument() {
|
154 |
23316
| if ( document == null ) {
|
155 |
11600
| document = createDocument();
|
156 |
| } |
157 |
23316
| return document;
|
158 |
| } |
159 |
| |
160 |
| |
161 |
| |
162 |
| |
163 |
11598
| public void setDocumentLocator(Locator locator) {
|
164 |
11598
| this.locator = locator;
|
165 |
| } |
166 |
| |
167 |
38
| public void processingInstruction(String target, String data) throws SAXException {
|
168 |
38
| if ( mergeAdjacentText && textInTextBuffer ) {
|
169 |
0
| completeCurrentTextNode();
|
170 |
| } |
171 |
38
| if ( currentElement != null ) {
|
172 |
2
| currentElement.addProcessingInstruction(target, data);
|
173 |
| } |
174 |
| else { |
175 |
36
| getDocument().addProcessingInstruction(target, data);
|
176 |
| } |
177 |
| } |
178 |
| |
179 |
11738
| public void startPrefixMapping(String prefix, String uri) throws SAXException {
|
180 |
11738
| namespaceStack.push( prefix, uri );
|
181 |
| } |
182 |
| |
183 |
11738
| public void endPrefixMapping(String prefix) throws SAXException {
|
184 |
11738
| namespaceStack.pop( prefix );
|
185 |
11738
| declaredNamespaceIndex = namespaceStack.size();
|
186 |
| } |
187 |
| |
188 |
11600
| public void startDocument() throws SAXException {
|
189 |
| |
190 |
11600
| document = null;
|
191 |
11600
| currentElement = null;
|
192 |
| |
193 |
11600
| elementStack.clear();
|
194 |
| |
195 |
11600
| if ( (elementHandler != null) &&
|
196 |
| (elementHandler instanceof DispatchHandler) ) { |
197 |
36
| elementStack.setDispatchHandler((DispatchHandler)elementHandler);
|
198 |
| } |
199 |
| |
200 |
11600
| namespaceStack.clear();
|
201 |
11600
| declaredNamespaceIndex = 0;
|
202 |
| |
203 |
11600
| if ( mergeAdjacentText && textBuffer == null ) {
|
204 |
8
| textBuffer = new StringBuffer();
|
205 |
| } |
206 |
11600
| textInTextBuffer = false;
|
207 |
| } |
208 |
| |
209 |
11600
| public void endDocument() throws SAXException {
|
210 |
11600
| namespaceStack.clear();
|
211 |
11600
| elementStack.clear();
|
212 |
11600
| currentElement = null;
|
213 |
11600
| textBuffer = null;
|
214 |
| } |
215 |
| |
216 |
168742
| public void startElement(String namespaceURI, String localName, String qualifiedName, Attributes attributes) throws SAXException {
|
217 |
168742
| if ( mergeAdjacentText && textInTextBuffer ) {
|
218 |
2
| completeCurrentTextNode();
|
219 |
| } |
220 |
| |
221 |
168742
| QName qName = namespaceStack.getQName(
|
222 |
| namespaceURI, localName, qualifiedName |
223 |
| ); |
224 |
| |
225 |
168742
| Branch branch = currentElement;
|
226 |
168742
| if ( branch == null ) {
|
227 |
11600
| branch = getDocument();
|
228 |
| } |
229 |
168742
| Element element = branch.addElement(qName);
|
230 |
| |
231 |
| |
232 |
168742
| addDeclaredNamespaces(element);
|
233 |
| |
234 |
| |
235 |
168742
| addAttributes( element, attributes );
|
236 |
| |
237 |
168742
| elementStack.pushElement(element);
|
238 |
168742
| currentElement = element;
|
239 |
| |
240 |
168742
| entity = null;
|
241 |
| |
242 |
168742
| if ( elementHandler != null ) {
|
243 |
156
| elementHandler.onStart(elementStack);
|
244 |
| } |
245 |
| } |
246 |
| |
247 |
168742
| public void endElement(String namespaceURI, String localName, String qName) throws SAXException {
|
248 |
168742
| if ( mergeAdjacentText && textInTextBuffer ) {
|
249 |
10
| completeCurrentTextNode();
|
250 |
| } |
251 |
| |
252 |
168742
| if ( elementHandler != null && currentElement != null ) {
|
253 |
156
| elementHandler.onEnd(elementStack);
|
254 |
| } |
255 |
168742
| elementStack.popElement();
|
256 |
168742
| currentElement = elementStack.peekElement();
|
257 |
| } |
258 |
| |
259 |
190194
| public void characters(char[] ch, int start, int end) throws SAXException {
|
260 |
190194
| if ( end == 0 ) {
|
261 |
0
| return;
|
262 |
| } |
263 |
| |
264 |
190194
| if ( currentElement != null ) {
|
265 |
190194
| if (entity != null) {
|
266 |
8
| if ( mergeAdjacentText && textInTextBuffer ) {
|
267 |
0
| completeCurrentTextNode();
|
268 |
| } |
269 |
8
| currentElement.addEntity(entity, new String(ch, start, end));
|
270 |
8
| entity = null;
|
271 |
| } |
272 |
190186
| else if (insideCDATASection) {
|
273 |
106
| if ( mergeAdjacentText && textInTextBuffer ) {
|
274 |
2
| completeCurrentTextNode();
|
275 |
| } |
276 |
106
| cdataText.append(new String(ch, start, end));
|
277 |
| } |
278 |
| else { |
279 |
190080
| if ( mergeAdjacentText ) {
|
280 |
50
| textBuffer.append(ch, start, end);
|
281 |
50
| textInTextBuffer = true;
|
282 |
| } |
283 |
| else { |
284 |
190030
| currentElement.addText(new String(ch, start, end));
|
285 |
| } |
286 |
| } |
287 |
| } |
288 |
| } |
289 |
| |
290 |
| |
291 |
| |
292 |
| |
293 |
| |
294 |
| |
295 |
| |
296 |
| |
297 |
256
| public void warning(SAXParseException exception) throws SAXException {
|
298 |
| |
299 |
| } |
300 |
| |
301 |
| |
302 |
| |
303 |
| |
304 |
| |
305 |
0
| public void error(SAXParseException exception) throws SAXException {
|
306 |
0
| throw exception;
|
307 |
| } |
308 |
| |
309 |
| |
310 |
| |
311 |
| |
312 |
0
| public void fatalError(SAXParseException exception) throws SAXException {
|
313 |
0
| throw exception;
|
314 |
| } |
315 |
| |
316 |
| |
317 |
| |
318 |
| |
319 |
22
| public void startDTD(String name, String publicId, String systemId) throws SAXException {
|
320 |
22
| getDocument().addDocType(name, publicId, systemId);
|
321 |
22
| insideDTDSection = true;
|
322 |
22
| internalDTDsubset = true;
|
323 |
| } |
324 |
| |
325 |
22
| public void endDTD() throws SAXException {
|
326 |
22
| insideDTDSection = false;
|
327 |
| |
328 |
22
| DocumentType docType = getDocument().getDocType();
|
329 |
22
| if ( docType != null ) {
|
330 |
22
| if ( internalDTDDeclarations != null ) {
|
331 |
8
| docType.setInternalDeclarations( internalDTDDeclarations );
|
332 |
| } |
333 |
22
| if ( externalDTDDeclarations != null ) {
|
334 |
6
| docType.setExternalDeclarations( externalDTDDeclarations );
|
335 |
| } |
336 |
| } |
337 |
| |
338 |
22
| internalDTDDeclarations = null;
|
339 |
22
| externalDTDDeclarations = null;
|
340 |
| } |
341 |
| |
342 |
32
| public void startEntity(String name) throws SAXException {
|
343 |
32
| ++entityLevel;
|
344 |
| |
345 |
| |
346 |
32
| entity = null;
|
347 |
32
| if (! insideDTDSection ) {
|
348 |
24
| if ( ! isIgnorableEntity(name) ) {
|
349 |
10
| entity = name;
|
350 |
| } |
351 |
| } |
352 |
| |
353 |
| |
354 |
| |
355 |
| |
356 |
| |
357 |
| |
358 |
| |
359 |
32
| internalDTDsubset = false;
|
360 |
| } |
361 |
| |
362 |
32
| public void endEntity(String name) throws SAXException {
|
363 |
32
| --entityLevel;
|
364 |
32
| entity = null;
|
365 |
32
| if ( entityLevel == 0 ) {
|
366 |
32
| internalDTDsubset = true;
|
367 |
| } |
368 |
| |
369 |
| } |
370 |
| |
371 |
106
| public void startCDATA() throws SAXException {
|
372 |
106
| insideCDATASection = true;
|
373 |
106
| cdataText = new StringBuffer();
|
374 |
| } |
375 |
| |
376 |
106
| public void endCDATA() throws SAXException {
|
377 |
106
| insideCDATASection = false;
|
378 |
106
| currentElement.addCDATA(cdataText.toString());
|
379 |
| } |
380 |
| |
381 |
822
| public void comment(char[] ch, int start, int end) throws SAXException {
|
382 |
822
| if (!ignoreComments) {
|
383 |
822
| if ( mergeAdjacentText && textInTextBuffer ) {
|
384 |
2
| completeCurrentTextNode();
|
385 |
| } |
386 |
822
| String text = new String(ch, start, end);
|
387 |
822
| if (!insideDTDSection && text.length() > 0) {
|
388 |
816
| if ( currentElement != null ) {
|
389 |
780
| currentElement.addComment(text);
|
390 |
| } |
391 |
| else { |
392 |
36
| getDocument().addComment(text);
|
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 |
12
| public void elementDecl(String name, String model) throws SAXException {
|
418 |
12
| if ( internalDTDsubset ) {
|
419 |
6
| if ( includeInternalDTDDeclarations ) {
|
420 |
6
| addDTDDeclaration( new ElementDecl( name, model ) );
|
421 |
| } |
422 |
| } |
423 |
| else { |
424 |
6
| if ( includeExternalDTDDeclarations ) {
|
425 |
6
| addExternalDTDDeclaration( new ElementDecl( name, model ) );
|
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 |
6
| public void attributeDecl(String eName,String aName,String type,String valueDefault,String value) throws SAXException {
|
455 |
6
| if ( internalDTDsubset ) {
|
456 |
6
| if ( includeInternalDTDDeclarations ) {
|
457 |
6
| addDTDDeclaration( new AttributeDecl( eName, aName, type, valueDefault, value) );
|
458 |
| } |
459 |
| } |
460 |
| else { |
461 |
0
| if ( includeExternalDTDDeclarations ) {
|
462 |
0
| addExternalDTDDeclaration( new AttributeDecl( eName, aName, type, valueDefault, value) );
|
463 |
| } |
464 |
| } |
465 |
| } |
466 |
| |
467 |
| |
468 |
| |
469 |
| |
470 |
| |
471 |
| |
472 |
| |
473 |
| |
474 |
| |
475 |
| |
476 |
| |
477 |
| |
478 |
| |
479 |
| |
480 |
| |
481 |
26
| public void internalEntityDecl(String name, String value) throws SAXException {
|
482 |
26
| if ( internalDTDsubset ) {
|
483 |
26
| if ( includeInternalDTDDeclarations ) {
|
484 |
26
| addDTDDeclaration( new InternalEntityDecl( name, value ) );
|
485 |
| } |
486 |
| } |
487 |
| else { |
488 |
0
| if ( includeExternalDTDDeclarations ) {
|
489 |
0
| addExternalDTDDeclaration( new InternalEntityDecl( name, value ) );
|
490 |
| } |
491 |
| } |
492 |
| } |
493 |
| |
494 |
| |
495 |
| |
496 |
| |
497 |
| |
498 |
| |
499 |
| |
500 |
| |
501 |
| |
502 |
| |
503 |
| |
504 |
| |
505 |
| |
506 |
| |
507 |
| |
508 |
| |
509 |
0
| public void externalEntityDecl(String name, String publicId, String systemId) throws SAXException {
|
510 |
0
| if ( internalDTDsubset ) {
|
511 |
0
| if ( includeInternalDTDDeclarations ) {
|
512 |
0
| addDTDDeclaration( new ExternalEntityDecl( name, publicId, systemId ) );
|
513 |
| } |
514 |
| } |
515 |
| else { |
516 |
0
| if ( includeExternalDTDDeclarations ) {
|
517 |
0
| addExternalDTDDeclaration( new ExternalEntityDecl( name, publicId, systemId ) );
|
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 |
0
| public void notationDecl(String name,String publicId,String systemId) throws SAXException {
|
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 |
0
| public void unparsedEntityDecl(String name,String publicId,String systemId,String notationName) throws SAXException {
|
576 |
| |
577 |
| } |
578 |
| |
579 |
| |
580 |
| |
581 |
| |
582 |
0
| public ElementStack getElementStack() {
|
583 |
0
| return elementStack;
|
584 |
| } |
585 |
| |
586 |
0
| public void setElementStack(ElementStack elementStack) {
|
587 |
0
| this.elementStack = elementStack;
|
588 |
| } |
589 |
| |
590 |
0
| public EntityResolver getEntityResolver() {
|
591 |
0
| return entityResolver;
|
592 |
| } |
593 |
| |
594 |
11560
| public void setEntityResolver(EntityResolver entityResolver) {
|
595 |
11560
| this.entityResolver = entityResolver;
|
596 |
| } |
597 |
| |
598 |
0
| public InputSource getInputSource() {
|
599 |
0
| return inputSource;
|
600 |
| } |
601 |
| |
602 |
11560
| public void setInputSource(InputSource inputSource) {
|
603 |
11560
| this.inputSource = inputSource;
|
604 |
| } |
605 |
| |
606 |
| |
607 |
| |
608 |
| |
609 |
0
| public boolean isIncludeInternalDTDDeclarations() {
|
610 |
0
| return includeInternalDTDDeclarations;
|
611 |
| } |
612 |
| |
613 |
| |
614 |
| |
615 |
| |
616 |
| |
617 |
| |
618 |
| |
619 |
11560
| public void setIncludeInternalDTDDeclarations(boolean includeInternalDTDDeclarations) {
|
620 |
11560
| this.includeInternalDTDDeclarations = includeInternalDTDDeclarations;
|
621 |
| } |
622 |
| |
623 |
| |
624 |
| |
625 |
| |
626 |
0
| public boolean isIncludeExternalDTDDeclarations() {
|
627 |
0
| return includeExternalDTDDeclarations;
|
628 |
| } |
629 |
| |
630 |
| |
631 |
| |
632 |
| |
633 |
| |
634 |
| |
635 |
| |
636 |
11560
| public void setIncludeExternalDTDDeclarations(boolean includeExternalDTDDeclarations) {
|
637 |
11560
| this.includeExternalDTDDeclarations = includeExternalDTDDeclarations;
|
638 |
| } |
639 |
| |
640 |
| |
641 |
| |
642 |
| |
643 |
0
| public boolean isMergeAdjacentText() {
|
644 |
0
| return mergeAdjacentText;
|
645 |
| } |
646 |
| |
647 |
| |
648 |
| |
649 |
| |
650 |
| |
651 |
11560
| public void setMergeAdjacentText(boolean mergeAdjacentText) {
|
652 |
11560
| this.mergeAdjacentText = mergeAdjacentText;
|
653 |
| } |
654 |
| |
655 |
| |
656 |
| |
657 |
| |
658 |
| |
659 |
| |
660 |
0
| public boolean isStripWhitespaceText() {
|
661 |
0
| return stripWhitespaceText;
|
662 |
| } |
663 |
| |
664 |
| |
665 |
| |
666 |
| |
667 |
| |
668 |
11560
| public void setStripWhitespaceText(boolean stripWhitespaceText) {
|
669 |
11560
| this.stripWhitespaceText = stripWhitespaceText;
|
670 |
| } |
671 |
| |
672 |
| |
673 |
| |
674 |
| |
675 |
| |
676 |
0
| public boolean isIgnoreComments() {
|
677 |
0
| return ignoreComments;
|
678 |
| } |
679 |
| |
680 |
| |
681 |
| |
682 |
| |
683 |
| |
684 |
11560
| public void setIgnoreComments(boolean ignoreComments) {
|
685 |
11560
| this.ignoreComments = ignoreComments;
|
686 |
| } |
687 |
| |
688 |
| |
689 |
| |
690 |
| |
691 |
| |
692 |
| |
693 |
| |
694 |
| |
695 |
16
| protected void completeCurrentTextNode() {
|
696 |
16
| if ( stripWhitespaceText ) {
|
697 |
0
| boolean whitespace = true;
|
698 |
0
| for ( int i = 0, size = textBuffer.length(); i < size; i++ ) {
|
699 |
0
| if ( ! Character.isWhitespace( textBuffer.charAt(i) ) ) {
|
700 |
0
| whitespace = false;
|
701 |
0
| break;
|
702 |
| } |
703 |
| } |
704 |
0
| if ( ! whitespace ) {
|
705 |
0
| currentElement.addText( textBuffer.toString() );
|
706 |
| } |
707 |
| } |
708 |
| else { |
709 |
16
| currentElement.addText( textBuffer.toString() );
|
710 |
| } |
711 |
16
| textBuffer.setLength(0);
|
712 |
16
| textInTextBuffer = false;
|
713 |
| } |
714 |
| |
715 |
| |
716 |
| |
717 |
11600
| protected Document createDocument() {
|
718 |
11600
| String encoding = getEncoding();
|
719 |
11600
| Document document = documentFactory.createDocument(encoding);
|
720 |
| |
721 |
| |
722 |
11600
| document.setEntityResolver(entityResolver);
|
723 |
11600
| if (inputSource != null) {
|
724 |
11558
| document.setName(inputSource.getSystemId());
|
725 |
| } |
726 |
| |
727 |
11600
| return document;
|
728 |
| } |
729 |
| |
730 |
11600
| private String getEncoding() {
|
731 |
11600
| if (locator == null) {
|
732 |
2
| return null;
|
733 |
| } |
734 |
| |
735 |
| |
736 |
| |
737 |
11598
| try {
|
738 |
11598
| Method m = locator.getClass().getMethod("getEncoding", new Class[]{});
|
739 |
14
| if (m != null) {
|
740 |
14
| return (String) m.invoke(locator, null);
|
741 |
| } |
742 |
| } catch (Exception e) { |
743 |
| |
744 |
| } |
745 |
| |
746 |
| |
747 |
11584
| return null;
|
748 |
| } |
749 |
| |
750 |
| |
751 |
| |
752 |
24
| protected boolean isIgnorableEntity(String name) {
|
753 |
24
| return "amp".equals( name )
|
754 |
| || "apos".equals( name ) |
755 |
| || "gt".equals( name ) |
756 |
| || "lt".equals( name ) |
757 |
| || "quot".equals( name ); |
758 |
| } |
759 |
| |
760 |
| |
761 |
| |
762 |
| |
763 |
| |
764 |
| |
765 |
168742
| protected void addDeclaredNamespaces(Element element) {
|
766 |
168742
| Namespace elementNamespace = element.getNamespace();
|
767 |
168742
| for ( int size = namespaceStack.size(); declaredNamespaceIndex < size; declaredNamespaceIndex++ ) {
|
768 |
11738
| Namespace namespace = namespaceStack.getNamespace(declaredNamespaceIndex);
|
769 |
| |
770 |
11738
| element.add( namespace );
|
771 |
| |
772 |
| } |
773 |
| } |
774 |
| |
775 |
| |
776 |
| |
777 |
168742
| protected void addAttributes( Element element, Attributes attributes ) {
|
778 |
| |
779 |
| |
780 |
| |
781 |
168742
| boolean noNamespaceAttributes = false;
|
782 |
168742
| if ( element instanceof AbstractElement ) {
|
783 |
| |
784 |
168742
| AbstractElement baseElement = (AbstractElement) element;
|
785 |
168742
| baseElement.setAttributes( attributes, namespaceStack, noNamespaceAttributes );
|
786 |
| } |
787 |
| else { |
788 |
0
| int size = attributes.getLength();
|
789 |
0
| for ( int i = 0; i < size; i++ ) {
|
790 |
0
| String attributeQualifiedName = attributes.getQName(i);
|
791 |
0
| if ( noNamespaceAttributes || ! attributeQualifiedName.startsWith( "xmlns" ) ) {
|
792 |
0
| String attributeURI = attributes.getURI(i);
|
793 |
0
| String attributeLocalName = attributes.getLocalName(i);
|
794 |
0
| String attributeValue = attributes.getValue(i);
|
795 |
| |
796 |
0
| QName attributeQName = namespaceStack.getAttributeQName(
|
797 |
| attributeURI, attributeLocalName, attributeQualifiedName |
798 |
| ); |
799 |
0
| element.addAttribute(attributeQName, attributeValue);
|
800 |
| } |
801 |
| } |
802 |
| } |
803 |
| } |
804 |
| |
805 |
| |
806 |
| |
807 |
38
| protected void addDTDDeclaration(Object declaration) {
|
808 |
38
| if ( internalDTDDeclarations == null ) {
|
809 |
8
| internalDTDDeclarations = new ArrayList();
|
810 |
| } |
811 |
38
| internalDTDDeclarations.add( declaration );
|
812 |
| } |
813 |
| |
814 |
| |
815 |
6
| protected void addExternalDTDDeclaration(Object declaration) {
|
816 |
6
| if ( externalDTDDeclarations == null ) {
|
817 |
6
| externalDTDDeclarations = new ArrayList();
|
818 |
| } |
819 |
6
| externalDTDDeclarations.add( declaration );
|
820 |
| } |
821 |
| |
822 |
11598
| protected ElementStack createElementStack() {
|
823 |
11598
| return new ElementStack();
|
824 |
| } |
825 |
| } |
826 |
| |
827 |
| |
828 |
| |
829 |
| |
830 |
| |
831 |
| |
832 |
| |
833 |
| |
834 |
| |
835 |
| |
836 |
| |
837 |
| |
838 |
| |
839 |
| |
840 |
| |
841 |
| |
842 |
| |
843 |
| |
844 |
| |
845 |
| |
846 |
| |
847 |
| |
848 |
| |
849 |
| |
850 |
| |
851 |
| |
852 |
| |
853 |
| |
854 |
| |
855 |
| |
856 |
| |
857 |
| |
858 |
| |
859 |
| |
860 |
| |
861 |
| |
862 |
| |
863 |
| |
864 |
| |
865 |
| |
866 |
| |
867 |
| |
868 |
| |
869 |
| |
870 |
| |
871 |
| |
872 |
| |
873 |
| |