List of usage examples for javax.xml.stream XMLStreamWriter setPrefix
public void setPrefix(String prefix, String uri) throws XMLStreamException;
From source file:org.apache.axis2.policy.model.MTOM10Assertion.java
public void serialize(XMLStreamWriter writer) throws XMLStreamException { String prefix = writer.getPrefix(NS); if (prefix == null) { prefix = PREFIX;//from w w w.jav a 2 s. c o m writer.setPrefix(PREFIX, NS); } writer.writeStartElement(PREFIX, MTOM_SERIALIZATION_CONFIG_LN, NS); if (optional) { writer.writeAttribute(Constants.ATTR_WSP, null, Constants.Q_ELEM_OPTIONAL_ATTR.getLocalPart(), "true"); } writer.writeNamespace(PREFIX, NS); writer.writeEndElement(); }
From source file:org.apache.axis2.policy.model.MTOM11Assertion.java
public void serialize(XMLStreamWriter writer) throws XMLStreamException { String prefix = writer.getPrefix(NS); if (prefix == null) { prefix = PREFIX;/*from ww w. j a v a 2s . co m*/ writer.setPrefix(PREFIX, NS); } writer.writeStartElement(PREFIX, MTOM_LN, NS); if (optional) { writer.writeAttribute(Constants.ATTR_WSP, null, Constants.Q_ELEM_OPTIONAL_ATTR.getLocalPart(), "true"); } writer.writeNamespace(PREFIX, NS); writer.writeEndElement(); }
From source file:org.apache.flex.compiler.config.Configuration.java
/** * @return Metadata XML string.//from w w w . j a va 2s .co m */ private final String generateMetadata() { final XMLOutputFactory xmlOutputFactory = XMLOutputFactory.newInstance(); assert xmlOutputFactory != null : "Expect XMLOutputFactory implementation."; final StringWriter stringWriter = new StringWriter(); XMLStreamWriter xmlWriter = null; try { xmlWriter = new XMLFormatter(xmlOutputFactory.createXMLStreamWriter(stringWriter)); xmlWriter.writeStartDocument(); xmlWriter.writeStartElement("rdf", "RDF", RDF_URI); xmlWriter.setPrefix("rdf", RDF_URI); xmlWriter.writeNamespace("rdf", RDF_URI); // write rdf:Description xmlWriter.writeStartElement(RDF_URI, "Description"); xmlWriter.setPrefix("dc", DC_URI); xmlWriter.setPrefix(VersionInfo.COMPILER_NAMESPACE_PREFIX, VersionInfo.COMPILER_NAMESPACE_URI); xmlWriter.writeNamespace("dc", DC_URI); xmlWriter.writeNamespace(VersionInfo.COMPILER_NAMESPACE_PREFIX, VersionInfo.COMPILER_NAMESPACE_URI); // write dc:format xmlWriter.writeStartElement(DC_URI, "format"); xmlWriter.writeCharacters("application/x-shockwave-flash"); xmlWriter.writeEndElement(); if (isFlex()) { // write localizedTitles writeMap(xmlWriter, DC_URI, "description", localizedDescriptions); // write localizedDescription writeMap(xmlWriter, DC_URI, "title", localizedTitles); // write publisher writeCollection(xmlWriter, DC_URI, "publisher", publishers); // write creators writeCollection(xmlWriter, DC_URI, "creator", creators); // write contributor writeCollection(xmlWriter, DC_URI, "contributor", contributors); // write language writeCollection(xmlWriter, DC_URI, "language", langs); // write date writeDate(xmlWriter); } // write compiledBy writeCompiledBy(xmlWriter); // write xmlWriter.writeEndElement(); // Description xmlWriter.writeEndDocument(); } catch (XMLStreamException e) { return ""; } return stringWriter.toString(); }
From source file:org.deegree.commons.xml.stax.FilteringXMLStreamWriterTest.java
private void writeDocument(XMLStreamWriter writer) throws XMLStreamException { writer.writeStartDocument();//from ww w .ja va2s. c o m writer.setPrefix("app", app); writer.setPrefix("nix", nix); writer.setPrefix("alles", alles); writer.writeStartElement(app, "a"); writer.writeNamespace("app", app); writer.writeNamespace("nix", nix); writer.writeNamespace("alles", alles); writer.writeStartElement(app, "b"); writer.writeStartElement(nix, "c"); writer.writeStartElement(app, "d"); writer.writeEndElement(); writer.writeStartElement(alles, "e"); writer.writeCharacters("sometext"); writer.writeEndElement(); writer.writeStartElement(app, "b"); writer.writeStartElement(nix, "c"); writer.writeEndElement(); writer.writeEndElement(); writer.writeEndElement(); writer.writeEndElement(); writer.writeEndElement(); writer.close(); }
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 . j a va2 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.provider.sextante.SextanteProcesslet.java
/** * Writes a {@link FeatureCollection}./* w w w . j ava 2 s .c om*/ * * @param gmlOutput * - {@link ComplexOutput} * @param coll * - {@link FeatureCollection} * * @throws ProcessletException */ public static void writeFeatureCollection(ComplexOutput gmlOutput, Feature coll) throws ProcessletException { try { XMLStreamWriter sw = gmlOutput.getXMLStreamWriter(); // determine and set namespaces HashMap<String, String> namespaces = determinePropertyNamespaces(coll); Set<String> namespaceURIs = namespaces.keySet(); for (String uri : namespaceURIs) { sw.setPrefix(namespaces.get(uri), uri); } // sw.setPrefix( VectorLayerAdapter.APP_PREFIX, VectorLayerAdapter.APP_NS ); // sw.setPrefix( "gml", CommonNamespaces.GML3_2_NS ); GMLStreamWriter gmlWriter = GMLOutputFactory .createGMLStreamWriter(FormatHelper.determineGMLVersion(gmlOutput), sw); // gmlWriter.setOutputCRS(new CRS( "EPSG:4326" )); gmlWriter.write(coll); } catch (Exception e) { throw new ProcessletException("Error exporting geometry: " + e.getMessage()); } }
From source file:org.mule.module.xml.util.XMLUtils.java
private static void writeStartElement(XMLStreamReader reader, XMLStreamWriter writer) throws XMLStreamException { String local = reader.getLocalName(); String uri = reader.getNamespaceURI(); String prefix = reader.getPrefix(); if (prefix == null) { prefix = ""; }//from w ww .j a va 2s. c om // System.out.println("STAXUTILS:writeStartElement : node name : " + local + " namespace URI" + uri); boolean writeElementNS = false; if (uri != null) { String boundPrefix = writer.getPrefix(uri); if (boundPrefix == null || !prefix.equals(boundPrefix)) { writeElementNS = true; } } // Write out the element name if (uri != null) { if (prefix.length() == 0 && StringUtils.isEmpty(uri)) { writer.writeStartElement(local); writer.setDefaultNamespace(uri); } else { writer.writeStartElement(prefix, local, uri); writer.setPrefix(prefix, uri); } } else { writer.writeStartElement(local); } // Write out the namespaces for (int i = 0; i < reader.getNamespaceCount(); i++) { String nsURI = reader.getNamespaceURI(i); String nsPrefix = reader.getNamespacePrefix(i); if (nsPrefix == null) { nsPrefix = ""; } if (nsPrefix.length() == 0) { writer.writeDefaultNamespace(nsURI); } else { writer.writeNamespace(nsPrefix, nsURI); } if (nsURI.equals(uri) && nsPrefix.equals(prefix)) { writeElementNS = false; } } // Check if the namespace still needs to be written. // We need this check because namespace writing works // different on Woodstox and the RI. if (writeElementNS) { if (prefix.length() == 0) { writer.writeDefaultNamespace(uri); } else { writer.writeNamespace(prefix, uri); } } // Write out attributes for (int i = 0; i < reader.getAttributeCount(); i++) { String ns = reader.getAttributeNamespace(i); String nsPrefix = reader.getAttributePrefix(i); if (ns == null || ns.length() == 0) { writer.writeAttribute(reader.getAttributeLocalName(i), reader.getAttributeValue(i)); } else if (nsPrefix == null || nsPrefix.length() == 0) { writer.writeAttribute(reader.getAttributeNamespace(i), reader.getAttributeLocalName(i), reader.getAttributeValue(i)); } else { writer.writeAttribute(reader.getAttributePrefix(i), reader.getAttributeNamespace(i), reader.getAttributeLocalName(i), reader.getAttributeValue(i)); } } }
From source file:org.osaf.cosmo.mc.CollectionService.java
public void writeTo(OutputStream out) throws IOException, XMLStreamException { XMLStreamWriter writer = XML_OUTPUT_FACTORY.createXMLStreamWriter(out); writer.setPrefix(PRE_XML, NS_XML); writer.setDefaultNamespace(NS_MC);//from w ww . ja v a2 s .com try { writer.writeStartDocument(); writer.writeStartElement(EL_MC_SERVICE); writer.writeDefaultNamespace(NS_MC); writer.writeAttribute(NS_XML, EL_XML_BASE, locator.getMorseCodeBase()); for (CollectionItem collection : collections) { writer.writeStartElement(EL_MC_COLLECTION); writer.writeAttribute(ATTR_MC_UUID, collection.getUid()); writer.writeAttribute(ATTR_MC_HREF, href(collection)); writer.writeStartElement(EL_MC_NAME); writer.writeCharacters(collection.getDisplayName()); writer.writeEndElement(); for (Ticket ticket : visibleTickets(collection)) { writer.writeStartElement(EL_MC_TICKET); writer.writeAttribute(ATTR_MC_TYPE, ticket.getType().toString()); writer.writeCharacters(ticket.getKey()); writer.writeEndElement(); } writer.writeEndElement(); } writer.writeEndElement(); writer.writeEndDocument(); } finally { writer.close(); } }
From source file:org.rhq.enterprise.server.sync.ExportingInputStream.java
/** * @param wrt/*w w w. j a v a 2 s . c om*/ * @throws XMLStreamException */ private void exportPrologue(XMLStreamWriter wrt) throws XMLStreamException { wrt.setDefaultNamespace(SynchronizationConstants.EXPORT_NAMESPACE); wrt.setPrefix(SynchronizationConstants.EXPORT_NAMESPACE_PREFIX, SynchronizationConstants.EXPORT_NAMESPACE); wrt.setPrefix(SynchronizationConstants.CONFIGURATION_INSTANCE_NAMESPACE_PREFIX, SynchronizationConstants.CONFIGURATION_INSTANCE_NAMESPACE); wrt.setPrefix(SynchronizationConstants.CONFIGURATION_NAMESPACE_PREFIX, SynchronizationConstants.CONFIGURATION_NAMESPACE); NamespaceContext nsContext = SynchronizationConstants.createConfigurationExportNamespaceContext(); wrt.setNamespaceContext(nsContext); wrt.writeStartDocument(); wrt.writeStartElement(SynchronizationConstants.EXPORT_NAMESPACE, SynchronizationConstants.CONFIGURATION_EXPORT_ELEMENT); wrt.writeNamespace(SynchronizationConstants.CONFIGURATION_INSTANCE_NAMESPACE_PREFIX, ConfigurationInstanceDescriptorUtil.NS_CONFIGURATION_INSTANCE); wrt.writeNamespace(SynchronizationConstants.CONFIGURATION_NAMESPACE_PREFIX, SynchronizationConstants.CONFIGURATION_NAMESPACE); writeValidators(wrt); }
From source file:org.slc.sli.modeling.xmi.comp.XmiMappingWriter.java
private static final void writeMappingDocument(final XmiComparison documentElement, final XMLStreamWriter xsw) throws XMLStreamException { xsw.writeProcessingInstruction("xml-stylesheet", "type='text/xsl' href='xmi-mapping.xsl'"); xsw.setPrefix("", XmiMappingConstants.NAMESPACE_URI); xsw.writeStartElement(XmiMappingConstants.DOCUMENT_ELEMENT.getLocalPart()); xsw.writeNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance"); xsw.writeAttribute("xsi", "http://www.w3.org/2001/XMLSchema-instance", "noNamespaceSchemaLocation", "xmi-mapping.xsd"); try {/*from w w w. ja va2s . com*/ writeReference(documentElement.getLhsDef(), XmiMappingConstants.LHS_MODEL, xsw); writeReference(documentElement.getRhsDef(), XmiMappingConstants.RHS_MODEL, xsw); for (final XmiMapping mapping : documentElement.getMappings()) { writeMapping(mapping, xsw); } } finally { xsw.writeEndElement(); } }