List of usage examples for javax.xml.stream XMLStreamConstants END_DOCUMENT
int END_DOCUMENT
To view the source code for javax.xml.stream XMLStreamConstants END_DOCUMENT.
Click Source Link
From source file:org.apache.axiom.om.impl.builder.StAXOMBuilder.java
/** * Method next.//from w w w. j ava2 s . c om * * @return Returns int. * @throws OMException */ public int next() throws OMException { try { // We need a loop here because we may decide to skip an event while (true) { if (done) { throw new OMException(); } int token = parserNext(); if (!cache) { return token; } // The current token should be the same as the // one just obtained. This bit of code is used to // detect invalid parser state. if (doTrace) { int currentParserToken = parser.getEventType(); if (currentParserToken != token) { log.debug("WARNING: The current state of the parser is not equal to the " + "state just received from the parser. The current state in the paser is " + XMLEventUtils.getEventTypeString(currentParserToken) + " the state just received is " + XMLEventUtils.getEventTypeString(token)); /* throw new OMException("The current token " + token + " does not match the current event " + "reported by the parser token. The parser did not update its state correctly. " + "The parser is " + parser); */ } } // Now log the current state of the parser if (doTrace) { logParserState(); } switch (token) { case XMLStreamConstants.START_ELEMENT: elementLevel++; lastNode = createNextOMElement(); break; case XMLStreamConstants.CHARACTERS: lastNode = createOMText(XMLStreamConstants.CHARACTERS); break; case XMLStreamConstants.CDATA: lastNode = createOMText(XMLStreamConstants.CDATA); break; case XMLStreamConstants.END_ELEMENT: endElement(); elementLevel--; break; case XMLStreamConstants.END_DOCUMENT: done = true; ((OMContainerEx) this.document).setComplete(true); break; case XMLStreamConstants.SPACE: try { lastNode = createOMText(XMLStreamConstants.SPACE); if (lastNode == null) { continue; } } catch (OMHierarchyException ex) { // The OM implementation doesn't allow text nodes at the current // position in the tree. Since it is only whitespace, we can safely // skip this event. continue; } break; case XMLStreamConstants.COMMENT: lastNode = createComment(); break; case XMLStreamConstants.DTD: createDTD(); break; case XMLStreamConstants.PROCESSING_INSTRUCTION: lastNode = createPI(); break; case XMLStreamConstants.ENTITY_REFERENCE: lastNode = createOMText(XMLStreamConstants.ENTITY_REFERENCE); break; default: throw new OMException(); } return token; } } catch (XMLStreamException e) { throw new OMException(e); } }
From source file:org.apache.axiom.om.impl.builder.StAXOMBuilder.java
/** * Dump the current event of the parser. *///from ww w. j a va2 s. co m protected void logParserState() { if (doTrace) { int currentEvent = parser.getEventType(); switch (currentEvent) { case XMLStreamConstants.START_ELEMENT: log.trace("START_ELEMENT: "); log.trace(" QName: " + parser.getName()); break; case XMLStreamConstants.START_DOCUMENT: log.trace("START_DOCUMENT: "); break; case XMLStreamConstants.CHARACTERS: log.trace("CHARACTERS: "); // This can bust up a datahandler //log.trace( "[" + parser.getText() + "]"); break; case XMLStreamConstants.CDATA: log.trace("CDATA: "); // This can but //log.trace( "[" + parser.getText() + "]"); break; case XMLStreamConstants.END_ELEMENT: log.trace("END_ELEMENT: "); log.trace(" QName: " + parser.getName()); break; case XMLStreamConstants.END_DOCUMENT: log.trace("END_DOCUMENT: "); break; case XMLStreamConstants.SPACE: log.trace("SPACE: "); //log.trace( "[" + parser.getText() + "]"); break; case XMLStreamConstants.COMMENT: log.trace("COMMENT: "); //log.trace( "[" + parser.getText() + "]"); break; case XMLStreamConstants.DTD: log.trace("DTD: "); log.trace("[" + parser.getText() + "]"); break; case XMLStreamConstants.PROCESSING_INSTRUCTION: log.trace("PROCESSING_INSTRUCTION: "); log.trace(" [" + parser.getPITarget() + "][" + parser.getPIData() + "]"); break; case XMLStreamConstants.ENTITY_REFERENCE: log.trace("ENTITY_REFERENCE: "); log.trace(" " + parser.getLocalName() + "[" + parser.getText() + "]"); break; default: log.trace("UNKNOWN_STATE: " + currentEvent); } } }
From source file:org.apache.axiom.om.impl.builder.StAXOMBuilder.java
/** * This method looks ahead to the next start element. * @return true if successful//ww w . j a v a 2s .co m */ public boolean lookahead() { try { while (true) { if (lookAheadToken < 0) { lookAheadToken = parserNext(); } if (lookAheadToken == XMLStreamConstants.START_ELEMENT) { return true; } else if (lookAheadToken == XMLStreamConstants.END_ELEMENT || lookAheadToken == XMLStreamConstants.START_DOCUMENT || lookAheadToken == XMLStreamConstants.END_DOCUMENT) { next(); return false; // leaving scope...start element not found } else { next(); // continue looking past whitespace etc. } } } catch (XMLStreamException e) { throw new OMException(e); } }
From source file:org.apache.axiom.om.impl.llom.OMElementImpl.java
/** * Gets the next sibling. This can be an OMAttribute or OMText or OMELement for others. * * @throws OMException/*from www . j a v a2 s . c o m*/ */ public OMNode getNextOMSibling() throws OMException { while (!done && builder != null) { if (builder.isCompleted()) { if (DEBUG_ENABLED) { log.debug("Builder is complete. Setting OMElement to complete."); } setComplete(true); } else { int token = builder.next(); if (token == XMLStreamConstants.END_DOCUMENT) { throw new OMException("Parser has already reached end of the document. No siblings found"); } } } return super.getNextOMSibling(); }
From source file:org.apache.axiom.om.impl.llom.OMStAXWrapper.java
/** * @return Returns String./*from w w w. j a v a 2s.c om*/ * @throws XMLStreamException * @see javax.xml.stream.XMLStreamReader#getElementText() */ public String getElementText() throws XMLStreamException { if (parser != null) { try { return parser.getElementText(); } catch (XMLStreamException e) { throw new OMStreamingException(e); } } else { /////////////////////////////////////////////////////// //// Code block directly from the API documentation /// if (getEventType() != XMLStreamConstants.START_ELEMENT) { throw new XMLStreamException("parser must be on START_ELEMENT to read next text", getLocation()); } int eventType = next(); StringBuffer content = new StringBuffer(); 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("element text content may not contain START_ELEMENT"); } else { throw new XMLStreamException("Unexpected event type " + eventType, getLocation()); } eventType = next(); } return content.toString(); /////////////////////////////////////////////////////////////// } }
From source file:org.apache.axiom.om.impl.SwitchingWrapper.java
/** * @return Returns String.// w w w. jav a 2s . c o m * @throws XMLStreamException * @see javax.xml.stream.XMLStreamReader#getElementText() */ public String getElementText() throws XMLStreamException { if (parser != null) { try { String elementText = parser.getElementText(); currentEvent = END_ELEMENT; return elementText; } catch (XMLStreamException e) { throw new OMStreamingException(e); } } else { /////////////////////////////////////////////////////// //// Code block directly from the API documentation /// if (getEventType() != XMLStreamConstants.START_ELEMENT) { throw new XMLStreamException("parser must be on START_ELEMENT to read next text", getLocation()); } int eventType = next(); StringBuffer content = new StringBuffer(); 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("element text content may not contain START_ELEMENT"); } else { throw new XMLStreamException("Unexpected event type " + eventType, getLocation()); } eventType = next(); } return content.toString(); /////////////////////////////////////////////////////////////// } }
From source file:org.apache.axiom.om.util.OMXMLStreamReaderValidator.java
/** * Dump the current event of the delegate. *///from ww w . j a va 2 s.co m protected void logParserState() { if (IS_ADV_DEBUG_ENABLED) { int currentEvent = delegate.getEventType(); switch (currentEvent) { case XMLStreamConstants.START_ELEMENT: log.trace("START_ELEMENT: "); log.trace(" QName: " + delegate.getName()); break; case XMLStreamConstants.START_DOCUMENT: log.trace("START_DOCUMENT: "); break; case XMLStreamConstants.CHARACTERS: log.trace("CHARACTERS: "); log.trace("[" + delegate.getText() + "]"); break; case XMLStreamConstants.CDATA: log.trace("CDATA: "); log.trace("[" + delegate.getText() + "]"); break; case XMLStreamConstants.END_ELEMENT: log.trace("END_ELEMENT: "); log.trace(" QName: " + delegate.getName()); break; case XMLStreamConstants.END_DOCUMENT: log.trace("END_DOCUMENT: "); break; case XMLStreamConstants.SPACE: log.trace("SPACE: "); log.trace("[" + delegate.getText() + "]"); break; case XMLStreamConstants.COMMENT: log.trace("COMMENT: "); log.trace("[" + delegate.getText() + "]"); break; case XMLStreamConstants.DTD: log.trace("DTD: "); log.trace("[" + delegate.getText() + "]"); break; case XMLStreamConstants.PROCESSING_INSTRUCTION: log.trace("PROCESSING_INSTRUCTION: "); log.trace(" [" + delegate.getPITarget() + "][" + delegate.getPIData() + "]"); break; case XMLStreamConstants.ENTITY_REFERENCE: log.trace("ENTITY_REFERENCE: "); log.trace(" " + delegate.getLocalName() + "[" + delegate.getText() + "]"); break; default: log.trace("UNKNOWN_STATE: " + currentEvent); } } }
From source file:org.apache.axiom.util.stax.debug.XMLStreamReaderValidator.java
/** * Dump the current event of the delegate. *//*from w ww . ja v a 2 s. c om*/ protected void logParserState() { if (IS_ADV_DEBUG_ENABLED) { int currentEvent = super.getEventType(); switch (currentEvent) { case XMLStreamConstants.START_ELEMENT: log.trace("START_ELEMENT: "); log.trace(" QName: " + super.getName()); break; case XMLStreamConstants.START_DOCUMENT: log.trace("START_DOCUMENT: "); break; case XMLStreamConstants.CHARACTERS: log.trace("CHARACTERS: "); log.trace("[" + super.getText() + "]"); break; case XMLStreamConstants.CDATA: log.trace("CDATA: "); log.trace("[" + super.getText() + "]"); break; case XMLStreamConstants.END_ELEMENT: log.trace("END_ELEMENT: "); log.trace(" QName: " + super.getName()); break; case XMLStreamConstants.END_DOCUMENT: log.trace("END_DOCUMENT: "); break; case XMLStreamConstants.SPACE: log.trace("SPACE: "); log.trace("[" + super.getText() + "]"); break; case XMLStreamConstants.COMMENT: log.trace("COMMENT: "); log.trace("[" + super.getText() + "]"); break; case XMLStreamConstants.DTD: log.trace("DTD: "); log.trace("[" + super.getText() + "]"); break; case XMLStreamConstants.PROCESSING_INSTRUCTION: log.trace("PROCESSING_INSTRUCTION: "); log.trace(" [" + super.getPITarget() + "][" + super.getPIData() + "]"); break; case XMLStreamConstants.ENTITY_REFERENCE: log.trace("ENTITY_REFERENCE: "); log.trace(" " + super.getLocalName() + "[" + super.getText() + "]"); break; default: log.trace("UNKNOWN_STATE: " + currentEvent); } } }
From source file:org.apache.axis2.jaxws.message.impl.XMLSpineImpl.java
private Block _getBlockFromOMElement(OMElement om, Object context, BlockFactory blockFactory, boolean setComplete) throws WebServiceException { try {//from w w w .j av a2 s .com QName qName = om.getQName(); OMNamespace ns = om.getNamespace(); // Save the ROLE // TODO Need to do the same for RELAY and MUSTUNDERSTAND String role = null; if (om instanceof SOAPHeaderBlock) { role = ((SOAPHeaderBlock) om).getRole(); } /* TODO We could gain performance if OMSourcedElement exposed a getDataSource method if (om instanceof OMSourcedElementImpl && ((OMSourcedElementImpl) om).getDataSource() instanceof Block) { Block oldBlock = (Block) ((OMSourcedElementImpl) om).getDataSource(); Block newBlock = blockFactory.createFrom(oldBlock, context); newBlock.setParent(getParent()); if (newBlock != oldBlock) { // Replace the OMElement with the OMSourcedElement that delegates to the block OMSourcedElementImpl newOM = new OMSourcedElementImpl(qName, soapFactory, newBlock); om.insertSiblingBefore(newOM); om.detach(); } return newBlock; } */ // Create the block Block block = blockFactory.createFrom(om, context, qName); block.setParent(getParent()); if (om instanceof SOAPHeaderBlock) { block.setProperty(SOAPHeaderBlock.ROLE_PROPERTY, role); } // Get the business object to force a parse block.getBusinessObject(false); // Replace the OMElement with the OMSourcedElement that delegates to the block OMElement newOM = _createOMElementFromBlock(qName.getLocalPart(), ns, block, soapFactory, (om.getParent() instanceof SOAPHeader)); om.insertSiblingBefore(newOM); // We want to set the om element and its parents to complete to // shutdown the parsing. if (setComplete) { // Get the root of the document OMElement root = om; while (root.getParent() instanceof OMElement) { root = (OMElement) root.getParent(); } try { if (!root.isComplete() && root.getBuilder() != null && !root.getBuilder().isCompleted()) { // Forward the parser to the end so it will close while (root.getBuilder().next() != XMLStreamConstants.END_DOCUMENT) { //do nothing } } } catch (Exception e) { // Log and continue if (log.isDebugEnabled()) { log.debug("Builder next error:" + e.getMessage()); log.trace(JavaUtils.stackToString(e)); } } OMContainer o = om; while (o != null && o instanceof OMContainerEx) { ((OMContainerEx) o).setComplete(true); if ((o instanceof OMNode) && (((OMNode) o).getParent()) instanceof OMContainer) { o = ((OMNode) o).getParent(); } else { o = null; } } } om.detach(); return block; } catch (XMLStreamException xse) { throw ExceptionFactory.makeWebServiceException(xse); } }
From source file:org.apache.solr.handler.AnalysisRequestHandler.java
NamedList<Object> processContent(XMLStreamReader parser, IndexSchema schema) throws XMLStreamException, IOException { NamedList<Object> result = new SimpleOrderedMap<Object>(); while (true) { int event = parser.next(); switch (event) { case XMLStreamConstants.END_DOCUMENT: { parser.close();//from w w w . java 2 s.c om return result; } case XMLStreamConstants.START_ELEMENT: { String currTag = parser.getLocalName(); if ("doc".equals(currTag)) { log.trace("Tokenizing doc..."); SolrInputDocument doc = readDoc(parser); SchemaField uniq = schema.getUniqueKeyField(); NamedList<NamedList<NamedList<Object>>> theTokens = new SimpleOrderedMap<NamedList<NamedList<Object>>>(); result.add(doc.getFieldValue(uniq.getName()).toString(), theTokens); for (String name : doc.getFieldNames()) { FieldType ft = schema.getFieldType(name); Analyzer analyzer = ft.getAnalyzer(); Collection<Object> vals = doc.getFieldValues(name); for (Object val : vals) { Reader reader = new StringReader(val.toString()); TokenStream tstream = analyzer.tokenStream(name, reader); NamedList<NamedList<Object>> tokens = getTokens(tstream); theTokens.add(name, tokens); } } } break; } } } }