List of usage examples for javax.xml.stream XMLStreamWriter writeStartElement
public void writeStartElement(String prefix, String localName, String namespaceURI) throws XMLStreamException;
From source file:org.asimba.wa.integrationtest.saml2.model.Response.java
protected void writeStatus(XMLStreamWriter writer) throws XMLStreamException { writer.writeStartElement("saml2p", "Status", "urn:oasis:names:tc:SAML:2.0:protocol"); writer.writeStartElement("saml2p", "StatusCode", "urn:oasis:names:tc:SAML:2.0:protocol"); writer.writeAttribute("Value", _statusCode); writer.writeEndElement();//from w ww.j a v a 2s . c o m writer.writeEndElement(); }
From source file:org.asimba.wa.integrationtest.saml2.model.Response.java
/** * Build response based on current state.<br/> * Only do Base64-encoding of the XML-document -- no deflating whatsoever may be done. * /*from w ww . j a va 2s . c o m*/ * @return * @throws XMLStreamException */ public String getResponse(int format) throws XMLStreamException { _logger.info("For ID: " + getId()); ByteArrayOutputStream baos = new ByteArrayOutputStream(); StringWriter sw = new StringWriter(); XMLOutputFactory factory = XMLOutputFactory.newInstance(); XMLStreamWriter writer = null; // ugly but effective: if (format == base64) { writer = factory.createXMLStreamWriter(baos); } else { writer = factory.createXMLStreamWriter(sw); } writer.writeStartElement("saml2p", "Response", "urn:oasis:names:tc:SAML:2.0:protocol"); writer.writeNamespace("saml2p", "urn:oasis:names:tc:SAML:2.0:protocol"); writer.writeNamespace("xs", "http://www.w3.org/2001/XMLSchema"); writer.writeAttribute("Destination", _destination); writer.writeAttribute("ID", _id); writer.writeAttribute("InResponseTo", _inResponseTo); writer.writeAttribute("IssueInstant", _issueInstant); writer.writeAttribute("Version", "2.0"); writeIssuer(writer); writeStatus(writer); _assertion.writeAssertion(writer); writer.writeEndElement(); // SAML2 writer.flush(); if (format == base64) { byte[] bain = baos.toByteArray(); byte[] encoded = Base64.encodeBase64(bain, false); String result = new String(encoded, Charset.forName("UTF-8")); return result; } else { return sw.toString(); } }
From source file:org.corpus_tools.salt.util.internal.persistence.SaltXML10Writer.java
/** * Writes a salt project to the xml stream. * //from w ww . j av a 2s .co m * @param xml * A pre-configured {@link XMLStreamWriter} * @param project */ public void writeSaltProject(XMLStreamWriter xml, SaltProject project) { try { xml.writeStartElement(NS_SALTCOMMON, TAG_SALT_PROJECT, NS_VALUE_SALTCOMMON); xml.writeNamespace(NS_SCORPUSSTRUCTURE, NS_VALUE_SCORPUSSTRUCTURE); xml.writeNamespace(NS_XMI, NS_VALUE_XMI); xml.writeNamespace(NS_XSI, NS_VALUE_XSI); xml.writeNamespace(NS_SALTCORE, NS_VALUE_SALTCORE); xml.writeNamespace(NS_SALTCOMMON, NS_VALUE_SALTCOMMON); xml.writeAttribute(NS_VALUE_XMI, ATT_XMI_VERSION, "2.0"); Iterator<SCorpusGraph> cGraphs = project.getCorpusGraphs().iterator(); while (cGraphs.hasNext()) { if (isPrettyPrint) { xml.writeCharacters("\n"); xml.writeCharacters("\t"); } writeCorpusGraph(xml, cGraphs.next(), true); } if (isPrettyPrint) { xml.writeCharacters("\n"); } xml.writeEndElement(); } catch (XMLStreamException e) { throw new SaltResourceException("Cannot store salt project to file '" + getLocationStr() + "'. ", e); } }
From source file:org.corpus_tools.salt.util.internal.persistence.SaltXML10Writer.java
/** * Writes a corpus graph to the xml stream * //from ww w . j a va 2 s. c om * @param graph * the corpus graph to be written * @param embedded * determines whether this corpus graph is part of a saltProject * @param xml * xml stream to write corpus graph to, if the passed one is * null, a new one will be created */ public void writeCorpusGraph(XMLStreamWriter xml, SCorpusGraph graph, boolean embedded) { try { if (!embedded) { xml.writeStartDocument("1.0"); if (isPrettyPrint) { xml.writeCharacters("\n"); xml.writeStartElement(NS_SALTCOMMON, TAG_SCORPUSGRAPH, NS_VALUE_SALTCOMMON); xml.writeNamespace(NS_SCORPUSSTRUCTURE, NS_VALUE_SCORPUSSTRUCTURE); xml.writeNamespace(NS_XMI, NS_VALUE_XMI); xml.writeNamespace(NS_XSI, NS_VALUE_XSI); xml.writeNamespace(NS_SALTCORE, NS_VALUE_SALTCORE); xml.writeNamespace(NS_SALTCOMMON, NS_VALUE_SALTCOMMON); xml.writeAttribute(NS_VALUE_XMI, ATT_XMI_VERSION, "2.0"); } } else { xml.writeStartElement(TAG_SCORPUSGRAPH); } // write all labels if (graph.getLabels() != null) { Iterator<Label> labelIt = graph.getLabels().iterator(); while (labelIt.hasNext()) { if (isPrettyPrint) { xml.writeCharacters("\n"); xml.writeCharacters("\t"); } writeLabel(xml, labelIt.next()); } } // stores the position of a single node in the list of nodes to // refer them in a relation Map<SNode, Integer> nodePositions = new HashMap<>(); // write all nodes if (graph.getNodes() != null) { Iterator<SNode> nodeIt = graph.getNodes().iterator(); Integer position = 0; while (nodeIt.hasNext()) { SNode node = nodeIt.next(); writeNode(xml, node, null); nodePositions.put(node, position); position++; } } // write all relations if (graph.getRelations() != null) { Iterator<SRelation<SNode, SNode>> relIt = graph.getRelations().iterator(); while (relIt.hasNext()) { SRelation<SNode, SNode> rel = relIt.next(); writeRelation(xml, rel, nodePositions, null); } } if (isPrettyPrint) { xml.writeCharacters("\n"); xml.writeCharacters("\t"); } xml.writeEndElement(); } catch (XMLStreamException e) { throw new SaltResourceException( "Cannot store salt project to file '" + getLocationStr() + "'. " + e.getMessage(), e); } finally { if (!embedded) { if (xml != null) { try { xml.flush(); xml.close(); } catch (XMLStreamException e) { throw new SaltResourceException("Cannot store salt project to file '" + getLocationStr() + "', because the opened stream is not closable. ", e); } } } } }
From source file:org.corpus_tools.salt.util.internal.persistence.SaltXML10Writer.java
/** * Writes a document graph to the xml stream. * //from w ww.j av a2 s .c om * @param xml * A pre-configured {@link XMLStreamWriter} * @param graph */ public void writeDocumentGraph(XMLStreamWriter xml, SDocumentGraph graph) { try { xml.writeStartElement(NS_SDOCUMENTSTRUCTURE, TAG_SDOCUMENTSTRUCTURE_SDOCUMENTGRAPH, NS_VALUE_SDOCUMENTSTRUCTURE); 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"); // write all labels Iterator<Label> labelIt = graph.getLabels().iterator(); while (labelIt.hasNext()) { if (isPrettyPrint) { xml.writeCharacters("\n"); xml.writeCharacters("\t"); } writeLabel(xml, labelIt.next()); } // stores the position of a single layer in the list of layers to // refer them in a relation Map<SLayer, Integer> layerPositions = new HashMap<>(); Iterator<SLayer> layerIt = graph.getLayers().iterator(); Integer position = 0; while (layerIt.hasNext()) { layerPositions.put(layerIt.next(), position); position++; } // stores the position of a single node in the list of nodes to // refer them in a relation Map<SNode, Integer> nodePositions = new HashMap<>(); // write all nodes Iterator<SNode> nodeIt = graph.getNodes().iterator(); position = 0; while (nodeIt.hasNext()) { SNode node = nodeIt.next(); writeNode(xml, node, layerPositions); nodePositions.put(node, position); position++; } // stores the position of a single relation in the list of relations // to refer them later Map<SRelation<SNode, SNode>, Integer> relPositions = new HashMap<>(); { // write all relations Iterator<SRelation<SNode, SNode>> relIt = graph.getRelations().iterator(); position = 0; while (relIt.hasNext()) { SRelation<SNode, SNode> rel = relIt.next(); writeRelation(xml, rel, nodePositions, layerPositions); relPositions.put(rel, position); position++; } } // write layers layerIt = graph.getLayers().iterator(); while (layerIt.hasNext()) { writeLayer(xml, layerIt.next(), nodePositions, relPositions); } if (isPrettyPrint) { xml.writeCharacters("\n"); } xml.writeEndElement(); } catch (XMLStreamException e) { throw new SaltResourceException("Cannot store document graph to file '" + getLocationStr() + "'. ", e); } }
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 w w . java2 s . com * @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 .jav a2s . 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 . c om*/ 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.csw.exporthandling.EbrimGetCapabilitiesHandler.java
private void export(XMLStreamWriter writer, Set<Sections> sections, ServiceIdentificationType identification, ServiceProviderType provider) throws XMLStreamException { writer.writeStartElement(WRS_PREFIX, "Capabilities", WRS_NS); writer.writeNamespace(WRS_PREFIX, WRS_NS); writer.writeNamespace(OWS_PREFIX, OWS_NS); writer.writeNamespace(OGC_PREFIX, OGCNS); writer.writeNamespace(XLINK_PREFIX, XLN_NS); writer.writeNamespace(XSINS, XSI_PREFIX); writer.writeAttribute("version", "2.0.2"); writer.writeAttribute("schemaLocation", WRS_NS + " " + WRS_SCHEMA, XSINS); // ows:ServiceIdentification if (sections.isEmpty() || sections.contains(Sections.ServiceIdentification)) { gcHelper.exportServiceIdentification(writer, identification, "urn:ogc:serviceType:CatalogueService:2.0.2:HTTP:ebRIM", "2.0.2", "http://www.opengeospatial.org/ogcna"); }//from w w w .ja v a 2 s . c om // ows:ServiceProvider if (sections.isEmpty() || sections.contains(Sections.ServiceProvider)) { exportServiceProvider100Old(writer, provider); } // ows:OperationsMetadata if (sections.isEmpty() || sections.contains(Sections.OperationsMetadata)) { exportOperationsMetadata(writer, OGCFrontController.getHttpGetURL(), OGCFrontController.getHttpPostURL(), OWS_NS); } // mandatory FilterCapabilitiesExporter.export110(writer); writer.writeEndElement(); writer.writeEndDocument(); }
From source file:org.deegree.services.csw.exporthandling.GetCapabilitiesHandler.java
private void export202(XMLStreamWriter writer, Set<Sections> sections, ServiceIdentificationType identification, DeegreeServicesMetadataType mainControllerConf, DeegreeServiceControllerType mainConf) throws XMLStreamException { writer.writeStartElement(CSW_PREFIX, "Capabilities", CSW_202_NS); writer.writeNamespace(CSW_PREFIX, CSW_202_NS); writer.writeNamespace(OWS_PREFIX, OWS_NS); writer.writeNamespace(OGC_PREFIX, OGCNS); writer.writeNamespace(XLINK_PREFIX, XLN_NS); writer.writeNamespace(XSI_PREFIX, XSINS); writer.writeAttribute("version", "2.0.2"); writer.writeAttribute(XSINS, "schemaLocation", CSW_202_NS + " " + CSW_202_DISCOVERY_SCHEMA); // ows:ServiceIdentification if (sections.isEmpty() || sections.contains(Sections.ServiceIdentification)) { gcHelper.exportServiceIdentification(writer, identification, "CSW", "2.0.2", null); }//from www. j a va 2 s . co m // ows:ServiceProvider if (sections.isEmpty() || sections.contains(Sections.ServiceProvider)) { exportServiceProvider100Old(writer, mainControllerConf.getServiceProvider()); } // ows:OperationsMetadata if (sections.isEmpty() || sections.contains(Sections.OperationsMetadata)) { exportOperationsMetadata(writer, OGCFrontController.getHttpGetURL(), OGCFrontController.getHttpPostURL(), OWS_NS); } // mandatory FilterCapabilitiesExporter.export110(writer); writer.writeEndElement(); writer.writeEndDocument(); }