List of usage examples for javax.xml.stream XMLStreamWriter writeCharacters
public void writeCharacters(String text) throws XMLStreamException;
From source file:org.deegree.services.ows.OWS110ExceptionReportSerializer.java
@Override public void serializeExceptionToXML(XMLStreamWriter writer, OWSException ex) throws XMLStreamException { if (ex == null || writer == null) { return;/*from ww w . j a v a 2s . co m*/ } writer.writeStartElement("ows", "ExceptionReport", OWS_NS); writer.writeNamespace("ows", OWS_NS); writer.writeNamespace("xsi", XSINS); writer.writeAttribute(XSINS, "schemaLocation", OWS_NS + " " + OWS_SCHEMA); writer.writeAttribute("version", "" + version); writer.writeStartElement(OWS_NS, "Exception"); writer.writeAttribute("exceptionCode", ex.getExceptionCode()); if (ex.getLocator() != null && !"".equals(ex.getLocator().trim())) { writer.writeAttribute("locator", ex.getLocator()); } String message = ex.getMessage(); if (message != null) { writer.writeStartElement(OWS_NS, "ExceptionText"); writer.writeCharacters(message); writer.writeEndElement(); } writer.writeEndElement(); // Exception writer.writeEndElement(); // ExceptionReport }
From source file:edu.stanford.cfuller.imageanalysistools.fitting.ImageObject.java
public void writeToXML(XMLStreamWriter xsw) { try {/*from w w w . j a v a2s .c om*/ 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:com.norconex.collector.http.client.impl.GenericHttpClientFactory.java
private void writeStringElement(XMLStreamWriter writer, String name, String value) throws XMLStreamException { writer.writeStartElement(name);/*from ww w.j av a 2 s . c o m*/ writer.writeCharacters(value); writer.writeEndElement(); }
From source file:com.microsoft.tfs.core.memento.XMLMemento.java
/** * Saves this {@link Memento} as an XML Element in the given writer * * @param writer/*from ww w .ja v a2 s .c om*/ * the writer (must not be <code>null</code>) */ private void writeAsElement(final XMLStreamWriter writer) throws XMLStreamException { writer.writeStartElement(name); /* * Write all attributes as XML attributes. */ for (final Iterator iterator = attributes.entrySet().iterator(); iterator.hasNext();) { final Entry entry = (Entry) iterator.next(); writer.writeAttribute((String) entry.getKey(), (String) entry.getValue()); } /* * Write the text node if there is one. */ if (textData != null) { writer.writeCharacters(textData); } /* * Write all children as elements. */ for (final Iterator iterator = children.iterator(); iterator.hasNext();) { final XMLMemento child = (XMLMemento) iterator.next(); child.writeAsElement(writer); } /* * Done with the element. */ writer.writeEndElement(); }
From source file:com.basistech.bbhmp.RosapiBundleCollectorMojo.java
private void writeMetadata(Map<Integer, List<BundleSpec>> bundlesByLevel) throws MojoExecutionException { OutputStream os = null;/*from w w w . j a va 2 s . com*/ File md = new File(outputDirectory, "bundles.xml"); try { os = new FileOutputStream(md); XMLStreamWriter writer = XMLOutputFactory.newFactory().createXMLStreamWriter(os); writer = new IndentingXMLStreamWriter(writer); writer.writeStartDocument("utf-8", "1.0"); writer.writeStartElement("bundles"); for (Integer level : bundlesByLevel.keySet()) { writer.writeStartElement("level"); writer.writeAttribute("level", Integer.toString(level)); for (BundleSpec spec : bundlesByLevel.get(level)) { writer.writeStartElement("bundle"); writer.writeAttribute("start", Boolean.toString(spec.start)); writer.writeCharacters(spec.filename); writer.writeEndElement(); } writer.writeEndElement(); } writer.writeEndElement(); writer.writeEndDocument(); writer.flush(); } catch (IOException | XMLStreamException e) { throw new MojoExecutionException("Failed to write metadata file " + md.toString(), e); } finally { IOUtils.closeQuietly(os); } }
From source file:com.microsoft.windowsazure.services.table.client.AtomPubParser.java
/** * Reserved for internal use. Writes an entity to the stream as an AtomPub Entry Resource, leaving the stream open * for additional writing./*from ww w .java 2s . c om*/ * * @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. */ protected static void writeEntityToStream(final TableEntity entity, final boolean isTableEntry, final XMLStreamWriter xmlw, final OperationContext opContext) throws XMLStreamException, StorageException { final HashMap<String, EntityProperty> properties = entity.writeEntity(opContext); if (properties == null) { throw new IllegalArgumentException("Entity did not produce properties to serialize"); } if (!isTableEntry) { Utility.assertNotNullOrEmpty(TableConstants.PARTITION_KEY, entity.getPartitionKey()); Utility.assertNotNullOrEmpty(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:de.qucosa.webapi.v1.DocumentResource.java
private String getDocumentUpdatedResponse() throws XMLStreamException { StringWriter sw = new StringWriter(); XMLStreamWriter w = xmlOutputFactory.createXMLStreamWriter(sw); w.writeStartDocument("UTF-8", "1.0"); w.writeStartElement("Opus"); w.writeStartElement("Opus_Document_Info"); w.writeCharacters("Update was successful."); w.writeEndElement();/*from w w w .j av a 2 s .co m*/ w.writeEndElement(); w.writeEndDocument(); w.flush(); return sw.toString(); }
From source file:com.norconex.committer.idol.IdolCommitter.java
protected void buildCfsXmlDocument(XMLStreamWriter writer, InputStream is, Properties properties) throws XMLStreamException, IOException { try {/*from www .j a v a 2s.c o m*/ writer.writeStartElement("add"); writer.writeStartElement("document"); // Create a database key for the idol XML document String targetIdField = getTargetReferenceField(); if (DEFAULT_IDOL_REFERENCE_FIELD.equalsIgnoreCase(targetIdField)) { writer.writeStartElement("reference"); writer.writeCharacters(properties.getString(targetIdField)); writer.writeEndElement(); } else { writer.writeStartElement("metadata"); writer.writeAttribute("name", targetIdField); writer.writeAttribute("value", properties.getString(targetIdField)); writer.writeEndElement(); } // Loop thru the list of properties and create XML fields // accordingly. for (Entry<String, List<String>> entry : properties.entrySet()) { if (!EqualsUtil.equalsAny(entry.getKey(), getTargetReferenceField(), getTargetContentField())) { for (String value : entry.getValue()) { writer.writeStartElement("metadata"); writer.writeAttribute("name", entry.getKey()); writer.writeAttribute("value", value); writer.writeEndElement(); } } } // Store content at specified location String targetCtntField = getTargetContentField(); String targetCtntValue = properties.getString(targetCtntField); writer.writeEndElement(); writer.writeStartElement("source"); writer.writeAttribute("content", Base64.encodeBase64String(targetCtntValue.getBytes(CharEncoding.UTF_8))); writer.writeEndElement(); writer.writeEndElement(); } finally { IOUtils.closeQuietly(is); } }
From source file:babel.content.pages.PageVersion.java
/** * To be called by ObjectWriter only./* w w w . j a v a 2 s.c o m*/ * @throws XMLStreamException */ public void persist(XMLStreamWriter writer) throws XMLStreamException { writer.writeStartElement(XML_TAG_PAGEVERSION); if (m_verProps.numKeys() > 0) { m_verProps.persist(writer); } if (m_parseMeta.numKeys() > 0) { m_parseMeta.persist(writer); } if (m_contentMeta.numKeys() > 0) { m_contentMeta.persist(writer); } if (m_outLinks != null) { String anchor; writer.writeStartElement(XML_TAG_OUT_LINKS); for (Outlink outlink : m_outLinks) { writer.writeStartElement(XML_TAG_LINK); anchor = outlink.getAnchor(); if ((anchor != null) && (anchor.length() != 0)) { writer.writeAttribute(XML_ATTRIB_ANCHOR, anchor); } writer.writeCharacters(outlink.getToUrl()); writer.writeEndElement(); } writer.writeEndElement(); } if (m_content.length() > 0) { writer.writeStartElement(XML_TAG_CONTENT); writer.writeCharacters(new String(Base64.encodeBase64(m_content.getBytes()))); //writer.writeCharacters(m_content); writer.writeEndElement(); } writer.writeEndElement(); }
From source file:com.github.lindenb.jvarkit.tools.vcfcmp.VcfCompareCallers.java
private void watch(XMLStreamWriter out, VariantContext ctx0, VariantContext ctx1, Genotype g0, Genotype g1, String sampleName, Counter<Category> count, Category cat) throws XMLStreamException { long n = count.incr(cat); if (out == null || n > super.numberOfExampleVariants) return;//w ww .j a v a 2 s . com VariantContext variants[] = new VariantContext[] { ctx0, ctx1 }; Genotype gts[] = new Genotype[] { g0, g1 }; out.writeStartElement("diff"); out.writeAttribute("type", cat.name()); out.writeAttribute("sample", sampleName); for (int i = 0; i < 2; ++i) { if (variants[i] == null) continue; out.writeStartElement("variant"); out.writeAttribute("file", String.valueOf(i + 1)); out.writeAttribute("type", String.valueOf(variants[i].getType())); out.writeStartElement("chrom"); out.writeCharacters(variants[i].getContig()); out.writeEndElement(); out.writeStartElement("pos"); out.writeCharacters(String.valueOf(variants[i].getStart())); out.writeEndElement(); out.writeStartElement("id"); out.writeCharacters(variants[i].hasID() ? variants[i].getID() : "."); out.writeEndElement(); out.writeStartElement("ref"); out.writeCharacters(String.valueOf(variants[i].getReference())); out.writeEndElement(); out.writeStartElement("alts"); out.writeCharacters(String.valueOf(variants[i].getAlternateAlleles())); out.writeEndElement(); if (gts[i] != null) { out.writeStartElement("genotype"); out.writeAttribute("type", String.valueOf(gts[i].getType())); for (Allele a : gts[i].getAlleles()) { out.writeStartElement("allele"); out.writeCharacters(a.toString()); out.writeEndElement(); } if (gts[i].hasDP()) { out.writeStartElement("dp"); out.writeCharacters(String.valueOf(gts[i].getDP())); out.writeEndElement(); } out.writeEndElement(); } out.writeEndElement(); } out.writeEndElement(); out.writeCharacters("\n"); }