List of usage examples for javax.xml.stream XMLStreamWriter writeNamespace
public void writeNamespace(String prefix, String namespaceURI) throws XMLStreamException;
From source file:com.predic8.membrane.core.http.xml.Response.java
@Override public void write(XMLStreamWriter out) throws XMLStreamException { out.writeStartElement("http", ELEMENT_NAME, Constants.HTTP_NS); out.writeNamespace("http", Constants.HTTP_NS); out.writeStartElement("status"); out.writeAttribute("code", "" + statusCode); out.writeCharacters(statusMessage);// w w w. j a v a 2s. co m out.writeEndElement(); writeIfNotNull(headers, out); if (body != null) { out.writeStartElement("body"); body.write(out); out.writeEndElement(); } out.writeEndElement(); }
From source file:jodtemplate.pptx.io.xml.SlideXmlRelsWriter.java
@Override public void write(final Resources resources, final Slide slide, final XMLOutputFactory xmlOutputFactory) throws XMLStreamException, IOException { final String slideXmlPath = FilenameUtils .normalize(slide.getPresentation().getFullPath() + slide.getRelationship().getTarget(), true); final String slideXmlRelsPath = Utils.getRelsPathNoPrefixSeparator(slideXmlPath); final Resource slideXmlRelsRes = resources.getResource(slideXmlRelsPath); try (final OutputStream os = slideXmlRelsRes.getOutputStream()) { os.write(/*from ww w. ja v a 2 s. c om*/ "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n".getBytes(CharEncoding.UTF_8)); final XMLStreamWriter writer = xmlOutputFactory.createXMLStreamWriter(os); writer.writeStartElement(OOXMLDocument.RELATIONSHIPS_ELEMENT); writer.writeNamespace("", OOXMLDocument.RELATIONSHIPS_RELS_NAMESPACE); for (Relationship rel : slide.getOtherRelationships()) { writer.writeEmptyElement(OOXMLDocument.RELATIONSHIPS_RELS_NAMESPACE, OOXMLDocument.RELATIONSHIP_ELEMENT); writer.writeAttribute(OOXMLDocument.RELATIONSHIPS_RELS_NAMESPACE, OOXMLDocument.ID_ATTRIBUTE, rel.getId()); writer.writeAttribute(OOXMLDocument.RELATIONSHIPS_RELS_NAMESPACE, OOXMLDocument.TYPE_ATTRIBUTE, rel.getType()); writer.writeAttribute(OOXMLDocument.RELATIONSHIPS_RELS_NAMESPACE, OOXMLDocument.TARGET_ATTRIBUTE, rel.getTarget()); if (StringUtils.isNotBlank(rel.getTargetMode())) { writer.writeAttribute(OOXMLDocument.RELATIONSHIPS_RELS_NAMESPACE, OOXMLDocument.TARGET_MODE_ATTRIBUTE, rel.getTargetMode()); } writer.flush(); } writer.writeEndElement(); writer.writeEndDocument(); writer.flush(); writer.close(); } }
From source file:com.pocketsoap.salesforce.soap.SoapRequestEntity.java
public final void writeRequest(OutputStream out) throws IOException { XMLOutputFactory f = XMLOutputFactory.newInstance(); try {/*from w ww . ja v a2 s. c om*/ 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.unitedinternet.cosmo.dav.CosmoDavException.java
public void writeTo(XMLStreamWriter writer) throws XMLStreamException { writer.setNamespaceContext(nsc);/* w w w .jav a2s . c o m*/ writer.writeStartElement("DAV:", "error"); for (String uri : nsc.getNamespaceURIs()) { writer.writeNamespace(nsc.getPrefix(uri), uri); } writeContent(writer); writer.writeEndElement(); }
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 w w w . jav 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: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. j ava2 s. 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. */ 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:org.maodian.flyingcat.xmpp.state.DefaultElementVisitor.java
@Override public State handleTLS(XmppContext xmppCtx, TLS tls) throws XMLStreamException { ChannelHandlerContext ctx = xmppCtx.getNettyChannelHandlerContext(); SSLEngine engine = SecureSslContextFactory.getServerContext().createSSLEngine(); engine.setUseClientMode(false);//w ww . jav a 2 s. c om SslHandler sslHandler = new SslHandler(engine, true); sslHandler.sslCloseFuture().addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) throws Exception { log.info("Close the socket since SSL connection has been closed by client"); future.channel().close(); } }); ctx.pipeline().addFirst("ssl", sslHandler); StringWriter writer = new StringWriter(); XMLStreamWriter xmlsw = XMLOutputFactoryHolder.getXMLOutputFactory().createXMLStreamWriter(writer); xmlsw.writeEmptyElement("", "proceed", XmppNamespace.TLS); xmlsw.setPrefix("", XmppNamespace.TLS); xmlsw.writeNamespace("", XmppNamespace.TLS); xmlsw.writeEndDocument(); xmppCtx.flush(writer.toString()); return xmppCtx.getGlobalContext().getTlsStreamState(); }
From source file:de.shadowhunt.subversion.internal.PropertiesUpdateOperation.java
@Override protected HttpUriRequest createRequest() { final URI uri = URIUtils.createURI(repository, resource); final DavTemplateRequest request = new DavTemplateRequest("PROPPATCH", uri); if (lockToken != null) { request.addHeader("If", "<" + uri + "> (<" + lockToken + ">)"); }/* w w w.j a v a2 s . c o m*/ final Writer body = new StringBuilderWriter(); try { final XMLStreamWriter writer = XML_OUTPUT_FACTORY.createXMLStreamWriter(body); writer.writeStartDocument(XmlConstants.ENCODING, XmlConstants.VERSION_1_0); writer.writeStartElement("propertyupdate"); writer.writeDefaultNamespace(XmlConstants.DAV_NAMESPACE); writer.setPrefix(XmlConstants.SUBVERSION_CUSTOM_PREFIX, XmlConstants.SUBVERSION_CUSTOM_NAMESPACE); writer.writeNamespace(XmlConstants.SUBVERSION_CUSTOM_PREFIX, XmlConstants.SUBVERSION_CUSTOM_NAMESPACE); writer.setPrefix(XmlConstants.SUBVERSION_DAV_PREFIX, XmlConstants.SUBVERSION_DAV_NAMESPACE); writer.writeNamespace(XmlConstants.SUBVERSION_DAV_PREFIX, XmlConstants.SUBVERSION_DAV_NAMESPACE); writer.setPrefix(XmlConstants.SUBVERSION_SVN_PREFIX, XmlConstants.SUBVERSION_SVN_NAMESPACE); writer.writeNamespace(XmlConstants.SUBVERSION_SVN_PREFIX, XmlConstants.SUBVERSION_SVN_NAMESPACE); writer.writeStartElement(type.action); writer.writeStartElement("prop"); for (final ResourceProperty property : properties) { final String prefix = property.getType().getPrefix(); if (type == Type.SET) { writer.writeStartElement(prefix, ResourcePropertyUtils.escapedKeyNameXml(property.getName())); writer.writeCharacters(property.getValue()); writer.writeEndElement(); } else { writer.writeEmptyElement(prefix, property.getName()); } } writer.writeEndElement(); // prop writer.writeEndElement(); // set || delete writer.writeEndElement(); // propertyupdate writer.writeEndDocument(); writer.close(); } catch (final XMLStreamException e) { throw new SubversionException("could not create request body", e); } final String bodyWithMakers = body.toString(); final String bodyWithoutMakers = ResourcePropertyUtils.filterMarker(bodyWithMakers); request.setEntity(new StringEntity(bodyWithoutMakers, CONTENT_TYPE_XML)); return request; }
From source file:com.adobe.acs.commons.wcm.impl.SiteMapServlet.java
@Override protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException { response.setContentType(request.getResponseContentType()); if (StringUtils.isNotEmpty(this.characterEncoding)) { response.setCharacterEncoding(characterEncoding); }/*from w w w . j a v a 2 s . co m*/ ResourceResolver resourceResolver = request.getResourceResolver(); PageManager pageManager = resourceResolver.adaptTo(PageManager.class); Page page = pageManager.getContainingPage(request.getResource()); XMLOutputFactory outputFactory = XMLOutputFactory.newFactory(); try { XMLStreamWriter stream = outputFactory.createXMLStreamWriter(response.getWriter()); stream.writeStartDocument("1.0"); stream.writeStartElement("", "urlset", NS); stream.writeNamespace("", NS); // first do the current page write(page, stream, resourceResolver); for (Iterator<Page> children = page.listChildren(new PageFilter(false, true), true); children .hasNext();) { write(children.next(), stream, resourceResolver); } if (damAssetTypes.size() > 0 && damAssetProperty.length() > 0) { for (Resource assetFolder : getAssetFolders(page, resourceResolver)) { writeAssets(stream, assetFolder, resourceResolver); } } stream.writeEndElement(); stream.writeEndDocument(); } catch (XMLStreamException e) { throw new IOException(e); } }
From source file:de.shadowhunt.subversion.internal.CommitMessageOperation.java
@Override protected HttpUriRequest createRequest() { final Writer body = new StringBuilderWriter(); try {/*from w ww .j a v a2 s .com*/ final XMLStreamWriter writer = XML_OUTPUT_FACTORY.createXMLStreamWriter(body); writer.writeStartDocument(XmlConstants.ENCODING, XmlConstants.VERSION_1_0); writer.writeStartElement("propertyupdate"); writer.writeDefaultNamespace(XmlConstants.DAV_NAMESPACE); writer.writeStartElement("set"); writer.writeStartElement("prop"); writer.setPrefix(XmlConstants.SUBVERSION_DAV_PREFIX, XmlConstants.SUBVERSION_DAV_NAMESPACE); writer.writeStartElement(XmlConstants.SUBVERSION_DAV_NAMESPACE, "log"); writer.writeNamespace(XmlConstants.SUBVERSION_DAV_PREFIX, XmlConstants.SUBVERSION_DAV_NAMESPACE); writer.writeCharacters(message); writer.writeEndElement(); // log writer.writeEndElement(); // prop writer.writeEndElement(); // set writer.writeEndElement(); // propertyupdate 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("PROPPATCH", uri); request.setEntity(new StringEntity(body.toString(), CONTENT_TYPE_XML)); return request; }