List of usage examples for javax.xml.stream XMLStreamWriter writeAttribute
public void writeAttribute(String localName, String value) throws XMLStreamException;
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 ww w. j a va2s . c om*/ // 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(); }
From source file:org.deegree.services.csw.exporthandling.GetCapabilitiesHandler.java
private void exportOperationsMetadata(XMLStreamWriter writer, String get, String post, String owsNS) throws XMLStreamException { writer.writeStartElement(owsNS, "OperationsMetadata"); if (isTransactionEnabled && !supportedOperations.contains(CSWRequestType.Transaction.name())) { supportedOperations.add(CSWRequestType.Transaction.name()); }//w w w . jav a 2 s.com for (String name : supportedOperations) { writer.writeStartElement(owsNS, "Operation"); writer.writeAttribute("name", name); exportDCP(writer, get, post, owsNS); if (name.equals(GetCapabilities.name())) { gcHelper.writeGetCapabilitiesParameters(writer, owsNS); } else if (name.equals(DescribeRecord.name())) { gcHelper.writeDescribeRecordParameters(writer, owsNS, typeNames, schemaOutputFormats, "XMLSCHEMA"); } else if (name.equals(GetRecords.name())) { gcHelper.writeGetRecordsParameters(writer, owsNS, typeNames, dataOutputFormats, outputSchemas, elementSetNames); writeGetRecordsConstraints(writer, owsNS); } else if (name.equals(GetRecordById.name())) { gcHelper.writeGetRecordByIdParameters(writer, owsNS, dataOutputFormats, outputSchemas); } writer.writeEndElement();// Operation } // if xPathQueryables are allowed than this should be set // writer.writeStartElement( owsNS, "Constraint" ); // writer.writeAttribute( "name", "XPathQueryables" ); // // writer.writeStartElement( owsNS, "Value" ); // writer.writeCharacters( "allowed" ); // writer.writeEndElement();// Value // // writer.writeEndElement();// Constraint writer.writeStartElement(owsNS, "Constraint"); writer.writeAttribute("name", "IsoProfiles"); writer.writeStartElement(owsNS, "Value"); writer.writeCharacters(CSWConstants.GMD_NS); writer.writeEndElement();// Value writer.writeEndElement();// Constraint // if XML and/or SOAP is supported writer.writeStartElement(owsNS, "Constraint"); writer.writeAttribute("name", "PostEncoding"); writer.writeStartElement(owsNS, "Value"); writer.writeCharacters("XML"); writer.writeEndElement();// Value writer.writeStartElement(owsNS, "Value"); writer.writeCharacters("SOAP"); writer.writeEndElement();// Value writer.writeEndElement();// Constraint InputStream extCapabilites = null; if (extendedCapabilities != null) { try { extCapabilites = extendedCapabilities.openStream(); } catch (IOException e) { LOG.warn("Could not open stream for extended capabilities. Ignore it!"); } } // additional inspire queryables if (this.isEnabledInspireExtension && extCapabilites == null) { extCapabilites = GetCapabilitiesHandler.class.getResourceAsStream("extendedCapInspire.xml"); } gcHelper.exportExtendedCapabilities(writer, owsNS, extCapabilites, varToValue); if (extCapabilites != null) { IOUtils.closeQuietly(extCapabilites); } writer.writeEndElement();// OperationsMetadata }
From source file:org.deegree.services.csw.exporthandling.GetCapabilitiesHandler.java
private void writeGetRecordsConstraints(XMLStreamWriter writer, String owsNS) throws XMLStreamException { writer.writeStartElement(owsNS, "Parameter"); writer.writeAttribute("name", "CONSTRAINTLANGUAGE"); writer.writeStartElement(owsNS, "Value"); writer.writeCharacters("Filter"); writer.writeEndElement();// Value writer.writeEndElement();// Parameter writer.writeStartElement(owsNS, "Constraint"); writer.writeAttribute("name", "SupportedISOQueryables"); for (String s : isoQueryables) { writer.writeStartElement(owsNS, "Value"); writer.writeCharacters(s);//from w w w .java2 s . co m writer.writeEndElement();// Value } writer.writeEndElement();// Constraint writer.writeStartElement(owsNS, "Constraint"); writer.writeAttribute("name", "AdditionalQueryables"); for (String val : additionalQueryables) { writeElement(writer, owsNS, "Value", val); } writer.writeEndElement();// Constraint }
From source file:org.deegree.services.csw.exporthandling.GetCapabilitiesHelper.java
/** * Writes the parameter and attributes for the mandatory DescribeRecord operation to the output. * /* w w w. j av a 2s. c o m*/ * @param writer * to write the output * @param owsNS * the OWS namespace * @throws XMLStreamException */ public void writeDescribeRecordParameters(XMLStreamWriter writer, String owsNS, String[] typeNames, String[] outputFormats, String schemaLanguage) throws XMLStreamException { if (typeNames != null && typeNames.length > 0) { writer.writeStartElement(owsNS, "Parameter"); writer.writeAttribute("name", "typeName"); for (String typeName : typeNames) { writeValue(writer, owsNS, typeName); } writer.writeEndElement();// Parameter } writeOutputFormat(writer, owsNS, outputFormats); writer.writeStartElement(owsNS, "Parameter"); writer.writeAttribute("name", "schemaLanguage"); writeValue(writer, owsNS, schemaLanguage); writer.writeEndElement();// Parameter }
From source file:org.deegree.services.csw.exporthandling.GetCapabilitiesHelper.java
private void writeOutputFormat(XMLStreamWriter writer, String owsNS, String[] outputFormats) throws XMLStreamException { writer.writeStartElement(owsNS, "Parameter"); writer.writeAttribute("name", "outputFormat"); for (String outputFormat : outputFormats) { writeValue(writer, owsNS, outputFormat); }//from www.j av a2s . c om writer.writeEndElement();// Parameter }
From source file:org.deegree.services.csw.exporthandling.GetCapabilitiesHelper.java
/** * Writes the parameter and attributes for the mandatory GetCapabilities operation to the output. * /*from w w w . j av a 2s. c o m*/ * @param writer * to write the output * @param owsNS * the OWS namespace * @throws XMLStreamException */ public void writeGetCapabilitiesParameters(XMLStreamWriter writer, String owsNS) throws XMLStreamException { writer.writeStartElement(owsNS, "Parameter"); writer.writeAttribute("name", "sections"); for (String value : parameterValues) { writer.writeStartElement(owsNS, "Value"); writer.writeCharacters(value); writer.writeEndElement();// Value } writer.writeEndElement();// Parameter // Constraints... }
From source file:org.deegree.services.csw.exporthandling.GetCapabilitiesHelper.java
/** * Writes the parameter and attributes for the mandatory GetRecords operation to the output. * // w ww.jav a 2s. com * @param writer * @param owsNS * @param typeNames * the typeNames to write * @param outputFormats * the outputFormats to write * @param outputSchemas * the outputSchemas to write * @param elementSetNames * the elementSetNames to write, if null this parameter will be ignored, can be <code>null</code> * @throws XMLStreamException */ public void writeGetRecordsParameters(XMLStreamWriter writer, String owsNS, String[] typeNames, String[] outputFormats, String[] outputSchemas, String[] elementSetNames) throws XMLStreamException { writer.writeStartElement(owsNS, "Parameter"); writer.writeAttribute("name", "typeNames"); for (String typeName : typeNames) { writeValue(writer, owsNS, typeName); } writer.writeEndElement();// Parameter writeOutputFormat(writer, owsNS, outputFormats); writer.writeStartElement(owsNS, "Parameter"); writer.writeAttribute("name", "outputSchema"); for (String outputSchema : outputSchemas) { writeValue(writer, owsNS, outputSchema); } writer.writeEndElement();// Parameter writer.writeStartElement(owsNS, "Parameter"); writer.writeAttribute("name", "resultType"); writeValue(writer, owsNS, "hits"); writeValue(writer, owsNS, "results"); writeValue(writer, owsNS, "validate"); writer.writeEndElement();// Parameter if (elementSetNames != null && elementSetNames.length > 0) { writer.writeStartElement(owsNS, "Parameter"); writer.writeAttribute("name", "ElementSetName"); for (String elementSetName : elementSetNames) { writeValue(writer, owsNS, elementSetName); } writer.writeEndElement();// Parameter } }
From source file:org.deegree.services.csw.exporthandling.GetCapabilitiesHelper.java
/** * Writes the parameter and attributes for the mandatory GetRecordById operation to the output.<br> * In this case the optional transaction operation uses this writing to the output, as well. * /*www .j a v a 2s . c o m*/ * @param writer * @param owsNS * @param outputFormats * the outpurFormats to write * @param outputSchemas * the outputSChemas to write * @throws XMLStreamException */ public void writeGetRecordByIdParameters(XMLStreamWriter writer, String owsNS, String[] outputFormats, String[] outputSchemas) throws XMLStreamException { writeOutputFormat(writer, owsNS, outputFormats); writer.writeStartElement(owsNS, "Parameter"); writer.writeAttribute("name", "outputSchema"); for (String outputSchema : outputSchemas) { writeValue(writer, owsNS, outputSchema); } writer.writeEndElement(); // Parameter }
From source file:org.deegree.services.csw.exporthandling.GetCapabilitiesHelper.java
private void writeTemplateElement(XMLStreamWriter writer, XMLStreamReader inStream, Map<String, String> varToValue) throws XMLStreamException { if (inStream.getEventType() != XMLStreamConstants.START_ELEMENT) { throw new XMLStreamException("Input stream does not point to a START_ELEMENT event."); }//from www . j av a 2s . c o m int openElements = 0; boolean firstRun = true; while (firstRun || openElements > 0) { firstRun = false; int eventType = inStream.getEventType(); switch (eventType) { case CDATA: { writer.writeCData(inStream.getText()); break; } case CHARACTERS: { String s = new String(inStream.getTextCharacters(), inStream.getTextStart(), inStream.getTextLength()); // TODO optimize for (String param : varToValue.keySet()) { String value = varToValue.get(param); s = s.replace(param, value); } writer.writeCharacters(s); break; } case END_ELEMENT: { writer.writeEndElement(); openElements--; break; } case START_ELEMENT: { if (inStream.getNamespaceURI() == "" || inStream.getPrefix() == DEFAULT_NS_PREFIX || inStream.getPrefix() == null) { writer.writeStartElement(inStream.getLocalName()); } else { if (writer.getNamespaceContext().getPrefix(inStream.getPrefix()) == "") { // TODO handle special cases for prefix binding, see // http://download.oracle.com/docs/cd/E17409_01/javase/6/docs/api/javax/xml/namespace/NamespaceContext.html#getNamespaceURI(java.lang.String) writer.setPrefix(inStream.getPrefix(), inStream.getNamespaceURI()); } writer.writeStartElement(inStream.getPrefix(), inStream.getLocalName(), inStream.getNamespaceURI()); } // copy all namespace bindings for (int i = 0; i < inStream.getNamespaceCount(); i++) { String nsPrefix = inStream.getNamespacePrefix(i); String nsURI = inStream.getNamespaceURI(i); writer.writeNamespace(nsPrefix, nsURI); } // copy all attributes for (int i = 0; i < inStream.getAttributeCount(); i++) { String localName = inStream.getAttributeLocalName(i); String nsPrefix = inStream.getAttributePrefix(i); String value = inStream.getAttributeValue(i); String nsURI = inStream.getAttributeNamespace(i); if (nsURI == null) { writer.writeAttribute(localName, value); } else { writer.writeAttribute(nsPrefix, nsURI, localName, value); } } openElements++; break; } default: { break; } } if (openElements > 0) { inStream.next(); } } }
From source file:org.deegree.services.wps.execute.ExecuteResponseXMLWriter.java
/** * Exports an {@link ExecuteResponse} object as a WPS 1.0.0 ExecuteResponse document. * /*from w ww . j av a2 s . com*/ * @param writer * writer where the XML is written to * @param response * object to be exported * @throws XMLStreamException */ public static void export100(XMLStreamWriter writer, ExecuteResponse response) throws XMLStreamException { // "wps:ExecuteResponse" (minOccurs="1", maxOccurs="1") writer.writeStartElement(WPS_PREFIX, "ExecuteResponse", WPS_NS); writer.writeNamespace(WPS_PREFIX, WPS_NS); writer.writeNamespace(OWS_PREFIX, OWS_NS); writer.writeNamespace(OGC_PREFIX, OGC_NS); writer.writeNamespace("xlink", XLN_NS); writer.writeNamespace("xsi", XSI_NS); writer.writeAttribute("service", "WPS"); writer.writeAttribute("version", "1.0.0"); writer.writeAttribute("xml:lang", "en"); writer.writeAttribute(XSI_NS, "schemaLocation", "http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsExecute_response.xsd"); // "serviceInstance" attribute (required) writer.writeAttribute("serviceInstance", response.getServiceInstance().toString()); // "statusLocation" attribute (optional) if (response.getStatusLocation() != null) { writer.writeAttribute("statusLocation", "" + response.getStatusLocation().getWebURL()); } // "wps:Process" element (minOccurs="1",maxOccurs="1") exportProcess(writer, response.getProcessDefinition()); // "wps:Status" element (minOccurs="1",maxOccurs="1") exportStatus(writer, response.getExecutionStatus()); // include inputs and output requests in the response? if (response.getLineage()) { // "wps:DataInputs" element (minOccurs="0",maxOccurs="1") exportDataInputs(writer, response); // "wps:OutputDefinitions" element (minOccurs="0",maxOccurs="1") exportOutputDefinitions(writer, response); } // "wps:ProcessOutputs" element (minOccurs="0",maxOccurs="1") if (response.getExecutionStatus().getExecutionState() == ExecutionState.SUCCEEDED) { // if process has finished successfully, include "wps:ProcessOutputs" element exportProcessOutputs(writer, response.getProcessOutputs(), response.getOutputDefinitions()); } writer.writeEndElement(); // ExecuteResponse }