Skip to content

Package: SAXBufferProcessor

SAXBufferProcessor

nameinstructionbranchcomplexitylinemethod
SAXBufferProcessor()
M: 38 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 12 C: 0
0%
M: 1 C: 0
0%
SAXBufferProcessor(XMLStreamBuffer)
M: 41 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 13 C: 0
0%
M: 1 C: 0
0%
SAXBufferProcessor(XMLStreamBuffer, boolean)
M: 0 C: 42
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 13
100%
M: 0 C: 1
100%
cacheNamespacePrefix(String)
M: 21 C: 18
46%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 3 C: 3
50%
M: 0 C: 1
100%
cacheNamespacePrefixIndex()
M: 21 C: 19
48%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 3 C: 3
50%
M: 0 C: 1
100%
cacheNamespacePrefixStartingIndex()
M: 21 C: 14
40%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 3 C: 3
50%
M: 0 C: 1
100%
fixNull(String)
M: 2 C: 4
67%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 0 C: 2
100%
M: 0 C: 1
100%
getContentHandler()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getDTDHandler()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getEntityResolver()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getErrorHandler()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getFeature(String)
M: 38 C: 0
0%
M: 10 C: 0
0%
M: 6 C: 0
0%
M: 11 C: 0
0%
M: 1 C: 0
0%
getLexicalHandler()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getProperty(String)
M: 13 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
isInscope()
M: 0 C: 9
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
parse(InputSource)
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
parse(String)
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
process()
M: 90 C: 67
43%
M: 11 C: 7
39%
M: 11 C: 4
27%
M: 27 C: 20
43%
M: 0 C: 1
100%
process(XMLStreamBuffer)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
process(XMLStreamBuffer, boolean)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
processAttributes(int)
M: 88 C: 0
0%
M: 7 C: 0
0%
M: 6 C: 0
0%
M: 20 C: 0
0%
M: 1 C: 0
0%
processComment(String)
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
processComment(char[], int, int)
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
processCommentAsCharArrayCopy()
M: 10 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
processCommentAsCharArrayMedium()
M: 14 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
processCommentAsCharArraySmall()
M: 14 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
processDocument()
M: 89 C: 0
0%
M: 11 C: 0
0%
M: 11 C: 0
0%
M: 29 C: 0
0%
M: 1 C: 0
0%
processElement(String, String, String, boolean)
M: 121 C: 104
46%
M: 15 C: 15
50%
M: 15 C: 8
35%
M: 37 C: 30
45%
M: 0 C: 1
100%
processEndPrefixMapping()
M: 1 C: 41
98%
M: 1 C: 3
75%
M: 1 C: 2
67%
M: 0 C: 6
100%
M: 0 C: 1
100%
processNamespaceAttribute(String, String)
M: 23 C: 12
34%
M: 3 C: 1
25%
M: 2 C: 1
33%
M: 4 C: 4
50%
M: 0 C: 1
100%
processNamespaceAttributes(int, boolean, Set)
M: 42 C: 33
44%
M: 10 C: 5
33%
M: 7 C: 3
30%
M: 11 C: 10
48%
M: 0 C: 1
100%
processProcessingInstruction(String, String)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
readInscopeNamespaces(Set)
M: 0 C: 30
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
reportFatalError(String)
M: 15 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
setContentHandler(ContentHandler)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
setDTDHandler(DTDHandler)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
setEntityResolver(EntityResolver)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
setErrorHandler(ErrorHandler)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
setFeature(String, boolean)
M: 53 C: 0
0%
M: 14 C: 0
0%
M: 8 C: 0
0%
M: 12 C: 0
0%
M: 1 C: 0
0%
setLexicalHandler(LexicalHandler)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
setProperty(String, Object)
M: 24 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
setXMLStreamBuffer(XMLStreamBuffer)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
setXMLStreamBuffer(XMLStreamBuffer, boolean)
M: 5 C: 11
69%
M: 1 C: 3
75%
M: 1 C: 2
67%
M: 1 C: 3
75%
M: 0 C: 1
100%
static {...}
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%

