List of usage examples for javax.xml.stream XMLStreamWriter writeStartElement
public void writeStartElement(String localName) throws XMLStreamException;
From source file:de.shadowhunt.subversion.internal.AbstractPropfindOperation.java
@Override protected HttpUriRequest createRequest() { final URI uri = URIUtils.createURI(repository, resource); final DavTemplateRequest request = new DavTemplateRequest("PROPFIND", uri); request.addHeader("Depth", depth.value); final Writer body = new StringBuilderWriter(); try {//from www.j a va 2 s . c om final XMLStreamWriter writer = XML_OUTPUT_FACTORY.createXMLStreamWriter(body); writer.writeStartDocument(XmlConstants.ENCODING, XmlConstants.VERSION_1_0); writer.writeStartElement("propfind"); writer.writeDefaultNamespace(XmlConstants.DAV_NAMESPACE); if (requestedProperties == null) { writer.writeEmptyElement("prop"); } else { if (requestedProperties.length == 0) { writer.writeEmptyElement("allprop"); } else { writer.writeStartElement("prop"); if (contains(XmlConstants.SUBVERSION_DAV_NAMESPACE)) { writer.writeNamespace(XmlConstants.SUBVERSION_DAV_PREFIX, XmlConstants.SUBVERSION_DAV_NAMESPACE); writer.setPrefix(XmlConstants.SUBVERSION_DAV_PREFIX, XmlConstants.SUBVERSION_DAV_NAMESPACE); } if (contains(XmlConstants.SUBVERSION_SVN_NAMESPACE)) { writer.writeNamespace(XmlConstants.SUBVERSION_SVN_PREFIX, XmlConstants.SUBVERSION_SVN_NAMESPACE); writer.setPrefix(XmlConstants.SUBVERSION_SVN_PREFIX, XmlConstants.SUBVERSION_SVN_NAMESPACE); } for (final ResourceProperty.Key requestedProperty : requestedProperties) { writer.writeEmptyElement(requestedProperty.getType().getPrefix(), requestedProperty.getName()); } writer.writeEndElement(); // prop } } writer.writeEndElement(); // propfind 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:babel.content.pages.Page.java
public void persist(XMLStreamWriter writer) throws XMLStreamException { writer.writeStartElement(XML_TAG_PAGE); writer.writeAttribute(XML_ATTRIB_URL, m_pageURL); if (m_pageProps.numKeys() > 0) { m_pageProps.persist(writer);/*from w w w.j a va 2 s. c o m*/ } for (PageVersion ver : m_versions) { ver.persist(writer); } writer.writeEndElement(); }
From source file:microsoft.exchange.webservices.data.core.EwsServiceXmlWriter.java
/** * @param element DOM element// w ww. j av a 2 s . c o 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:com.flexive.shared.media.FxMetadata.java
/** * Get this metadata object as XML document * * @return XML document//w w w . ja va2s . c om * @throws FxApplicationException on errors */ public String toXML() throws FxApplicationException { StringWriter sw = new StringWriter(2000); try { XMLStreamWriter writer = getXmlOutputFactory().createXMLStreamWriter(sw); writer.writeStartDocument(); writer.writeStartElement("metadata"); writer.writeAttribute("mediatype", getMediaType().name()); writer.writeAttribute("mimetype", getMimeType()); writer.writeAttribute("filename", getFilename()); writeXMLTags(writer); for (FxMetadataItem mdi : getMetadata()) { final String value = mdi.getValue().replaceAll("[\\x00-\\x1F]", ""); //filter out control characters if (StringUtils.isEmpty(value)) continue; writer.writeStartElement("meta"); writer.writeAttribute("key", mdi.getKey()); writer.writeCData(value); writer.writeEndElement(); } writer.writeEndElement(); writer.writeEndDocument(); writer.flush(); writer.close(); } catch (XMLStreamException e) { throw new FxApplicationException(e, "ex.general.xml", e.getMessage()); } return sw.getBuffer().toString(); }
From source file:com.norconex.jef4.status.FileJobStatusStore.java
@Override public void saveToXML(Writer out) throws IOException { XMLOutputFactory factory = XMLOutputFactory.newInstance(); try {/*w w w. j av a2 s .c o m*/ XMLStreamWriter writer = factory.createXMLStreamWriter(out); writer.writeStartElement("statusStore"); writer.writeAttribute("class", getClass().getCanonicalName()); writer.writeStartElement("statusDir"); writer.writeCharacters(new File(statusDir).getAbsolutePath()); writer.writeEndElement(); writer.writeEndElement(); writer.flush(); writer.close(); } catch (XMLStreamException e) { throw new IOException("Cannot save as XML.", e); } }
From source file:microsoft.exchange.webservices.data.core.EwsUtilities.java
/** * Write trace start element.// w w w. j a va 2 s .c o m * * @param writer the writer to write the start element to * @param traceTag the trace tag * @param includeVersion if true, include build version attribute * @throws XMLStreamException the XML stream exception */ private static void writeTraceStartElement(XMLStreamWriter writer, String traceTag, boolean includeVersion) throws XMLStreamException { writer.writeStartElement("Trace"); writer.writeAttribute("Tag", traceTag); writer.writeAttribute("Tid", Thread.currentThread().getId() + ""); Date d = new Date(); DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss'Z'"); df.setTimeZone(TimeZone.getTimeZone("UTC")); String formattedString = df.format(d); writer.writeAttribute("Time", formattedString); if (includeVersion) { writer.writeAttribute("Version", EwsUtilities.getBuildVersion()); } }
From source file:com.fiorano.openesb.application.application.LogManager.java
protected void toJXMLString(XMLStreamWriter writer) throws XMLStreamException, FioranoException { writer.writeStartElement(ELEM_LOG_MANAGER); {//from w w w . jav a 2s . c o m writer.writeAttribute(ATTR_LOGGER_CLASS, loggerClass); Iterator iter = props.entrySet().iterator(); while (iter.hasNext()) { Map.Entry entry = (Map.Entry) iter.next(); writer.writeStartElement(ELEM_PARAM); { writer.writeAttribute(ATTR_PROPERTY_NAME, (String) entry.getKey()); writer.writeCharacters((String) entry.getValue()); } writer.writeEndElement(); } } writer.writeEndElement(); }
From source file:com.norconex.committer.solr.SolrCommitter.java
@Override protected void saveToXML(XMLStreamWriter writer) throws XMLStreamException { writer.writeStartElement("solrURL"); writer.writeCharacters(solrURL);/*from w w w .j av a 2 s. c o m*/ writer.writeEndElement(); writer.writeStartElement("solrUpdateURLParams"); for (String name : updateUrlParams.keySet()) { writer.writeStartElement("param"); writer.writeAttribute("name", name); writer.writeCharacters(updateUrlParams.get(name)); writer.writeEndElement(); } writer.writeEndElement(); }
From source file:com.norconex.committer.elasticsearch.ElasticsearchCommitter.java
@Override protected void saveToXML(XMLStreamWriter writer) throws XMLStreamException { writer.writeStartElement("clusterName"); writer.writeCharacters(clusterName); writer.writeEndElement();/*w w w . j a v a 2s. co m*/ writer.writeStartElement("indexName"); writer.writeCharacters(indexName); writer.writeEndElement(); writer.writeStartElement("typeName"); writer.writeCharacters(typeName); writer.writeEndElement(); }
From source file:net.solarnetwork.web.support.SimpleXmlHttpMessageConverter.java
private void writeElement(String name, Map<?, ?> props, XMLStreamWriter writer, boolean close) throws IOException, XMLStreamException { writer.writeStartElement(name); Map<String, Object> nested = null; if (props != null) { for (Map.Entry<?, ?> me : props.entrySet()) { String key = me.getKey().toString(); Object val = me.getValue(); if (propertySerializerRegistrar != null) { val = propertySerializerRegistrar.serializeProperty(name, val.getClass(), props, val); }/* ww w .jav a2 s .c o m*/ if (val instanceof Date) { SimpleDateFormat sdf = SDF.get(); Date date = (Date) val; val = sdf.format(date); } else if (val instanceof Collection) { if (nested == null) { nested = new LinkedHashMap<String, Object>(5); } nested.put(key, val); val = null; } else if (val instanceof Map<?, ?>) { if (nested == null) { nested = new LinkedHashMap<String, Object>(5); } nested.put(key, val); val = null; } else if (classNamesAllowedForNesting != null && !(val instanceof Enum<?>)) { for (String prefix : classNamesAllowedForNesting) { if (val.getClass().getName().startsWith(prefix)) { if (nested == null) { nested = new LinkedHashMap<String, Object>(5); } nested.put(key, val); val = null; break; } } } if (val != null) { writer.writeAttribute(key, val.toString()); } } } if (nested != null) { for (Map.Entry<String, Object> me : nested.entrySet()) { outputObject(me.getValue(), me.getKey(), writer); } } if (close) { writer.writeEndElement(); } }