List of usage examples for javax.xml.stream XMLStreamWriter setPrefix
public void setPrefix(String prefix, String uri) throws XMLStreamException;
From source file:eionet.cr.util.odp.ODPDatasetsPacker.java
/** * Registers the given namespaces in the given {@link XMLStreamWriter}, by calling setPrefix(...) of the latter for each. * * @param xmlWriter The namespaces to register. * @param xmlWriter The writer to register in. * @throws XMLStreamException In case the write throws exception. *///from w ww . jav a 2s .c o m private void registerNamespaces(List<Namespace> namespaces, XMLStreamWriter xmlWriter) throws XMLStreamException { for (Namespace namespace : namespaces) { xmlWriter.setPrefix(namespace.getPrefix(), namespace.getUri()); } }
From source file:de.shadowhunt.subversion.internal.MergeOperation.java
@Override protected HttpUriRequest createRequest() { final DavTemplateRequest request = new DavTemplateRequest("MERGE", repository); request.addHeader("X-SVN-Options", "release-locks"); final Writer body = new StringBuilderWriter(); try {//from w w w. j ava 2s .c o m final XMLStreamWriter writer = XML_OUTPUT_FACTORY.createXMLStreamWriter(body); writer.writeStartDocument(XmlConstants.ENCODING, XmlConstants.VERSION_1_0); writer.writeStartElement("merge"); writer.writeDefaultNamespace(XmlConstants.DAV_NAMESPACE); writer.writeStartElement("source"); writer.writeStartElement("href"); writer.writeCData(repository.getPath() + resource.getValue()); writer.writeEndElement(); // href writer.writeEndElement(); // source writer.writeEmptyElement("no-auto-merge"); writer.writeEmptyElement("no-checkout"); writer.writeStartElement("prop"); writer.writeEmptyElement("checked-in"); writer.writeEmptyElement("version-name"); writer.writeEmptyElement("resourcetype"); writer.writeEmptyElement("creationdate"); writer.writeEmptyElement("creator-displayname"); writer.writeEndElement(); // prop if (!infoSet.isEmpty()) { writer.setPrefix(XmlConstants.SVN_PREFIX, XmlConstants.SVN_NAMESPACE); writer.writeStartElement(XmlConstants.SVN_NAMESPACE, "lock-token-list"); writer.writeNamespace(XmlConstants.SVN_PREFIX, XmlConstants.SVN_NAMESPACE); for (final Info info : infoSet) { final String lockToken = info.getLockToken(); assert (lockToken != null) : "must not be null"; final Resource infoResource = info.getResource(); writer.writeStartElement(XmlConstants.SVN_NAMESPACE, "lock"); writer.writeStartElement(XmlConstants.SVN_NAMESPACE, "lock-path"); writer.writeCData(infoResource.getValueWithoutLeadingSeparator()); writer.writeEndElement(); // lock-path writer.writeStartElement(XmlConstants.SVN_NAMESPACE, "lock-token"); writer.writeCharacters(lockToken); writer.writeEndElement(); // lock-token writer.writeEndElement(); // lock } writer.writeEndElement(); // lock-token-list } writer.writeEndElement(); // merge writer.writeEndDocument(); writer.close(); } catch (final XMLStreamException e) { throw new SubversionException("could not create request body", e); } request.setEntity(new StringEntity(body.toString(), CONTENT_TYPE_XML)); return request; }
From source file:de.uni_koblenz.jgralab.utilities.rsa2tg.SchemaGraph2XMI.java
/** * Creates the root <code>XMI</code> tag of the whole document. It calls * {@link SchemaGraph2XMI#createModelElement(XMLStreamWriter, SchemaGraph)} * to create its content./*ww w .j a v a2 s . c om*/ * * @param writer * {@link XMLStreamWriter} of the current XMI file * @param schemaGraph * {@link SchemaGraph} to be converted into an XMI * @throws XMLStreamException */ private void createRootElement(XMLStreamWriter writer, SchemaGraph schemaGraph) throws XMLStreamException { // start root element writer.writeStartElement(XMIConstants4SchemaGraph2XMI.NAMESPACE_PREFIX_XMI, XMIConstants4SchemaGraph2XMI.XMI_TAG_XMI, XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI); writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI, XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_VERSION, XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_VERSION_VALUE); writer.setPrefix(XMIConstants4SchemaGraph2XMI.NAMESPACE_PREFIX_XSI, XMIConstants4SchemaGraph2XMI.NAMESPACE_XSI); writer.setPrefix(XMIConstants4SchemaGraph2XMI.NAMESPACE_PREFIX_EECORE, XMIConstants4SchemaGraph2XMI.NAMESPACE_EECORE); writer.setPrefix(XMIConstants4SchemaGraph2XMI.NAMESPACE_PREFIX_ECORE, XMIConstants4SchemaGraph2XMI.NAMESPACE_ECORE); writer.setPrefix(XMIConstants4SchemaGraph2XMI.NAMESPACE_PREFIX_UML, XMIConstants4SchemaGraph2XMI.NAMESPACE_UML); writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XSI, XMIConstants4SchemaGraph2XMI.XSI_ATTRIBUTE_SCHEMALOCATION, XMIConstants4SchemaGraph2XMI.SCHEMALOCATION); // create model element createModelElement(writer, schemaGraph); // close root element writer.writeEndElement(); }
From source file:nl.nn.adapterframework.soap.Wsdl.java
/** * Writes the WSDL to an output stream/*w w w. j av a 2s.com*/ * @param out * @param servlet The servlet what is used as the web service (because this needs to be present in the WSDL) * @throws XMLStreamException * @throws IOException */ public void wsdl(OutputStream out, String servlet) throws XMLStreamException, IOException, ConfigurationException, NamingException { XMLStreamWriter w = WsdlUtils.getWriter(out, isIndent()); w.writeStartDocument(XmlUtils.STREAM_FACTORY_ENCODING, "1.0"); w.setPrefix(WSDL_NAMESPACE_PREFIX, WSDL_NAMESPACE); w.setPrefix(XSD_NAMESPACE_PREFIX, XSD_NAMESPACE); w.setPrefix(soapPrefix, soapNamespace); if (jmsActive) { if (esbSoap) { w.setPrefix(SOAP_JMS_NAMESPACE_PREFIX, ESB_SOAP_JMS_NAMESPACE); w.setPrefix(ESB_SOAP_JNDI_NAMESPACE_PREFIX, ESB_SOAP_JNDI_NAMESPACE); } else { w.setPrefix(SOAP_JMS_NAMESPACE_PREFIX, SOAP_JMS_NAMESPACE); } } w.setPrefix(getTargetNamespacePrefix(), getTargetNamespace()); for (String prefix : namespaceByPrefix.keySet()) { w.setPrefix(prefix, namespaceByPrefix.get(prefix)); } w.writeStartElement(WSDL_NAMESPACE, "definitions"); { w.writeNamespace(WSDL_NAMESPACE_PREFIX, WSDL_NAMESPACE); w.writeNamespace(XSD_NAMESPACE_PREFIX, XSD_NAMESPACE); w.writeNamespace(soapPrefix, soapNamespace); if (esbSoap) { w.writeNamespace(ESB_SOAP_JNDI_NAMESPACE_PREFIX, ESB_SOAP_JNDI_NAMESPACE); } w.writeNamespace(getTargetNamespacePrefix(), getTargetNamespace()); for (String prefix : namespaceByPrefix.keySet()) { w.writeNamespace(prefix, namespaceByPrefix.get(prefix)); } w.writeAttribute("targetNamespace", getTargetNamespace()); documentation(w); types(w); messages(w); portType(w); binding(w); service(w, servlet); } w.writeEndDocument(); warnings(w); w.close(); }
From source file:nz.co.jsrsolutions.ds3.test.RetrieveTestData.java
public static void main(String[] args) { logger.info("Starting application [ rtd ] ..."); try {/*w ww .j ava 2s . c om*/ config.addConfiguration( new XMLConfiguration(RetrieveTestData.class.getClassLoader().getResource(CONFIG_FILENAME))); HierarchicalConfiguration appConfig = config.configurationAt(APPLICATION_CONFIG_ROOT); EodDataProvider eodDataProvider = null; OutputStream out = new FileOutputStream(OUTPUT_FILENAME); XMLOutputFactory factory = XMLOutputFactory.newInstance(); XMLStreamWriter writer = factory.createXMLStreamWriter(out); eodDataProvider = EodDataProviderFactory.create(appConfig, EODDATA_PROVIDER_NAME); writer.writeStartDocument("utf-8", "1.0"); writer.writeCharacters(NEWLINE); writer.writeComment("Test data for running DataScraper unit tests against"); writer.writeCharacters(NEWLINE); writer.setPrefix(XML_PREFIX, XML_NAMESPACE_URI); writer.writeStartElement(XML_NAMESPACE_URI, TESTDATA_LOCALNAME); writer.writeNamespace(XML_PREFIX, XML_NAMESPACE_URI); writer.writeCharacters(NEWLINE); serializeExchanges(eodDataProvider, writer); serializeSymbols(eodDataProvider, writer); serializeQuotes(eodDataProvider, writer); writer.writeEndElement(); writer.writeCharacters(NEWLINE); writer.writeEndDocument(); writer.flush(); writer.close(); } catch (ConfigurationException ce) { logger.error(ce.toString()); ce.printStackTrace(); } catch (Exception e) { logger.error(e.toString()); logger.error(e); } logger.info("Exiting application [ rtd ] ..."); }
From source file:org.apache.axiom.om.impl.serialize.StreamingOMSerializer.java
/** * Method serializeNamespace.// w w w.ja va 2 s .com * * @param prefix * @param URI * @param writer * @throws XMLStreamException */ private void serializeNamespace(String prefix, String URI, XMLStreamWriter writer) throws XMLStreamException { String prefix1 = writer.getPrefix(URI); if (prefix1 == null) { writer.writeNamespace(prefix, URI); writer.setPrefix(prefix, URI); } }
From source file:org.apache.axiom.om.impl.util.OMSerializerUtil.java
/** * Method serializeNamespace.//from ww w . ja v a 2 s.c o m * * @param namespace * @param writer * @throws XMLStreamException * @deprecated Use serializeStartpart instead */ public static void serializeNamespace(OMNamespace namespace, XMLStreamWriter writer) throws XMLStreamException { if (namespace == null) { return; } String uri = namespace.getNamespaceURI(); String prefix = namespace.getPrefix(); if (uri != null && !"".equals(uri)) { String prefixFromWriter = writer.getPrefix(uri); // Handling Default Namespaces First // Case 1 : // here we are trying define a default namespace. But has this been defined in the current context. // yes, there can be a default namespace, but it may have a different URI. If its a different URI // then explicitly define the default namespace here. // Case 2 : // The passed in namespace is a default ns, but there is a non-default ns declared // in the current scope. if (("".equals(prefix) && "".equals(prefixFromWriter) && !uri.equals(writer.getNamespaceContext().getNamespaceURI(""))) || (prefix != null && "".equals(prefix) && (prefixFromWriter == null || !prefix.equals(prefixFromWriter)))) { // this has not been declared earlier writer.writeDefaultNamespace(uri); writer.setDefaultNamespace(uri); } else { prefix = prefix == null ? getNextNSPrefix(writer) : prefix; if (prefix != null && !prefix.equals(prefixFromWriter) && !checkForPrefixInTheCurrentContext(writer, uri, prefix)) { writer.writeNamespace(prefix, uri); writer.setPrefix(prefix, uri); } } } else { // now the nsURI passed is "" or null. Meaning we gonna work with defaultNS. // check whether there is a defaultNS already declared. If yes, is it the same as this ? String currentDefaultNSURI = writer.getNamespaceContext().getNamespaceURI(""); if ((currentDefaultNSURI != null && !currentDefaultNSURI.equals(uri)) || uri != null && !uri.equals(currentDefaultNSURI)) { // this has not been declared earlier writer.writeDefaultNamespace(uri); writer.setDefaultNamespace(uri); } } }
From source file:org.apache.axiom.om.impl.util.OMSerializerUtil.java
/** * Generate setPrefix/setDefaultNamespace if the prefix is not associated * * @param prefix/*from w ww .j av a 2 s . c o m*/ * @param namespace * @param writer * @param attr * @return prefix name if a setPrefix/setDefaultNamespace is performed */ public static String generateSetPrefix(String prefix, String namespace, XMLStreamWriter writer, boolean attr) throws XMLStreamException { prefix = (prefix == null) ? "" : prefix; // If the prefix and namespace are already associated, no generation is needed if (isAssociated(prefix, namespace, writer)) { return null; } // Attributes without a prefix always are associated with the unqualified namespace // according to the schema specification. No generation is needed. if (prefix.length() == 0 && namespace == null && attr) { return null; } // Generate setPrefix/setDefaultNamespace if the prefix is not associated. String newPrefix = null; if (namespace != null) { // Qualified Namespace if (prefix.length() == 0) { writer.setDefaultNamespace(namespace); newPrefix = ""; } else { writer.setPrefix(prefix, namespace); newPrefix = prefix; } } else { // Unqualified Namespace // Disable the default namespace writer.setDefaultNamespace(""); newPrefix = ""; } return newPrefix; }
From source file:org.apache.axis2.databinding.utils.ConverterUtil.java
public static void serializeAnyType(Object value, XMLStreamWriter xmlStreamWriter) throws XMLStreamException { if (value instanceof String) { serializeAnyType("string", value.toString(), xmlStreamWriter); } else if (value instanceof Integer) { serializeAnyType("int", value.toString(), xmlStreamWriter); } else if (value instanceof Boolean) { serializeAnyType("boolean", value.toString(), xmlStreamWriter); } else if (value instanceof URI) { serializeAnyType("anyURI", value.toString(), xmlStreamWriter); } else if (value instanceof Byte) { serializeAnyType("byte", value.toString(), xmlStreamWriter); } else if (value instanceof Date) { serializeAnyType("date", convertToString((Date) value), xmlStreamWriter); } else if (value instanceof Calendar) { serializeAnyType("dateTime", convertToString((Calendar) value), xmlStreamWriter); } else if (value instanceof Time) { serializeAnyType("time", convertToString((Time) value), xmlStreamWriter); } else if (value instanceof Float) { serializeAnyType("float", value.toString(), xmlStreamWriter); } else if (value instanceof Long) { serializeAnyType("long", value.toString(), xmlStreamWriter); } else if (value instanceof Double) { serializeAnyType("double", value.toString(), xmlStreamWriter); } else if (value instanceof Short) { serializeAnyType("short", value.toString(), xmlStreamWriter); } else if (value instanceof BigDecimal) { serializeAnyType("decimal", ((BigDecimal) value).toPlainString(), xmlStreamWriter); } else if (value instanceof DataHandler) { addTypeAttribute(xmlStreamWriter, "base64Binary"); try {//from www .j a va 2s . co m XMLStreamWriterUtils.writeDataHandler(xmlStreamWriter, (DataHandler) value, null, true); } catch (IOException ex) { throw new XMLStreamException("Unable to read data handler", ex); } } else if (value instanceof QName) { QName qNameValue = (QName) value; String prefix = xmlStreamWriter.getPrefix(qNameValue.getNamespaceURI()); if (prefix == null) { prefix = BeanUtil.getUniquePrefix(); xmlStreamWriter.writeNamespace(prefix, qNameValue.getNamespaceURI()); xmlStreamWriter.setPrefix(prefix, qNameValue.getNamespaceURI()); } String attributeValue = qNameValue.getLocalPart(); if (!prefix.equals("")) { attributeValue = prefix + ":" + attributeValue; } serializeAnyType("QName", attributeValue, xmlStreamWriter); } else if (value instanceof UnsignedByte) { serializeAnyType("unsignedByte", convertToString((UnsignedByte) value), xmlStreamWriter); } else if (value instanceof UnsignedLong) { serializeAnyType("unsignedLong", convertToString((UnsignedLong) value), xmlStreamWriter); } else if (value instanceof UnsignedShort) { serializeAnyType("unsignedShort", convertToString((UnsignedShort) value), xmlStreamWriter); } else if (value instanceof UnsignedInt) { serializeAnyType("unsignedInt", convertToString((UnsignedInt) value), xmlStreamWriter); } else if (value instanceof PositiveInteger) { serializeAnyType("positiveInteger", convertToString((PositiveInteger) value), xmlStreamWriter); } else if (value instanceof NegativeInteger) { serializeAnyType("negativeInteger", convertToString((NegativeInteger) value), xmlStreamWriter); } else if (value instanceof NonNegativeInteger) { serializeAnyType("nonNegativeInteger", convertToString((NonNegativeInteger) value), xmlStreamWriter); } else if (value instanceof NonPositiveInteger) { serializeAnyType("nonPositiveInteger", convertToString((NonPositiveInteger) value), xmlStreamWriter); } else { throw new XMLStreamException("Unknow type can not serialize"); } }
From source file:org.apache.axis2.databinding.utils.ConverterUtil.java
private static void addTypeAttribute(XMLStreamWriter xmlStreamWriter, String type) throws XMLStreamException { String prefix = xmlStreamWriter.getPrefix(Constants.XSI_NAMESPACE); if (prefix == null) { prefix = BeanUtil.getUniquePrefix(); xmlStreamWriter.writeNamespace(prefix, Constants.XSI_NAMESPACE); xmlStreamWriter.setPrefix(prefix, Constants.XSI_NAMESPACE); }/* w w w . j av a 2 s . co m*/ prefix = xmlStreamWriter.getPrefix(Constants.XSD_NAMESPACE); if (prefix == null) { prefix = BeanUtil.getUniquePrefix(); xmlStreamWriter.writeNamespace(prefix, Constants.XSD_NAMESPACE); xmlStreamWriter.setPrefix(prefix, Constants.XSD_NAMESPACE); } String attributeValue = null; if (prefix.equals("")) { attributeValue = type; } else { attributeValue = prefix + ":" + type; } xmlStreamWriter.writeAttribute(Constants.XSI_NAMESPACE, "type", attributeValue); }