List of usage examples for javax.xml.stream XMLStreamWriter writeStartElement
public void writeStartElement(String namespaceURI, String localName) throws XMLStreamException;
From source file:com.adobe.acs.commons.wcm.impl.SiteMapServlet.java
@SuppressWarnings("squid:S1192") private void write(Page page, XMLStreamWriter stream, ResourceResolver resolver) throws XMLStreamException { if (isHidden(page)) { return;//from w w w .j a v a2s.c om } stream.writeStartElement(NS, "url"); String loc = ""; if (!extensionlessUrls) { loc = externalizer.externalLink(resolver, externalizerDomain, String.format("%s.html", page.getPath())); } else { String urlFormat = removeTrailingSlash ? "%s" : "%s/"; loc = externalizer.externalLink(resolver, externalizerDomain, String.format(urlFormat, page.getPath())); } writeElement(stream, "loc", loc); if (includeLastModified) { Calendar cal = page.getLastModified(); if (cal != null) { writeElement(stream, "lastmod", DATE_FORMAT.format(cal)); } } if (includeInheritValue) { HierarchyNodeInheritanceValueMap hierarchyNodeInheritanceValueMap = new HierarchyNodeInheritanceValueMap( page.getContentResource()); writeFirstPropertyValue(stream, "changefreq", changefreqProperties, hierarchyNodeInheritanceValueMap); writeFirstPropertyValue(stream, "priority", priorityProperties, hierarchyNodeInheritanceValueMap); } else { ValueMap properties = page.getProperties(); writeFirstPropertyValue(stream, "changefreq", changefreqProperties, properties); writeFirstPropertyValue(stream, "priority", priorityProperties, properties); } stream.writeEndElement(); }
From source file:com.amalto.core.load.io.XMLStreamUnwrapper.java
/** * Moves to next record in stream and stores it in {@link #stringWriter}. *//*from ww w .j ava 2 s . com*/ private void moveToNext() { try { XMLStreamWriter writer = xmlOutputFactory.createXMLStreamWriter(stringWriter); boolean hasMadeChanges; do { if (!reader.hasNext()) { break; } hasMadeChanges = false; // Keep a state to skip line feeds final XMLEvent event = reader.nextEvent(); if (event.isEndElement()) { level--; } else if (event.isStartElement()) { level++; } else if (event.isEndDocument()) { level--; } if (level >= RECORD_LEVEL) { if (event.isEndElement()) { writer.writeEndElement(); hasMadeChanges = true; } else if (event.isStartElement()) { final StartElement startElement = event.asStartElement(); final QName name = startElement.getName(); writer.writeStartElement(name.getNamespaceURI(), name.getLocalPart()); boolean isRecordRootElement = (RECORD_LEVEL == level - 1); if (isRecordRootElement) { for (int i = 0; i < rootNamespaceList.size(); i++) { Namespace namespace = rootNamespaceList.get(i); writer.writeNamespace(namespace.getPrefix(), namespace.getNamespaceURI()); } } // Declare namespaces (if any) final Iterator elementNamespaces = startElement.getNamespaces(); while (elementNamespaces.hasNext()) { Namespace elementNamespace = (Namespace) elementNamespaces.next(); if (isRecordRootElement) { if (rootNamespaceList.size() > 0) { for (int i = 0; i < rootNamespaceList.size(); i++) { Namespace namespace = rootNamespaceList.get(i); if (!namespace.getPrefix().equals(elementNamespace.getPrefix()) || !namespace.getNamespaceURI() .equals(elementNamespace.getNamespaceURI())) { writer.writeNamespace(elementNamespace.getPrefix(), elementNamespace.getNamespaceURI()); } } } else { writer.writeNamespace(elementNamespace.getPrefix(), elementNamespace.getNamespaceURI()); } } else { writer.writeNamespace(elementNamespace.getPrefix(), elementNamespace.getNamespaceURI()); } } // Write attributes final Iterator attributes = startElement.getAttributes(); while (attributes.hasNext()) { Attribute attribute = (Attribute) attributes.next(); QName attributeName = attribute.getName(); String value = attribute.getValue(); if (StringUtils.isEmpty(attributeName.getNamespaceURI())) { writer.writeAttribute(attributeName.getLocalPart(), value); } else { writer.writeAttribute(attributeName.getNamespaceURI(), attributeName.getLocalPart(), value); } } hasMadeChanges = true; } else if (event.isCharacters()) { final String text = event.asCharacters().getData().trim(); if (!text.isEmpty()) { writer.writeCharacters(text); hasMadeChanges = true; } } } } while (level > RECORD_LEVEL || !hasMadeChanges); writer.flush(); } catch (XMLStreamException e) { throw new RuntimeException("Unexpected parsing exception.", e); } }
From source file:eionet.cr.util.odp.ODPDatasetsPacker.java
/** * @param writer/*from w w w .j a va2 s . c om*/ * @throws XMLStreamException */ private void writeManifestHeader(XMLStreamWriter writer) throws XMLStreamException { // Start the XML document writer.writeStartDocument(ENCODING, "1.0"); // Register all relevant namespaces. registerNamespaces(MANIFEST_FILE_NAMESPACES, writer); // Write root element start tag (i.e. <ecodp:manifest>) writer.writeStartElement(Namespace.ECODP.getUri(), "manifest"); // Write namespace prefixes in the root element start tag. for (Namespace namespace : MANIFEST_FILE_NAMESPACES) { writer.writeNamespace(namespace.getPrefix(), namespace.getUri()); } // It's ok to instantiate SimpleDateFormat every time here, since this method gets called once per package generation. String packageId = PACKAGE_ID_PREFIX + new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); String generationDateTime = Util.virtuosoDateToString(new Date()); writer.writeAttribute(Namespace.ECODP.getUri(), "creation-date-time", generationDateTime); writer.writeAttribute(Namespace.ECODP.getUri(), "package-id", packageId); writer.writeAttribute(Namespace.ECODP.getUri(), "priority", "normal"); writer.writeAttribute(Namespace.ECODP.getUri(), "publisher", "http://publications.europa.eu/resource/authority/corporate-body/CNECT"); writer.writeAttribute(Namespace.ECODP.getUri(), "version", "1.0"); writer.writeAttribute(Namespace.XSI.getUri(), "schemaLocation", "http://open-data.europa.eu/ontologies/protocol-v1.0/odp-protocol.xsd"); }
From source file:de.escidoc.core.common.util.xml.XmlUtility.java
/** * Adds a new element to the provided {@code XMLStreamWriter} containing a simple xlink with the provided * values. The new element is empty.//from w w w. j av a2 s. co m * * @param writer The {@code XMLStreamWriter} object to add the element to. * @param elementName The name of the new element. * @param xlinkTitle The title of the xlink contained in the new element. * @param xlinkHref The href of the xlink contained in the new element. * @param namespaceUri The namespace URI of the new element. * @throws XMLStreamException Thrown in case of an xml stream error. */ public static void addReferencingElement(final XMLStreamWriter writer, final String elementName, final String xlinkTitle, final String xlinkHref, final String namespaceUri) throws XMLStreamException { writer.writeStartElement(namespaceUri, elementName); addXlinkAttributes(writer, xlinkTitle, xlinkHref); writer.writeEndElement(); }
From source file:de.uni_koblenz.jgralab.utilities.rsa2tg.SchemaGraph2XMI.java
/** * This method creates an <code>extension</code> tag. It is used in profile * application and to create stereotypes of the form * <code><<keyValue>></code>. In the first case a * <code>references</code> child is created in the other a * <code>details</code> child. To create the first one <code>nelement</code> * has to be <code>null</code>. * /*from w w w . jav a 2 s . co m*/ * @param writer * {@link XMLStreamWriter} of the current XMI file * @param nelement * {@link NamedElement} if null <code>references</code> is * created otherwise the stereotype <code>keyValue</code>. * @param keyValue * {@link String} the stereotype to be created * @throws XMLStreamException */ private void createExtension(XMLStreamWriter writer, NamedElement nelement, String keyValue) throws XMLStreamException { // start Extension writer.writeStartElement(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI, XMIConstants4SchemaGraph2XMI.XMI_TAG_EXTENSION); writer.writeAttribute(XMIConstants4SchemaGraph2XMI.ATTRIBUTE_EXTENDER, XMIConstants4SchemaGraph2XMI.NAMESPACE_ECORE); // start eAnnotations writer.writeStartElement(XMIConstants4SchemaGraph2XMI.TAG_EANNOTATIONS); writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI, XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_TYPE, XMIConstants4SchemaGraph2XMI.EANNOTATIONS_TYPE_VALUE); writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI, XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_ID, nelement != null ? nelement.get_qualifiedName() + "_" + XMIConstants4SchemaGraph2XMI.TAG_EANNOTATIONS : XMIConstants4SchemaGraph2XMI.TAG_EANNOTATIONS + System.currentTimeMillis()); writer.writeAttribute(XMIConstants4SchemaGraph2XMI.EANNOTATIONS_ATTRIBUTE_SOURCE, XMIConstants4SchemaGraph2XMI.EANNOTATIONS_ATTRIBUTE_SOURCE_VALUE); if (nelement != null) { // write details writer.writeEmptyElement(XMIConstants4SchemaGraph2XMI.TAG_DETAILS); writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI, XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_TYPE, XMIConstants4SchemaGraph2XMI.DETAILS_ATTRIBUTE_TYPE_VALUE); writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI, XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_ID, nelement.get_qualifiedName() + "_" + XMIConstants4SchemaGraph2XMI.TAG_DETAILS); writer.writeAttribute(XMIConstants4SchemaGraph2XMI.DETAILS_ATTRIBUTE_KEY, keyValue); } else { // write references writer.writeEmptyElement(XMIConstants4SchemaGraph2XMI.TAG_REFERENCES); writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI, XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_TYPE, XMIConstants4SchemaGraph2XMI.REFERENCES_TYPE_VALUE); writer.writeAttribute(XMIConstants4SchemaGraph2XMI.ATTRIBUTE_HREF, XMIConstants4SchemaGraph2XMI.REFERENCES_HREF_VALUE); } // close eAnnotations writer.writeEndElement(); // close Extension writer.writeEndElement(); }
From source file:de.escidoc.core.common.util.xml.XmlUtility.java
/** * Adds a new element to the provided {@code XMLStreamWriter} object containing a {@code String} value. * * @param writer The {@code XMLStreamWriter} object to add the element to. * @param elementName The name of the new element. * @param elementContent The {@code String} that shall be set as the value of the new element. * @param namespaceUri The namespace URI of the new element. * @param createEmpty Flag indicating if a an empty element shall be created if the provided data is * {@code null} ( {@code true} ), or if the element shall not be created ( * {@code false} ). * @throws XMLStreamException Thrown in case of an xml stream error. */// w w w .j ava 2 s . com public static void addElement(final XMLStreamWriter writer, final String elementName, final String elementContent, final String namespaceUri, final boolean createEmpty) throws XMLStreamException { if (elementContent == null) { if (createEmpty) { writer.writeEmptyElement(namespaceUri, elementName); } } else { writer.writeStartElement(namespaceUri, elementName); writer.writeCharacters(elementContent); writer.writeEndElement(); } }
From source file:de.escidoc.core.common.util.xml.XmlUtility.java
/** * Adds a new element to the provided {@code XMLStreamWriter} object containing a date value. * * @param writer The {@code XMLStreamWriter} object to add the element to. * @param elementName The name of the new element. * @param elementContent The {@code Date} that shall be set as the value of the new element. * @param namespaceUri The namespace URI of the new element. * @param createEmpty Flag indicating if a an empty element shall be created if the provided data is * {@code null} ( {@code true} ), or if the element shall not be created ( * {@code false} ). * @throws XMLStreamException Thrown in case of an xml stream error. */// w ww . ja v a 2 s . c o m public static void addElement(final XMLStreamWriter writer, final String elementName, final DateTime elementContent, final String namespaceUri, final boolean createEmpty) throws XMLStreamException { if (elementContent == null) { if (createEmpty) { writer.writeEmptyElement(namespaceUri, elementName); } } else { writer.writeStartElement(namespaceUri, elementName); writer.writeCharacters(elementContent.withZone(DateTimeZone.UTC).toString(Constants.TIMESTAMP_FORMAT)); writer.writeEndElement(); } }
From source file:de.uni_koblenz.jgralab.utilities.rsa2tg.SchemaGraph2XMI.java
/** * Creates the <code>Model</code> tag and its content consisting of * <ul>//from w w w . j a v a 2s . c o m * <li>the {@link GraphClass},</li> * <li>the defaultPackage and its content,</li> * <li>the representation of the domains in * {@link SchemaGraph2XMI#typesToBeDeclaredAtTheEnd} and</li> * <li>and the profile application</li> * </ul> * by calling the corresponding methods. * * @param writer * {@link XMLStreamWriter} of the current XMI file * @param schemaGraph * {@link SchemaGraph} to be converted into an XMI * @throws XMLStreamException */ private void createModelElement(XMLStreamWriter writer, SchemaGraph schemaGraph) throws XMLStreamException { de.uni_koblenz.jgralab.grumlschema.structure.Schema schema = schemaGraph.getFirstSchema(); // start model writer.writeStartElement(XMIConstants4SchemaGraph2XMI.NAMESPACE_UML, XMIConstants4SchemaGraph2XMI.UML_TAG_MODEL); writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI, XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_ID, schema.get_packagePrefix() + "." + schema.get_name()); writer.writeAttribute(XMIConstants4SchemaGraph2XMI.ATTRIBUTE_NAME, schema.get_packagePrefix() + "." + schema.get_name()); // convert graph class createAttributedElementClass(writer, schemaGraph.getFirstGraphClass()); createPackage(writer, (Package) schemaGraph.getFirstSchema().getFirstContainsDefaultPackageIncidence().getThat()); // create Types if (!typesToBeDeclaredAtTheEnd.isEmpty()) { createTypes(writer); } // create profileApplication createProfileApplication(writer); // end model writer.writeEndElement(); }
From source file:nl.armatiek.xslweb.serializer.RequestSerializer.java
private void dataElement(XMLStreamWriter xsw, String uri, String localName, String text) throws XMLStreamException { if (text == null) { return;// w w w .jav a 2 s . c o m } if (text.equals("")) { xsw.writeEmptyElement(uri, localName); } else { xsw.writeStartElement(uri, localName); xsw.writeCharacters(text); xsw.writeEndElement(); } }
From source file:nl.nn.adapterframework.soap.Wsdl.java
/** * Writes the WSDL to an output stream/*from w ww .ja va 2 s .c o m*/ * @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(); }