List of usage examples for javax.xml.stream XMLStreamConstants START_DOCUMENT
int START_DOCUMENT
To view the source code for javax.xml.stream XMLStreamConstants START_DOCUMENT.
Click Source Link
From source file:org.apache.axiom.om.impl.builder.StAXOMBuilder.java
/** * Dump the current event of the parser. *//*from w ww . jav a 2 s . com*/ 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//from w ww.ja v a2 s . com */ 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.util.OMXMLStreamReaderValidator.java
/** * Dump the current event of the delegate. *//*from w w w .j a v a 2s. c om*/ 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 o m 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.synapse.commons.json.JsonDataSource.java
public void serialize(XMLStreamWriter xmlWriter) throws XMLStreamException { XMLStreamReader reader = getReader(); xmlWriter.writeStartDocument();// www . ja v a 2 s.c o m while (reader.hasNext()) { int x = reader.next(); switch (x) { case XMLStreamConstants.START_ELEMENT: xmlWriter.writeStartElement(reader.getPrefix(), reader.getLocalName(), reader.getNamespaceURI()); int namespaceCount = reader.getNamespaceCount(); for (int i = namespaceCount - 1; i >= 0; i--) { xmlWriter.writeNamespace(reader.getNamespacePrefix(i), reader.getNamespaceURI(i)); } int attributeCount = reader.getAttributeCount(); for (int i = 0; i < attributeCount; i++) { xmlWriter.writeAttribute(reader.getAttributePrefix(i), reader.getAttributeNamespace(i), reader.getAttributeLocalName(i), reader.getAttributeValue(i)); } break; case XMLStreamConstants.START_DOCUMENT: break; case XMLStreamConstants.CHARACTERS: xmlWriter.writeCharacters(reader.getText()); break; case XMLStreamConstants.CDATA: xmlWriter.writeCData(reader.getText()); break; case XMLStreamConstants.END_ELEMENT: xmlWriter.writeEndElement(); break; case XMLStreamConstants.END_DOCUMENT: xmlWriter.writeEndDocument(); break; case XMLStreamConstants.SPACE: break; case XMLStreamConstants.COMMENT: xmlWriter.writeComment(reader.getText()); break; case XMLStreamConstants.DTD: xmlWriter.writeDTD(reader.getText()); break; case XMLStreamConstants.PROCESSING_INSTRUCTION: xmlWriter.writeProcessingInstruction(reader.getPITarget(), reader.getPIData()); break; case XMLStreamConstants.ENTITY_REFERENCE: xmlWriter.writeEntityRef(reader.getLocalName()); break; default: throw new OMException(); } } xmlWriter.writeEndDocument(); xmlWriter.flush(); xmlWriter.close(); }
From source file:org.apereo.portal.xml.stream.IndentingXMLEventWriter.java
@Override public void add(XMLEvent event) throws XMLStreamException { switch (event.getEventType()) { case XMLStreamConstants.CHARACTERS: case XMLStreamConstants.CDATA: case XMLStreamConstants.SPACE: { wrappedWriter.add(event);//from w w w . j av a 2s .c o m afterData(); return; } case XMLStreamConstants.START_ELEMENT: { beforeStartElement(); wrappedWriter.add(event); afterStartElement(); return; } case XMLStreamConstants.END_ELEMENT: { beforeEndElement(); wrappedWriter.add(event); afterEndElement(); return; } case XMLStreamConstants.START_DOCUMENT: case XMLStreamConstants.PROCESSING_INSTRUCTION: case XMLStreamConstants.COMMENT: case XMLStreamConstants.DTD: { beforeMarkup(); wrappedWriter.add(event); afterMarkup(); return; } case XMLStreamConstants.END_DOCUMENT: { wrappedWriter.add(event); afterEndDocument(); break; } default: { wrappedWriter.add(event); return; } } }
From source file:org.deegree.services.wps.execute.ExecuteResponseXMLWriter.java
private static void exportXMLOutput(XMLStreamWriter writer, ComplexOutputImpl output) throws XMLStreamException { // "wps:ComplexData" element writer.writeStartElement(WPS_NS, "ComplexData"); String mimeType = output.getRequestedMimeType(); if (mimeType != null) { writer.writeAttribute("mimeType", mimeType); }/*from ww w .j a v a 2s.c o m*/ String schema = output.getRequestedSchema(); if (schema != null) { writer.writeAttribute("schema", schema); } // NOTE: Providing the encoding attribute doesn't make any sense for inline XML output (always defined by the // surrounding document) XMLStreamReader reader = output.getStreamReader(); // skip start document event // apadberg: the following line was necessary when Axiom 1.2.8 is used, // it is commented out because of revised behavior in Axiom 1.2.9 if (reader.getEventType() == XMLStreamConstants.START_DOCUMENT) { reader.next(); } if (reader.getEventType() == XMLStreamConstants.START_ELEMENT) { XMLAdapter.writeElement(writer, reader); } else { LOG.warn("No element in XMLOutput found, skipping it in response document."); } writer.writeEndElement(); }
From source file:org.mcisb.subliminal.SubliminalUtils.java
/** * /* ww w . ja v a2 s.c o m*/ * @param elementName * @param is * @param onlyValues * @return Collection * @throws XMLStreamException * @throws UnsupportedEncodingException */ private static Collection<String> getElements(final String elementName, final InputStream is, final boolean onlyValues) throws XMLStreamException, UnsupportedEncodingException { final Collection<String> elements = new ArrayList<>(); final ByteArrayOutputStream os = new ByteArrayOutputStream(); final XMLEventReader reader = XMLInputFactory.newInstance() .createXMLEventReader(new InputStreamReader(is, Charset.defaultCharset().name())); final XMLEventWriter writer = XMLOutputFactory.newInstance() .createXMLEventWriter(new OutputStreamWriter(os, Charset.defaultCharset().name())); boolean read = false; String characters = null; while (reader.peek() != null) { final XMLEvent event = (XMLEvent) reader.next(); switch (event.getEventType()) { case XMLStreamConstants.START_DOCUMENT: case XMLStreamConstants.END_DOCUMENT: { // Ignore. break; } case XMLStreamConstants.START_ELEMENT: { read = read || elementName.equals(event.asStartElement().getName().getLocalPart()); if (read && !onlyValues) { writer.add(event); } break; } case XMLStreamConstants.ATTRIBUTE: { if (read && !onlyValues) { writer.add(event); } break; } case XMLStreamConstants.CHARACTERS: { if (read && !onlyValues) { writer.add(event); } characters = event.asCharacters().getData(); break; } case XMLStreamConstants.END_ELEMENT: { if (read && !onlyValues) { writer.add(event); } if (elementName.equals(event.asEndElement().getName().getLocalPart())) { writer.flush(); if (characters != null) { elements.add(characters); } os.reset(); read = false; } break; } default: { // Ignore break; } } } return elements; }
From source file:org.mule.module.xml.filters.AbstractJaxpFilter.java
public Node toDOMNode(Object src) throws Exception { if (src instanceof Node) { return (Document) src; } else if (src instanceof org.dom4j.Document) { org.dom4j.Document dom4j = (org.dom4j.Document) src; DOMDocument dom = new DOMDocument(); dom.setDocument(dom4j);//from w w w. java 2 s.c o m return dom; } else if (src instanceof OutputHandler) { OutputHandler handler = ((OutputHandler) src); ByteArrayOutputStream output = new ByteArrayOutputStream(); handler.write(RequestContext.getEvent(), output); InputStream stream = new ByteArrayInputStream(output.toByteArray()); return getDocumentBuilderFactory().newDocumentBuilder().parse(stream); } else if (src instanceof byte[]) { ByteArrayInputStream stream = new ByteArrayInputStream((byte[]) src); return getDocumentBuilderFactory().newDocumentBuilder().parse(stream); } else if (src instanceof InputStream) { return getDocumentBuilderFactory().newDocumentBuilder().parse((InputStream) src); } else if (src instanceof String) { return getDocumentBuilderFactory().newDocumentBuilder() .parse(new InputSource(new StringReader((String) src))); } else if (src instanceof XMLStreamReader) { XMLStreamReader xsr = (XMLStreamReader) src; // StaxSource requires that we advance to a start element/document event if (!xsr.isStartElement() && xsr.getEventType() != XMLStreamConstants.START_DOCUMENT) { xsr.nextTag(); } return getDocumentBuilderFactory().newDocumentBuilder().parse(new InputSource()); } else if (src instanceof DelayedResult) { DelayedResult result = ((DelayedResult) src); DOMResult domResult = new DOMResult(); result.write(domResult); return domResult.getNode(); } else { return (Node) xmlToDom.transform(src); } }
From source file:org.mule.module.xml.util.XMLUtils.java
/** * Convert our object to a Source type efficiently. *//*from ww w. j av a 2 s .com*/ public static javax.xml.transform.Source toXmlSource(javax.xml.stream.XMLInputFactory xmlInputFactory, boolean useStaxSource, Object src) throws Exception { if (src instanceof javax.xml.transform.Source) { return (Source) src; } else if (src instanceof byte[]) { ByteArrayInputStream stream = new ByteArrayInputStream((byte[]) src); return toStreamSource(xmlInputFactory, useStaxSource, stream); } else if (src instanceof InputStream) { return toStreamSource(xmlInputFactory, useStaxSource, (InputStream) src); } else if (src instanceof String) { if (useStaxSource) { return new StaxSource(xmlInputFactory.createXMLStreamReader(new StringReader((String) src))); } else { return new StreamSource(new StringReader((String) src)); } } else if (src instanceof org.dom4j.Document) { return new DocumentSource((org.dom4j.Document) src); } else if (src instanceof org.xml.sax.InputSource) { return new SAXSource((InputSource) src); } // TODO MULE-3555 else if (src instanceof XMLStreamReader) { XMLStreamReader xsr = (XMLStreamReader) src; // StaxSource requires that we advance to a start element/document event if (!xsr.isStartElement() && xsr.getEventType() != XMLStreamConstants.START_DOCUMENT) { xsr.nextTag(); } return new StaxSource((XMLStreamReader) src); } else if (src instanceof org.w3c.dom.Document || src instanceof org.w3c.dom.Element) { return new DOMSource((org.w3c.dom.Node) src); } else if (src instanceof DelayedResult) { DelayedResult result = ((DelayedResult) src); DOMResult domResult = new DOMResult(); result.write(domResult); return new DOMSource(domResult.getNode()); } else if (src instanceof OutputHandler) { OutputHandler handler = ((OutputHandler) src); ByteArrayOutputStream output = new ByteArrayOutputStream(); handler.write(RequestContext.getEvent(), output); return toStreamSource(xmlInputFactory, useStaxSource, new ByteArrayInputStream(output.toByteArray())); } else { return null; } }