List of usage examples for javax.xml.stream XMLStreamWriter writeEndDocument
public void writeEndDocument() throws XMLStreamException;
From source file:com.microsoft.windowsazure.storage.table.TableParser.java
/** * Reserved for internal use. Writes a single entity to the specified <code>OutputStream</code> as a complete XML * document./* w w w .ja v a 2 s . c o m*/ * * @param outStream * The <code>OutputStream</code> to write the entity to. * @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 opContext * An {@link OperationContext} object used to track the execution of the operation. * @throws XMLStreamException * if an error occurs creating or accessing the stream. * @throws StorageException * if a Storage service error occurs. */ private static void writeSingleAtomEntity(final OutputStream outStream, final TableEntity entity, final boolean isTableEntry, final OperationContext opContext) throws XMLStreamException, StorageException { final XMLOutputFactory xmlOutFactoryInst = XMLOutputFactory.newInstance(); XMLStreamWriter xmlw = xmlOutFactoryInst.createXMLStreamWriter(outStream, Constants.UTF8_CHARSET); // default is UTF8 xmlw.writeStartDocument(Constants.UTF8_CHARSET, "1.0"); writeAtomEntity(entity, isTableEntry, xmlw, opContext); // end doc xmlw.writeEndDocument(); xmlw.flush(); }
From source file:eu.interedition.collatex.cli.Engine.java
void write() throws IOException { final SimpleVariantGraphSerializer serializer = new SimpleVariantGraphSerializer(variantGraph); if ("csv".equals(outputFormat)) { serializer.toCsv(out);/*from w ww . j a va2 s. co m*/ } else if ("dot".equals(outputFormat)) { serializer.toDot(out); } else if ("graphml".equals(outputFormat) || "tei".equals(outputFormat)) { XMLStreamWriter xml = null; try { xml = XMLOutputFactory.newInstance().createXMLStreamWriter(out); xml.writeStartDocument(outputCharset.name(), "1.0"); if ("graphml".equals(outputFormat)) { serializer.toGraphML(xml); } else { serializer.toTEI(xml); } xml.writeEndDocument(); } catch (XMLStreamException e) { throw new IOException(e); } finally { if (xml != null) { try { xml.close(); } catch (XMLStreamException e) { throw new IOException(e); } } } } else { JsonProcessor.write(variantGraph, out); } }
From source file:de.qucosa.webapi.v1.SearchResource.java
private ResponseEntity<String> errorResponse(String message, HttpStatus status) throws XMLStreamException { StringWriter sw = new StringWriter(); XMLStreamWriter w = xmlOutputFactory.createXMLStreamWriter(sw); w.writeStartDocument("UTF-8", "1.0"); w.writeStartElement("Opus"); w.writeEmptyElement("SearchResult"); w.writeStartElement("Error"); w.writeAttribute("message", message); w.writeEndElement();/*from w w w. j a va 2 s . com*/ w.writeEndElement(); w.writeEndDocument(); w.flush(); return new ResponseEntity<>(sw.toString(), status); }
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 {//from w ww .jav a 2 s . co m 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:org.maodian.flyingcat.xmpp.codec.PresenceCodec.java
@Override public void encode(Object object, XMLStreamWriter xmlsw) throws XMLStreamException { Presence p = (Presence) object;//from w w w . j a v a 2 s .c o m xmlsw.writeEmptyElement("presence"); writeAttributeIfNotBlank(xmlsw, "id", p.getId()); writeRequiredAttribute(xmlsw, "to", p.getTo().toBareJID()); writeRequiredAttribute(xmlsw, "from", StringUtils.isBlank(p.getFrom().getResource()) ? p.getFrom().toBareJID() : p.getFrom().toFullJID()); // if there is a 'type' attribute, then it's a request, otherwise is a notification if (p.getType() != null) { writeRequiredAttribute(xmlsw, "type", p.getType().name().toLowerCase()); } xmlsw.writeEndDocument(); }
From source file:de.shadowhunt.subversion.internal.LockOperation.java
@Override protected HttpUriRequest createRequest() { final URI uri = URIUtils.createURI(repository, resource); final DavTemplateRequest request = new DavTemplateRequest("LOCK", uri); if (steal) {/*w w w . j a v a 2s.c o m*/ request.addHeader("X-SVN-Options", "lock-steal"); } final Writer body = new StringBuilderWriter(); try { final XMLStreamWriter writer = XML_OUTPUT_FACTORY.createXMLStreamWriter(body); writer.writeStartDocument(XmlConstants.ENCODING, XmlConstants.VERSION_1_0); writer.writeStartElement("lockinfo"); writer.writeDefaultNamespace(XmlConstants.DAV_NAMESPACE); writer.writeStartElement("lockscope"); writer.writeEmptyElement("exclusive"); writer.writeEndElement(); // lockscope writer.writeStartElement("locktype"); writer.writeEmptyElement("write"); writer.writeEndElement(); // locktype writer.writeEndElement(); //lockinfo 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:com.pocketsoap.salesforce.soap.SoapRequestEntity.java
public final void writeRequest(OutputStream out) throws IOException { XMLOutputFactory f = XMLOutputFactory.newInstance(); try {// w w w .j ava 2s . co m XMLStreamWriter w = f.createXMLStreamWriter(new BufferedOutputStream(out, 1024), "UTF-8"); w.writeStartDocument(); w.writeStartElement("s", "Envelope", SOAP_NS); w.writeNamespace("s", SOAP_NS); w.writeNamespace("p", PARTNER_NS); w.setPrefix("p", PARTNER_NS); w.setPrefix("s", SOAP_NS); if (hasHeaders()) { w.writeStartElement(SOAP_NS, "Header"); writeHeaders(w); w.writeEndElement(); } w.writeStartElement(SOAP_NS, "Body"); writeBody(w); w.writeEndElement();//body w.writeEndElement();//envelope w.writeEndDocument(); w.close(); } catch (XMLStreamException e) { throw new IOException("Error generating request xml", e); } }
From source file:org.maodian.flyingcat.xmpp.codec.InfoQueryCodec.java
@Override public void encode(Object object, XMLStreamWriter xmlsw) throws XMLStreamException { InfoQuery iq = (InfoQuery) object;/*from ww w .j a va 2 s. c o m*/ xmlsw.writeStartElement("iq"); writeRequiredAttribute(xmlsw, "id", iq.getId()); writeRequiredAttribute(xmlsw, "type", iq.getType()); writeAttributeIfNotBlank(xmlsw, "from", iq.getFrom()); writeAttributeIfNotBlank(xmlsw, "to", iq.getTo()); writeAttributeIfNotBlank(xmlsw, XMLConstants.XML_NS_PREFIX, XMLConstants.XML_NS_URI, "lang", iq.getLanguage()); Object payload = iq.getPayload(); if (payload != null) { Encoder encoder = findEncoder(payload.getClass()); encoder.encode(payload, xmlsw); } xmlsw.writeEndDocument(); }
From source file:de.shadowhunt.subversion.internal.httpv1.CheckoutOperation.java
@Override protected HttpUriRequest createRequest() { final Writer body = new StringBuilderWriter(); try {//from www.j ava 2s . c o m final XMLStreamWriter writer = XML_OUTPUT_FACTORY.createXMLStreamWriter(body); writer.writeStartDocument(XmlConstants.ENCODING, XmlConstants.VERSION_1_0); writer.writeStartElement("checkout"); writer.writeDefaultNamespace(XmlConstants.DAV_NAMESPACE); writer.writeStartElement("activity-set"); writer.writeStartElement("href"); final URI transactionURI = URIUtils.createURI(repository, transaction); writer.writeCData(transactionURI.toString()); writer.writeEndElement(); // href writer.writeEndElement(); // activity-set writer.writeEmptyElement("apply-to-version"); writer.writeEndElement(); //checkout writer.writeEndDocument(); writer.close(); } catch (final XMLStreamException e) { throw new SubversionException("could not create request body", e); } final URI uri = URIUtils.createURI(repository, resource); final DavTemplateRequest request = new DavTemplateRequest("CHECKOUT", uri); request.setEntity(new StringEntity(body.toString(), CONTENT_TYPE_XML)); return request; }
From source file:de.shadowhunt.subversion.internal.ResolveOperation.java
@Override protected HttpUriRequest createRequest() { final Writer body = new StringBuilderWriter(); try {/*from w w w . j av a2 s.c om*/ final XMLStreamWriter writer = XML_OUTPUT_FACTORY.createXMLStreamWriter(body); writer.writeStartDocument(XmlConstants.ENCODING, XmlConstants.VERSION_1_0); writer.writeStartElement("get-locations"); writer.writeDefaultNamespace(XmlConstants.SVN_NAMESPACE); writer.writeEmptyElement("path"); writer.writeStartElement("peg-revision"); writer.writeCharacters(revision.toString()); writer.writeEndElement(); // peg-revision writer.writeStartElement("location-revision"); writer.writeCharacters(expected.toString()); writer.writeEndElement(); // location-revision writer.writeEndElement(); //get-locations writer.writeEndDocument(); writer.close(); } catch (final XMLStreamException e) { throw new SubversionException("could not create request body", e); } final URI uri = URIUtils.createURI(repository, resource); final DavTemplateRequest request = new DavTemplateRequest("REPORT", uri); request.setEntity(new StringEntity(body.toString(), CONTENT_TYPE_XML)); return request; }