List of usage examples for javax.xml.stream XMLStreamWriter writeStartElement
public void writeStartElement(String prefix, String localName, String namespaceURI) throws XMLStreamException;
From source file:com.pocketsoap.salesforce.soap.SoapRequestEntity.java
public final void writeRequest(OutputStream out) throws IOException { XMLOutputFactory f = XMLOutputFactory.newInstance(); try {//www . j a v a2 s . 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.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 va 2 s . c om } 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:org.elasticsearch.discovery.ec2.AmazonEC2Fixture.java
/** * Generates a XML response that describe the EC2 instances *///from www . j a v a 2 s . c o m private byte[] generateDescribeInstancesResponse() { final XMLOutputFactory xmlOutputFactory = XMLOutputFactory.newFactory(); xmlOutputFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, true); final StringWriter out = new StringWriter(); XMLStreamWriter sw; try { sw = xmlOutputFactory.createXMLStreamWriter(out); sw.writeStartDocument(); String namespace = "http://ec2.amazonaws.com/doc/2013-02-01/"; sw.setDefaultNamespace(namespace); sw.writeStartElement(XMLConstants.DEFAULT_NS_PREFIX, "DescribeInstancesResponse", namespace); { sw.writeStartElement("requestId"); sw.writeCharacters(UUID.randomUUID().toString()); sw.writeEndElement(); sw.writeStartElement("reservationSet"); { if (Files.exists(nodes)) { for (String address : Files.readAllLines(nodes)) { sw.writeStartElement("item"); { sw.writeStartElement("reservationId"); sw.writeCharacters(UUID.randomUUID().toString()); sw.writeEndElement(); sw.writeStartElement("instancesSet"); { sw.writeStartElement("item"); { sw.writeStartElement("instanceId"); sw.writeCharacters(UUID.randomUUID().toString()); sw.writeEndElement(); sw.writeStartElement("imageId"); sw.writeCharacters(UUID.randomUUID().toString()); sw.writeEndElement(); sw.writeStartElement("instanceState"); { sw.writeStartElement("code"); sw.writeCharacters("16"); sw.writeEndElement(); sw.writeStartElement("name"); sw.writeCharacters("running"); sw.writeEndElement(); } sw.writeEndElement(); sw.writeStartElement("privateDnsName"); sw.writeCharacters(address); sw.writeEndElement(); sw.writeStartElement("dnsName"); sw.writeCharacters(address); sw.writeEndElement(); sw.writeStartElement("instanceType"); sw.writeCharacters("m1.medium"); sw.writeEndElement(); sw.writeStartElement("placement"); { sw.writeStartElement("availabilityZone"); sw.writeCharacters("use-east-1e"); sw.writeEndElement(); sw.writeEmptyElement("groupName"); sw.writeStartElement("tenancy"); sw.writeCharacters("default"); sw.writeEndElement(); } sw.writeEndElement(); sw.writeStartElement("privateIpAddress"); sw.writeCharacters(address); sw.writeEndElement(); sw.writeStartElement("ipAddress"); sw.writeCharacters(address); sw.writeEndElement(); } sw.writeEndElement(); } sw.writeEndElement(); } sw.writeEndElement(); } } sw.writeEndElement(); } sw.writeEndElement(); sw.writeEndDocument(); sw.flush(); } } catch (Exception e) { throw new RuntimeException(e); } return out.toString().getBytes(UTF_8); }
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); }//w ww. jav a2 s.c o 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:org.maodian.flyingcat.xmpp.state.StreamState.java
private void doHandle(XmppContext context, XMLStreamReader xmlsr, XMLStreamWriter xmlsw) throws XMLStreamException { xmlsr.nextTag();/*from w w w .j ava 2 s .co m*/ QName qname = new QName(XmppNamespace.STREAM, "stream"); if (!xmlsr.getName().equals(qname)) { throw new XmppException(StreamError.INVALID_NAMESPACE).set("QName", xmlsr.getName()); } // throw exception if client version > 1.0 BigDecimal version = new BigDecimal(xmlsr.getAttributeValue("", "version")); if (version.compareTo(SUPPORTED_VERSION) > 0) { throw new XmppException(StreamError.UNSUPPORTED_VERSION); } xmlsw.writeStartDocument(); xmlsw.writeStartElement("stream", "stream", XmppNamespace.STREAM); xmlsw.writeNamespace("stream", XmppNamespace.STREAM); xmlsw.writeDefaultNamespace(XmppNamespace.CLIENT_CONTENT); xmlsw.writeAttribute("id", RandomStringUtils.randomAlphabetic(32)); xmlsw.writeAttribute("version", "1.0"); xmlsw.writeAttribute("from", "localhost"); xmlsw.writeAttribute(XMLConstants.XML_NS_PREFIX, XMLConstants.XML_NS_URI, "lang", "en"); String from = xmlsr.getAttributeValue(null, "from"); if (from != null) { xmlsw.writeAttribute("to", from); } // features xmlsw.writeStartElement(XmppNamespace.STREAM, "features"); writeFeatures(xmlsw); xmlsw.writeEndElement(); }
From source file:com.fiorano.openesb.application.application.Application.java
/** * Writes manageable properties file with the specified label * @param applicationFolderName event process folder * @param label environment label/*from ww w.jav a2 s. c o m*/ * @throws FioranoException FioranoException * @throws XMLStreamException XMLStreamException */ public void writeManageableProperties(File applicationFolderName, Label label) throws FioranoException, XMLStreamException { File manageablePropertiesFile = getManageablePropertiesFile(applicationFolderName, label); if (!manageablePropertiesFile.exists()) manageablePropertiesFile.getParentFile().mkdirs(); XMLOutputFactory outputFactory = XMLUtils.getStaxOutputFactory(); // System.out.println(".....:"+outputFactory); //outputFactory.setProperty(XMLOutputFactory.INDENTATION, "/t"); XMLStreamWriter writer = null; FileOutputStream fos = null; try { fos = new FileOutputStream(manageablePropertiesFile); writer = outputFactory.createXMLStreamWriter(fos); writer.writeStartDocument(); { writer.writeStartElement(ELEM_TARGET, ELEM_TARGET, Namespaces.URI_TARGET); writer.writeAttribute(XMLNS_TARGET, Namespaces.URI_TARGET); writer.writeAttribute(XMLNS_XSI, Namespaces.URI_XSI); writer.writeAttribute(XSI_LOCATION, Namespaces.URI_ENV_XSD); { for (ServiceInstance instance : getServiceInstances()) { instance.writeManageableProperties(writer); } } writer.writeEndElement(); } writer.writeEndDocument(); writer.flush(); } catch (XMLStreamException e) { throw new FioranoException(e); } catch (IOException e) { throw new FioranoException(e); } finally { try { if (writer != null) writer.close(); } catch (XMLStreamException e) { // Ignore } try { if (fos != null) fos.close(); } catch (IOException e) { // Ignore } } }
From source file:de.uni_koblenz.jgralab.utilities.rsa2tg.SchemaGraph2XMI.java
/** * Creates the root <code>XMI</code> tag of the whole document. It calls * {@link SchemaGraph2XMI#createModelElement(XMLStreamWriter, SchemaGraph)} * to create its content.//w w w . ja v a2s . c o m * * @param writer * {@link XMLStreamWriter} of the current XMI file * @param schemaGraph * {@link SchemaGraph} to be converted into an XMI * @throws XMLStreamException */ private void createRootElement(XMLStreamWriter writer, SchemaGraph schemaGraph) throws XMLStreamException { // start root element writer.writeStartElement(XMIConstants4SchemaGraph2XMI.NAMESPACE_PREFIX_XMI, XMIConstants4SchemaGraph2XMI.XMI_TAG_XMI, XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI); writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI, XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_VERSION, XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_VERSION_VALUE); writer.setPrefix(XMIConstants4SchemaGraph2XMI.NAMESPACE_PREFIX_XSI, XMIConstants4SchemaGraph2XMI.NAMESPACE_XSI); writer.setPrefix(XMIConstants4SchemaGraph2XMI.NAMESPACE_PREFIX_EECORE, XMIConstants4SchemaGraph2XMI.NAMESPACE_EECORE); writer.setPrefix(XMIConstants4SchemaGraph2XMI.NAMESPACE_PREFIX_ECORE, XMIConstants4SchemaGraph2XMI.NAMESPACE_ECORE); writer.setPrefix(XMIConstants4SchemaGraph2XMI.NAMESPACE_PREFIX_UML, XMIConstants4SchemaGraph2XMI.NAMESPACE_UML); writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XSI, XMIConstants4SchemaGraph2XMI.XSI_ATTRIBUTE_SCHEMALOCATION, XMIConstants4SchemaGraph2XMI.SCHEMALOCATION); // create model element createModelElement(writer, schemaGraph); // close root element writer.writeEndElement(); }
From source file:org.activiti.bpmn.converter.export.BPMNDIExport.java
public static void writeBPMNDI(BpmnModel model, XMLStreamWriter xtw) throws Exception { // BPMN DI information xtw.writeStartElement(BPMNDI_PREFIX, ELEMENT_DI_DIAGRAM, BPMNDI_NAMESPACE); String processId = null;/*from w w w . j av a2 s .com*/ if (model.getPools().size() > 0) { processId = "Collaboration"; } else { processId = model.getMainProcess().getId(); } xtw.writeAttribute(ATTRIBUTE_ID, "BPMNDiagram_" + processId); xtw.writeStartElement(BPMNDI_PREFIX, ELEMENT_DI_PLANE, BPMNDI_NAMESPACE); xtw.writeAttribute(ATTRIBUTE_DI_BPMNELEMENT, processId); xtw.writeAttribute(ATTRIBUTE_ID, "BPMNPlane_" + processId); for (String elementId : model.getLocationMap().keySet()) { if (model.getFlowElement(elementId) != null || model.getArtifact(elementId) != null || model.getPool(elementId) != null || model.getLane(elementId) != null) { xtw.writeStartElement(BPMNDI_PREFIX, ELEMENT_DI_SHAPE, BPMNDI_NAMESPACE); xtw.writeAttribute(ATTRIBUTE_DI_BPMNELEMENT, elementId); xtw.writeAttribute(ATTRIBUTE_ID, "BPMNShape_" + elementId); GraphicInfo graphicInfo = model.getGraphicInfo(elementId); FlowElement flowElement = model.getFlowElement(elementId); if (flowElement instanceof SubProcess && graphicInfo.getExpanded() != null) { xtw.writeAttribute(ATTRIBUTE_DI_IS_EXPANDED, String.valueOf(graphicInfo.getExpanded())); } xtw.writeStartElement(OMGDC_PREFIX, ELEMENT_DI_BOUNDS, OMGDC_NAMESPACE); xtw.writeAttribute(ATTRIBUTE_DI_HEIGHT, "" + graphicInfo.getHeight()); xtw.writeAttribute(ATTRIBUTE_DI_WIDTH, "" + graphicInfo.getWidth()); xtw.writeAttribute(ATTRIBUTE_DI_X, "" + graphicInfo.getX()); xtw.writeAttribute(ATTRIBUTE_DI_Y, "" + graphicInfo.getY()); xtw.writeEndElement(); xtw.writeEndElement(); } } for (String elementId : model.getFlowLocationMap().keySet()) { if (model.getFlowElement(elementId) != null || model.getArtifact(elementId) != null) { xtw.writeStartElement(BPMNDI_PREFIX, ELEMENT_DI_EDGE, BPMNDI_NAMESPACE); xtw.writeAttribute(ATTRIBUTE_DI_BPMNELEMENT, elementId); xtw.writeAttribute(ATTRIBUTE_ID, "BPMNEdge_" + elementId); List<GraphicInfo> graphicInfoList = model.getFlowLocationGraphicInfo(elementId); for (GraphicInfo graphicInfo : graphicInfoList) { xtw.writeStartElement(OMGDI_PREFIX, ELEMENT_DI_WAYPOINT, OMGDI_NAMESPACE); xtw.writeAttribute(ATTRIBUTE_DI_X, "" + graphicInfo.getX()); xtw.writeAttribute(ATTRIBUTE_DI_Y, "" + graphicInfo.getY()); xtw.writeEndElement(); } GraphicInfo labelGraphicInfo = model.getLabelGraphicInfo(elementId); FlowElement flowElement = model.getFlowElement(elementId); if (labelGraphicInfo != null && flowElement != null && StringUtils.isNotEmpty(flowElement.getName())) { xtw.writeStartElement(BPMNDI_PREFIX, ELEMENT_DI_LABEL, BPMNDI_NAMESPACE); xtw.writeStartElement(OMGDC_PREFIX, ELEMENT_DI_BOUNDS, OMGDC_NAMESPACE); xtw.writeAttribute(ATTRIBUTE_DI_HEIGHT, "" + labelGraphicInfo.getHeight()); xtw.writeAttribute(ATTRIBUTE_DI_WIDTH, "" + labelGraphicInfo.getWidth()); xtw.writeAttribute(ATTRIBUTE_DI_X, "" + labelGraphicInfo.getX()); xtw.writeAttribute(ATTRIBUTE_DI_Y, "" + labelGraphicInfo.getY()); xtw.writeEndElement(); xtw.writeEndElement(); } xtw.writeEndElement(); } } // end BPMN DI elements xtw.writeEndElement(); xtw.writeEndElement(); }
From source file:org.activiti.bpmn.converter.export.FailedJobRetryCountExport.java
public static void writeFailedJobRetryCount(Activity activity, XMLStreamWriter xtw) throws Exception { String failedJobRetryCycle = activity.getFailedJobRetryTimeCycleValue(); if (failedJobRetryCycle != null) { if (StringUtils.isNotEmpty(failedJobRetryCycle)) { xtw.writeStartElement(ACTIVITI_EXTENSIONS_PREFIX, FAILED_JOB_RETRY_TIME_CYCLE, ACTIVITI_EXTENSIONS_NAMESPACE); xtw.writeCharacters(failedJobRetryCycle); xtw.writeEndElement();//ww w .j ava 2 s . com } } }
From source file:org.activiti.designer.export.bpmn20.export.CallActivityExport.java
private static void writeParameter(IOParameter parameter, String name, XMLStreamWriter xtw) throws Exception { xtw.writeStartElement(ACTIVITI_EXTENSIONS_PREFIX, name, ACTIVITI_EXTENSIONS_NAMESPACE); if (StringUtils.isNotEmpty(parameter.getSourceExpression())) { xtw.writeAttribute("sourceExpression", parameter.getSourceExpression()); } else if (StringUtils.isNotEmpty(parameter.getSource())) { xtw.writeAttribute("source", parameter.getSource()); }//from w w w.j a v a 2s. co m if (StringUtils.isNotEmpty(parameter.getTargetExpression())) { xtw.writeAttribute("targetExpression", parameter.getTargetExpression()); } else if (StringUtils.isNotEmpty(parameter.getTarget())) { xtw.writeAttribute("target", parameter.getTarget()); } xtw.writeEndElement(); }