Example usage for javax.xml.stream XMLStreamWriter writeCharacters

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

Introduction

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

Prototype

public void writeCharacters(String text) throws XMLStreamException;

Source Link

Document

Write text to the output

Usage

From source file:org.deegree.protocol.wps.client.wps100.ExecuteRequest100Writer.java

private void writePoint(XMLStreamWriter writer, double[] coords) throws XMLStreamException {
    String s = "";
    for (int i = 0; i < coords.length; i++) {
        s += coords[i];/*from   w  w  w  .j  a v a 2 s  .  c  o m*/
        if (i != coords.length - 1) {
            s += " ";
        }
    }
    writer.writeCharacters(s);
}

From source file:org.deegree.services.csw.exporthandling.EbrimGetCapabilitiesHandler.java

protected void exportOperationsMetadata(XMLStreamWriter writer, String get, String post, String owsNS)
        throws XMLStreamException {
    writer.writeStartElement(owsNS, "OperationsMetadata");

    for (String name : supportedOperations) {
        if (!name.equals(CSWRequestType.GetRepositoryItem.name())) {
            writer.writeStartElement(owsNS, "Operation");
            writer.writeAttribute("name", name);
            exportDCP(writer, get, post, owsNS);
            if (name.equals(CSWRequestType.GetCapabilities.name())) {
                writeParam(owsNS, "AcceptVersions", "2.0.2", "1.0.0");
                gcHelper.writeGetCapabilitiesParameters(writer, owsNS);
                writer.writeEndElement();// Operation
            } else if (name.equals(CSWRequestType.DescribeRecord.name())) {
                writeParam(owsNS, "version", "2.0.2", "1.0.0");
                gcHelper.writeDescribeRecordParameters(writer, owsNS, null, outputFormats, schemaLang);
                writeParam(owsNS, "typeNames", "csw:Record", "rim:RegistryPackage", "rim:ExtrinsicObject",
                        "rim:RegistryObject");
                writer.writeEndElement();// Operation
            } else if (name.equals(CSWRequestType.GetRecords.name())) {
                writeParam(owsNS, "version", "2.0.2", "1.0.0");
                gcHelper.writeGetRecordsParameters(writer, owsNS,
                        new String[] { "csw:Record", "rim:RegistryPackage", "rim:ExtrinsicObject",
                                "rim:RegistryObject" },
                        outputFormats, new String[] { "urn:oasis:names:tc:ebxml-regrep:xsd:rim:3.0" }, null);
                writeParam(owsNS, "CONSTRAINTLANGUAGE", "FILTER");
                writeParam(owsNS, "ElementSetName", "brief", "summary", "full");
                writer.writeEndElement();// Operation
            } else if (name.equals(CSWRequestType.GetRecordById.name())) {
                writeParam(owsNS, "version", "2.0.2", "1.0.0");
                gcHelper.writeGetRecordByIdParameters(writer, owsNS, outputFormats,
                        new String[] { EbrimProfile.RIM_NS });
                writeParam(owsNS, "TypeName", "csw:Record", "rim:RegistryPackage", "rim:ExtrinsicObject",
                        "rim:RegistryObject");
                writer.writeEndElement();// Operation
                // } else if ( name.equals( CSWebRIMRequestType.GetRepositoryItem.name() ) ) {
                // writeParam( owsNS, "version", "2.0.2", "1.0.0" );
                // writer.writeEndElement();// Operation
            }//ww w.ja v  a  2s. com
        }
    }
    writeParam(owsNS, "service", EbrimProfile.SERVICENAME_CSW, EbrimProfile.SERVICENAME_CSW_EBRIM,
            EbrimProfile.SERVICENAME_WRS);
    // 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

    writer.writeStartElement(owsNS, "Constraint");
    writer.writeAttribute("name", "srsName");
    writer.writeStartElement(owsNS, "Value");
    writer.writeCharacters("urn:ogc:def:crs:EPSG:4326");
    writer.writeEndElement();// Value
    writer.writeStartElement(owsNS, "Metadata");
    writer.writeAttribute(CommonNamespaces.XLNNS, "type", "simple");
    writer.writeAttribute(CommonNamespaces.XLNNS, "title", "EPSG geodetic parameters");
    writer.writeAttribute(CommonNamespaces.XLNNS, "href", "http://www.epsg-registry.org/");
    writer.writeEndElement();// Metadata
    writer.writeEndElement();// Constraint

    if (extendedCapabilities != null) {
        InputStream extCapabilites = null;
        try {
            extCapabilites = extendedCapabilities.openStream();
            gcHelper.exportExtendedCapabilities(writer, owsNS, extCapabilites, null);
        } catch (IOException e) {
            LOG.warn("Could not open stream for extended capabilities. Ignore it!");
        } finally {
            IOUtils.closeQuietly(extCapabilites);
        }
    }

    writer.writeEndElement();// OperationsMetadata
}

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());
    }//from   w  ww  . jav a 2  s.  co  m

    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 www .j av a2 s.  c  om
        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 GetCapabilities operation to the output.
 * /*  www.  j  a  v  a 2 s  . 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

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  w w  w . java  2s  .c om
    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.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  ww  w  . java2 s .  c o  m
                    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

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 ww. j ava2s .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());
    }/*w w w  .j a v  a 2s.  co 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 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.ja  va2 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();
}