Example usage for javax.xml.stream XMLStreamWriter writeEmptyElement

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

Introduction

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

Prototype

public void writeEmptyElement(String prefix, String localName, String namespaceURI) throws XMLStreamException;

Source Link

Document

Writes an empty element tag to the output

Usage

From source file:org.maodian.flyingcat.xmpp.state.DefaultElementVisitor.java

@Override
public State handleTLS(XmppContext xmppCtx, TLS tls) throws XMLStreamException {
    ChannelHandlerContext ctx = xmppCtx.getNettyChannelHandlerContext();
    SSLEngine engine = SecureSslContextFactory.getServerContext().createSSLEngine();
    engine.setUseClientMode(false);/*from w w w  .  j av a2  s  .  c  om*/
    SslHandler sslHandler = new SslHandler(engine, true);
    sslHandler.sslCloseFuture().addListener(new ChannelFutureListener() {

        @Override
        public void operationComplete(ChannelFuture future) throws Exception {
            log.info("Close the socket since SSL connection has been closed by client");
            future.channel().close();
        }
    });
    ctx.pipeline().addFirst("ssl", sslHandler);

    StringWriter writer = new StringWriter();
    XMLStreamWriter xmlsw = XMLOutputFactoryHolder.getXMLOutputFactory().createXMLStreamWriter(writer);
    xmlsw.writeEmptyElement("", "proceed", XmppNamespace.TLS);
    xmlsw.setPrefix("", XmppNamespace.TLS);
    xmlsw.writeNamespace("", XmppNamespace.TLS);
    xmlsw.writeEndDocument();
    xmppCtx.flush(writer.toString());
    return xmppCtx.getGlobalContext().getTlsStreamState();
}

From source file:org.maodian.flyingcat.xmpp.codec.RosterCodec.java

@Override
public void encode(Object object, XMLStreamWriter xmlsw) throws XMLStreamException {
    Roster roster = (Roster) object;/*from  w w w . ja v a2 s. c  om*/
    xmlsw.writeStartElement("", "query", XmppNamespace.ROSTER);
    xmlsw.writeDefaultNamespace(XmppNamespace.ROSTER);
    writeAttributeIfNotBlank(xmlsw, "ver", roster.getVersion());
    for (Contact c : roster) {
        xmlsw.writeEmptyElement("", "item", XmppNamespace.ROSTER);
        writeRequiredAttribute(xmlsw, "jid", c.getJabberId());
        writeAttributeIfNotBlank(xmlsw, "name", c.getName());
        writeAttributeIfNotBlank(xmlsw, "subscription", c.getSubscription());
        writeAttributeIfNotBlank(xmlsw, "ask", c.getAsk());
    }
    xmlsw.writeEndElement();
}

From source file:org.maodian.flyingcat.xmpp.extensions.xep0030.QueryInfoCodec.java

@Override
public void encode(Object object, XMLStreamWriter xmlsw) throws XMLStreamException {
    xmlsw.writeStartElement("", "query", ServiceDiscovery.INFORMATION);
    xmlsw.writeDefaultNamespace(ServiceDiscovery.INFORMATION);

    QueryInfo qi = (QueryInfo) object;/*  ww  w  .  j  av  a2s .co m*/
    List<Identity> identityList = qi.getIdentityList();
    for (Identity identity : identityList) {
        xmlsw.writeEmptyElement("", "identity", ServiceDiscovery.INFORMATION);
        xmlsw.writeAttribute("category", identity.getCategory());
        xmlsw.writeAttribute("type", identity.getType());
    }

    List<Feature> featureList = qi.getFeatureList();
    for (Feature feature : featureList) {
        xmlsw.writeEmptyElement(ServiceDiscovery.INFORMATION, "feature");
        xmlsw.writeAttribute("var", feature.getVar());
    }
}

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;//w ww .j  a va  2 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();
}