Coverage

1: /*
2: * Copyright (c) 2005, 2021 Oracle and/or its affiliates. All rights reserved.
3: *
4: * This program and the accompanying materials are made available under the
5: * terms of the Eclipse Distribution License v. 1.0, which is available at
6: * http://www.eclipse.org/org/documents/edl-v10.php.
7: *
8: * SPDX-License-Identifier: BSD-3-Clause
9: */
10:
11: package com.sun.xml.stream.buffer.sax;
12:
13: import com.sun.xml.stream.buffer.AbstractProcessor;
14: import com.sun.xml.stream.buffer.AttributesHolder;
15: import com.sun.xml.stream.buffer.XMLStreamBuffer;
16: import org.xml.sax.ContentHandler;
17: import org.xml.sax.DTDHandler;
18: import org.xml.sax.EntityResolver;
19: import org.xml.sax.ErrorHandler;
20: import org.xml.sax.InputSource;
21: import org.xml.sax.SAXException;
22: import org.xml.sax.SAXNotRecognizedException;
23: import org.xml.sax.SAXNotSupportedException;
24: import org.xml.sax.SAXParseException;
25: import org.xml.sax.XMLReader;
26: import org.xml.sax.ext.LexicalHandler;
27: import org.xml.sax.helpers.LocatorImpl;
28:
29: import javax.xml.XMLConstants;
30: import java.io.IOException;
31: import java.util.Collections;
32: import java.util.HashSet;
33: import java.util.Map;
34: import java.util.Set;
35:
36: /**
37: * A processor of a {@link XMLStreamBuffer} that that reads the XML infoset as
38: * {@link XMLReader}.
39: */
40: public class SAXBufferProcessor extends AbstractProcessor implements XMLReader {
41: /**
42: * Reference to entity resolver.
43: */
44: protected EntityResolver _entityResolver = DEFAULT_LEXICAL_HANDLER;
45:
46: /**
47: * Reference to dtd handler.
48: */
49: protected DTDHandler _dtdHandler = DEFAULT_LEXICAL_HANDLER;
50:
51: /**
52: * Reference to content handler.
53: */
54: protected ContentHandler _contentHandler = DEFAULT_LEXICAL_HANDLER;
55:
56: /**
57: * Reference to error handler.
58: */
59: protected ErrorHandler _errorHandler = DEFAULT_LEXICAL_HANDLER;
60:
61: /**
62: * Reference to lexical handler.
63: */
64: protected LexicalHandler _lexicalHandler = DEFAULT_LEXICAL_HANDLER;
65:
66: /**
67: * SAX Namespace attributes features
68: */
69: protected boolean _namespacePrefixesFeature = false;
70:
71: protected AttributesHolder _attributes = new AttributesHolder();
72:
73: protected String[] _namespacePrefixes = new String[16];
74: protected int _namespacePrefixesIndex;
75:
76: protected int[] _namespaceAttributesStartingStack = new int[16];
77: protected int[] _namespaceAttributesStack = new int[16];
78: protected int _namespaceAttributesStackIndex;
79:
80: public SAXBufferProcessor() {
81: super();
82: }
83:
84: /**
85: * @deprecated
86: * Use {@link #SAXBufferProcessor(XMLStreamBuffer, boolean)}
87: */
88: @Deprecated
89: public SAXBufferProcessor(XMLStreamBuffer buffer) {
90: setXMLStreamBuffer(buffer);
91: }
92:
93: /**
94: * @param produceFragmentEvent
95: * True to generate fragment SAX events without start/endDocument.
96: * False to generate a full document SAX events.
97: */
98: public SAXBufferProcessor(XMLStreamBuffer buffer, boolean produceFragmentEvent) {
99: setXMLStreamBuffer(buffer,produceFragmentEvent);
100: }
101:
102: @Override
103: public boolean getFeature(String name)
104: throws SAXNotRecognizedException, SAXNotSupportedException {
105:• if (name.equals(Features.NAMESPACES_FEATURE)) {
106: return true;
107:• } else if (name.equals(Features.NAMESPACE_PREFIXES_FEATURE)) {
108: return _namespacePrefixesFeature;
109:• } else if (name.equals(Features.EXTERNAL_GENERAL_ENTITIES)) {
110: return true;
111:• } else if (name.equals(Features.EXTERNAL_PARAMETER_ENTITIES)) {
112: return true;
113:• } else if (name.equals(Features.STRING_INTERNING_FEATURE)) {
114: return _stringInterningFeature;
115: } else {
116: throw new SAXNotRecognizedException(
117: "Feature not supported: " + name);
118: }
119: }
120:
121: @Override
122: public void setFeature(String name, boolean value)
123: throws SAXNotRecognizedException, SAXNotSupportedException {
124:• if (name.equals(Features.NAMESPACES_FEATURE)) {
125:• if (!value) {
126: throw new SAXNotSupportedException(name + ":" + value);
127: }
128:• } else if (name.equals(Features.NAMESPACE_PREFIXES_FEATURE)) {
129: _namespacePrefixesFeature = value;
130:• } else if (name.equals(Features.EXTERNAL_GENERAL_ENTITIES)) {
131: // ignore
132:• } else if (name.equals(Features.EXTERNAL_PARAMETER_ENTITIES)) {
133: // ignore
134:• } else if (name.equals(Features.STRING_INTERNING_FEATURE)) {
135:• if (value != _stringInterningFeature) {
136: throw new SAXNotSupportedException(name + ":" + value);
137: }
138: } else {
139: throw new SAXNotRecognizedException(
140: "Feature not supported: " + name);
141: }
142: }
143:
144: @Override
145: public Object getProperty(String name)
146: throws SAXNotRecognizedException, SAXNotSupportedException {
147:• if (name.equals(Properties.LEXICAL_HANDLER_PROPERTY)) {
148: return getLexicalHandler();
149: } else {
150: throw new SAXNotRecognizedException("Property not recognized: " + name);
151: }
152: }
153:
154: @Override
155: public void setProperty(String name, Object value)
156: throws SAXNotRecognizedException, SAXNotSupportedException {
157:• if (name.equals(Properties.LEXICAL_HANDLER_PROPERTY)) {
158:• if (value instanceof LexicalHandler) {
159: setLexicalHandler((LexicalHandler)value);
160: } else {
161: throw new SAXNotSupportedException(Properties.LEXICAL_HANDLER_PROPERTY);
162: }
163: } else {
164: throw new SAXNotRecognizedException("Property not recognized: " + name);
165: }
166: }
167:
168: @Override
169: public void setEntityResolver(EntityResolver resolver) {
170: _entityResolver = resolver;
171: }
172:
173: @Override
174: public EntityResolver getEntityResolver() {
175: return _entityResolver;
176: }
177:
178: @Override
179: public void setDTDHandler(DTDHandler handler) {
180: _dtdHandler = handler;
181: }
182:
183: @Override
184: public DTDHandler getDTDHandler() {
185: return _dtdHandler;
186: }
187:
188: @Override
189: public void setContentHandler(ContentHandler handler) {
190: _contentHandler = handler;
191: }
192:
193: @Override
194: public ContentHandler getContentHandler() {
195: return _contentHandler;
196: }
197:
198: @Override
199: public void setErrorHandler(ErrorHandler handler) {
200: _errorHandler = handler;
201: }
202:
203: @Override
204: public ErrorHandler getErrorHandler() {
205: return _errorHandler;
206: }
207:
208: public void setLexicalHandler(LexicalHandler handler) {
209: _lexicalHandler = handler;
210: }
211:
212: public LexicalHandler getLexicalHandler() {
213: return _lexicalHandler;
214: }
215:
216: @Override
217: public void parse(InputSource input) throws IOException, SAXException {
218: // InputSource is ignored
219: process();
220: }
221:
222: @Override
223: public void parse(String systemId) throws IOException, SAXException {
224: // systemId is ignored
225: process();
226: }
227:
228: /**
229: * Short-hand for {@link #setXMLStreamBuffer(XMLStreamBuffer)} then {@link #process()}.
230: *
231: * @deprecated
232: * Use {@link #process(XMLStreamBuffer, boolean)}
233: */
234: @Deprecated
235: public final void process(XMLStreamBuffer buffer) throws SAXException {
236: setXMLStreamBuffer(buffer);
237: process();
238: }
239:
240: /**
241: * Short-hand for {@link #setXMLStreamBuffer(XMLStreamBuffer,boolean)} then {@link #process()}.
242: *
243: * @param produceFragmentEvent
244: * True to generate fragment SAX events without start/endDocument.
245: * False to generate a full document SAX events.
246: */
247: public final void process(XMLStreamBuffer buffer, boolean produceFragmentEvent) throws SAXException {
248: setXMLStreamBuffer(buffer);
249: process();
250: }
251:
252: /**
253: * Resets the parser to read from the beginning of the given {@link XMLStreamBuffer}.
254: *
255: * @deprecated
256: * Use {@link #setXMLStreamBuffer(XMLStreamBuffer, boolean)}.
257: */
258: @Deprecated
259: public void setXMLStreamBuffer(XMLStreamBuffer buffer) {
260: setBuffer(buffer);
261: }
262:
263: /**
264: * Resets the parser to read from the beginning of the given {@link XMLStreamBuffer}.
265: *
266: * @param produceFragmentEvent
267: * True to generate fragment SAX events without start/endDocument.
268: * False to generate a full document SAX events.
269: */
270: public void setXMLStreamBuffer(XMLStreamBuffer buffer, boolean produceFragmentEvent) {
271:• if(!produceFragmentEvent && _treeCount>1)
272: throw new IllegalStateException("Can't write a forest to a full XML infoset");
273: setBuffer(buffer,produceFragmentEvent);
274: }
275:
276: /**
277: * Parse the sub-tree (or a whole document) that {@link XMLStreamBuffer}
278: * points to, and sends events to handlers.
279: *
280: * <p>
281: * TODO:
282: * We probably need two modes for a sub-tree event generation. One for
283: * firing a sub-tree as if it's a whole document (in which case start/endDocument
284: * and appropriate additional namespace bindings are necessary), and the other
285: * mode for firing a subtree as a subtree, like it does today.
286: * A stream buffer SAX feature could be used to specify this.
287: *
288: * @throws SAXException
289: * Follow the same semantics as {@link XMLReader#parse(InputSource)}.
290: */
291: public final void process() throws SAXException {
292:• if(!_fragmentMode) {
293: LocatorImpl nullLocator = new LocatorImpl();
294: nullLocator.setSystemId(_buffer.getSystemId());
295: nullLocator.setLineNumber(-1);
296: nullLocator.setColumnNumber(-1);
297: _contentHandler.setDocumentLocator(nullLocator);
298:
299: _contentHandler.startDocument();
300: // TODO: if we are writing a fragment stream buffer as a full XML document,
301: // we need to declare in-scope namespaces as if they are on the root element.
302: }
303:
304:• while (_treeCount>0) {
305: final int item = readEiiState();
306:• switch(item) {
307: case STATE_DOCUMENT:
308: processDocument();
309: _treeCount--;
310: break;
311: case STATE_END:
312: // Empty buffer
313: return;
314: case STATE_ELEMENT_U_LN_QN:
315: processElement(readStructureString(), readStructureString(), readStructureString(), isInscope());
316: _treeCount--;
317: break;
318: case STATE_ELEMENT_P_U_LN:
319: {
320: final String prefix = readStructureString();
321: final String uri = readStructureString();
322: final String localName = readStructureString();
323: processElement(uri, localName, getQName(prefix, localName),isInscope());
324: _treeCount--;
325: break;
326: }
327: case STATE_ELEMENT_U_LN: {
328: final String uri = readStructureString();
329: final String localName = readStructureString();
330: processElement(uri, localName, localName,isInscope());
331: _treeCount--;
332: break;
333: }
334: case STATE_ELEMENT_LN:
335: {
336: final String localName = readStructureString();
337: processElement("", localName, localName,isInscope());
338: _treeCount--;
339: break;
340: }
341: case STATE_COMMENT_AS_CHAR_ARRAY_SMALL:
342: processCommentAsCharArraySmall();
343: break;
344: case STATE_COMMENT_AS_CHAR_ARRAY_MEDIUM:
345: processCommentAsCharArrayMedium();
346: break;
347: case STATE_COMMENT_AS_CHAR_ARRAY_COPY:
348: processCommentAsCharArrayCopy();
349: break;
350: case STATE_COMMENT_AS_STRING:
351: processComment(readContentString());
352: break;
353: case STATE_PROCESSING_INSTRUCTION:
354: processProcessingInstruction(readStructureString(), readStructureString());
355: break;
356: default:
357: throw reportFatalError("Illegal state for DIIs: "+item);
358: }
359: }
360:
361:• if(!_fragmentMode)
362: _contentHandler.endDocument();
363: }
364:
365: private void processCommentAsCharArraySmall() throws SAXException {
366: final int length = readStructure();
367: final int start = readContentCharactersBuffer(length);
368: processComment(_contentCharactersBuffer, start, length);
369: }
370:
371: /**
372: * Report a fatal error and abort.
373: *
374: * This is necessary to follow the SAX semantics of error handling.
375: */
376: private SAXParseException reportFatalError(String msg) throws SAXException {
377: SAXParseException spe = new SAXParseException(msg, null);
378:• if(_errorHandler!=null)
379: _errorHandler.fatalError(spe);
380: return spe;
381: }
382:
383: private boolean isInscope() {
384:• return _buffer.getInscopeNamespaces().size() > 0;
385: }
386:
387: private void processDocument() throws SAXException {
388: while(true) {
389: int item = readEiiState();
390:• switch(item) {
391: case STATE_ELEMENT_U_LN_QN:
392: processElement(readStructureString(), readStructureString(), readStructureString(),isInscope());
393: break;
394: case STATE_ELEMENT_P_U_LN:
395: {
396: final String prefix = readStructureString();
397: final String uri = readStructureString();
398: final String localName = readStructureString();
399: processElement(uri, localName, getQName(prefix, localName),isInscope());
400: break;
401: }
402: case STATE_ELEMENT_U_LN: {
403: final String uri = readStructureString();
404: final String localName = readStructureString();
405: processElement(uri, localName, localName,isInscope());
406: break;
407: }
408: case STATE_ELEMENT_LN:
409: {
410: final String localName = readStructureString();
411: processElement("", localName, localName,isInscope());
412: break;
413: }
414: case STATE_COMMENT_AS_CHAR_ARRAY_SMALL:
415: processCommentAsCharArraySmall();
416: break;
417: case STATE_COMMENT_AS_CHAR_ARRAY_MEDIUM:
418: processCommentAsCharArrayMedium();
419: break;
420: case STATE_COMMENT_AS_CHAR_ARRAY_COPY:
421: processCommentAsCharArrayCopy();
422: break;
423: case STATE_COMMENT_AS_STRING:
424: processComment(readContentString());
425: break;
426: case STATE_PROCESSING_INSTRUCTION:
427: processProcessingInstruction(readStructureString(), readStructureString());
428: break;
429: case STATE_END:
430: return;
431: default:
432: throw reportFatalError("Illegal state for child of DII: "+item);
433: }
434: }
435: }
436:
437: protected void processElement(String uri, String localName, String qName, boolean inscope) throws SAXException {
438: boolean hasAttributes = false;
439: boolean hasNamespaceAttributes = false;
440: int item = peekStructure();
441:• Set<String> prefixSet = inscope ? new HashSet<>() : Collections.<String>emptySet();
442:• if ((item & TYPE_MASK) == T_NAMESPACE_ATTRIBUTE) {
443: cacheNamespacePrefixStartingIndex();
444: hasNamespaceAttributes = true;
445: item = processNamespaceAttributes(item, inscope, prefixSet);
446: }
447:• if (inscope) {
448: readInscopeNamespaces(prefixSet);
449: }
450:
451:• if ((item & TYPE_MASK) == T_ATTRIBUTE) {
452: hasAttributes = true;
453: processAttributes(item);
454: }
455:
456: _contentHandler.startElement(uri, localName, qName, _attributes);
457:
458:• if (hasAttributes) {
459: _attributes.clear();
460: }
461:
462: do {
463: item = readEiiState();
464:• switch(item) {
465: case STATE_ELEMENT_U_LN_QN:
466: processElement(readStructureString(), readStructureString(), readStructureString(), false);
467: break;
468: case STATE_ELEMENT_P_U_LN:
469: {
470: final String p = readStructureString();
471: final String u = readStructureString();
472: final String ln = readStructureString();
473: processElement(u, ln, getQName(p, ln),false);
474: break;
475: }
476: case STATE_ELEMENT_U_LN: {
477: final String u = readStructureString();
478: final String ln = readStructureString();
479: processElement(u, ln, ln,false);
480: break;
481: }
482: case STATE_ELEMENT_LN: {
483: final String ln = readStructureString();
484: processElement("", ln, ln,false);
485: break;
486: }
487: case STATE_TEXT_AS_CHAR_ARRAY_SMALL:
488: {
489: final int length = readStructure();
490: int start = readContentCharactersBuffer(length);
491: _contentHandler.characters(_contentCharactersBuffer, start, length);
492: break;
493: }
494: case STATE_TEXT_AS_CHAR_ARRAY_MEDIUM:
495: {
496: final int length = readStructure16();
497: int start = readContentCharactersBuffer(length);
498: _contentHandler.characters(_contentCharactersBuffer, start, length);
499: break;
500: }
501: case STATE_TEXT_AS_CHAR_ARRAY_COPY:
502: {
503: final char[] ch = readContentCharactersCopy();
504:
505: _contentHandler.characters(ch, 0, ch.length);
506: break;
507: }
508: case STATE_TEXT_AS_STRING:
509: {
510: final String s = readContentString();
511: _contentHandler.characters(s.toCharArray(), 0, s.length());
512: break;
513: }
514: case STATE_TEXT_AS_OBJECT:
515: {
516: final CharSequence c = (CharSequence)readContentObject();
517: final String s = c.toString();
518: _contentHandler.characters(s.toCharArray(), 0, s.length());
519: break;
520: }
521: case STATE_COMMENT_AS_CHAR_ARRAY_SMALL:
522: processCommentAsCharArraySmall();
523: break;
524: case STATE_COMMENT_AS_CHAR_ARRAY_MEDIUM:
525: processCommentAsCharArrayMedium();
526: break;
527: case STATE_COMMENT_AS_CHAR_ARRAY_COPY:
528: processCommentAsCharArrayCopy();
529: break;
530: case T_COMMENT_AS_STRING:
531: processComment(readContentString());
532: break;
533: case STATE_PROCESSING_INSTRUCTION:
534: processProcessingInstruction(readStructureString(), readStructureString());
535: break;
536: case STATE_END:
537: break;
538: default:
539: throw reportFatalError("Illegal state for child of EII: "+item);
540: }
541:• } while(item != STATE_END);
542:
543: _contentHandler.endElement(uri, localName, qName);
544:
545:• if (hasNamespaceAttributes) {
546: processEndPrefixMapping();
547: }
548: }
549:
550: private void readInscopeNamespaces(Set<String> prefixSet) throws SAXException {
551:• for (Map.Entry<String, String> e : _buffer.getInscopeNamespaces().entrySet()) {
552: String key = fixNull(e.getKey());
553: // If the prefix is already written, do not write the prefix
554:• if (!prefixSet.contains(key)) {
555: processNamespaceAttribute(key,e.getValue());
556: }
557: }
558:
559: }
560:
561: private static String fixNull(String s) {
562:• if (s == null) return "";
563: else return s;
564: }
565: private void processCommentAsCharArrayCopy() throws SAXException {
566: final char[] ch = readContentCharactersCopy();
567: processComment(ch, 0, ch.length);
568: }
569:
570: private void processCommentAsCharArrayMedium() throws SAXException {
571: final int length = readStructure16();
572: final int start = readContentCharactersBuffer(length);
573: processComment(_contentCharactersBuffer, start, length);
574: }
575:
576: private void processEndPrefixMapping() throws SAXException {
577: final int end = _namespaceAttributesStack[--_namespaceAttributesStackIndex];
578: // final int start = (_namespaceAttributesStackIndex > 0) ? _namespaceAttributesStack[_namespaceAttributesStackIndex] : 0;
579:• final int start = (_namespaceAttributesStackIndex >= 0) ? _namespaceAttributesStartingStack[_namespaceAttributesStackIndex] : 0;
580:
581:• for (int i = end - 1; i >= start; i--) {
582: _contentHandler.endPrefixMapping(_namespacePrefixes[i]);
583: }
584: _namespacePrefixesIndex = start;
585: }
586:
587: private int processNamespaceAttributes(int item,boolean collectPrefixes, Set<String> prefixSet) throws SAXException {
588: do {
589: String prefix;
590:• switch(getNIIState(item)) {
591: case STATE_NAMESPACE_ATTRIBUTE:
592: // Undeclaration of default namespace
593: processNamespaceAttribute("", "");
594:• if(collectPrefixes) {
595: prefixSet.add("");
596: }
597: break;
598: case STATE_NAMESPACE_ATTRIBUTE_P:
599: // Undeclaration of namespace
600: prefix = readStructureString();
601: processNamespaceAttribute(prefix, "");
602:• if(collectPrefixes) {
603: prefixSet.add(prefix);
604: }
605: break;
606: case STATE_NAMESPACE_ATTRIBUTE_P_U:
607: // Declaration with prefix
608: prefix = readStructureString();
609: processNamespaceAttribute(prefix, readStructureString());
610:• if(collectPrefixes) {
611: prefixSet.add(prefix);
612: }
613: break;
614: case STATE_NAMESPACE_ATTRIBUTE_U:
615: // Default declaration
616: processNamespaceAttribute("", readStructureString());
617:• if(collectPrefixes) {
618: prefixSet.add("");
619: }
620: break;
621: default:
622: throw reportFatalError("Illegal state: "+item);
623: }
624: readStructure();
625:
626: item = peekStructure();
627:• } while((item & TYPE_MASK) == T_NAMESPACE_ATTRIBUTE);
628:
629:
630: cacheNamespacePrefixIndex();
631:
632: return item;
633: }
634:
635: private void processAttributes(int item) throws SAXException {
636: do {
637:• switch(getAIIState(item)) {
638: case STATE_ATTRIBUTE_U_LN_QN:
639: _attributes.addAttributeWithQName(readStructureString(), readStructureString(), readStructureString(), readStructureString(), readContentString());
640: break;
641: case STATE_ATTRIBUTE_P_U_LN:
642: {
643: final String p = readStructureString();
644: final String u = readStructureString();
645: final String ln = readStructureString();
646: _attributes.addAttributeWithQName(u, ln, getQName(p, ln), readStructureString(), readContentString());
647: break;
648: }
649: case STATE_ATTRIBUTE_U_LN: {
650: final String u = readStructureString();
651: final String ln = readStructureString();
652: _attributes.addAttributeWithQName(u, ln, ln, readStructureString(), readContentString());
653: break;
654: }
655: case STATE_ATTRIBUTE_LN: {
656: final String ln = readStructureString();
657: _attributes.addAttributeWithQName("", ln, ln, readStructureString(), readContentString());
658: break;
659: }
660: default:
661: throw reportFatalError("Illegal state: "+item);
662: }
663: readStructure();
664:
665: item = peekStructure();
666:• } while((item & TYPE_MASK) == T_ATTRIBUTE);
667: }
668:
669: private void processNamespaceAttribute(String prefix, String uri) throws SAXException {
670: _contentHandler.startPrefixMapping(prefix, uri);
671:
672:• if (_namespacePrefixesFeature) {
673: // Add the namespace delcaration as an attribute
674:• if (prefix != "") {
675: _attributes.addAttributeWithQName(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, prefix,
676: getQName(XMLConstants.XMLNS_ATTRIBUTE, prefix),
677: "CDATA", uri);
678: } else {
679: _attributes.addAttributeWithQName(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, XMLConstants.XMLNS_ATTRIBUTE,
680: XMLConstants.XMLNS_ATTRIBUTE,
681: "CDATA", uri);
682: }
683: }
684:
685: cacheNamespacePrefix(prefix);
686: }
687:
688: private void cacheNamespacePrefix(String prefix) {
689:• if (_namespacePrefixesIndex == _namespacePrefixes.length) {
690: final String[] namespaceAttributes = new String[_namespacePrefixesIndex * 3 / 2 + 1];
691: System.arraycopy(_namespacePrefixes, 0, namespaceAttributes, 0, _namespacePrefixesIndex);
692: _namespacePrefixes = namespaceAttributes;
693: }
694:
695: _namespacePrefixes[_namespacePrefixesIndex++] = prefix;
696: }
697:
698: private void cacheNamespacePrefixIndex() {
699:• if (_namespaceAttributesStackIndex == _namespaceAttributesStack.length) {
700: final int[] namespaceAttributesStack = new int[_namespaceAttributesStackIndex * 3 /2 + 1];
701: System.arraycopy(_namespaceAttributesStack, 0, namespaceAttributesStack, 0, _namespaceAttributesStackIndex);
702: _namespaceAttributesStack = namespaceAttributesStack;
703: }
704:
705: _namespaceAttributesStack[_namespaceAttributesStackIndex++] = _namespacePrefixesIndex;
706: }
707:
708: private void cacheNamespacePrefixStartingIndex() {
709:• if (_namespaceAttributesStackIndex == _namespaceAttributesStartingStack.length) {
710: final int[] namespaceAttributesStart = new int[_namespaceAttributesStackIndex * 3 /2 + 1];
711: System.arraycopy(_namespaceAttributesStartingStack, 0, namespaceAttributesStart, 0, _namespaceAttributesStackIndex);
712: _namespaceAttributesStartingStack = namespaceAttributesStart;
713: }
714: _namespaceAttributesStartingStack[_namespaceAttributesStackIndex] = _namespacePrefixesIndex;
715: }
716:
717: private void processComment(String s) throws SAXException {
718: processComment(s.toCharArray(), 0, s.length());
719: }
720:
721: private void processComment(char[] ch, int start, int length) throws SAXException {
722: _lexicalHandler.comment(ch, start, length);
723: }
724:
725: private void processProcessingInstruction(String target, String data) throws SAXException {
726: _contentHandler.processingInstruction(target, data);
727: }
728:
729: private static final DefaultWithLexicalHandler DEFAULT_LEXICAL_HANDLER = new DefaultWithLexicalHandler();
730: }