List of usage examples for javax.xml.stream XMLStreamWriter writeEndElement
public void writeEndElement() throws XMLStreamException;
From source file:com.fiorano.openesb.application.aps.InPortInst.java
public void toJXMLString(XMLStreamWriter writer) throws XMLStreamException { //Start InPortInst writer.writeStartElement("InPortInst"); writer.writeAttribute("isSyncRequestType", "" + isSyncRequestType()); writer.writeAttribute("isDisabled", "" + isDisabled()); FioranoStackSerializer.writeElement("Name", m_strPortName, writer); if (!StringUtils.isEmpty(m_strDscription)) { FioranoStackSerializer.writeElement("Description", m_strDscription, writer); }/*from w w w . j av a 2s. com*/ if (m_strXSDRef != null) { FioranoStackSerializer.writeElement(PortInstConstants.PORT_XSDREF, m_strXSDRef, writer); } if (!StringUtils.isEmpty(m_strJavaClass)) { FioranoStackSerializer.writeElement("JavaClass", m_strJavaClass, writer); } if (m_params != null && m_params.size() > 0) { Enumeration enums = m_params.elements(); while (enums.hasMoreElements()) { Param param = (Param) enums.nextElement(); if (!StringUtils.isEmpty(param.getParamName()) && !StringUtils.isEmpty(param.getParamValue())) { if (!checkIfDefaultValue(param.getParamName(), param.getParamValue())) { param.toJXMLString(writer); } } } } //End InPortInst 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. *///from w ww . jav a 2 s . com 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:com.microsoft.windowsazure.storage.table.TableParser.java
/** * Reserved for internal use. Writes an entity to the stream as an AtomPub Entry Resource, leaving the stream open * for additional writing.//from w w w . j a v a 2s . c o m * * @param entity * The instance implementing {@link TableEntity} to write to the output stream. * @param isTableEntry * A flag indicating the entity is a reference to a table at the top level of the storage service when * <code>true<code> and a reference to an entity within a table when <code>false</code>. * @param xmlw * The <code>XMLStreamWriter</code> to write the entity to. * @param opContext * An {@link OperationContext} object used to track the execution of the operation. * * @throws XMLStreamException * if an error occurs accessing the stream. * @throws StorageException * if a Storage service error occurs. */ private static void writeAtomEntity(final TableEntity entity, final boolean isTableEntry, final XMLStreamWriter xmlw, final OperationContext opContext) throws XMLStreamException, StorageException { HashMap<String, EntityProperty> properties = entity.writeEntity(opContext); if (properties == null) { properties = new HashMap<String, EntityProperty>(); } if (!isTableEntry) { Utility.assertNotNull(TableConstants.PARTITION_KEY, entity.getPartitionKey()); Utility.assertNotNull(TableConstants.ROW_KEY, entity.getRowKey()); Utility.assertNotNull(TableConstants.TIMESTAMP, entity.getTimestamp()); } // Begin entry xmlw.writeStartElement("entry"); xmlw.writeNamespace("d", ODataConstants.DATA_SERVICES_NS); xmlw.writeNamespace("m", ODataConstants.DATA_SERVICES_METADATA_NS); // default namespace xmlw.writeNamespace(null, ODataConstants.ATOM_NS); // Content xmlw.writeStartElement(ODataConstants.CONTENT); xmlw.writeAttribute(ODataConstants.TYPE, ODataConstants.ODATA_CONTENT_TYPE); // m:properties xmlw.writeStartElement("m", ODataConstants.PROPERTIES, ODataConstants.DATA_SERVICES_METADATA_NS); if (!isTableEntry) { // d:PartitionKey xmlw.writeStartElement("d", TableConstants.PARTITION_KEY, ODataConstants.DATA_SERVICES_NS); xmlw.writeAttribute("xml", "xml", "space", "preserve"); xmlw.writeCharacters(entity.getPartitionKey()); xmlw.writeEndElement(); // d:RowKey xmlw.writeStartElement("d", TableConstants.ROW_KEY, ODataConstants.DATA_SERVICES_NS); xmlw.writeAttribute("xml", "xml", "space", "preserve"); xmlw.writeCharacters(entity.getRowKey()); xmlw.writeEndElement(); // d:Timestamp if (entity.getTimestamp() == null) { entity.setTimestamp(new Date()); } xmlw.writeStartElement("d", TableConstants.TIMESTAMP, ODataConstants.DATA_SERVICES_NS); xmlw.writeAttribute("m", ODataConstants.DATA_SERVICES_METADATA_NS, ODataConstants.TYPE, EdmType.DATE_TIME.toString()); xmlw.writeCharacters(Utility.getTimeByZoneAndFormat(entity.getTimestamp(), Utility.UTC_ZONE, Utility.ISO8061_LONG_PATTERN)); xmlw.writeEndElement(); } for (final Entry<String, EntityProperty> ent : properties.entrySet()) { if (ent.getKey().equals(TableConstants.PARTITION_KEY) || ent.getKey().equals(TableConstants.ROW_KEY) || ent.getKey().equals(TableConstants.TIMESTAMP) || ent.getKey().equals("Etag")) { continue; } EntityProperty currProp = ent.getValue(); // d:PropName xmlw.writeStartElement("d", ent.getKey(), ODataConstants.DATA_SERVICES_NS); if (currProp.getEdmType() == EdmType.STRING) { xmlw.writeAttribute("xml", "xml", "space", "preserve"); } else if (currProp.getEdmType().toString().length() != 0) { String edmTypeString = currProp.getEdmType().toString(); if (edmTypeString.length() != 0) { xmlw.writeAttribute("m", ODataConstants.DATA_SERVICES_METADATA_NS, ODataConstants.TYPE, edmTypeString); } } if (currProp.getIsNull()) { xmlw.writeAttribute("m", ODataConstants.DATA_SERVICES_METADATA_NS, ODataConstants.NULL, Constants.TRUE); } // Write Value xmlw.writeCharacters(currProp.getValueAsString()); // End d:PropName xmlw.writeEndElement(); } // End m:properties xmlw.writeEndElement(); // End content xmlw.writeEndElement(); // End entry xmlw.writeEndElement(); }
From source file:edu.jhu.pha.vospace.node.Node.java
public String getXmlMetadata(Detail detail) { StringWriter jobWriter = new StringWriter(); try {// www . j a v a 2s .co m XMLStreamWriter xsw = XMLOutputFactory.newInstance().createXMLStreamWriter(jobWriter); xsw.writeStartDocument(); xsw.setDefaultNamespace(VOS_NAMESPACE); xsw.writeStartElement("node"); xsw.writeNamespace("xsi", XSI_NAMESPACE); xsw.writeNamespace(null, VOS_NAMESPACE); xsw.writeAttribute("xsi:type", this.getType().getTypeName()); xsw.writeAttribute("uri", this.getUri().toString()); if (detail == Detail.max) { xsw.writeStartElement("properties"); Map<String, String> properties = this.getMetastore().getProperties(this.getUri()); properties.put(LENGTH_PROPERTY, Long.toString(getNodeInfo().getSize())); properties.put(DATE_PROPERTY, dropboxDateFormat.format(getNodeInfo().getMtime())); if (this.getType() == NodeType.DATA_NODE || this.getType() == NodeType.STRUCTURED_DATA_NODE || this.getType() == NodeType.UNSTRUCTURED_DATA_NODE) { properties.put(CONTENTTYPE_PROPERTY, getNodeInfo().getContentType()); } for (String propUri : properties.keySet()) { xsw.writeStartElement("property"); xsw.writeAttribute("uri", propUri); xsw.writeCharacters(properties.get(propUri)); xsw.writeEndElement(); } xsw.writeEndElement(); xsw.writeStartElement("accepts"); xsw.writeEndElement(); xsw.writeStartElement("provides"); xsw.writeEndElement(); xsw.writeStartElement("capabilities"); xsw.writeEndElement(); if (this.getType() == NodeType.CONTAINER_NODE) { NodesList childrenList = ((ContainerNode) this).getDirectChildren(false, 0, -1); List<Node> children = childrenList.getNodesList(); xsw.writeStartElement("nodes"); for (Node childNode : children) { xsw.writeStartElement("node"); xsw.writeAttribute("uri", childNode.getUri().getId().toString()); xsw.writeEndElement(); } xsw.writeEndElement(); } } xsw.writeEndElement(); xsw.writeEndDocument(); xsw.close(); } catch (XMLStreamException e) { e.printStackTrace(); throw new InternalServerErrorException(e); } return jobWriter.getBuffer().toString(); }
From source file:de.codesourcery.eve.skills.util.XMLMapper.java
public void write(Collection<?> beans, IFieldConverters converters, OutputStream outstream) throws XMLStreamException, IntrospectionException, IllegalArgumentException, IllegalAccessException { final XMLOutputFactory factory = XMLOutputFactory.newInstance(); final XMLStreamWriter writer = factory.createXMLStreamWriter(outstream, OUTPUT_ENCODING); try {// w w w . j av a 2 s. c om writer.writeStartDocument(OUTPUT_ENCODING, "1.0"); writer.writeStartElement("rows"); if (beans.isEmpty()) { writer.writeEndDocument(); return; } final Class<?> beanClass = beans.iterator().next().getClass(); final BeanDescription desc = createBeanDescription(beanClass); final Collection<Field> fields = desc.getFields(); if (fields.isEmpty()) { writer.writeEndDocument(); return; } for (Object bean : beans) { writer.writeStartElement("row"); for (Field f : fields) { final Object fieldValue = f.get(bean); final String[] values = converters.getConverter(f).toString(fieldValue); final String attrName = this.propertyNameMappings.get(f.getName()); if (values == null) { writer.writeAttribute(f.getName(), NIL); } else if (attrName == null) { writer.writeAttribute(f.getName(), toAttributeValue(values)); } else { writer.writeAttribute(attrName, toAttributeValue(values)); } } writer.writeEndElement(); } writer.writeEndDocument(); } finally { writer.close(); } }
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 . ja v a 2s. c o m } 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:edu.stanford.cfuller.imageanalysistools.fitting.ImageObject.java
public void writeToXML(XMLStreamWriter xsw) { try {// w w w. j a va 2 s . c o m xsw.writeStartElement(OBJECT_ELEMENT); xsw.writeAttribute(LABEL_ATTR, Integer.toString(this.label)); xsw.writeAttribute(IMAGE_ATTR, this.imageID); xsw.writeCharacters("\n"); for (int i = 0; i < this.numberOfChannels; i++) { xsw.writeStartElement(CHANNEL_ELEMENT); xsw.writeAttribute(CH_ID_ATTR, Integer.toString(i)); xsw.writeCharacters("\n"); xsw.writeStartElement(FIT_ELEMENT); xsw.writeAttribute(R2_ATTR, Double.toString(this.getFitR2ByChannel().get(i))); xsw.writeAttribute(ERROR_ATTR, Double.toString(this.getFitErrorByChannel().get(i))); xsw.writeAttribute(N_PHOTONS_ATTR, Double.toString(this.getNPhotonsByChannel().get(i))); xsw.writeCharacters("\n"); xsw.writeStartElement(PARAMETERS_ELEMENT); xsw.writeCharacters(this.getFitParametersByChannel().get(i).toString().replace(";", ",") .replace("}", "").replace("{", "")); xsw.writeEndElement(); //parameters xsw.writeCharacters("\n"); xsw.writeStartElement(POSITION_ELEMENT); xsw.writeCharacters(this.getPositionForChannel(i).toString().replace(";", ",").replace("}", "") .replace("{", "")); xsw.writeEndElement(); //position xsw.writeCharacters("\n"); xsw.writeEndElement(); //fit xsw.writeCharacters("\n"); xsw.writeEndElement(); //channel xsw.writeCharacters("\n"); } xsw.writeStartElement(SERIAL_ELEMENT); xsw.writeAttribute(ENCODING_ATTR, ENCODING_NAME); ByteArrayOutputStream bytesOutput = new ByteArrayOutputStream(); try { ObjectOutputStream oos = new ObjectOutputStream(bytesOutput); oos.writeObject(this); } catch (java.io.IOException e) { LoggingUtilities.getLogger() .severe("Exception encountered while serializing ImageObject: " + e.getMessage()); } Base64BinaryAdapter adapter = new Base64BinaryAdapter(); xsw.writeCharacters(adapter.marshal(bytesOutput.toByteArray())); xsw.writeEndElement(); //serial xsw.writeCharacters("\n"); xsw.writeEndElement(); //object xsw.writeCharacters("\n"); } catch (XMLStreamException e) { LoggingUtilities.getLogger() .severe("Exception encountered while writing XML correction output: " + e.getMessage()); } }
From source file:ca.uhn.fhir.parser.XmlParser.java
@Override public void encodeTagListToWriter(TagList theTagList, Writer theWriter) throws IOException { try {/*w w w.java 2 s . c o m*/ XMLStreamWriter eventWriter = createXmlWriter(theWriter); eventWriter.writeStartElement(TagList.ELEMENT_NAME_LC); eventWriter.writeDefaultNamespace(FHIR_NS); for (Tag next : theTagList) { eventWriter.writeStartElement(TagList.ATTR_CATEGORY); if (isNotBlank(next.getTerm())) { eventWriter.writeAttribute(Tag.ATTR_TERM, next.getTerm()); } if (isNotBlank(next.getLabel())) { eventWriter.writeAttribute(Tag.ATTR_LABEL, next.getLabel()); } if (isNotBlank(next.getScheme())) { eventWriter.writeAttribute(Tag.ATTR_SCHEME, next.getScheme()); } eventWriter.writeEndElement(); } eventWriter.writeEndElement(); eventWriter.close(); } catch (XMLStreamException e) { throw new ConfigurationException("Failed to initialize STaX event factory", e); } }
From source file:microsoft.exchange.webservices.data.core.EwsServiceXmlWriter.java
/** * @param element DOM element/*from w w w . j ava2 s . co m*/ * @param writer XML stream writer * @throws XMLStreamException the XML stream exception */ public static void addElement(Element element, XMLStreamWriter writer) throws XMLStreamException { String nameSpace = element.getNamespaceURI(); String prefix = element.getPrefix(); String localName = element.getLocalName(); if (prefix == null) { prefix = ""; } if (localName == null) { localName = element.getNodeName(); if (localName == null) { throw new IllegalStateException("Element's local name cannot be null!"); } } String decUri = writer.getNamespaceContext().getNamespaceURI(prefix); boolean declareNamespace = decUri == null || !decUri.equals(nameSpace); if (nameSpace == null || nameSpace.length() == 0) { writer.writeStartElement(localName); } else { writer.writeStartElement(prefix, localName, nameSpace); } NamedNodeMap attrs = element.getAttributes(); for (int i = 0; i < attrs.getLength(); i++) { Node attr = attrs.item(i); String name = attr.getNodeName(); String attrPrefix = ""; int prefixIndex = name.indexOf(':'); if (prefixIndex != -1) { attrPrefix = name.substring(0, prefixIndex); name = name.substring(prefixIndex + 1); } if ("xmlns".equals(attrPrefix)) { writer.writeNamespace(name, attr.getNodeValue()); if (name.equals(prefix) && attr.getNodeValue().equals(nameSpace)) { declareNamespace = false; } } else { if ("xmlns".equals(name) && "".equals(attrPrefix)) { writer.writeNamespace("", attr.getNodeValue()); if (attr.getNodeValue().equals(nameSpace)) { declareNamespace = false; } } else { writer.writeAttribute(attrPrefix, attr.getNamespaceURI(), name, attr.getNodeValue()); } } } if (declareNamespace) { if (nameSpace == null) { writer.writeNamespace(prefix, ""); } else { writer.writeNamespace(prefix, nameSpace); } } NodeList nodes = element.getChildNodes(); for (int i = 0; i < nodes.getLength(); i++) { Node n = nodes.item(i); writeNode(n, writer); } writer.writeEndElement(); }
From source file:ca.uhn.fhir.parser.XmlParser.java
private void encodeBundleToWriterDstu2(Bundle theBundle, XMLStreamWriter theEventWriter) throws XMLStreamException { theEventWriter.writeStartElement("Bundle"); theEventWriter.writeDefaultNamespace(FHIR_NS); writeOptionalTagWithValue(theEventWriter, "id", theBundle.getId().getIdPart()); InstantDt updated = (InstantDt) theBundle.getResourceMetadata().get(ResourceMetadataKeyEnum.UPDATED); IdDt bundleId = theBundle.getId();/*from w w w . ja v a 2 s . com*/ if (bundleId != null && isNotBlank(bundleId.getVersionIdPart()) || (updated != null && !updated.isEmpty())) { theEventWriter.writeStartElement("meta"); writeOptionalTagWithValue(theEventWriter, "versionId", bundleId.getVersionIdPart()); if (updated != null) { writeOptionalTagWithValue(theEventWriter, "lastUpdated", updated.getValueAsString()); } theEventWriter.writeEndElement(); } writeOptionalTagWithValue(theEventWriter, "type", theBundle.getType().getValue()); writeOptionalTagWithValue(theEventWriter, "total", theBundle.getTotalResults().getValueAsString()); writeBundleResourceLink(theEventWriter, "first", theBundle.getLinkFirst()); writeBundleResourceLink(theEventWriter, "previous", theBundle.getLinkPrevious()); writeBundleResourceLink(theEventWriter, "next", theBundle.getLinkNext()); writeBundleResourceLink(theEventWriter, "last", theBundle.getLinkLast()); writeBundleResourceLink(theEventWriter, "self", theBundle.getLinkSelf()); for (BundleEntry nextEntry : theBundle.getEntries()) { theEventWriter.writeStartElement("entry"); boolean deleted = false; if (nextEntry.getDeletedAt() != null && nextEntry.getDeletedAt().isEmpty() == false) { deleted = true; } writeBundleResourceLink(theEventWriter, "alternate", nextEntry.getLinkAlternate()); if (nextEntry.getResource() != null && nextEntry.getResource().getId().getBaseUrl() != null) { writeOptionalTagWithValue(theEventWriter, "fullUrl", nextEntry.getResource().getId().getValue()); } IResource resource = nextEntry.getResource(); if (resource != null && !resource.isEmpty() && !deleted) { theEventWriter.writeStartElement("resource"); encodeResourceToXmlStreamWriter(resource, theEventWriter, false, true); theEventWriter.writeEndElement(); // content } else { ourLog.debug("Bundle entry contains null resource"); } if (nextEntry.getSearchMode().isEmpty() == false || nextEntry.getScore().isEmpty() == false) { theEventWriter.writeStartElement("search"); writeOptionalTagWithValue(theEventWriter, "mode", nextEntry.getSearchMode().getValueAsString()); writeOptionalTagWithValue(theEventWriter, "score", nextEntry.getScore().getValueAsString()); theEventWriter.writeEndElement(); // IResource nextResource = nextEntry.getResource(); } if (nextEntry.getTransactionMethod().isEmpty() == false || nextEntry.getLinkSearch().isEmpty() == false) { theEventWriter.writeStartElement("request"); writeOptionalTagWithValue(theEventWriter, "method", nextEntry.getTransactionMethod().getValue()); writeOptionalTagWithValue(theEventWriter, "url", nextEntry.getLinkSearch().getValue()); theEventWriter.writeEndElement(); } if (deleted) { theEventWriter.writeStartElement("deleted"); writeOptionalTagWithValue(theEventWriter, "type", nextEntry.getId().getResourceType()); writeOptionalTagWithValue(theEventWriter, "id", nextEntry.getId().getIdPart()); writeOptionalTagWithValue(theEventWriter, "versionId", nextEntry.getId().getVersionIdPart()); writeOptionalTagWithValue(theEventWriter, "instant", nextEntry.getDeletedAt().getValueAsString()); theEventWriter.writeEndElement(); } theEventWriter.writeEndElement(); // entry } theEventWriter.writeEndElement(); theEventWriter.close(); }