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.wps.execute.ExecuteResponseXMLWriter.java
private static void exportDataInputs(XMLStreamWriter writer, ExecuteResponse response) throws XMLStreamException { // "wps:DataInputs" (minOccurs="0", maxOccurs="1") writer.writeStartElement(WPS_NS, "DataInputs"); for (ProcessletInput input : response.getDataInputs().getParameters()) { // "wps:Input" (minOccurs="1", maxOccurs="1") writer.writeStartElement(WPS_NS, "Input"); // "ows:Identifier" (minOccurs="1", maxOccurs="1") writer.writeStartElement(OWS_NS, "Identifier"); if (input.getIdentifier().getCodeSpace() != null) { writer.writeAttribute("codeSpace", input.getIdentifier().getCodeSpace()); }/*from ww w . j av a 2 s .c om*/ writer.writeCharacters(input.getIdentifier().getCode()); writer.writeEndElement(); // "ows:Title" (minOccurs="0", maxOccurs="1") if (input.getTitle() != null) { writer.writeStartElement(OWS_NS, "Title"); if (input.getTitle().getLanguage() != null) { writer.writeAttribute("xml:lang", input.getTitle().getLanguage()); } writer.writeCharacters(input.getTitle().getString()); writer.writeEndElement(); } // "ows:Abstract" (minOccurs="0", maxOccurs="1") if (input.getAbstract() != null) { writer.writeStartElement(OWS_NS, "Abstract"); if (input.getAbstract().getLanguage() != null) { writer.writeAttribute("xml:lang", input.getAbstract().getLanguage()); } writer.writeCharacters(input.getAbstract().getString()); writer.writeEndElement(); } if (input instanceof LiteralInput) { exportLiteralInput(writer, (LiteralInput) input); } else if (input instanceof BoundingBoxInput) { exportBoundingBoxInput(writer, (BoundingBoxInput) input); } else if (input instanceof ComplexInput) { exportComplexInput(writer, (ComplexInput) input); } writer.writeEndElement(); } writer.writeEndElement(); }
From source file:org.deegree.services.wps.execute.ExecuteResponseXMLWriter.java
private static void exportLiteralInput(XMLStreamWriter writer, LiteralInput input) throws XMLStreamException { // "wps:Data" element writer.writeStartElement(WPS_NS, "Data"); // "wps:LiteralData" element writer.writeStartElement(WPS_NS, "LiteralData"); // "dataType" attribute (optional) if (input.getDataType() != null) { writer.writeAttribute("dataType", input.getDataType()); }/* w ww.j a v a2 s . c o m*/ // "uom" attribute (optional) if (input.getUOM() != null) { writer.writeAttribute("uom", input.getUOM()); } writer.writeCharacters(input.getValue()); writer.writeEndElement(); writer.writeEndElement(); }
From source file:org.deegree.services.wps.execute.ExecuteResponseXMLWriter.java
private static void exportComplexInput(XMLStreamWriter writer, ComplexInput input) throws XMLStreamException { if (input instanceof EmbeddedComplexInput) { writer.writeStartElement(WPS_NS, "Data"); XMLStreamReader reader = ((EmbeddedComplexInput) input).getComplexDataAsXMLStream(); // copy "wps:ComplexData" element writeElement(writer, reader);/*from w ww . j ava 2 s .c o m*/ writer.writeEndElement(); } else if (input instanceof ReferencedComplexInput) { writer.writeStartElement(WPS_NS, "Reference"); ReferencedComplexInput referencedInput = (ReferencedComplexInput) input; // "mimeType" attribute (optional) if (referencedInput.getMimeType() != null) { writer.writeAttribute("mimeType", referencedInput.getMimeType()); } // "encoding" attribute (optional) if (referencedInput.getEncoding() != null) { writer.writeAttribute("encoding", referencedInput.getEncoding()); } // "schema" attribute (optional) if (referencedInput.getSchema() != null) { writer.writeAttribute("schema", referencedInput.getSchema()); } // "xlink:href" attribute (required) writer.writeAttribute(XLN_NS, "href", "" + referencedInput.getURL()); writer.writeEndElement(); } }
From source file:org.deegree.services.wps.execute.ExecuteResponseXMLWriter.java
private static void exportOutputDefinitions(XMLStreamWriter writer, ExecuteResponse response) throws XMLStreamException { // "wps:OutputDefinitions" (minOccurs="0", maxOccurs="1") writer.writeStartElement(WPS_NS, "OutputDefinitions"); // request must contain a response document (otherwise lineage could not be true) ResponseDocument responseDoc = (ResponseDocument) response.getRequest().getResponseForm(); for (RequestedOutput output : responseDoc.getOutputDefinitions()) { // "ows:Output" (minOccurs="1", maxOccurs="unbounded") writer.writeStartElement(WPS_NS, "Output"); // "asReference" attribute (optional) writer.writeAttribute("asReference", "" + output.getAsReference()); // "uom" attribute (optional) if (output.getUom() != null) { writer.writeAttribute("uom", output.getUom()); }/*from w w w . j a va 2 s .c o m*/ // "mimeType" attribute (optional) if (output.getMimeType() != null) { writer.writeAttribute("mimeType", output.getMimeType()); } // "encoding" attribute (optional) if (output.getEncoding() != null) { writer.writeAttribute("encoding", output.getEncoding()); } // "schema" attribute (optional) if (output.getSchemaURL() != null) { writer.writeAttribute("schema", "" + output.getSchemaURL()); } // "ows:Identifier" (minOccurs="1", maxOccurs="1") writer.writeStartElement(OWS_NS, "Identifier"); if (output.getIdentifier().getCodeSpace() != null) { writer.writeAttribute("codeSpace", output.getIdentifier().getCodeSpace()); } writer.writeCharacters(output.getIdentifier().getCode()); writer.writeEndElement(); // "ows:Title" (minOccurs="0", maxOccurs="1") if (output.getTitle() != null) { writer.writeStartElement(OWS_NS, "Title"); if (output.getTitle().getLanguage() != null) { writer.writeAttribute("xml:lang", output.getTitle().getLanguage()); } writer.writeCharacters(output.getTitle().getString()); writer.writeEndElement(); } // "ows:Abstract" (minOccurs="0", maxOccurs="1") if (output.getAbstract() != null) { writer.writeStartElement(OWS_NS, "Abstract"); if (output.getAbstract().getLanguage() != null) { writer.writeAttribute("xml:lang", output.getAbstract().getLanguage()); } writer.writeCharacters(output.getAbstract().getString()); writer.writeEndElement(); } writer.writeEndElement(); } writer.writeEndElement(); }
From source file:org.deegree.services.wps.execute.ExecuteResponseXMLWriter.java
private static void exportStatus(XMLStreamWriter writer, ProcessExecution state) throws XMLStreamException { writer.writeStartElement(WPS_NS, "Status"); // "creationTime" attribute (mandatory) long creationTime = state.getFinishTime(); if (creationTime == -1) { // use creation time of document if process execution has not been finished yet creationTime = System.currentTimeMillis(); }/* w w w. ja v a 2s .c o m*/ writer.writeAttribute("creationTime", ISO8601Converter.formatDateTime(new Date(creationTime))); switch (state.getExecutionState()) { case ACCEPTED: writeElement(writer, WPS_NS, "ProcessAccepted", state.getAcceptedMessage()); break; case STARTED: writer.writeStartElement(WPS_NS, "ProcessStarted"); writer.writeAttribute("percentCompleted", "" + state.getPercentCompleted()); if (state.getStartMessage() != null) { writer.writeCharacters(state.getStartMessage()); } writer.writeEndElement(); break; case PAUSED: writer.writeStartElement(WPS_NS, "ProcessPaused"); writer.writeAttribute("percentCompleted", "" + state.getPercentCompleted()); if (state.getPauseMessage() != null) { writer.writeCharacters(state.getPauseMessage()); } writer.writeEndElement(); break; case SUCCEEDED: writeElement(writer, WPS_NS, "ProcessSucceeded", state.getSucceededMessage()); break; case FAILED: writer.writeStartElement(WPS_NS, "ProcessFailed"); OWS110ExceptionReportSerializer exceptionAdapter = new OWS110ExceptionReportSerializer(VERSION_100); exceptionAdapter.serializeExceptionToXML(writer, state.getFailedException()); writer.writeEndElement(); break; } writer.writeEndElement(); }
From source file:org.deegree.services.wps.execute.ExecuteResponseXMLWriter.java
private static void exportOutput(XMLStreamWriter writer, ProcessletOutputImpl output, RequestedOutput requestedOutput) throws XMLStreamException { // "wps:Output" element writer.writeStartElement(WPS_NS, "Output"); ProcessletOutputDefinition outputType = output.getDefinition(); // "ows:Identifier" (minOccurs="1", maxOccurs="1") writer.writeStartElement(OWS_NS, "Identifier"); if (outputType.getIdentifier().getCodeSpace() != null) { writer.writeAttribute("codeSpace", outputType.getIdentifier().getCodeSpace()); }//from www . j a v a 2 s . c om writer.writeCharacters(outputType.getIdentifier().getValue()); writer.writeEndElement(); // "ows:Title" (minOccurs="1", maxOccurs="1") if (outputType.getTitle() != null) { writer.writeStartElement(OWS_NS, "Title"); if (outputType.getTitle().getLang() != null) { writer.writeAttribute("xml:lang", outputType.getTitle().getLang()); } writer.writeCharacters(outputType.getTitle().getValue()); writer.writeEndElement(); } // "ows:Abstract" (minOccurs="0", maxOccurs="1") if (outputType.getAbstract() != null) { writer.writeStartElement(OWS_NS, "Abstract"); if (outputType.getAbstract().getLang() != null) { writer.writeAttribute("xml:lang", outputType.getAbstract().getLang()); } writer.writeCharacters(outputType.getAbstract().getValue()); writer.writeEndElement(); } // "ows:Metadata" (minOccurs="0", maxOccurs="unbounded") if (outputType.getMetadata() != null) { for (ProcessletOutputDefinition.Metadata metadata : outputType.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(); } } // choice: "wps:Reference" or "wps:Data" (minOccurs="1", maxOccurs="1") // (ignore asReference for Literal or BoundingBoxOutput) if (!requestedOutput.getAsReference() || output instanceof BoundingBoxOutputImpl || output instanceof LiteralOutputImpl) { writer.writeStartElement(WPS_NS, "Data"); if (output instanceof BoundingBoxOutputImpl) { exportBoundingBoxOutput(writer, (BoundingBoxOutputImpl) output); } else if (output instanceof LiteralOutputImpl) { exportLiteralOutput(writer, (LiteralOutputImpl) output); } else if (output instanceof ComplexOutputImpl) { exportComplexOutput(writer, (ComplexOutputImpl) output); } writer.writeEndElement(); } else { writer.writeStartElement(WPS_NS, "Reference"); String href = null; String mimeType = null; if (output instanceof ComplexOutputImpl) { ComplexOutputImpl complexOutput = (ComplexOutputImpl) output; href = complexOutput.getWebURL(); mimeType = complexOutput.getRequestedMimeType(); } if (mimeType == null) { LOG.warn("No mime type info available -> text/xml"); mimeType = "text/xml"; } writer.writeAttribute("href", "" + href); writer.writeAttribute("mimeType", mimeType); writer.writeEndElement(); } writer.writeEndElement(); }
From source file:org.deegree.services.wps.execute.ExecuteResponseXMLWriter.java
private static void exportLiteralOutput(XMLStreamWriter writer, LiteralOutputImpl output) throws XMLStreamException { // "wps:LiteralData" element writer.writeStartElement(WPS_NS, "LiteralData"); // "dataType" attribute (optional) if (output.getDataType() != null) { writer.writeAttribute("dataType", output.getDataType()); }/*from www. ja v a 2 s . c om*/ // "uom" attribute (optional) if (output.getRequestedUOM() != null) { writer.writeAttribute("uom", output.getRequestedUOM()); } writer.writeCharacters(output.getValue()); writer.writeEndElement(); }
From source file:org.deegree.services.wps.execute.ExecuteResponseXMLWriter.java
private static void exportXMLOutput(XMLStreamWriter writer, ComplexOutputImpl output) throws XMLStreamException { // "wps:ComplexData" element writer.writeStartElement(WPS_NS, "ComplexData"); String mimeType = output.getRequestedMimeType(); if (mimeType != null) { writer.writeAttribute("mimeType", mimeType); }/*from ww w . j a v a2 s .c o m*/ String schema = output.getRequestedSchema(); if (schema != null) { writer.writeAttribute("schema", schema); } // NOTE: Providing the encoding attribute doesn't make any sense for inline XML output (always defined by the // surrounding document) XMLStreamReader reader = output.getStreamReader(); // skip start document event // apadberg: the following line was necessary when Axiom 1.2.8 is used, // it is commented out because of revised behavior in Axiom 1.2.9 if (reader.getEventType() == XMLStreamConstants.START_DOCUMENT) { reader.next(); } if (reader.getEventType() == XMLStreamConstants.START_ELEMENT) { XMLAdapter.writeElement(writer, reader); } else { LOG.warn("No element in XMLOutput found, skipping it in response document."); } writer.writeEndElement(); }
From source file:org.deegree.services.wps.execute.ExecuteResponseXMLWriter.java
private static void exportBinaryOutput(XMLStreamWriter writer, ComplexOutputImpl output) throws XMLStreamException { // "wps:ComplexData" element writer.writeStartElement(WPS_NS, "ComplexData"); String mimeType = output.getRequestedMimeType(); if (mimeType != null) { writer.writeAttribute("mimeType", mimeType); }/*from w w w. jav a 2s .com*/ LOG.warn("TODO Handle other encodings. Using fixed encoding: base64."); writer.writeAttribute("encoding", "base64"); ByteArrayOutputStream os = new ByteArrayOutputStream(); InputStream is = output.getInputStream(); byte[] buffer = new byte[1024]; int bytesRead = 0; try { while ((bytesRead = is.read(buffer)) != -1) { os.write(buffer, 0, bytesRead); } os.flush(); os.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } byte[] binary = os.toByteArray(); String base64 = Base64.encodeBase64String(binary); writer.writeCharacters(base64); writer.writeEndElement(); }
From source file:org.deegree.tools.services.wms.FeatureTypesToLayerTree.java
/** * @param args//from www . ja v a2 s . co m */ public static void main(String[] args) { Options options = initOptions(); // for the moment, using the CLI API there is no way to respond to a help argument; see // https://issues.apache.org/jira/browse/CLI-179 if (args.length == 0 || (args.length > 0 && (args[0].contains("help") || args[0].contains("?")))) { CommandUtils.printHelp(options, FeatureTypesToLayerTree.class.getSimpleName(), null, null); } XMLStreamWriter out = null; try { CommandLine line = new PosixParser().parse(options, args); String storeFile = line.getOptionValue("f"); String nm = new File(storeFile).getName(); String storeId = nm.substring(0, nm.length() - 4); FileOutputStream os = new FileOutputStream(line.getOptionValue("o")); XMLOutputFactory fac = XMLOutputFactory.newInstance(); out = new IndentingXMLStreamWriter(fac.createXMLStreamWriter(os)); out.setDefaultNamespace(ns); Workspace ws = new DefaultWorkspace(new File("nix")); ws.initAll(); DefaultResourceIdentifier<FeatureStore> identifier = new DefaultResourceIdentifier<FeatureStore>( FeatureStoreProvider.class, "unknown"); ws.add(new DefaultResourceLocation<FeatureStore>(new File(storeFile), identifier)); ws.prepare(identifier); FeatureStore store = ws.init(identifier, null); AppSchema schema = store.getSchema(); // prepare document out.writeStartDocument(); out.writeStartElement(ns, "deegreeWMS"); out.writeDefaultNamespace(ns); out.writeAttribute("configVersion", "0.5.0"); out.writeNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance"); out.writeAttribute("http://www.w3.org/2001/XMLSchema-instance", "schemaLocation", "http://www.deegree.org/services/wms http://schemas.deegree.org/wms/0.5.0/wms_configuration.xsd"); out.writeStartElement(ns, "ServiceConfiguration"); HashSet<FeatureType> visited = new HashSet<FeatureType>(); if (schema.getRootFeatureTypes().length == 1) { writeLayer(visited, out, schema.getRootFeatureTypes()[0], storeId); } else { out.writeCharacters("\n"); out.writeStartElement(ns, "UnrequestableLayer"); XMLAdapter.writeElement(out, ns, "Title", "Root Layer"); for (FeatureType ft : schema.getRootFeatureTypes()) { writeLayer(visited, out, ft, storeId); } out.writeEndElement(); out.writeCharacters("\n"); } out.writeEndElement(); out.writeEndElement(); out.writeEndDocument(); } catch (ParseException exp) { System.err.println(Messages.getMessage("TOOL_COMMANDLINE_ERROR", exp.getMessage())); CommandUtils.printHelp(options, FeatureTypesToLayerTree.class.getSimpleName(), null, null); } catch (ResourceInitException e) { LOG.info("The feature store could not be loaded: '{}'", e.getLocalizedMessage()); LOG.trace("Stack trace:", e); } catch (FileNotFoundException e) { LOG.info("A file could not be found: '{}'", e.getLocalizedMessage()); LOG.trace("Stack trace:", e); } catch (XMLStreamException e) { LOG.info("The XML output could not be written: '{}'", e.getLocalizedMessage()); LOG.trace("Stack trace:", e); } catch (FactoryConfigurationError e) { LOG.info("The XML system could not be initialized: '{}'", e.getLocalizedMessage()); LOG.trace("Stack trace:", e); } finally { if (out != null) { try { out.close(); } catch (XMLStreamException e) { LOG.trace("Stack trace:", e); } } } }