Example usage for javax.xml.stream XMLStreamWriter writeEndElement

List of usage examples for javax.xml.stream XMLStreamWriter writeEndElement

Introduction

In this page you can find the example usage for javax.xml.stream XMLStreamWriter writeEndElement.

Prototype

public void writeEndElement() throws XMLStreamException;

Source Link

Document

Writes an end tag to the output relying on the internal state of the writer to determine the prefix and local name of the event.

Usage

From source file:org.deegree.services.sos.SOSController.java

private void doGetFeatureOfInterest(GetFeatureOfInterest foi, HttpResponseBuffer response)
        throws IOException, XMLStreamException {
    XMLStreamWriter xmlWriter = response.getXMLWriter();

    List<String> foiIDs = Arrays.asList(foi.getFoiID());

    xmlWriter.writeStartElement(SA_PREFIX, "SamplingFeatureCollection", SA_NS);
    xmlWriter.writeNamespace(SA_PREFIX, SA_NS);
    xmlWriter.writeNamespace(XSI_PREFIX, XSINS);
    xmlWriter.writeNamespace(XLINK_PREFIX, XLNNS);
    xmlWriter.writeNamespace(GML_PREFIX, GMLNS);

    xmlWriter.writeAttribute(XSI_PREFIX, XSINS, "schemaLocation",
            "http://www.opengis.net/sampling/1.0 http://schemas.opengis.net/sampling/1.0.0/sampling.xsd");

    // TODO a url should be specified in the xlink:href of sampledFeature
    xmlWriter.writeEmptyElement(SA_PREFIX, "sampledFeature", SA_NS);

    for (Offering offering : sosService.getAllOfferings()) {
        for (Procedure procedure : offering.getProcedures()) {
            if (foiIDs.contains(procedure.getFeatureOfInterestHref())) {
                Geometry procGeometry = procedure.getLocation();
                if (procGeometry instanceof Point) { // TODO check if the procedure can have some other geometries
                    // and if so,
                    // handle them

                    xmlWriter.writeStartElement(SA_PREFIX, "member", SA_NS);

                    xmlWriter.writeStartElement(SA_PREFIX, "SamplingPoint", SA_NS);
                    xmlWriter.writeStartElement(GML_PREFIX, "name", GMLNS);
                    xmlWriter.writeCharacters(procedure.getFeatureOfInterestHref());
                    // TODO if the GetFeatureOfInterest does not provide a foi but a location instead, search
                    // for all
                    // sensors
                    // inside that BBOX
                    xmlWriter.writeEndElement();

                    // TODO a url should be specified in the xlink:href of sampledFeature
                    xmlWriter.writeEmptyElement(SA_PREFIX, "sampledFeature", SA_NS);

                    xmlWriter.writeStartElement(SA_PREFIX, "position", SA_NS);
                    // exporting a gml:Point TODO use GML encoder
                    xmlWriter.writeStartElement(GML_PREFIX, "Point", GMLNS);
                    // have the last part of the foiID as the Point id attribute
                    String[] foiParts = procedure.getFeatureOfInterestHref().split(":");
                    xmlWriter.writeAttribute(GML_PREFIX, GMLNS, "id", foiParts[foiParts.length - 1]);

                    xmlWriter.writeStartElement(GML_PREFIX, "pos", GMLNS);
                    ICRS foiCRS = null;/*from  w  w  w.  j  a  va  2  s.  c  om*/
                    foiCRS = procGeometry.getCoordinateSystem();
                    xmlWriter.writeAttribute("srsName", foiCRS.getCode().toString());

                    Point p = (Point) procGeometry;
                    xmlWriter.writeCharacters(p.get0() + " " + p.get1());
                    xmlWriter.writeEndElement(); // gml:pos
                    xmlWriter.writeEndElement(); // gml:Point
                    xmlWriter.writeEndElement(); // gml:position
                    xmlWriter.writeEndElement(); // sa:SamplingPoint
                    xmlWriter.writeEndElement(); // sa:member
                }
            }
        }
    }

    xmlWriter.writeEndElement(); // sa:SamplingFeatureCollection
    xmlWriter.writeEndDocument();
    xmlWriter.flush();
}

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  ava2  s  .co  m
 * @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
}

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());
        }//w w  w  .  j  a  v  a 2 s .co  m
        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());
    }/*from w w  w. ja  v a  2s. c  om*/

    // "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 exportBoundingBoxInput(XMLStreamWriter writer, BoundingBoxInput input)
        throws XMLStreamException {

    // "wps:Data" element
    writer.writeStartElement(WPS_NS, "Data");

    // "wps:BoundingBoxData" element
    writer.writeStartElement(WPS_NS, "BoundingBoxData");
    OWSCommonXMLAdapter.exportBoundingBoxType(writer, input.getValue());
    writer.writeEndElement();

    writer.writeEndElement();/*from w  w w .  j a v a  2  s.co m*/
}

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  w w.  j a v a 2s  . c om
        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());
        }/*ww w.  jav a2  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 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());
    }/*www  . j a  va  2s  .  com*/
    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.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();
    }//ww  w.ja v a  2  s.  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 exportProcessOutputs(XMLStreamWriter writer, ProcessletOutputs outputs,
        List<RequestedOutput> requestedOutputs) throws XMLStreamException {

    LOG.debug("Exporting process outputs");

    // "wps:ProcessOutputs" element
    writer.writeStartElement(WPS_NS, "ProcessOutputs");

    for (RequestedOutput requestedOutput : requestedOutputs) {
        LOG.debug("- exporting " + requestedOutput.getIdentifier());
        ProcessletOutput output = outputs.getParameter(requestedOutput.getIdentifier());
        exportOutput(writer, (ProcessletOutputImpl) output, requestedOutput);
    }//from  w w  w  . ja  v  a  2 s . com

    writer.writeEndElement();
}