List of usage examples for javax.xml.stream XMLStreamWriter writeAttribute
public void writeAttribute(String localName, String value) throws XMLStreamException;
From source file:com.norconex.collector.http.filter.impl.SegmentCountURLFilter.java
@Override public void saveToXML(Writer out) throws IOException { XMLOutputFactory factory = XMLOutputFactory.newInstance(); try {//from w w w . j a v a 2s. c o m XMLStreamWriter writer = factory.createXMLStreamWriter(out); writer.writeStartElement("filter"); writer.writeAttribute("class", getClass().getCanonicalName()); super.saveToXML(writer); writer.writeAttribute("count", Integer.toString(count)); writer.writeAttribute("duplicate", Boolean.toString(duplicate)); writer.writeAttribute("separator", separator); writer.writeEndElement(); writer.flush(); writer.close(); } catch (XMLStreamException e) { throw new IOException("Cannot save as XML.", e); } }
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);/* ww w. j a v a2s . c om*/ } for (PageVersion ver : m_versions) { ver.persist(writer); } writer.writeEndElement(); }
From source file:com.github.fritaly.graphml4j.GeneralStyle.java
private void writeBorderStyle(XMLStreamWriter writer) throws XMLStreamException { Validate.notNull(writer, "The given stream writer is null"); // y:BorderStyle writer.writeEmptyElement("y:BorderStyle"); writer.writeAttribute("color", Utils.encode(borderColor)); writer.writeAttribute("type", borderType.getValue()); writer.writeAttribute("width", String.format("%.1f", borderWidth)); }
From source file:microsoft.exchange.webservices.data.core.EwsUtilities.java
/** * Write trace start element.//from w ww . ja v a2s.co 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.flexive.shared.media.FxMetadata.java
/** * Get this metadata object as XML document * * @return XML document//from ww w. java2 s. co m * @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 ava2s .co 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:com.fiorano.openesb.application.application.RemoteServiceInstance.java
protected void toJXMLString(XMLStreamWriter writer) throws XMLStreamException, FioranoException { writer.writeStartElement(ELEM_REMOTE_SERVICE_INSTANCE); {/*from w w w . j av a 2s . co m*/ writer.writeAttribute(ATTR_NAME, name); writer.writeAttribute(ATTR_APPLICATION_GUID, applicationGUID); writer.writeAttribute(ATTR_APPLICATION_VERSION, String.valueOf(applicationVersion)); writer.writeAttribute(ATTR_APPLICATION_SCHEMA_VERSION, applicationSchemaVersion); writer.writeAttribute(ATTR_REMOTE_NAME, remoteName); } writer.writeEndElement(); }
From source file:com.github.fritaly.graphml4j.GeneralStyle.java
private void writeFill(XMLStreamWriter writer) throws XMLStreamException { Validate.notNull(writer, "The given stream writer is null"); // y:Fill//from w w w .j a v a 2 s . c o m writer.writeEmptyElement("y:Fill"); if (fillColor != null) { writer.writeAttribute("color", Utils.encode(fillColor)); } if (fillColor2 != null) { writer.writeAttribute("color2", Utils.encode(fillColor2)); } writer.writeAttribute("transparent", Boolean.toString(transparentFill)); }
From source file:com.fiorano.openesb.application.application.LogManager.java
protected void toJXMLString(XMLStreamWriter writer) throws XMLStreamException, FioranoException { writer.writeStartElement(ELEM_LOG_MANAGER); {/* w w w . j a va 2s. com*/ 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.collector.http.url.impl.GenericURLNormalizer.java
@Override public void saveToXML(Writer out) throws IOException { XMLOutputFactory factory = XMLOutputFactory.newInstance(); try {/*from w w w . j a v a 2 s . c om*/ XMLStreamWriter writer = factory.createXMLStreamWriter(out); writer.writeStartElement("urlNormalizer"); writer.writeAttribute("class", getClass().getCanonicalName()); writer.writeStartElement("normalizations"); writer.writeCharacters(StringUtils.join(normalizations, ",")); writer.writeEndElement(); writer.writeStartElement("replacements"); for (Replace replace : replaces) { writer.writeStartElement("replace"); writer.writeStartElement("match"); writer.writeCharacters(replace.getMatch()); writer.writeEndElement(); writer.writeStartElement("replacement"); writer.writeCharacters(replace.getReplacement()); writer.writeEndElement(); writer.writeEndElement(); } writer.writeEndElement(); writer.writeEndElement(); writer.flush(); writer.close(); } catch (XMLStreamException e) { throw new IOException("Cannot save as XML.", e); } }