List of usage examples for javax.xml.stream XMLStreamWriter writeAttribute
public void writeAttribute(String namespaceURI, String localName, String value) throws XMLStreamException;
From source file:org.corpus_tools.salt.util.internal.persistence.SaltXML10Writer.java
/** * Writes the passed relation object to the passed {@link XMLStreamWriter}. //from w ww . ja v a 2s .co m * @param layer * @param xml * stream to write data to * @param nodePositions * a map containing all positions of a single node in the list of * nodes * @param relPositions * a map containing all positions of a single relation in the * list of relations * @throws XMLStreamException */ public void writeLayer(XMLStreamWriter xml, Layer layer, Map<SNode, Integer> nodePositions, Map<SRelation<SNode, SNode>, Integer> relPositions) throws XMLStreamException { if (isPrettyPrint) { xml.writeCharacters("\n"); xml.writeCharacters("\t"); } xml.writeStartElement(TAG_LAYERS); // write type xml.writeAttribute(NS_VALUE_XSI, ATT_XSI_TYPE, "saltCore:SLayer"); // write nodes if (layer.getNodes().size() > 0) { StringBuilder nodeAtt = new StringBuilder(); Iterator<SNode> nodeIt = layer.getNodes().iterator(); boolean isFirst = true; while (nodeIt.hasNext()) { if (!isFirst) { nodeAtt.append(" "); } isFirst = false; nodeAtt.append("/"); if (writtenRootObjects != null) { // write full notation when there are multiple root objects in the file nodeAtt.append(writtenRootObjects.size()); } nodeAtt.append("/@nodes."); nodeAtt.append(nodePositions.get(nodeIt.next())); } xml.writeAttribute(ATT_NODES, nodeAtt.toString()); } // write relations if (layer.getRelations().size() > 0) { StringBuilder relAtt = new StringBuilder(); Iterator<SRelation<SNode, SNode>> relIt = layer.getRelations().iterator(); boolean isFirst = true; while (relIt.hasNext()) { if (!isFirst) { relAtt.append(" "); } isFirst = false; relAtt.append("//@edges."); relAtt.append(relPositions.get(relIt.next())); } xml.writeAttribute(ATT_EDGES, relAtt.toString()); } // write all labels Iterator<Label> labelIt = layer.getLabels().iterator(); while (labelIt.hasNext()) { if (isPrettyPrint) { xml.writeCharacters("\n"); xml.writeCharacters("\t"); xml.writeCharacters("\t"); } writeLabel(xml, labelIt.next()); } if (isPrettyPrint) { xml.writeCharacters("\n"); xml.writeCharacters("\t"); } xml.writeEndElement(); }
From source file:org.corpus_tools.salt.util.internal.persistence.SaltXML10Writer.java
/** * Writes an Salt XMI header to the {@link XMLStreamWriter}. * Salt XMI has a certain header structure (including the namespaces). * This helper function writes this header to an existing * {@link XMLStreamWriter}./* w ww .ja v a 2 s .c o m*/ * @param xml * @throws XMLStreamException */ public void writeXMIRootElement(XMLStreamWriter xml) throws XMLStreamException { xml.writeStartElement(NS_XMI, "XMI", NS_VALUE_XMI); xml.writeNamespace(NS_SDOCUMENTSTRUCTURE, NS_VALUE_SDOCUMENTSTRUCTURE); xml.writeNamespace(NS_XMI, NS_VALUE_XMI); xml.writeNamespace(NS_XSI, NS_VALUE_XSI); xml.writeNamespace(NS_SALTCORE, NS_VALUE_SALTCORE); xml.writeAttribute(NS_VALUE_XMI, ATT_XMI_VERSION, "2.0"); if (isPrettyPrint) { xml.writeCharacters("\n"); } }
From source file:org.deegree.services.controller.AbstractOWS.java
/** * Convenience method that may be used by controller implementations to produce OGC-SOAP responses. * <p>//from ww w. j ava 2 s . c o m * Performs the following actions using the given {@link HttpResponseBuffer}: * <ul> * <li>Sets the content type to <code>application/soap+xml</code></li> * <li>Opens <code>soapenv:Envelope</code> and <code>soapenv:Body</code> elements</li> * </ul> * </p> * <p> * After calling this method, the controller may simply write the normal OGC-XML response using the * {@link HttpResponseBuffer#getXMLWriter()} object and call {@link #endSOAPResponse(HttpResponseBuffer)} * afterwards. * </p> * * @see #endSOAPResponse(HttpResponseBuffer) * * @param response * @throws XMLStreamException * @throws IOException */ protected void beginSOAPResponse(HttpResponseBuffer response) throws XMLStreamException, IOException { response.setContentType("application/soap+xml"); XMLStreamWriter xmlWriter = response.getXMLWriter(); String soapEnvNS = "http://www.w3.org/2003/05/soap-envelope"; String xsiNS = "http://www.w3.org/2001/XMLSchema-instance"; xmlWriter.writeStartElement("soapenv", "Envelope", soapEnvNS); xmlWriter.writeNamespace("soapenv", soapEnvNS); xmlWriter.writeNamespace("xsi", xsiNS); xmlWriter.writeAttribute(xsiNS, "schemaLocation", "http://www.w3.org/2003/05/soap-envelope http://www.w3.org/2003/05/soap-envelope"); xmlWriter.writeStartElement(soapEnvNS, "Body"); }
From source file:org.deegree.services.csw.CSWController.java
@Override public void doSOAP(SOAPEnvelope soapDoc, HttpServletRequest request, HttpResponseBuffer response, List<FileItem> multiParts, SOAPFactory factory) throws OMException, ServletException { SOAPVersion version = soapDoc.getVersion(); try {//from w w w . j a va 2 s. co m if (version instanceof SOAP11Version) { response.setContentType("application/soap+xml"); XMLStreamWriter xmlWriter = response.getXMLWriter(); String soapEnvNS = "http://schemas.xmlsoap.org/soap/envelope/"; String xsiNS = "http://www.w3.org/2001/XMLSchema-instance"; xmlWriter.writeStartElement("soap", "Envelope", soapEnvNS); xmlWriter.writeNamespace("soap", soapEnvNS); xmlWriter.writeNamespace("xsi", xsiNS); xmlWriter.writeAttribute(xsiNS, "schemaLocation", "http://schemas.xmlsoap.org/soap/envelope/ http://schemas.xmlsoap.org/soap/envelope/"); xmlWriter.writeStartElement(soapEnvNS, "Body"); } else { beginSOAPResponse(response); } doXML(soapDoc.getBody().getFirstElement(), response); } catch (XMLStreamException e) { LOG.debug(e.getMessage(), e); sendSoapException(soapDoc, factory, response, new OWSException(e.getMessage(), e, NO_APPLICABLE_CODE), request, version); } catch (OWSException e) { LOG.debug(e.getMessage(), e); sendSoapException(soapDoc, factory, response, e, request, version); } catch (IOException e) { LOG.debug(e.getMessage(), e); sendSoapException(soapDoc, factory, response, new OWSException(e.getMessage(), e, NO_APPLICABLE_CODE), request, version); } catch (MissingParameterException e) { LOG.debug(e.getMessage(), e); sendSoapException(soapDoc, factory, response, new OWSException(e.getMessage(), e, MISSING_PARAMETER_VALUE), request, version); } catch (InvalidParameterValueException e) { LOG.debug(e.getMessage(), e); sendSoapException(soapDoc, factory, response, new OWSException(e.getMessage(), e, INVALID_PARAMETER_VALUE), request, version); } catch (FailedAuthentication e) { LOG.debug(e.getMessage(), e); sendSoapException(soapDoc, factory, response, new OWSException(e.getMessage(), e, NO_APPLICABLE_CODE), request, version); } catch (Throwable t) { String msg = "An unexpected error occured: " + t.getMessage(); LOG.debug(msg, t); sendSoapException(soapDoc, factory, response, new OWSException(msg, t, NO_APPLICABLE_CODE), request, version); } }
From source file:org.deegree.services.wfs.WebFeatureService.java
@Override public void doSOAP(SOAPEnvelope soapDoc, HttpServletRequest request, HttpResponseBuffer response, List<FileItem> multiParts, SOAPFactory factory) throws ServletException, IOException, org.deegree.services.authentication.SecurityException { LOG.debug("doSOAP"); if (disableBuffering) { super.doSOAP(soapDoc, request, response, multiParts, factory); return;//from w w w . ja v a2 s. com } Version requestVersion = null; try { if (soapDoc.getVersion() instanceof SOAP11Version) { response.setContentType("application/soap+xml"); XMLStreamWriter xmlWriter = response.getXMLWriter(); String soapEnvNS = "http://schemas.xmlsoap.org/soap/envelope/"; String xsiNS = "http://www.w3.org/2001/XMLSchema-instance"; xmlWriter.writeStartElement("soap", "Envelope", soapEnvNS); xmlWriter.writeNamespace("soap", soapEnvNS); xmlWriter.writeNamespace("xsi", xsiNS); xmlWriter.writeAttribute(xsiNS, "schemaLocation", "http://schemas.xmlsoap.org/soap/envelope/ http://schemas.xmlsoap.org/soap/envelope/"); xmlWriter.writeStartElement(soapEnvNS, "Body"); } else { beginSOAPResponse(response); } OMElement body = soapDoc.getBody().getFirstElement().cloneOMElement(); XMLStreamReader bodyXmlStream = body.getXMLStreamReaderWithoutCaching(); String requestName = body.getLocalName(); WFSRequestType requestType = getRequestTypeByName(requestName); // check if requested version is supported and offered (except for GetCapabilities) requestVersion = getVersion(body.getAttributeValue(new QName("version"))); if (requestType != WFSRequestType.GetCapabilities) { requestVersion = checkVersion(requestVersion); // needed for CITE 1.1.0 compliance String serviceAttr = body.getAttributeValue(new QName("service")); if (serviceAttr != null && !("WFS".equals(serviceAttr) || "".equals(serviceAttr))) { throw new OWSException("Wrong service attribute: '" + serviceAttr + "' -- must be 'WFS'.", INVALID_PARAMETER_VALUE, "service"); } } switch (requestType) { case CreateStoredQuery: CreateStoredQueryXMLAdapter createStoredQueryAdapter = new CreateStoredQueryXMLAdapter(); createStoredQueryAdapter.setRootElement(body); CreateStoredQuery createStoredQuery = createStoredQueryAdapter.parse(); storedQueryHandler.doCreateStoredQuery(createStoredQuery, response); break; case DescribeFeatureType: DescribeFeatureTypeXMLAdapter describeFtAdapter = new DescribeFeatureTypeXMLAdapter(); describeFtAdapter.setRootElement(body); DescribeFeatureType describeFt = describeFtAdapter.parse(); Format format = determineFormat(requestVersion, describeFt.getOutputFormat(), "outputFormat"); format.doDescribeFeatureType(describeFt, response, true); break; case DropStoredQuery: DropStoredQueryXMLAdapter dropStoredQueryAdapter = new DropStoredQueryXMLAdapter(); dropStoredQueryAdapter.setRootElement(body); DropStoredQuery dropStoredQuery = dropStoredQueryAdapter.parse(); storedQueryHandler.doDropStoredQuery(dropStoredQuery, response); break; case DescribeStoredQueries: DescribeStoredQueriesXMLAdapter describeStoredQueriesAdapter = new DescribeStoredQueriesXMLAdapter(); describeStoredQueriesAdapter.setRootElement(body); DescribeStoredQueries describeStoredQueries = describeStoredQueriesAdapter.parse(); storedQueryHandler.doDescribeStoredQueries(describeStoredQueries, response); break; case GetCapabilities: GetCapabilitiesXMLAdapter getCapabilitiesAdapter = new GetCapabilitiesXMLAdapter(); getCapabilitiesAdapter.setRootElement(body); GetCapabilities wfsRequest = getCapabilitiesAdapter.parse(requestVersion); doGetCapabilities(wfsRequest, response); break; case GetFeature: GetFeatureXMLAdapter getFeatureAdapter = new GetFeatureXMLAdapter(); getFeatureAdapter.setRootElement(body); GetFeature getFeature = getFeatureAdapter.parse(); format = determineFormat(requestVersion, getFeature.getPresentationParams().getOutputFormat(), "outputFormat"); format.doGetFeature(getFeature, response); break; case GetFeatureWithLock: checkTransactionsEnabled(requestName); GetFeatureWithLockXMLAdapter getFeatureWithLockAdapter = new GetFeatureWithLockXMLAdapter(); getFeatureWithLockAdapter.setRootElement(body); GetFeatureWithLock getFeatureWithLock = getFeatureWithLockAdapter.parse(); format = determineFormat(requestVersion, getFeatureWithLock.getPresentationParams().getOutputFormat(), "outputFormat"); format.doGetFeature(getFeatureWithLock, response); break; case GetGmlObject: GetGmlObjectXMLAdapter getGmlObjectAdapter = new GetGmlObjectXMLAdapter(); getGmlObjectAdapter.setRootElement(body); GetGmlObject getGmlObject = getGmlObjectAdapter.parse(); format = determineFormat(requestVersion, getGmlObject.getOutputFormat(), "outputFormat"); format.doGetGmlObject(getGmlObject, response); break; case GetPropertyValue: GetPropertyValueXMLAdapter getPropertyValueAdapter = new GetPropertyValueXMLAdapter(); getPropertyValueAdapter.setRootElement(body); GetPropertyValue getPropertyValue = getPropertyValueAdapter.parse(); format = determineFormat(requestVersion, getPropertyValue.getPresentationParams().getOutputFormat(), "outputFormat"); format.doGetPropertyValue(getPropertyValue, response); break; case ListStoredQueries: ListStoredQueriesXMLAdapter listStoredQueriesAdapter = new ListStoredQueriesXMLAdapter(); listStoredQueriesAdapter.setRootElement(body); ListStoredQueries listStoredQueries = listStoredQueriesAdapter.parse(); storedQueryHandler.doListStoredQueries(listStoredQueries, response); break; case LockFeature: checkTransactionsEnabled(requestName); LockFeatureXMLAdapter lockFeatureAdapter = new LockFeatureXMLAdapter(); lockFeatureAdapter.setRootElement(body); LockFeature lockFeature = lockFeatureAdapter.parse(); lockFeatureHandler.doLockFeature(lockFeature, response); break; case Transaction: checkTransactionsEnabled(requestName); TransactionXmlReader transactionReader = new TransactionXmlReaderFactory() .createReader(requestVersion); Transaction transaction = transactionReader.read(bodyXmlStream); new TransactionHandler(this, service, transaction, idGenMode).doTransaction(response); break; default: throw new RuntimeException("Internal error: Unhandled request '" + requestName + "'."); } endSOAPResponse(response); } catch (OWSException e) { LOG.debug(e.getMessage(), e); sendSoapException(soapDoc, factory, response, e, request, requestVersion); } catch (XMLParsingException e) { LOG.trace("Stack trace:", e); sendSoapException(soapDoc, factory, response, new OWSException(e.getMessage(), INVALID_PARAMETER_VALUE), request, requestVersion); } catch (MissingParameterException e) { LOG.trace("Stack trace:", e); sendSoapException(soapDoc, factory, response, new OWSException(e), request, requestVersion); } catch (InvalidParameterValueException e) { LOG.trace("Stack trace:", e); sendSoapException(soapDoc, factory, response, new OWSException(e), request, requestVersion); } catch (Throwable e) { LOG.trace("Stack trace:", e); sendSoapException(soapDoc, factory, response, new OWSException(e.getMessage(), NO_APPLICABLE_CODE), request, requestVersion); } }
From source file:org.deegree.services.wps.execute.ExecuteResponseXMLWriter.java
private static void exportProcess(XMLStreamWriter writer, ProcessDefinition process) throws XMLStreamException { // "wps:Process" (minOccurs="1", maxOccurs="1") writer.writeStartElement(WPS_NS, "Process"); writer.writeAttribute(WPS_NS, "processVersion", process.getProcessVersion()); // "ows:Identifier" (minOccurs="1", maxOccurs="1") writer.writeStartElement(OWS_NS, "Identifier"); if (process.getIdentifier().getCodeSpace() != null) { writer.writeAttribute("codeSpace", process.getIdentifier().getCodeSpace()); }// w w w .ja va 2 s . c o m writer.writeCharacters(process.getIdentifier().getValue()); writer.writeEndElement(); // "ows:Title" (minOccurs="1", maxOccurs="1") if (process.getTitle() != null) { writer.writeStartElement(OWS_NS, "Title"); if (process.getTitle().getLang() != null) { writer.writeAttribute("xml:lang", process.getTitle().getLang()); } writer.writeCharacters(process.getTitle().getValue()); writer.writeEndElement(); } // "ows:Abstract" (minOccurs="0", maxOccurs="1") if (process.getAbstract() != null) { writer.writeStartElement(OWS_NS, "Abstract"); if (process.getAbstract().getLang() != null) { writer.writeAttribute("xml:lang", process.getAbstract().getLang()); } writer.writeCharacters(process.getAbstract().getValue()); writer.writeEndElement(); } // "ows:Metadata" (minOccurs="0", maxOccurs="unbounded") if (process.getMetadata() != null) { for (Metadata metadata : process.getMetadata()) { writer.writeStartElement(OWS_NS, "Metadata"); if (metadata.getAbout() != null) { writer.writeAttribute("about", metadata.getAbout()); } if (metadata.getHref() != null) { writer.writeAttribute(XLN_NS, "href", metadata.getHref()); } writer.writeEndElement(); } } // "wps:Profile" (minOccurs="0", maxOccurs="unbounded") if (process.getProfile() != null) { for (String profile : process.getProfile()) { writeElement(writer, WPS_NS, "Profile", profile); } } // "wps:WSDL" (minOccurs="0", maxOccurs="unbounded") if (process.getWSDL() != null) { writeElement(writer, WPS_NS, "WSDL", XLN_NS, "href", process.getWSDL()); } writer.writeEndElement(); // wps:Process }
From source file:org.flowable.cmmn.converter.export.GenericEventListenerExport.java
@Override protected void writePlanItemDefinitionSpecificAttributes(GenericEventListener genericEventListener, XMLStreamWriter xtw) throws Exception { super.writePlanItemDefinitionSpecificAttributes(genericEventListener, xtw); if (StringUtils.isNotEmpty(genericEventListener.getAvailableConditionExpression())) { xtw.writeAttribute(FLOWABLE_EXTENSIONS_NAMESPACE, CmmnXmlConstants.ATTRIBUTE_EVENT_LISTENER_AVAILABLE_CONDITION, genericEventListener.getAvailableConditionExpression()); }/*w w w .j a v a 2 s. c o m*/ }
From source file:org.flowable.cmmn.converter.export.SignalEventListenerExport.java
@Override protected void writePlanItemDefinitionSpecificAttributes(SignalEventListener signalEventListener, XMLStreamWriter xtw) throws Exception { super.writePlanItemDefinitionSpecificAttributes(signalEventListener, xtw); xtw.writeAttribute(FLOWABLE_EXTENSIONS_NAMESPACE, CmmnXmlConstants.ATTRIBUTE_EVENT_LISTENER_TYPE, "signal"); if (StringUtils.isNotEmpty(signalEventListener.getSignalRef())) { xtw.writeAttribute(FLOWABLE_EXTENSIONS_NAMESPACE, CmmnXmlConstants.ATTRIBUTE_EVENT_LISTENER_SIGNAL_REF, signalEventListener.getSignalRef()); }/*from w w w . j a v a 2 s . c o m*/ if (StringUtils.isNotEmpty(signalEventListener.getAvailableConditionExpression())) { xtw.writeAttribute(FLOWABLE_EXTENSIONS_NAMESPACE, CmmnXmlConstants.ATTRIBUTE_EVENT_LISTENER_AVAILABLE_CONDITION, signalEventListener.getAvailableConditionExpression()); } }
From source file:org.osaf.cosmo.mc.CollectionService.java
public void writeTo(OutputStream out) throws IOException, XMLStreamException { XMLStreamWriter writer = XML_OUTPUT_FACTORY.createXMLStreamWriter(out); writer.setPrefix(PRE_XML, NS_XML);/*from w w w . j a va2 s.co m*/ writer.setDefaultNamespace(NS_MC); try { writer.writeStartDocument(); writer.writeStartElement(EL_MC_SERVICE); writer.writeDefaultNamespace(NS_MC); writer.writeAttribute(NS_XML, EL_XML_BASE, locator.getMorseCodeBase()); for (CollectionItem collection : collections) { writer.writeStartElement(EL_MC_COLLECTION); writer.writeAttribute(ATTR_MC_UUID, collection.getUid()); writer.writeAttribute(ATTR_MC_HREF, href(collection)); writer.writeStartElement(EL_MC_NAME); writer.writeCharacters(collection.getDisplayName()); writer.writeEndElement(); for (Ticket ticket : visibleTickets(collection)) { writer.writeStartElement(EL_MC_TICKET); writer.writeAttribute(ATTR_MC_TYPE, ticket.getType().toString()); writer.writeCharacters(ticket.getKey()); writer.writeEndElement(); } writer.writeEndElement(); } writer.writeEndElement(); writer.writeEndDocument(); } finally { writer.close(); } }