List of usage examples for javax.xml.stream XMLStreamReader getEventType
public int getEventType();
From source file:org.apache.xml.security.stax.impl.processor.input.AbstractDecryptInputProcessor.java
private void forwardToWrapperElement(XMLStreamReader xmlStreamReader) throws XMLStreamException { do {/*from w ww . j a va 2 s . co m*/ if (xmlStreamReader.getEventType() == XMLStreamConstants.START_ELEMENT && xmlStreamReader.getName().equals(wrapperElementName)) { xmlStreamReader.next(); break; } xmlStreamReader.next(); } while (xmlStreamReader.hasNext()); }
From source file:org.deegree.client.core.renderer.OutputXMLRenderer.java
private void encodeXML(ResponseWriter writer, String value) throws IOException { int depth = 0; try {//from w w w.j av a 2 s .c o m XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(new StringReader(value)); boolean lastWasEndElement = false; boolean lastWasComment = false; while (reader.hasNext()) { switch (reader.getEventType()) { case XMLStreamConstants.START_ELEMENT: if (!lastWasComment) { writer.startElement("br", null); writer.endElement("br"); } writer.write(getSpaces(depth)); writer.startElement("span", null); writer.writeAttribute("class", "sign", null); writer.write("<"); writer.endElement("span"); writer.startElement("span", null); writer.writeAttribute("class", "tag", null); String prefix = reader.getPrefix(); writer.write( (prefix != null && prefix.length() > 0 ? prefix + ":" : "") + reader.getLocalName()); writer.endElement("span"); for (int i = 0; i < reader.getAttributeCount(); i++) { writer.startElement("span", null); writer.writeAttribute("class", "attributeName", null); writer.write(" "); String attributePrefix = reader.getAttributePrefix(i); writer.write( (attributePrefix != null && attributePrefix.length() > 0 ? attributePrefix + ":" : "") + reader.getAttributeLocalName(i)); writer.endElement("span"); writer.startElement("span", null); writer.writeAttribute("class", "sign", null); writer.write("=\""); writer.endElement("span"); writer.startElement("span", null); writer.writeAttribute("class", "text", null); writer.write(encodeString(reader.getAttributeValue(i))); writer.endElement("span"); writer.startElement("span", null); writer.writeAttribute("class", "sign", null); writer.write("\""); writer.endElement("span"); } for (int i = 0; i < reader.getNamespaceCount(); i++) { writer.startElement("span", null); writer.writeAttribute("class", "attributeName", null); writer.write(" "); String nsPrefix = reader.getNamespacePrefix(i); writer.write("xmlns"); if (nsPrefix != null && !nsPrefix.isEmpty()) { writer.write(":" + nsPrefix); } writer.endElement("span"); writer.startElement("span", null); writer.writeAttribute("class", "sign", null); writer.write("=\""); writer.endElement("span"); writer.startElement("span", null); writer.writeAttribute("class", "text", null); writer.write(reader.getNamespaceURI(i)); writer.endElement("span"); writer.startElement("span", null); writer.writeAttribute("class", "sign", null); writer.write("\""); writer.endElement("span"); } writer.startElement("span", null); writer.writeAttribute("class", "sign", null); writer.write(">"); writer.endElement("span"); depth++; lastWasEndElement = false; lastWasComment = false; break; case XMLStreamConstants.CHARACTERS: String text = reader.getText(); if (text.trim().length() > 0) { writer.startElement("span", null); writer.writeAttribute("class", "text", null); writer.write(encodeString(text)); writer.endElement("span"); lastWasEndElement = false; lastWasComment = false; } break; case XMLStreamConstants.END_ELEMENT: depth--; if (lastWasEndElement) { writer.startElement("br", null); writer.endElement("br"); writer.write(getSpaces(depth)); } writer.startElement("span", null); writer.writeAttribute("class", "sign", null); writer.write("</"); writer.endElement("span"); writer.startElement("span", null); writer.writeAttribute("class", "tag", null); prefix = reader.getPrefix(); writer.write( (prefix != null && prefix.length() > 0 ? prefix + ":" : "") + reader.getLocalName()); writer.endElement("span"); writer.startElement("span", null); writer.writeAttribute("class", "sign", null); writer.write(">"); writer.endElement("span"); lastWasEndElement = true; lastWasComment = false; break; case XMLStreamConstants.COMMENT: writer.startElement("div", null); writer.writeAttribute("class", "comment", null); writer.write("</!--" + reader.getText() + "-->"); writer.endElement("div"); lastWasEndElement = false; lastWasComment = true; break; default: break; } reader.next(); } reader.close(); } catch (Throwable e) { if (depth == 0) { writer.writeText("Response could not parsed as XML.", null); } else { writer.writeText("... (if you want the complete document, please click the download button)", null); } } }
From source file:org.deegree.gml.geometry.GML3GeometryWriterTest.java
private Geometry readAIXMGeometry(String fileName) throws ClassCastException, ClassNotFoundException, InstantiationException, IllegalAccessException, XMLStreamException, FactoryConfigurationError, IOException, XMLParsingException, UnknownCRSException { String schemaUrl = this.getClass().getResource("../aixm/schema/message/AIXM_BasicMessage.xsd").toString(); GMLAppSchemaReader adapter = new GMLAppSchemaReader(null, null, schemaUrl); AppSchema schema = adapter.extractAppSchema(); GMLStreamReader gmlStream = createGMLStreamReader(GML_32, this.getClass().getResource("../aixm/geometry/" + fileName)); gmlStream.setApplicationSchema(schema); XMLStreamReader xmlReader = gmlStream.getXMLReader(); Assert.assertEquals(START_ELEMENT, xmlReader.getEventType()); QName elName = xmlReader.getName(); Assert.assertTrue(gmlStream.isGeometryElement()); Geometry geom = gmlStream.readGeometry(); Assert.assertEquals(END_ELEMENT, xmlReader.getEventType()); Assert.assertEquals(elName, xmlReader.getName()); return geom;// www .j a v a 2 s . c om }
From source file:org.deegree.services.csw.exporthandling.GetCapabilitiesHelper.java
private void writeTemplateElement(XMLStreamWriter writer, XMLStreamReader inStream, Map<String, String> varToValue) throws XMLStreamException { if (inStream.getEventType() != XMLStreamConstants.START_ELEMENT) { throw new XMLStreamException("Input stream does not point to a START_ELEMENT event."); }/* w w w .ja va 2 s . c o m*/ int openElements = 0; boolean firstRun = true; while (firstRun || openElements > 0) { firstRun = false; int eventType = inStream.getEventType(); switch (eventType) { case CDATA: { writer.writeCData(inStream.getText()); break; } case CHARACTERS: { String s = new String(inStream.getTextCharacters(), inStream.getTextStart(), inStream.getTextLength()); // TODO optimize for (String param : varToValue.keySet()) { String value = varToValue.get(param); s = s.replace(param, value); } writer.writeCharacters(s); break; } case END_ELEMENT: { writer.writeEndElement(); openElements--; break; } case START_ELEMENT: { if (inStream.getNamespaceURI() == "" || inStream.getPrefix() == DEFAULT_NS_PREFIX || inStream.getPrefix() == null) { writer.writeStartElement(inStream.getLocalName()); } else { if (writer.getNamespaceContext().getPrefix(inStream.getPrefix()) == "") { // TODO handle special cases for prefix binding, see // http://download.oracle.com/docs/cd/E17409_01/javase/6/docs/api/javax/xml/namespace/NamespaceContext.html#getNamespaceURI(java.lang.String) writer.setPrefix(inStream.getPrefix(), inStream.getNamespaceURI()); } writer.writeStartElement(inStream.getPrefix(), inStream.getLocalName(), inStream.getNamespaceURI()); } // copy all namespace bindings for (int i = 0; i < inStream.getNamespaceCount(); i++) { String nsPrefix = inStream.getNamespacePrefix(i); String nsURI = inStream.getNamespaceURI(i); writer.writeNamespace(nsPrefix, nsURI); } // copy all attributes for (int i = 0; i < inStream.getAttributeCount(); i++) { String localName = inStream.getAttributeLocalName(i); String nsPrefix = inStream.getAttributePrefix(i); String value = inStream.getAttributeValue(i); String nsURI = inStream.getAttributeNamespace(i); if (nsURI == null) { writer.writeAttribute(localName, value); } else { writer.writeAttribute(nsPrefix, nsURI, localName, value); } } openElements++; break; } default: { break; } } if (openElements > 0) { inStream.next(); } } }
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 w w w . j a v a2 s . 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.deegree.services.wps.provider.jrxml.contentprovider.Utils.java
public static ProcessletInputs getInputs(String parameterId, String mimeType, String schema, InputStream complexInput) throws IOException, XMLStreamException, FactoryConfigurationError { List<ProcessletInput> inputs = new ArrayList<ProcessletInput>(); ProcessletInputs in = new ProcessletInputs(inputs); ComplexInputDefinition definition = new ComplexInputDefinition(); definition.setTitle(getAsLanguageStringType(parameterId)); definition.setIdentifier(getAsCodeType(parameterId)); ComplexFormatType format = new ComplexFormatType(); format.setEncoding("UTF-8"); format.setMimeType(mimeType);/*from w ww .j a v a 2 s.com*/ format.setSchema(schema); definition.setDefaultFormat(format); definition.setMaxOccurs(BigInteger.valueOf(1)); definition.setMinOccurs(BigInteger.valueOf(0)); File f = File.createTempFile("tmpStore", ""); StreamBufferStore store = new StreamBufferStore(1024, f); XMLStreamReader xmlReader = XMLInputFactory.newInstance().createXMLStreamReader(complexInput); XMLStreamWriter xmlWriter = null; try { xmlWriter = XMLOutputFactory.newInstance().createXMLStreamWriter(store); if (xmlReader.getEventType() == START_DOCUMENT) { xmlReader.nextTag(); } XMLAdapter.writeElement(xmlWriter, xmlReader); } finally { try { xmlReader.close(); } catch (XMLStreamException e) { // nothing to do } try { xmlWriter.close(); } catch (XMLStreamException e) { // nothing to do } IOUtils.closeQuietly(store); } ComplexInputImpl mapProcesslet = new EmbeddedComplexInput(definition, new LanguageString("title", "ger"), new LanguageString("summary", "ger"), format, store); inputs.add(mapProcesslet); return in; }
From source file:org.eclipse.koneki.protocols.omadm.client.basic.DMBasicSession.java
private void readGet(final XMLStreamReader reader) throws XMLStreamException { reader.nextTag();//from w ww . jav a 2 s . c o m // CmdID final String cmdID = reader.getElementText(); reader.nextTag(); // Meta? if (reader.getLocalName().equals("Meta")) { //$NON-NLS-1$ jumpToEndTag(reader, "Meta"); //$NON-NLS-1$ reader.nextTag(); } // Item+ boolean continueGet = true; do { switch (reader.getEventType()) { case XMLStreamReader.START_ELEMENT: // Performs the get command final DMItem item = readItem(reader, new DMMeta()); reader.nextTag(); final Status status = this.commandHandler.get(item.getTargetURI()); final DMNode results = status.getResult(); if (results != null) { this.statusManager.putStatus(this.currentServerMsgID, cmdID, "Get", item.getTargetURI(), null, //$NON-NLS-1$ String.valueOf(status.getCode()), results.getFormat(), results.getType(), results.getData()); } else { this.statusManager.putStatus(this.currentServerMsgID, cmdID, "Get", item.getTargetURI(), null, //$NON-NLS-1$ String.valueOf(status.getCode())); } // Fire get event for (final ProtocolListener messageListener : this.protocolLinsteners) { messageListener.get(item.getTargetURI(), status); } break; case XMLStreamReader.END_ELEMENT: continueGet = false; break; default: break; } } while (continueGet); }
From source file:org.eclipse.koneki.protocols.omadm.client.basic.DMBasicSession.java
private void readAdd(final XMLStreamReader reader, final DMMeta parentMeta) throws XMLStreamException { reader.nextTag();/*from ww w . j a va 2 s. c o m*/ // CmdID final String cmdID = reader.getElementText(); reader.nextTag(); // Meta? final DMMeta globalMeta = new DMMeta(parentMeta); if (reader.getLocalName().equals("Meta")) { //$NON-NLS-1$ globalMeta.putAll(readMeta(reader)); reader.nextTag(); } // Item+ boolean continueAdd = true; do { switch (reader.getEventType()) { case XMLEvent.START_ELEMENT: // Performs the add command final DMItem item = readItem(reader, globalMeta); reader.nextTag(); final Status status = this.commandHandler.add(item.getTargetURI(), item.getMeta().getFormat(), item.getMeta().getType(), item.getData()); this.statusManager.putStatus(this.currentServerMsgID, cmdID, "Add", item.getTargetURI(), null, //$NON-NLS-1$ String.valueOf(status.getCode())); // Fire add event for (final ProtocolListener messageListener : this.protocolLinsteners) { messageListener.add(item.getTargetURI(), item.getData(), status); } break; case XMLEvent.END_ELEMENT: continueAdd = false; break; default: break; } } while (continueAdd); }
From source file:org.eclipse.koneki.protocols.omadm.client.basic.DMBasicSession.java
private void readDelete(final XMLStreamReader reader) throws XMLStreamException { reader.nextTag();/* w w w .j ava2 s . co m*/ // CmdID final String cmdID = reader.getElementText(); reader.nextTag(); // Meta? if (reader.getLocalName().equals("Meta")) { //$NON-NLS-1$ jumpToEndTag(reader, "Meta"); //$NON-NLS-1$ reader.nextTag(); } // Item+ boolean continueDelete = true; do { switch (reader.getEventType()) { case XMLEvent.START_ELEMENT: final DMItem item = readItem(reader, new DMMeta()); reader.nextTag(); final Status status = this.commandHandler.delete(item.getTargetURI()); this.statusManager.putStatus(this.currentServerMsgID, cmdID, "Delete", item.getTargetURI(), null, //$NON-NLS-1$ String.valueOf(status.getCode())); // Fire delete event for (final ProtocolListener messageListener : this.protocolLinsteners) { messageListener.delete(item.getTargetURI(), status); } break; case XMLEvent.END_ELEMENT: continueDelete = false; break; default: break; } } while (continueDelete); }
From source file:org.eclipse.koneki.protocols.omadm.client.basic.DMBasicSession.java
private void readReplace(final XMLStreamReader reader, final DMMeta parentMeta) throws XMLStreamException { reader.nextTag();/*from ww w.j ava 2 s .com*/ // CmdID final String cmdID = reader.getElementText(); reader.nextTag(); // Meta? final DMMeta globalMeta = new DMMeta(parentMeta); if (reader.getLocalName().equals("Meta")) { //$NON-NLS-1$ globalMeta.putAll(readMeta(reader)); reader.nextTag(); } // Item+ boolean continueReplace = true; do { switch (reader.getEventType()) { case XMLEvent.START_ELEMENT: final DMItem item = readItem(reader, globalMeta); reader.nextTag(); final Status status = this.commandHandler.replace(item.getTargetURI(), item.getMeta().getFormat(), item.getMeta().getType(), item.getData()); this.statusManager.putStatus(this.currentServerMsgID, cmdID, "Replace", item.getTargetURI(), null, //$NON-NLS-1$ String.valueOf(status.getCode())); // Fire replace event for (final ProtocolListener messageListener : this.protocolLinsteners) { messageListener.replace(item.getTargetURI(), item.getData(), status); } break; case XMLEvent.END_ELEMENT: continueReplace = false; break; default: break; } } while (continueReplace); }