Java Code Examples for javax.xml.stream.XMLStreamConstants#COMMENT
The following examples show how to use
javax.xml.stream.XMLStreamConstants#COMMENT .
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: XMLStreamReaderImpl.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
/** Skips any insignificant events (COMMENT and PROCESSING_INSTRUCTION) * until a START_ELEMENT or * END_ELEMENT is reached. If other than space characters are * encountered, an exception is thrown. This method should * be used when processing element-only content because * the parser is not able to recognize ignorable whitespace if * then DTD is missing or not interpreted. * @return the event type of the element read * @throws XMLStreamException if the current event is not white space */ public int nextTag() throws XMLStreamException { int eventType = next(); while((eventType == XMLStreamConstants.CHARACTERS && isWhiteSpace()) // skip whitespace || (eventType == XMLStreamConstants.CDATA && isWhiteSpace()) // skip whitespace || eventType == XMLStreamConstants.SPACE || eventType == XMLStreamConstants.PROCESSING_INSTRUCTION || eventType == XMLStreamConstants.COMMENT ) { eventType = next(); } if (eventType != XMLStreamConstants.START_ELEMENT && eventType != XMLStreamConstants.END_ELEMENT) { throw new XMLStreamException( "found: " + getEventTypeString(eventType) + ", expected " + getEventTypeString(XMLStreamConstants.START_ELEMENT) + " or " + getEventTypeString(XMLStreamConstants.END_ELEMENT), getLocation()); } return eventType; }
Example 2
Source File: BaseXMLEventReader.java From lams with GNU General Public License v2.0 | 6 votes |
@Override public final XMLEvent nextTag() throws XMLStreamException { XMLEvent event = this.nextEvent(); while ((event.isCharacters() && event.asCharacters().isWhiteSpace()) || event.isProcessingInstruction() || event.getEventType() == XMLStreamConstants.COMMENT) { event = this.nextEvent(); } if (!event.isStartElement() && event.isEndElement()) { throw new XMLStreamException("Unexpected event type '" + XMLStreamConstantsUtils.getEventName(event.getEventType()) + "' encountered. Found event: " + event, event.getLocation()); } return event; }
Example 3
Source File: XMLStreamReaderImpl.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
/** Skips any insignificant events (COMMENT and PROCESSING_INSTRUCTION) * until a START_ELEMENT or * END_ELEMENT is reached. If other than space characters are * encountered, an exception is thrown. This method should * be used when processing element-only content because * the parser is not able to recognize ignorable whitespace if * then DTD is missing or not interpreted. * @return the event type of the element read * @throws XMLStreamException if the current event is not white space */ public int nextTag() throws XMLStreamException { int eventType = next(); while((eventType == XMLStreamConstants.CHARACTERS && isWhiteSpace()) // skip whitespace || (eventType == XMLStreamConstants.CDATA && isWhiteSpace()) // skip whitespace || eventType == XMLStreamConstants.SPACE || eventType == XMLStreamConstants.PROCESSING_INSTRUCTION || eventType == XMLStreamConstants.COMMENT ) { eventType = next(); } if (eventType != XMLStreamConstants.START_ELEMENT && eventType != XMLStreamConstants.END_ELEMENT) { throw new XMLStreamException( "found: " + getEventTypeString(eventType) + ", expected " + getEventTypeString(XMLStreamConstants.START_ELEMENT) + " or " + getEventTypeString(XMLStreamConstants.END_ELEMENT), getLocation()); } return eventType; }
Example 4
Source File: XMLStreamReaderImpl.java From JDKSourceCode1.8 with MIT License | 6 votes |
/** Skips any insignificant events (COMMENT and PROCESSING_INSTRUCTION) * until a START_ELEMENT or * END_ELEMENT is reached. If other than space characters are * encountered, an exception is thrown. This method should * be used when processing element-only content because * the parser is not able to recognize ignorable whitespace if * then DTD is missing or not interpreted. * @return the event type of the element read * @throws XMLStreamException if the current event is not white space */ public int nextTag() throws XMLStreamException { int eventType = next(); while((eventType == XMLStreamConstants.CHARACTERS && isWhiteSpace()) // skip whitespace || (eventType == XMLStreamConstants.CDATA && isWhiteSpace()) // skip whitespace || eventType == XMLStreamConstants.SPACE || eventType == XMLStreamConstants.PROCESSING_INSTRUCTION || eventType == XMLStreamConstants.COMMENT ) { eventType = next(); } if (eventType != XMLStreamConstants.START_ELEMENT && eventType != XMLStreamConstants.END_ELEMENT) { throw new XMLStreamException( "found: " + getEventTypeString(eventType) + ", expected " + getEventTypeString(XMLStreamConstants.START_ELEMENT) + " or " + getEventTypeString(XMLStreamConstants.END_ELEMENT), getLocation()); } return eventType; }
Example 5
Source File: XMLStreamReaderImpl.java From jdk1.8-source-analysis with Apache License 2.0 | 6 votes |
/** Skips any insignificant events (COMMENT and PROCESSING_INSTRUCTION) * until a START_ELEMENT or * END_ELEMENT is reached. If other than space characters are * encountered, an exception is thrown. This method should * be used when processing element-only content because * the parser is not able to recognize ignorable whitespace if * then DTD is missing or not interpreted. * @return the event type of the element read * @throws XMLStreamException if the current event is not white space */ public int nextTag() throws XMLStreamException { int eventType = next(); while((eventType == XMLStreamConstants.CHARACTERS && isWhiteSpace()) // skip whitespace || (eventType == XMLStreamConstants.CDATA && isWhiteSpace()) // skip whitespace || eventType == XMLStreamConstants.SPACE || eventType == XMLStreamConstants.PROCESSING_INSTRUCTION || eventType == XMLStreamConstants.COMMENT ) { eventType = next(); } if (eventType != XMLStreamConstants.START_ELEMENT && eventType != XMLStreamConstants.END_ELEMENT) { throw new XMLStreamException( "found: " + getEventTypeString(eventType) + ", expected " + getEventTypeString(XMLStreamConstants.START_ELEMENT) + " or " + getEventTypeString(XMLStreamConstants.END_ELEMENT), getLocation()); } return eventType; }
Example 6
Source File: XMLStreamReaderImpl.java From Bytecoder with Apache License 2.0 | 5 votes |
/** * Reads the content of a text-only element. Precondition: the current event * is START_ELEMENT. Postcondition: The current event is the corresponding * END_ELEMENT. * * @throws XMLStreamException if the current event is not a START_ELEMENT or * if a non text element is encountered */ public String getElementText() throws XMLStreamException { if (getEventType() != XMLStreamConstants.START_ELEMENT) { throw new XMLStreamException( "parser must be on START_ELEMENT to read next text", getLocation()); } int eventType = next(); StringBuilder content = new StringBuilder(); while (eventType != XMLStreamConstants.END_ELEMENT) { if (eventType == XMLStreamConstants.CHARACTERS || eventType == XMLStreamConstants.CDATA || eventType == XMLStreamConstants.SPACE || eventType == XMLStreamConstants.ENTITY_REFERENCE) { content.append(getText()); } else if (eventType == XMLStreamConstants.PROCESSING_INSTRUCTION || eventType == XMLStreamConstants.COMMENT) { // skipping } else if (eventType == XMLStreamConstants.END_DOCUMENT) { throw new XMLStreamException( "unexpected end of document when reading element text content"); } else if (eventType == XMLStreamConstants.START_ELEMENT) { throw new XMLStreamException("elementGetText() function expects text " + "only elment but START_ELEMENT was encountered.", getLocation()); } else { throw new XMLStreamException( "Unexpected event type " + eventType, getLocation()); } eventType = next(); } return content.toString(); }
Example 7
Source File: XmlPolicyModelUnmarshaller.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
private String unmarshalNodeContent(final NamespaceVersion nsVersion, final ModelNode node, final QName nodeElementName, final XMLEventReader reader) throws PolicyException { StringBuilder valueBuffer = null; loop: while (reader.hasNext()) { try { final XMLEvent xmlParserEvent = reader.nextEvent(); switch (xmlParserEvent.getEventType()) { case XMLStreamConstants.COMMENT: break; // skipping the comments case XMLStreamConstants.CHARACTERS: valueBuffer = processCharacters(node.getType(), xmlParserEvent.asCharacters(), valueBuffer); break; case XMLStreamConstants.END_ELEMENT: checkEndTagName(nodeElementName, xmlParserEvent.asEndElement()); break loop; // data exctraction for currently processed policy node is done case XMLStreamConstants.START_ELEMENT: final StartElement childElement = xmlParserEvent.asStartElement(); ModelNode childNode = addNewChildNode(nsVersion, node, childElement); String value = unmarshalNodeContent(nsVersion, childNode, childElement.getName(), reader); if (childNode.isDomainSpecific()) { parseAssertionData(nsVersion, value, childNode, childElement); } break; default: throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0011_UNABLE_TO_UNMARSHALL_POLICY_XML_ELEM_EXPECTED())); } } catch (XMLStreamException e) { throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0068_FAILED_TO_UNMARSHALL_POLICY_EXPRESSION(), e)); } } return (valueBuffer == null) ? null : valueBuffer.toString().trim(); }
Example 8
Source File: AbstractXMLStreamReader.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public boolean hasText() { int eventType = getEventType(); return eventType == XMLStreamConstants.SPACE || eventType == XMLStreamConstants.CHARACTERS || eventType == XMLStreamConstants.COMMENT || eventType == XMLStreamConstants.CDATA || eventType == XMLStreamConstants.ENTITY_REFERENCE; }
Example 9
Source File: XmlPolicyModelUnmarshaller.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
/** * See {@link PolicyModelUnmarshaller#unmarshalModel(Object) base method documentation}. */ public PolicySourceModel unmarshalModel(final Object storage) throws PolicyException { final XMLEventReader reader = createXMLEventReader(storage); PolicySourceModel model = null; loop: while (reader.hasNext()) { try { final XMLEvent event = reader.peek(); switch (event.getEventType()) { case XMLStreamConstants.START_DOCUMENT: case XMLStreamConstants.COMMENT: reader.nextEvent(); break; // skipping the comments and start document events case XMLStreamConstants.CHARACTERS: processCharacters(ModelNode.Type.POLICY, event.asCharacters(), null); // we advance the reader only if there is no exception thrown from // the processCharacters(...) call. Otherwise we don't modify the stream reader.nextEvent(); break; case XMLStreamConstants.START_ELEMENT: if (NamespaceVersion.resolveAsToken(event.asStartElement().getName()) == XmlToken.Policy) { StartElement rootElement = reader.nextEvent().asStartElement(); model = initializeNewModel(rootElement); unmarshalNodeContent(model.getNamespaceVersion(), model.getRootNode(), rootElement.getName(), reader); break loop; } else { throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0048_POLICY_ELEMENT_EXPECTED_FIRST())); } default: throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0048_POLICY_ELEMENT_EXPECTED_FIRST())); } } catch (XMLStreamException e) { throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0068_FAILED_TO_UNMARSHALL_POLICY_EXPRESSION(), e)); } } return model; }
Example 10
Source File: AbstractXMLStreamReader.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public int nextTag() throws XMLStreamException { int eventType = next(); while (eventType == XMLStreamConstants.CHARACTERS && isWhiteSpace() || eventType == XMLStreamConstants.CDATA && isWhiteSpace() || eventType == XMLStreamConstants.SPACE || eventType == XMLStreamConstants.PROCESSING_INSTRUCTION || eventType == XMLStreamConstants.COMMENT) { eventType = next(); } if (eventType != XMLStreamConstants.START_ELEMENT && eventType != XMLStreamConstants.END_ELEMENT) { throw new XMLStreamException("expected start or end tag", getLocation()); } return eventType; }
Example 11
Source File: ListBasedXMLEventReader.java From java-technology-stack with MIT License | 5 votes |
@Override @Nullable public XMLEvent nextTag() throws XMLStreamException { checkIfClosed(); while (true) { XMLEvent event = nextEvent(); switch (event.getEventType()) { case XMLStreamConstants.START_ELEMENT: case XMLStreamConstants.END_ELEMENT: return event; case XMLStreamConstants.END_DOCUMENT: return null; case XMLStreamConstants.SPACE: case XMLStreamConstants.COMMENT: case XMLStreamConstants.PROCESSING_INSTRUCTION: continue; case XMLStreamConstants.CDATA: case XMLStreamConstants.CHARACTERS: if (!event.asCharacters().isWhiteSpace()) { throw new XMLStreamException( "Non-ignorable whitespace CDATA or CHARACTERS event: " + event); } break; default: throw new XMLStreamException("Expected START_ELEMENT or END_ELEMENT: " + event); } } }
Example 12
Source File: ListBasedXMLEventReader.java From spring-analysis-note with MIT License | 5 votes |
@Override @Nullable public XMLEvent nextTag() throws XMLStreamException { checkIfClosed(); while (true) { XMLEvent event = nextEvent(); switch (event.getEventType()) { case XMLStreamConstants.START_ELEMENT: case XMLStreamConstants.END_ELEMENT: return event; case XMLStreamConstants.END_DOCUMENT: return null; case XMLStreamConstants.SPACE: case XMLStreamConstants.COMMENT: case XMLStreamConstants.PROCESSING_INSTRUCTION: continue; case XMLStreamConstants.CDATA: case XMLStreamConstants.CHARACTERS: if (!event.asCharacters().isWhiteSpace()) { throw new XMLStreamException( "Non-ignorable whitespace CDATA or CHARACTERS event: " + event); } break; default: throw new XMLStreamException("Expected START_ELEMENT or END_ELEMENT: " + event); } } }
Example 13
Source File: XMLStreamReaderImpl.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * Reads the content of a text-only element. Precondition: the current event * is START_ELEMENT. Postcondition: The current event is the corresponding * END_ELEMENT. * * @throws XMLStreamException if the current event is not a START_ELEMENT or * if a non text element is encountered */ public String getElementText() throws XMLStreamException { if (getEventType() != XMLStreamConstants.START_ELEMENT) { throw new XMLStreamException( "parser must be on START_ELEMENT to read next text", getLocation()); } int eventType = next(); StringBuilder content = new StringBuilder(); while (eventType != XMLStreamConstants.END_ELEMENT) { if (eventType == XMLStreamConstants.CHARACTERS || eventType == XMLStreamConstants.CDATA || eventType == XMLStreamConstants.SPACE || eventType == XMLStreamConstants.ENTITY_REFERENCE) { content.append(getText()); } else if (eventType == XMLStreamConstants.PROCESSING_INSTRUCTION || eventType == XMLStreamConstants.COMMENT) { // skipping } else if (eventType == XMLStreamConstants.END_DOCUMENT) { throw new XMLStreamException( "unexpected end of document when reading element text content"); } else if (eventType == XMLStreamConstants.START_ELEMENT) { throw new XMLStreamException("elementGetText() function expects text " + "only elment but START_ELEMENT was encountered.", getLocation()); } else { throw new XMLStreamException( "Unexpected event type " + eventType, getLocation()); } eventType = next(); } return content.toString(); }
Example 14
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 15
Source File: TubelineFeatureReader.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
private TubelineFeature parseFactories(final boolean enabled, final StartElement element, final XMLEventReader reader) throws WebServiceException { int elementRead = 0; loop: while (reader.hasNext()) { try { final XMLEvent event = reader.nextEvent(); switch (event.getEventType()) { case XMLStreamConstants.COMMENT: break; // skipping the comments and start document events case XMLStreamConstants.CHARACTERS: if (event.asCharacters().isWhiteSpace()) { break; } else { // TODO: logging message throw LOGGER.logSevereException(new WebServiceException("No character data allowed, was " + event.asCharacters())); } case XMLStreamConstants.START_ELEMENT: // TODO implement elementRead++; break; case XMLStreamConstants.END_ELEMENT: elementRead--; if (elementRead < 0) { final EndElement endElement = event.asEndElement(); if (!element.getName().equals(endElement.getName())) { // TODO logging message throw LOGGER.logSevereException(new WebServiceException("End element does not match " + endElement)); } break loop; } else { break; } default: // TODO logging message throw LOGGER.logSevereException(new WebServiceException("Unexpected event, was " + event)); } } catch (XMLStreamException e) { // TODO logging message throw LOGGER.logSevereException(new WebServiceException("Failed to unmarshal XML document", e)); } } // TODO implement return new TubelineFeature(enabled); }
Example 16
Source File: XMLDocumentFragmentScannerImpl.java From TencentKona-8 with GNU General Public License v2.0 | 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 17
Source File: StAXSchemaParser.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
public void parse(XMLEventReader input) throws XMLStreamException, XNIException { XMLEvent currentEvent = input.peek(); if (currentEvent != null) { int eventType = currentEvent.getEventType(); if (eventType != XMLStreamConstants.START_DOCUMENT && eventType != XMLStreamConstants.START_ELEMENT) { throw new XMLStreamException(); } fLocationWrapper.setLocation(currentEvent.getLocation()); fSchemaDOMParser.startDocument(fLocationWrapper, null, fNamespaceContext, null); loop: while (input.hasNext()) { currentEvent = input.nextEvent(); eventType = currentEvent.getEventType(); switch (eventType) { case XMLStreamConstants.START_ELEMENT: ++fDepth; StartElement start = currentEvent.asStartElement(); fillQName(fElementQName, start.getName()); fLocationWrapper.setLocation(start.getLocation()); fNamespaceContext.setNamespaceContext(start.getNamespaceContext()); fillXMLAttributes(start); fillDeclaredPrefixes(start); addNamespaceDeclarations(); fNamespaceContext.pushContext(); fSchemaDOMParser.startElement(fElementQName, fAttributes, null); break; case XMLStreamConstants.END_ELEMENT: EndElement end = currentEvent.asEndElement(); fillQName(fElementQName, end.getName()); fillDeclaredPrefixes(end); fLocationWrapper.setLocation(end.getLocation()); fSchemaDOMParser.endElement(fElementQName, null); fNamespaceContext.popContext(); --fDepth; if (fDepth <= 0) { break loop; } break; case XMLStreamConstants.CHARACTERS: sendCharactersToSchemaParser(currentEvent.asCharacters().getData(), false); break; case XMLStreamConstants.SPACE: sendCharactersToSchemaParser(currentEvent.asCharacters().getData(), true); break; case XMLStreamConstants.CDATA: fSchemaDOMParser.startCDATA(null); sendCharactersToSchemaParser(currentEvent.asCharacters().getData(), false); fSchemaDOMParser.endCDATA(null); break; case XMLStreamConstants.PROCESSING_INSTRUCTION: ProcessingInstruction pi = (ProcessingInstruction)currentEvent; fillProcessingInstruction(pi.getData()); fSchemaDOMParser.processingInstruction(pi.getTarget(), fTempString, null); break; case XMLStreamConstants.DTD: /* There shouldn't be a DTD in the schema */ break; case XMLStreamConstants.ENTITY_REFERENCE: /* Not needed for schemas */ break; case XMLStreamConstants.COMMENT: /* No point in sending comments */ break; case XMLStreamConstants.START_DOCUMENT: fDepth++; /* We automatically call startDocument before the loop */ break; case XMLStreamConstants.END_DOCUMENT: /* We automatically call endDocument after the loop */ break; } } fLocationWrapper.setLocation(null); fNamespaceContext.setNamespaceContext(null); fSchemaDOMParser.endDocument(null); } }
Example 18
Source File: StAXSchemaParser.java From Bytecoder with Apache License 2.0 | 4 votes |
public void parse(XMLEventReader input) throws XMLStreamException, XNIException { XMLEvent currentEvent = input.peek(); if (currentEvent != null) { int eventType = currentEvent.getEventType(); if (eventType != XMLStreamConstants.START_DOCUMENT && eventType != XMLStreamConstants.START_ELEMENT) { throw new XMLStreamException(); } fLocationWrapper.setLocation(currentEvent.getLocation()); fSchemaDOMParser.startDocument(fLocationWrapper, null, fNamespaceContext, null); loop: while (input.hasNext()) { currentEvent = input.nextEvent(); eventType = currentEvent.getEventType(); switch (eventType) { case XMLStreamConstants.START_ELEMENT: ++fDepth; StartElement start = currentEvent.asStartElement(); fillQName(fElementQName, start.getName()); fLocationWrapper.setLocation(start.getLocation()); fNamespaceContext.setNamespaceContext(start.getNamespaceContext()); fillXMLAttributes(start); fillDeclaredPrefixes(start); addNamespaceDeclarations(); fNamespaceContext.pushContext(); fSchemaDOMParser.startElement(fElementQName, fAttributes, null); break; case XMLStreamConstants.END_ELEMENT: EndElement end = currentEvent.asEndElement(); fillQName(fElementQName, end.getName()); fillDeclaredPrefixes(end); fLocationWrapper.setLocation(end.getLocation()); fSchemaDOMParser.endElement(fElementQName, null); fNamespaceContext.popContext(); --fDepth; if (fDepth <= 0) { break loop; } break; case XMLStreamConstants.CHARACTERS: sendCharactersToSchemaParser(currentEvent.asCharacters().getData(), false); break; case XMLStreamConstants.SPACE: sendCharactersToSchemaParser(currentEvent.asCharacters().getData(), true); break; case XMLStreamConstants.CDATA: fSchemaDOMParser.startCDATA(null); sendCharactersToSchemaParser(currentEvent.asCharacters().getData(), false); fSchemaDOMParser.endCDATA(null); break; case XMLStreamConstants.PROCESSING_INSTRUCTION: ProcessingInstruction pi = (ProcessingInstruction)currentEvent; fillProcessingInstruction(pi.getData()); fSchemaDOMParser.processingInstruction(pi.getTarget(), fTempString, null); break; case XMLStreamConstants.DTD: /* There shouldn't be a DTD in the schema */ break; case XMLStreamConstants.ENTITY_REFERENCE: /* Not needed for schemas */ break; case XMLStreamConstants.COMMENT: /* No point in sending comments */ break; case XMLStreamConstants.START_DOCUMENT: fDepth++; /* We automatically call startDocument before the loop */ break; case XMLStreamConstants.END_DOCUMENT: /* We automatically call endDocument after the loop */ break; } } fLocationWrapper.setLocation(null); fNamespaceContext.setNamespaceContext(null); fSchemaDOMParser.endDocument(null); } }
Example 19
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 20
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); } }