Java Code Examples for javax.xml.stream.XMLStreamConstants#ATTRIBUTE
The following examples show how to use
javax.xml.stream.XMLStreamConstants#ATTRIBUTE .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StAXStream2SAX.java From jdk1.8-source-analysis with Apache License 2.0 | 5 votes |
/** * Get the attributes associated with the given START_ELEMENT or ATTRIBUTE * StAXevent. * * @return the StAX attributes converted to an org.xml.sax.Attributes */ private Attributes getAttributes() { AttributesImpl attrs = new AttributesImpl(); int eventType = staxStreamReader.getEventType(); if (eventType != XMLStreamConstants.ATTRIBUTE && eventType != XMLStreamConstants.START_ELEMENT) { throw new InternalError( "getAttributes() attempting to process: " + eventType); } // in SAX, namespace declarations are not part of attributes by default. // (there's a property to control that, but as far as we are concerned // we don't use it.) So don't add xmlns:* to attributes. // gather non-namespace attrs for (int i = 0; i < staxStreamReader.getAttributeCount(); i++) { String uri = staxStreamReader.getAttributeNamespace(i); if(uri==null) uri=""; String localName = staxStreamReader.getAttributeLocalName(i); String prefix = staxStreamReader.getAttributePrefix(i); String qName; if(prefix==null || prefix.length()==0) qName = localName; else qName = prefix + ':' + localName; String type = staxStreamReader.getAttributeType(i); String value = staxStreamReader.getAttributeValue(i); attrs.addAttribute(uri, localName, qName, type, value); } return attrs; }
Example 2
Source File: XMLStreamConstantsUtils.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Get the human readable event name for the numeric event id */ public static String getEventName(int eventId) { switch (eventId) { case XMLStreamConstants.START_ELEMENT: return "StartElementEvent"; case XMLStreamConstants.END_ELEMENT: return "EndElementEvent"; case XMLStreamConstants.PROCESSING_INSTRUCTION: return "ProcessingInstructionEvent"; case XMLStreamConstants.CHARACTERS: return "CharacterEvent"; case XMLStreamConstants.COMMENT: return "CommentEvent"; case XMLStreamConstants.START_DOCUMENT: return "StartDocumentEvent"; case XMLStreamConstants.END_DOCUMENT: return "EndDocumentEvent"; case XMLStreamConstants.ENTITY_REFERENCE: return "EntityReferenceEvent"; case XMLStreamConstants.ATTRIBUTE: return "AttributeBase"; case XMLStreamConstants.DTD: return "DTDEvent"; case XMLStreamConstants.CDATA: return "CDATA"; } return "UNKNOWN_EVENT_TYPE"; }
Example 3
Source File: Util.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public final static String getEventTypeString(int eventType) { switch (eventType){ case XMLStreamConstants.START_ELEMENT: return "START_ELEMENT"; case XMLStreamConstants.END_ELEMENT: return "END_ELEMENT"; case XMLStreamConstants.PROCESSING_INSTRUCTION: return "PROCESSING_INSTRUCTION"; case XMLStreamConstants.CHARACTERS: return "CHARACTERS"; case XMLStreamConstants.COMMENT: return "COMMENT"; case XMLStreamConstants.START_DOCUMENT: return "START_DOCUMENT"; case XMLStreamConstants.END_DOCUMENT: return "END_DOCUMENT"; case XMLStreamConstants.ENTITY_REFERENCE: return "ENTITY_REFERENCE"; case XMLStreamConstants.ATTRIBUTE: return "ATTRIBUTE"; case XMLStreamConstants.DTD: return "DTD"; case XMLStreamConstants.CDATA: return "CDATA"; } return "UNKNOWN_EVENT_TYPE"; }
Example 4
Source File: StAXStream2SAX.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
/** * Get the attributes associated with the given START_ELEMENT or ATTRIBUTE * StAXevent. * * @return the StAX attributes converted to an org.xml.sax.Attributes */ private Attributes getAttributes() { AttributesImpl attrs = new AttributesImpl(); int eventType = staxStreamReader.getEventType(); if (eventType != XMLStreamConstants.ATTRIBUTE && eventType != XMLStreamConstants.START_ELEMENT) { throw new InternalError( "getAttributes() attempting to process: " + eventType); } // in SAX, namespace declarations are not part of attributes by default. // (there's a property to control that, but as far as we are concerned // we don't use it.) So don't add xmlns:* to attributes. // gather non-namespace attrs for (int i = 0; i < staxStreamReader.getAttributeCount(); i++) { String uri = staxStreamReader.getAttributeNamespace(i); if(uri==null) uri=""; String localName = staxStreamReader.getAttributeLocalName(i); String prefix = staxStreamReader.getAttributePrefix(i); String qName; if(prefix==null || prefix.length()==0) qName = localName; else qName = prefix + ':' + localName; String type = staxStreamReader.getAttributeType(i); String value = staxStreamReader.getAttributeValue(i); attrs.addAttribute(uri, localName, qName, type, value); } return attrs; }
Example 5
Source File: Util.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
public final static String getEventTypeString(int eventType) { switch (eventType){ case XMLStreamConstants.START_ELEMENT: return "START_ELEMENT"; case XMLStreamConstants.END_ELEMENT: return "END_ELEMENT"; case XMLStreamConstants.PROCESSING_INSTRUCTION: return "PROCESSING_INSTRUCTION"; case XMLStreamConstants.CHARACTERS: return "CHARACTERS"; case XMLStreamConstants.COMMENT: return "COMMENT"; case XMLStreamConstants.START_DOCUMENT: return "START_DOCUMENT"; case XMLStreamConstants.END_DOCUMENT: return "END_DOCUMENT"; case XMLStreamConstants.ENTITY_REFERENCE: return "ENTITY_REFERENCE"; case XMLStreamConstants.ATTRIBUTE: return "ATTRIBUTE"; case XMLStreamConstants.DTD: return "DTD"; case XMLStreamConstants.CDATA: return "CDATA"; } return "UNKNOWN_EVENT_TYPE"; }
Example 6
Source File: XMLStreamReaderToContentHandler.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
/** * Get the attributes associated with the given START_ELEMENT or ATTRIBUTE * StAXevent. * * @return the StAX attributes converted to an org.xml.sax.Attributes */ private Attributes getAttributes() { AttributesImpl attrs = new AttributesImpl(); int eventType = staxStreamReader.getEventType(); if (eventType != XMLStreamConstants.ATTRIBUTE && eventType != XMLStreamConstants.START_ELEMENT) { throw new InternalError( "getAttributes() attempting to process: " + eventType); } // in SAX, namespace declarations are not part of attributes by default. // (there's a property to control that, but as far as we are concerned // we don't use it.) So don't add xmlns:* to attributes. // gather non-namespace attrs for (int i = 0; i < staxStreamReader.getAttributeCount(); i++) { String uri = staxStreamReader.getAttributeNamespace(i); if(uri==null) uri=""; String localName = staxStreamReader.getAttributeLocalName(i); String prefix = staxStreamReader.getAttributePrefix(i); String qName; if(prefix==null || prefix.length()==0) qName = localName; else qName = prefix + ':' + localName; String type = staxStreamReader.getAttributeType(i); String value = staxStreamReader.getAttributeValue(i); attrs.addAttribute(uri, localName, qName, type, value); } return attrs; }
Example 7
Source File: StAXStream2SAX.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * Get the attributes associated with the given START_ELEMENT or ATTRIBUTE * StAXevent. * * @return the StAX attributes converted to an org.xml.sax.Attributes */ private Attributes getAttributes() { AttributesImpl attrs = new AttributesImpl(); int eventType = staxStreamReader.getEventType(); if (eventType != XMLStreamConstants.ATTRIBUTE && eventType != XMLStreamConstants.START_ELEMENT) { throw new InternalError( "getAttributes() attempting to process: " + eventType); } // in SAX, namespace declarations are not part of attributes by default. // (there's a property to control that, but as far as we are concerned // we don't use it.) So don't add xmlns:* to attributes. // gather non-namespace attrs for (int i = 0; i < staxStreamReader.getAttributeCount(); i++) { String uri = staxStreamReader.getAttributeNamespace(i); if(uri==null) uri=""; String localName = staxStreamReader.getAttributeLocalName(i); String prefix = staxStreamReader.getAttributePrefix(i); String qName; if(prefix==null || prefix.length()==0) qName = localName; else qName = prefix + ':' + localName; String type = staxStreamReader.getAttributeType(i); String value = staxStreamReader.getAttributeValue(i); attrs.addAttribute(uri, localName, qName, type, value); } return attrs; }
Example 8
Source File: Util.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
public final static String getEventTypeString(int eventType) { switch (eventType){ case XMLStreamConstants.START_ELEMENT: return "START_ELEMENT"; case XMLStreamConstants.END_ELEMENT: return "END_ELEMENT"; case XMLStreamConstants.PROCESSING_INSTRUCTION: return "PROCESSING_INSTRUCTION"; case XMLStreamConstants.CHARACTERS: return "CHARACTERS"; case XMLStreamConstants.COMMENT: return "COMMENT"; case XMLStreamConstants.START_DOCUMENT: return "START_DOCUMENT"; case XMLStreamConstants.END_DOCUMENT: return "END_DOCUMENT"; case XMLStreamConstants.ENTITY_REFERENCE: return "ENTITY_REFERENCE"; case XMLStreamConstants.ATTRIBUTE: return "ATTRIBUTE"; case XMLStreamConstants.DTD: return "DTD"; case XMLStreamConstants.CDATA: return "CDATA"; } return "UNKNOWN_EVENT_TYPE"; }
Example 9
Source File: XMLStreamConstantsUtils.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Get the human readable event name for the numeric event id */ public static String getEventName(int eventId) { switch (eventId) { case XMLStreamConstants.START_ELEMENT: return "StartElementEvent"; case XMLStreamConstants.END_ELEMENT: return "EndElementEvent"; case XMLStreamConstants.PROCESSING_INSTRUCTION: return "ProcessingInstructionEvent"; case XMLStreamConstants.CHARACTERS: return "CharacterEvent"; case XMLStreamConstants.COMMENT: return "CommentEvent"; case XMLStreamConstants.START_DOCUMENT: return "StartDocumentEvent"; case XMLStreamConstants.END_DOCUMENT: return "EndDocumentEvent"; case XMLStreamConstants.ENTITY_REFERENCE: return "EntityReferenceEvent"; case XMLStreamConstants.ATTRIBUTE: return "AttributeBase"; case XMLStreamConstants.DTD: return "DTDEvent"; case XMLStreamConstants.CDATA: return "CDATA"; } return "UNKNOWN_EVENT_TYPE"; }
Example 10
Source File: XMLStreamReaderToContentHandler.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
/** * Get the attributes associated with the given START_ELEMENT or ATTRIBUTE * StAXevent. * * @return the StAX attributes converted to an org.xml.sax.Attributes */ private Attributes getAttributes() { AttributesImpl attrs = new AttributesImpl(); int eventType = staxStreamReader.getEventType(); if (eventType != XMLStreamConstants.ATTRIBUTE && eventType != XMLStreamConstants.START_ELEMENT) { throw new InternalError( "getAttributes() attempting to process: " + eventType); } // in SAX, namespace declarations are not part of attributes by default. // (there's a property to control that, but as far as we are concerned // we don't use it.) So don't add xmlns:* to attributes. // gather non-namespace attrs for (int i = 0; i < staxStreamReader.getAttributeCount(); i++) { String uri = staxStreamReader.getAttributeNamespace(i); if(uri==null) uri=""; String localName = staxStreamReader.getAttributeLocalName(i); String prefix = staxStreamReader.getAttributePrefix(i); String qName; if(prefix==null || prefix.length()==0) qName = localName; else qName = prefix + ':' + localName; String type = staxStreamReader.getAttributeType(i); String value = staxStreamReader.getAttributeValue(i); attrs.addAttribute(uri, localName, qName, type, value); } return attrs; }
Example 11
Source File: XMLStreamReaderToContentHandler.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
public void bridge() throws XMLStreamException { try { // remembers the nest level of elements to know when we are done. int depth=0; // if the parser is at the start tag, proceed to the first element int event = staxStreamReader.getEventType(); if(event == XMLStreamConstants.START_DOCUMENT) { // nextTag doesn't correctly handle DTDs while( !staxStreamReader.isStartElement() ) event = staxStreamReader.next(); } if( event!=XMLStreamConstants.START_ELEMENT) throw new IllegalStateException("The current event is not START_ELEMENT\n but " + event); handleStartDocument(); for(int i=0; i < inscopeNamespaces.length; i+=2) { saxHandler.startPrefixMapping(inscopeNamespaces[i], inscopeNamespaces[i+1]); } OUTER: do { // These are all of the events listed in the javadoc for // XMLEvent. // The spec only really describes 11 of them. switch (event) { case XMLStreamConstants.START_ELEMENT : depth++; handleStartElement(); break; case XMLStreamConstants.END_ELEMENT : handleEndElement(); depth--; if(depth==0 && eagerQuit) break OUTER; break; case XMLStreamConstants.CHARACTERS : handleCharacters(); break; case XMLStreamConstants.ENTITY_REFERENCE : handleEntityReference(); break; case XMLStreamConstants.PROCESSING_INSTRUCTION : handlePI(); break; case XMLStreamConstants.COMMENT : handleComment(); break; case XMLStreamConstants.DTD : handleDTD(); break; case XMLStreamConstants.ATTRIBUTE : handleAttribute(); break; case XMLStreamConstants.NAMESPACE : handleNamespace(); break; case XMLStreamConstants.CDATA : handleCDATA(); break; case XMLStreamConstants.ENTITY_DECLARATION : handleEntityDecl(); break; case XMLStreamConstants.NOTATION_DECLARATION : handleNotationDecl(); break; case XMLStreamConstants.SPACE : handleSpace(); break; default : throw new InternalError("processing event: " + event); } event=staxStreamReader.next(); } while (depth!=0); for(int i=0; i < inscopeNamespaces.length; i+=2) { saxHandler.endPrefixMapping(inscopeNamespaces[i]); } handleEndDocument(); } catch (SAXException e) { throw new XMLStreamException2(e); } }
Example 12
Source File: ParsingUtils.java From galleon with Apache License 2.0 | 4 votes |
public static XMLStreamException unexpectedContent(final XMLStreamReader reader) { final String kind; switch (reader.getEventType()) { case XMLStreamConstants.ATTRIBUTE: kind = "attribute"; break; case XMLStreamConstants.CDATA: kind = "cdata"; break; case XMLStreamConstants.CHARACTERS: kind = "characters"; break; case XMLStreamConstants.COMMENT: kind = "comment"; break; case XMLStreamConstants.DTD: kind = "dtd"; break; case XMLStreamConstants.END_DOCUMENT: kind = "document end"; break; case XMLStreamConstants.END_ELEMENT: kind = "element end"; break; case XMLStreamConstants.ENTITY_DECLARATION: kind = "entity declaration"; break; case XMLStreamConstants.ENTITY_REFERENCE: kind = "entity ref"; break; case XMLStreamConstants.NAMESPACE: kind = "namespace"; break; case XMLStreamConstants.NOTATION_DECLARATION: kind = "notation declaration"; break; case XMLStreamConstants.PROCESSING_INSTRUCTION: kind = "processing instruction"; break; case XMLStreamConstants.SPACE: kind = "whitespace"; break; case XMLStreamConstants.START_DOCUMENT: kind = "document start"; break; case XMLStreamConstants.START_ELEMENT: kind = "element start"; break; default: kind = "unknown"; break; } return new XMLStreamException("unexpected content: " + kind + (reader.hasName() ? reader.getName() : null) + (reader.hasText() ? reader.getText() : null), reader.getLocation()); }
Example 13
Source File: StAXStream2SAX.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
public void bridge() throws XMLStreamException { try { // remembers the nest level of elements to know when we are done. int depth=0; // skip over START_DOCUMENT int event = staxStreamReader.getEventType(); if (event == XMLStreamConstants.START_DOCUMENT) { event = staxStreamReader.next(); } // If not a START_ELEMENT (e.g., a DTD), skip to next tag if (event != XMLStreamConstants.START_ELEMENT) { event = staxStreamReader.nextTag(); // An error if a START_ELEMENT isn't found now if (event != XMLStreamConstants.START_ELEMENT) { throw new IllegalStateException("The current event is " + "not START_ELEMENT\n but" + event); } } handleStartDocument(); do { // These are all of the events listed in the javadoc for // XMLEvent. // The spec only really describes 11 of them. switch (event) { case XMLStreamConstants.START_ELEMENT : depth++; handleStartElement(); break; case XMLStreamConstants.END_ELEMENT : handleEndElement(); depth--; break; case XMLStreamConstants.CHARACTERS : handleCharacters(); break; case XMLStreamConstants.ENTITY_REFERENCE : handleEntityReference(); break; case XMLStreamConstants.PROCESSING_INSTRUCTION : handlePI(); break; case XMLStreamConstants.COMMENT : handleComment(); break; case XMLStreamConstants.DTD : handleDTD(); break; case XMLStreamConstants.ATTRIBUTE : handleAttribute(); break; case XMLStreamConstants.NAMESPACE : handleNamespace(); break; case XMLStreamConstants.CDATA : handleCDATA(); break; case XMLStreamConstants.ENTITY_DECLARATION : handleEntityDecl(); break; case XMLStreamConstants.NOTATION_DECLARATION : handleNotationDecl(); break; case XMLStreamConstants.SPACE : handleSpace(); break; default : throw new InternalError("processing event: " + event); } event=staxStreamReader.next(); } while (depth!=0); handleEndDocument(); } catch (SAXException e) { throw new XMLStreamException(e); } }
Example 14
Source File: StAXStream2SAX.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
public void bridge() throws XMLStreamException { try { // remembers the nest level of elements to know when we are done. int depth=0; // skip over START_DOCUMENT int event = staxStreamReader.getEventType(); if (event == XMLStreamConstants.START_DOCUMENT) { event = staxStreamReader.next(); } // If not a START_ELEMENT (e.g., a DTD), skip to next tag if (event != XMLStreamConstants.START_ELEMENT) { event = staxStreamReader.nextTag(); // An error if a START_ELEMENT isn't found now if (event != XMLStreamConstants.START_ELEMENT) { throw new IllegalStateException("The current event is " + "not START_ELEMENT\n but" + event); } } handleStartDocument(); do { // These are all of the events listed in the javadoc for // XMLEvent. // The spec only really describes 11 of them. switch (event) { case XMLStreamConstants.START_ELEMENT : depth++; handleStartElement(); break; case XMLStreamConstants.END_ELEMENT : handleEndElement(); depth--; break; case XMLStreamConstants.CHARACTERS : handleCharacters(); break; case XMLStreamConstants.ENTITY_REFERENCE : handleEntityReference(); break; case XMLStreamConstants.PROCESSING_INSTRUCTION : handlePI(); break; case XMLStreamConstants.COMMENT : handleComment(); break; case XMLStreamConstants.DTD : handleDTD(); break; case XMLStreamConstants.ATTRIBUTE : handleAttribute(); break; case XMLStreamConstants.NAMESPACE : handleNamespace(); break; case XMLStreamConstants.CDATA : handleCDATA(); break; case XMLStreamConstants.ENTITY_DECLARATION : handleEntityDecl(); break; case XMLStreamConstants.NOTATION_DECLARATION : handleNotationDecl(); break; case XMLStreamConstants.SPACE : handleSpace(); break; default : throw new InternalError("processing event: " + event); } event=staxStreamReader.next(); } while (depth!=0); handleEndDocument(); } catch (SAXException e) { throw new XMLStreamException(e); } }
Example 15
Source File: XMLStreamReaderToContentHandler.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
public void bridge() throws XMLStreamException { try { // remembers the nest level of elements to know when we are done. int depth=0; // if the parser is at the start tag, proceed to the first element int event = staxStreamReader.getEventType(); if(event == XMLStreamConstants.START_DOCUMENT) { // nextTag doesn't correctly handle DTDs while( !staxStreamReader.isStartElement() ) event = staxStreamReader.next(); } if( event!=XMLStreamConstants.START_ELEMENT) throw new IllegalStateException("The current event is not START_ELEMENT\n but " + event); handleStartDocument(); for(int i=0; i < inscopeNamespaces.length; i+=2) { saxHandler.startPrefixMapping(inscopeNamespaces[i], inscopeNamespaces[i+1]); } OUTER: do { // These are all of the events listed in the javadoc for // XMLEvent. // The spec only really describes 11 of them. switch (event) { case XMLStreamConstants.START_ELEMENT : depth++; handleStartElement(); break; case XMLStreamConstants.END_ELEMENT : handleEndElement(); depth--; if(depth==0 && eagerQuit) break OUTER; break; case XMLStreamConstants.CHARACTERS : handleCharacters(); break; case XMLStreamConstants.ENTITY_REFERENCE : handleEntityReference(); break; case XMLStreamConstants.PROCESSING_INSTRUCTION : handlePI(); break; case XMLStreamConstants.COMMENT : handleComment(); break; case XMLStreamConstants.DTD : handleDTD(); break; case XMLStreamConstants.ATTRIBUTE : handleAttribute(); break; case XMLStreamConstants.NAMESPACE : handleNamespace(); break; case XMLStreamConstants.CDATA : handleCDATA(); break; case XMLStreamConstants.ENTITY_DECLARATION : handleEntityDecl(); break; case XMLStreamConstants.NOTATION_DECLARATION : handleNotationDecl(); break; case XMLStreamConstants.SPACE : handleSpace(); break; default : throw new InternalError("processing event: " + event); } event=staxStreamReader.next(); } while (depth!=0); for(int i=0; i < inscopeNamespaces.length; i+=2) { saxHandler.endPrefixMapping(inscopeNamespaces[i]); } handleEndDocument(); } catch (SAXException e) { throw new XMLStreamException2(e); } }
Example 16
Source File: XMLStreamWriterImpl.java From Bytecoder with Apache License 2.0 | 4 votes |
/** * * @param uri * @return */ private void correctPrefix(QName attr, int type) { String tmpPrefix; String prefix; String uri; prefix = attr.prefix; uri = attr.uri; boolean isSpecialCaseURI = false; if (prefix == null || prefix.equals(XMLConstants.DEFAULT_NS_PREFIX)) { if (uri == null) { return; } if (XMLConstants.DEFAULT_NS_PREFIX.equals(prefix) && uri.equals(XMLConstants.DEFAULT_NS_PREFIX)) return; uri = fSymbolTable.addSymbol(uri); QName decl; for (int i = 0; i < fNamespaceDecls.size(); i++) { decl = fNamespaceDecls.get(i); if ((decl != null) && (decl.uri.equals(attr.uri))) { attr.prefix = decl.prefix; return; } } tmpPrefix = fNamespaceContext.getPrefix(uri); if (XMLConstants.DEFAULT_NS_PREFIX.equals(tmpPrefix)) { if (type == XMLStreamConstants.START_ELEMENT) { return; } else if (type == XMLStreamConstants.ATTRIBUTE) { //the uri happens to be the same as that of the default namespace tmpPrefix = getAttrPrefix(uri); isSpecialCaseURI = true; } } if (tmpPrefix == null) { StringBuilder genPrefix = new StringBuilder("zdef"); for (int i = 0; i < 1; i++) { genPrefix.append(fPrefixGen.nextInt()); } prefix = genPrefix.toString(); prefix = fSymbolTable.addSymbol(prefix); } else { prefix = fSymbolTable.addSymbol(tmpPrefix); } if (tmpPrefix == null) { if (isSpecialCaseURI) { addAttrNamespace(prefix, uri); } else { QName qname = new QName(); qname.setValues(prefix, XMLConstants.XMLNS_ATTRIBUTE, null, uri); fNamespaceDecls.add(qname); fInternalNamespaceContext.declarePrefix(fSymbolTable.addSymbol( prefix), uri); } } } attr.prefix = prefix; }
Example 17
Source File: StAXStream2SAX.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
public void bridge() throws XMLStreamException { try { // remembers the nest level of elements to know when we are done. int depth=0; // skip over START_DOCUMENT int event = staxStreamReader.getEventType(); if (event == XMLStreamConstants.START_DOCUMENT) { event = staxStreamReader.next(); } // If not a START_ELEMENT (e.g., a DTD), skip to next tag if (event != XMLStreamConstants.START_ELEMENT) { event = staxStreamReader.nextTag(); // An error if a START_ELEMENT isn't found now if (event != XMLStreamConstants.START_ELEMENT) { throw new IllegalStateException("The current event is " + "not START_ELEMENT\n but" + event); } } handleStartDocument(); do { // These are all of the events listed in the javadoc for // XMLEvent. // The spec only really describes 11 of them. switch (event) { case XMLStreamConstants.START_ELEMENT : depth++; handleStartElement(); break; case XMLStreamConstants.END_ELEMENT : handleEndElement(); depth--; break; case XMLStreamConstants.CHARACTERS : handleCharacters(); break; case XMLStreamConstants.ENTITY_REFERENCE : handleEntityReference(); break; case XMLStreamConstants.PROCESSING_INSTRUCTION : handlePI(); break; case XMLStreamConstants.COMMENT : handleComment(); break; case XMLStreamConstants.DTD : handleDTD(); break; case XMLStreamConstants.ATTRIBUTE : handleAttribute(); break; case XMLStreamConstants.NAMESPACE : handleNamespace(); break; case XMLStreamConstants.CDATA : handleCDATA(); break; case XMLStreamConstants.ENTITY_DECLARATION : handleEntityDecl(); break; case XMLStreamConstants.NOTATION_DECLARATION : handleNotationDecl(); break; case XMLStreamConstants.SPACE : handleSpace(); break; default : throw new InternalError("processing event: " + event); } event=staxStreamReader.next(); } while (depth!=0); handleEndDocument(); } catch (SAXException e) { throw new XMLStreamException(e); } }
Example 18
Source File: StAXStream2SAX.java From jdk1.8-source-analysis with Apache License 2.0 | 4 votes |
public void bridge() throws XMLStreamException { try { // remembers the nest level of elements to know when we are done. int depth=0; // skip over START_DOCUMENT int event = staxStreamReader.getEventType(); if (event == XMLStreamConstants.START_DOCUMENT) { event = staxStreamReader.next(); } // If not a START_ELEMENT (e.g., a DTD), skip to next tag if (event != XMLStreamConstants.START_ELEMENT) { event = staxStreamReader.nextTag(); // An error if a START_ELEMENT isn't found now if (event != XMLStreamConstants.START_ELEMENT) { throw new IllegalStateException("The current event is " + "not START_ELEMENT\n but" + event); } } handleStartDocument(); do { // These are all of the events listed in the javadoc for // XMLEvent. // The spec only really describes 11 of them. switch (event) { case XMLStreamConstants.START_ELEMENT : depth++; handleStartElement(); break; case XMLStreamConstants.END_ELEMENT : handleEndElement(); depth--; break; case XMLStreamConstants.CHARACTERS : handleCharacters(); break; case XMLStreamConstants.ENTITY_REFERENCE : handleEntityReference(); break; case XMLStreamConstants.PROCESSING_INSTRUCTION : handlePI(); break; case XMLStreamConstants.COMMENT : handleComment(); break; case XMLStreamConstants.DTD : handleDTD(); break; case XMLStreamConstants.ATTRIBUTE : handleAttribute(); break; case XMLStreamConstants.NAMESPACE : handleNamespace(); break; case XMLStreamConstants.CDATA : handleCDATA(); break; case XMLStreamConstants.ENTITY_DECLARATION : handleEntityDecl(); break; case XMLStreamConstants.NOTATION_DECLARATION : handleNotationDecl(); break; case XMLStreamConstants.SPACE : handleSpace(); break; default : throw new InternalError("processing event: " + event); } event=staxStreamReader.next(); } while (depth!=0); handleEndDocument(); } catch (SAXException e) { throw new XMLStreamException(e); } }
Example 19
Source File: XMLDocumentFragmentScannerImpl.java From JDKSourceCode1.8 with MIT License | 4 votes |
/** * Scans a document. * * @param complete True if the scanner should scan the document * completely, pushing all events to the registered * document handler. A value of false indicates that * that the scanner should only scan the next portion * of the document and return. A scanner instance is * permitted to completely scan a document if it does * not support this "pull" scanning model. * * @return True if there is more to scan, false otherwise. */ public boolean scanDocument(boolean complete) throws IOException, XNIException { // keep dispatching "events" fEntityManager.setEntityHandler(this); //System.out.println(" get Document Handler in NSDocumentHandler " + fDocumentHandler ); int event = next(); do { switch (event) { case XMLStreamConstants.START_DOCUMENT : //fDocumentHandler.startDocument(fEntityManager.getEntityScanner(),fEntityManager.getEntityScanner().getVersion(),fNamespaceContext,null);// not able to get break; case XMLStreamConstants.START_ELEMENT : //System.out.println(" in scann element"); //fDocumentHandler.startElement(getElementQName(),fAttributes,null); break; case XMLStreamConstants.CHARACTERS : fEntityScanner.checkNodeCount(fEntityScanner.fCurrentEntity); fDocumentHandler.characters(getCharacterData(),null); break; case XMLStreamConstants.SPACE: //check if getCharacterData() is the right function to retrieve ignorableWhitespace information. //System.out.println("in the space"); //fDocumentHandler.ignorableWhitespace(getCharacterData(), null); break; case XMLStreamConstants.ENTITY_REFERENCE : fEntityScanner.checkNodeCount(fEntityScanner.fCurrentEntity); //entity reference callback are given in startEntity break; case XMLStreamConstants.PROCESSING_INSTRUCTION : fEntityScanner.checkNodeCount(fEntityScanner.fCurrentEntity); fDocumentHandler.processingInstruction(getPITarget(),getPIData(),null); break; case XMLStreamConstants.COMMENT : fEntityScanner.checkNodeCount(fEntityScanner.fCurrentEntity); fDocumentHandler.comment(getCharacterData(),null); break; case XMLStreamConstants.DTD : //all DTD related callbacks are handled in DTDScanner. //1. Stax doesn't define DTD states as it does for XML Document. //therefore we don't need to take care of anything here. So Just break; break; case XMLStreamConstants.CDATA: fEntityScanner.checkNodeCount(fEntityScanner.fCurrentEntity); fDocumentHandler.startCDATA(null); //xxx: check if CDATA values comes from getCharacterData() function fDocumentHandler.characters(getCharacterData(),null); fDocumentHandler.endCDATA(null); //System.out.println(" in CDATA of the XMLNSDocumentScannerImpl"); break; case XMLStreamConstants.NOTATION_DECLARATION : break; case XMLStreamConstants.ENTITY_DECLARATION : break; case XMLStreamConstants.NAMESPACE : break; case XMLStreamConstants.ATTRIBUTE : break; case XMLStreamConstants.END_ELEMENT : //do not give callback here. //this callback is given in scanEndElement function. //fDocumentHandler.endElement(getElementQName(),null); break; default : throw new InternalError("processing event: " + event); } //System.out.println("here in before calling next"); event = next(); //System.out.println("here in after calling next"); } while (event!=XMLStreamConstants.END_DOCUMENT && complete); if(event == XMLStreamConstants.END_DOCUMENT) { fDocumentHandler.endDocument(null); return false; } return true; }
Example 20
Source File: XMLStreamReaderToContentHandler.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
public void bridge() throws XMLStreamException { try { // remembers the nest level of elements to know when we are done. int depth=0; // if the parser is at the start tag, proceed to the first element int event = staxStreamReader.getEventType(); if(event == XMLStreamConstants.START_DOCUMENT) { // nextTag doesn't correctly handle DTDs while( !staxStreamReader.isStartElement() ) event = staxStreamReader.next(); } if( event!=XMLStreamConstants.START_ELEMENT) throw new IllegalStateException("The current event is not START_ELEMENT\n but " + event); handleStartDocument(); for(int i=0; i < inscopeNamespaces.length; i+=2) { saxHandler.startPrefixMapping(inscopeNamespaces[i], inscopeNamespaces[i+1]); } OUTER: do { // These are all of the events listed in the javadoc for // XMLEvent. // The spec only really describes 11 of them. switch (event) { case XMLStreamConstants.START_ELEMENT : depth++; handleStartElement(); break; case XMLStreamConstants.END_ELEMENT : handleEndElement(); depth--; if(depth==0 && eagerQuit) break OUTER; break; case XMLStreamConstants.CHARACTERS : handleCharacters(); break; case XMLStreamConstants.ENTITY_REFERENCE : handleEntityReference(); break; case XMLStreamConstants.PROCESSING_INSTRUCTION : handlePI(); break; case XMLStreamConstants.COMMENT : handleComment(); break; case XMLStreamConstants.DTD : handleDTD(); break; case XMLStreamConstants.ATTRIBUTE : handleAttribute(); break; case XMLStreamConstants.NAMESPACE : handleNamespace(); break; case XMLStreamConstants.CDATA : handleCDATA(); break; case XMLStreamConstants.ENTITY_DECLARATION : handleEntityDecl(); break; case XMLStreamConstants.NOTATION_DECLARATION : handleNotationDecl(); break; case XMLStreamConstants.SPACE : handleSpace(); break; default : throw new InternalError("processing event: " + event); } event=staxStreamReader.next(); } while (depth!=0); for(int i=0; i < inscopeNamespaces.length; i+=2) { saxHandler.endPrefixMapping(inscopeNamespaces[i]); } handleEndDocument(); } catch (SAXException e) { throw new XMLStreamException2(e); } }