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.corpus_tools.salt.util.internal.persistence.SaltXML10Writer.java

/**
 * Writes the passed node object to the passed {@link XMLStreamWriter}.
 * /*from  ww w .  j  av  a  2 s  .  co m*/
 * @param node
 *            to be persist
 * @param xml
 *            stream to write data to
 * @param layerPositions
 * @throws XMLStreamException
 */
public void writeNode(XMLStreamWriter xml, Node node, Map<? extends Layer, Integer> layerPositions)
        throws XMLStreamException {
    if (isPrettyPrint) {
        xml.writeCharacters("\n");
        xml.writeCharacters("\t");
    }
    xml.writeStartElement(TAG_NODES);
    String type = "";
    // write type as attribute
    if (node instanceof STextualDS) {
        type = TYPE_STEXTUALDS;
    } else if (node instanceof STimeline) {
        type = TYPE_STIMELINE;
    } else if (node instanceof SMedialDS) {
        type = TYPE_SAUDIODS;
    } else if (node instanceof SToken) {
        type = TYPE_STOKEN;
    } else if (node instanceof SSpan) {
        type = TYPE_SSPAN;
    } else if (node instanceof SStructure) {
        type = TYPE_SSTRUCTURE;
    } else if (node instanceof SDocument) {
        type = TYPE_SDOCUMENT;
    } else if (node instanceof SCorpus) {
        type = TYPE_SCORPUS;
    }
    xml.writeAttribute(NS_VALUE_XSI, ATT_XSI_TYPE, type);

    // write layers
    if (node.getLayers().size() > 0) {
        StringBuilder layerAtt = new StringBuilder();
        Iterator<? extends Layer> layerIt = node.getLayers().iterator();
        boolean isFirst = true;
        while (layerIt.hasNext()) {
            if (!isFirst) {
                layerAtt.append(" ");
            }
            isFirst = false;
            layerAtt.append("/");
            if (writtenRootObjects != null) {
                layerAtt.append(writtenRootObjects.size());
            }
            layerAtt.append("/@layers.");
            layerAtt.append(layerPositions.get(layerIt.next()));
        }
        xml.writeAttribute(ATT_LAYERS, layerAtt.toString());
    }

    // write all labels
    Iterator<Label> labelIt = node.getLabels().iterator();
    while (labelIt.hasNext()) {
        if (isPrettyPrint) {
            xml.writeCharacters("\n");
            xml.writeCharacters("\t");
            xml.writeCharacters("\t");
        }
        writeLabel(xml, labelIt.next());
    }
    if (isPrettyPrint) {
        xml.writeCharacters("\n");
        xml.writeCharacters("\t");
    }
    xml.writeEndElement();
}

From source file:org.corpus_tools.salt.util.internal.persistence.SaltXML10Writer.java

/**
 * Writes the passed relation object to the passed {@link XMLStreamWriter}.
 * /*ww w  .  j  a v  a2s.  c  o  m*/
 * @param relation
 *            to be persist
 * @param xml
 *            stream to write data to
 * @param nodePositions
 *            a map containing all positions of nodes in the list of nodes
 * @param layerPositions
 * @throws XMLStreamException
 */
public void writeRelation(XMLStreamWriter xml, Relation relation, Map<? extends Node, Integer> nodePositions,
        Map<? extends Layer, Integer> layerPositions) throws XMLStreamException {
    if (isPrettyPrint) {
        xml.writeCharacters("\n");
        xml.writeCharacters("\t");
    }
    xml.writeStartElement(TAG_EDGES);

    // write type
    String type = "";
    if (relation instanceof STextualRelation) {
        type = TYPE_STEXTUAL_RELATION;
    } else if (relation instanceof STimelineRelation) {
        type = TYPE_STIMELINE_RELATION;
    } else if (relation instanceof SMedialRelation) {
        type = TYPE_SAUDIO_RELATION;
    } else if (relation instanceof SSpanningRelation) {
        type = TYPE_SSPANNING_RELATION;
    } else if (relation instanceof SDominanceRelation) {
        type = TYPE_SDOMINANCE_RELATION;
    } else if (relation instanceof SPointingRelation) {
        type = TYPE_SPOINTING_RELATION;
    } else if (relation instanceof SOrderRelation) {
        type = TYPE_SORDER_RELATION;
    } else if (relation instanceof SCorpusRelation) {
        type = TYPE_SCORPUS_RELATION;
    } else if (relation instanceof SCorpusDocumentRelation) {
        type = TYPE_SCORPUS_DOCUMENT_RELATION;
    }
    xml.writeAttribute(NS_VALUE_XSI, ATT_XSI_TYPE, type);
    int sourcePos = nodePositions.get(relation.getSource());
    int targetPos = nodePositions.get(relation.getTarget());
    if (writtenRootObjects == null) {
        // write shorcut notation if there is only one root object in the file
        xml.writeAttribute(ATT_SOURCE, "//@nodes." + sourcePos);
        xml.writeAttribute(ATT_TARGET, "//@nodes." + targetPos);
    } else {
        // write full notation when there are multiple root objects in the file
        int rootIndex = writtenRootObjects.size();
        xml.writeAttribute(ATT_SOURCE, "/" + rootIndex + "/@nodes." + sourcePos);
        xml.writeAttribute(ATT_TARGET, "/" + rootIndex + "/@nodes." + targetPos);
    }

    // write layers
    if (relation.getLayers().size() > 0) {
        StringBuilder layerAtt = new StringBuilder();
        Iterator<Layer> layerIt = relation.getLayers().iterator();
        boolean isFirst = true;
        while (layerIt.hasNext()) {
            if (!isFirst) {
                layerAtt.append(" ");
            }
            isFirst = false;
            layerAtt.append("/");
            if (writtenRootObjects != null) {
                // write full notation when there are multiple root objects in the file
                layerAtt.append(writtenRootObjects.size());
            }
            layerAtt.append("/@layers.");
            layerAtt.append(layerPositions.get(layerIt.next()));
        }
        xml.writeAttribute(ATT_LAYERS, layerAtt.toString());
    }

    // write all labels
    Iterator<Label> labelIt = relation.getLabels().iterator();
    while (labelIt.hasNext()) {
        if (isPrettyPrint) {
            xml.writeCharacters("\n");
            xml.writeCharacters("\t");
            xml.writeCharacters("\t");
        }
        writeLabel(xml, labelIt.next());
    }
    if (isPrettyPrint) {
        xml.writeCharacters("\n");
        xml.writeCharacters("\t");
    }
    xml.writeEndElement();
}

From source file:org.corpus_tools.salt.util.internal.persistence.SaltXML10Writer.java

/**
 * Writes the passed relation object to the passed {@link XMLStreamWriter}.
        /*from ww w. j  a va  2  s .  c  o m*/
 * @param layer
 * @param xml
 *            stream to write data to
 * @param nodePositions
 *            a map containing all positions of a single node in the list of
 *            nodes
 * @param relPositions
 *            a map containing all positions of a single relation in the
 *            list of relations
 * @throws XMLStreamException
 */
public void writeLayer(XMLStreamWriter xml, Layer layer, Map<SNode, Integer> nodePositions,
        Map<SRelation<SNode, SNode>, Integer> relPositions) throws XMLStreamException {
    if (isPrettyPrint) {
        xml.writeCharacters("\n");
        xml.writeCharacters("\t");
    }
    xml.writeStartElement(TAG_LAYERS);
    // write type
    xml.writeAttribute(NS_VALUE_XSI, ATT_XSI_TYPE, "saltCore:SLayer");

    // write nodes
    if (layer.getNodes().size() > 0) {
        StringBuilder nodeAtt = new StringBuilder();
        Iterator<SNode> nodeIt = layer.getNodes().iterator();
        boolean isFirst = true;
        while (nodeIt.hasNext()) {
            if (!isFirst) {
                nodeAtt.append(" ");
            }
            isFirst = false;
            nodeAtt.append("/");
            if (writtenRootObjects != null) {
                // write full notation when there are multiple root objects in the file
                nodeAtt.append(writtenRootObjects.size());
            }
            nodeAtt.append("/@nodes.");
            nodeAtt.append(nodePositions.get(nodeIt.next()));
        }
        xml.writeAttribute(ATT_NODES, nodeAtt.toString());
    }

    // write relations
    if (layer.getRelations().size() > 0) {
        StringBuilder relAtt = new StringBuilder();
        Iterator<SRelation<SNode, SNode>> relIt = layer.getRelations().iterator();
        boolean isFirst = true;
        while (relIt.hasNext()) {
            if (!isFirst) {
                relAtt.append(" ");
            }
            isFirst = false;
            relAtt.append("//@edges.");
            relAtt.append(relPositions.get(relIt.next()));
        }
        xml.writeAttribute(ATT_EDGES, relAtt.toString());
    }

    // write all labels
    Iterator<Label> labelIt = layer.getLabels().iterator();
    while (labelIt.hasNext()) {
        if (isPrettyPrint) {
            xml.writeCharacters("\n");
            xml.writeCharacters("\t");
            xml.writeCharacters("\t");
        }
        writeLabel(xml, labelIt.next());
    }
    if (isPrettyPrint) {
        xml.writeCharacters("\n");
        xml.writeCharacters("\t");
    }
    xml.writeEndElement();
}

From source file:org.corpus_tools.salt.util.VisJsVisualizer.java

private void writeHTML(File outputFolder) throws XMLStreamException, IOException {

    int nodeDist = 0;
    int sprLength = 0;
    double sprConstant = 0.0;

    try (OutputStream os = new FileOutputStream(new File(outputFolder, HTML_FILE));
            FileOutputStream fos = new FileOutputStream(tmpFile)) {
        XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
        XMLStreamWriter xmlWriter = outputFactory.createXMLStreamWriter(os, "UTF-8");

        setNodeWriter(os);/* w  w w  .j  a  va2 s. com*/
        setEdgeWriter(fos);

        xmlWriter.writeStartDocument("UTF-8", "1.0");
        xmlWriter.writeCharacters(NEWLINE);
        xmlWriter.writeStartElement(TAG_HTML);
        xmlWriter.writeCharacters(NEWLINE);

        xmlWriter.writeStartElement(TAG_HEAD);
        xmlWriter.writeCharacters(NEWLINE);

        xmlWriter.writeStartElement(TAG_TITLE);
        xmlWriter.writeCharacters("Salt Document Tree");
        xmlWriter.writeEndElement();
        xmlWriter.writeCharacters(NEWLINE);

        xmlWriter.writeStartElement(TAG_STYLE);
        xmlWriter.writeAttribute(ATT_TYPE, "text/css");
        xmlWriter.writeCharacters(NEWLINE);
        xmlWriter.writeCharacters("body {" + NEWLINE + "font: 10pt sans;" + NEWLINE + "}" + NEWLINE
                + "#mynetwork {" + NEWLINE + "height: 90%;" + NEWLINE + "width: 90%;" + NEWLINE
                + "border: 1px solid lightgray; " + NEWLINE + "text-align: center;" + NEWLINE + "}" + NEWLINE
                + "#loadingBar {" + NEWLINE + "position:absolute;" + NEWLINE + "top:0px;" + NEWLINE
                + "left:0px;" + NEWLINE + "width: 0px;" + NEWLINE + "height: 0px;" + NEWLINE
                + "background-color:rgba(200,200,200,0.8);" + NEWLINE + "-webkit-transition: all 0.5s ease;"
                + NEWLINE + "-moz-transition: all 0.5s ease;" + NEWLINE + "-ms-transition: all 0.5s ease;"
                + NEWLINE + "-o-transition: all 0.5s ease;" + NEWLINE + "transition: all 0.5s ease;" + NEWLINE
                + "opacity:1;" + NEWLINE + "}" + NEWLINE + "#wrapper {" + NEWLINE + "position:absolute;"
                + NEWLINE + "width: 1200px;" + NEWLINE + "height: 90%;" + NEWLINE + "}" + NEWLINE + "#text {"
                + NEWLINE + "position:absolute;" + NEWLINE + "top:8px;" + NEWLINE + "left:530px;" + NEWLINE
                + "width:30px;" + NEWLINE + "height:50px;" + NEWLINE + "margin:auto auto auto auto;" + NEWLINE
                + "font-size:16px;" + NEWLINE + "color: #000000;" + NEWLINE + "}" + NEWLINE
                + "div.outerBorder {" + NEWLINE + "position:relative;" + NEWLINE + "top:400px;" + NEWLINE
                + "width:600px;" + NEWLINE + "height:44px;" + NEWLINE + "margin:auto auto auto auto;" + NEWLINE
                + "border:8px solid rgba(0,0,0,0.1);" + NEWLINE
                + "background: rgb(252,252,252); /* Old browsers */" + NEWLINE
                + "background: -moz-linear-gradient(top,  rgba(252,252,252,1) 0%, rgba(237,237,237,1) 100%); /* FF3.6+ */"
                + NEWLINE
                + "background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(252,252,252,1)), color-stop(100%,rgba(237,237,237,1))); /* Chrome,Safari4+ */"
                + NEWLINE
                + "background: -webkit-linear-gradient(top,  rgba(252,252,252,1) 0%,rgba(237,237,237,1) 100%); /* Chrome10+,Safari5.1+ */"
                + NEWLINE
                + "background: -o-linear-gradient(top,  rgba(252,252,252,1) 0%,rgba(237,237,237,1) 100%); /* Opera 11.10+ */"
                + NEWLINE
                + "background: -ms-linear-gradient(top,  rgba(252,252,252,1) 0%,rgba(237,237,237,1) 100%); /* IE10+ */"
                + NEWLINE
                + "background: linear-gradient(to bottom,  rgba(252,252,252,1) 0%,rgba(237,237,237,1) 100%); /* W3C */"
                + NEWLINE
                + "filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#fcfcfc', endColorstr='#ededed',GradientType=0 ); /* IE6-9 */"
                + NEWLINE + "border-radius:72px;" + NEWLINE + "box-shadow: 0px 0px 10px rgba(0,0,0,0.2);"
                + NEWLINE + "}" + NEWLINE + "#border {" + NEWLINE + "position:absolute;" + NEWLINE + "top:10px;"
                + NEWLINE + "left:10px;" + NEWLINE + "width:500px;" + NEWLINE + "height:23px;" + NEWLINE
                + "margin:auto auto auto auto;" + NEWLINE + "box-shadow: 0px 0px 4px rgba(0,0,0,0.2);" + NEWLINE
                + "border-radius:10px;" + NEWLINE + "}" + NEWLINE + "#bar {" + NEWLINE + "position:absolute;"
                + NEWLINE + "top:0px;" + NEWLINE + "left:0px;" + NEWLINE + "width:20px;" + NEWLINE
                + "height:20px;" + NEWLINE + "margin:auto auto auto auto;" + NEWLINE + "border-radius:6px;"
                + NEWLINE + "border:1px solid rgba(30,30,30,0.05);" + NEWLINE
                + "background: rgb(0, 173, 246); /* Old browsers */" + NEWLINE
                + "box-shadow: 2px 0px 4px rgba(0,0,0,0.4);" + NEWLINE + "}" + NEWLINE);
        xmlWriter.writeEndElement();
        xmlWriter.writeCharacters(NEWLINE);

        xmlWriter.writeStartElement(TAG_SCRIPT);
        xmlWriter.writeAttribute(ATT_SRC, VIS_JS_SRC);
        xmlWriter.writeAttribute(ATT_TYPE, "text/javascript");
        xmlWriter.writeCharacters(NEWLINE);
        xmlWriter.writeEndElement();
        xmlWriter.writeCharacters(NEWLINE);

        xmlWriter.writeStartElement(TAG_SCRIPT);
        xmlWriter.writeAttribute(ATT_SRC, JQUERY_SRC);
        xmlWriter.writeAttribute(ATT_TYPE, "text/javascript");
        xmlWriter.writeCharacters(NEWLINE);
        xmlWriter.writeEndElement();
        xmlWriter.writeCharacters(NEWLINE);

        xmlWriter.writeEmptyElement(TAG_LINK);
        xmlWriter.writeAttribute(ATT_HREF, VIS_CSS_SRC);
        xmlWriter.writeAttribute(ATT_REL, "stylesheet");
        xmlWriter.writeAttribute(ATT_TYPE, "text/css");
        xmlWriter.writeCharacters(NEWLINE);

        xmlWriter.writeStartElement(TAG_SCRIPT);
        xmlWriter.writeAttribute(ATT_TYPE, "text/javascript");
        xmlWriter.writeCharacters(NEWLINE + "function frameSize() {" + NEWLINE
                + "$(document).ready(function() {" + NEWLINE + "function elementResize() {" + NEWLINE
                + "var browserWidth = $(window).width()*0.98;" + NEWLINE
                + "document.getElementById('mynetwork').style.width = browserWidth;" + NEWLINE + "}" + NEWLINE
                + "elementResize();" + NEWLINE + "$(window).bind(\"resize\", function(){" + NEWLINE
                + "elementResize();" + NEWLINE + "});" + NEWLINE + "});" + NEWLINE + "}" + NEWLINE);
        xmlWriter.writeEndElement();
        xmlWriter.writeCharacters(NEWLINE);

        xmlWriter.writeStartElement(TAG_SCRIPT);
        xmlWriter.writeAttribute(ATT_TYPE, "text/javascript");
        xmlWriter.writeCharacters(NEWLINE + "function start(){" + NEWLINE + "loadSaltObjectAndDraw();" + NEWLINE
                + "frameSize();" + NEWLINE + "}" + NEWLINE + "var nodesJson = [];" + NEWLINE
                + "var edgesJson = [];" + NEWLINE + "var network = null;" + NEWLINE
                + "function loadSaltObjectAndDraw() {" + NEWLINE + "var nodesJson = " + NEWLINE);
        xmlWriter.flush();

        try {
            buildJSON();
        } catch (SaltParameterException e) {
            throw new SaltParameterException(e.getMessage());
        } catch (SaltException e) {
            throw new SaltException(e.getMessage());
        }

        if (nNodes < 20) {
            nodeDist = 120;
            sprConstant = 1.2;
            sprLength = 120;
        } else if (nNodes >= 20 && nNodes < 100) {
            nodeDist = 150;
            sprConstant = 1.1;
            sprLength = 160;
        } else if (nNodes >= 100 && nNodes < 400) {
            nodeDist = 180;
            sprConstant = 0.9;
            sprLength = 180;
        } else if (nNodes >= 400 && nNodes < 800) {
            nodeDist = 200;
            sprConstant = 0.6;
            sprLength = 200;
        } else {
            nodeDist = 250;
            sprConstant = 0.3;
            sprLength = 230;
        }
        ;

        // write nodes as array
        nodeWriter.flush();

        xmlWriter.writeCharacters(";" + NEWLINE);
        xmlWriter.writeCharacters("var edgesJson = " + NEWLINE);
        xmlWriter.flush();

        // write edges as array to tmp file
        edgeWriter.flush();

        // copy edges from tmp file
        ByteStreams.copy(new FileInputStream(tmpFile), os);

        xmlWriter.writeCharacters(";" + NEWLINE);

        xmlWriter.writeCharacters("var nodeDist =" + nodeDist + ";" + NEWLINE);

        xmlWriter.writeCharacters("draw(nodesJson, edgesJson, nodeDist);" + NEWLINE + "}" + NEWLINE
                + "var directionInput = document.getElementById(\"direction\");" + NEWLINE
                + "function destroy() {" + NEWLINE + "if (network !== null) {" + NEWLINE + "network.destroy();"
                + NEWLINE + "network = null;" + NEWLINE + "}" + NEWLINE + "}" + NEWLINE + NEWLINE
                + "function draw(nodesJson, edgesJson, nodeDist) {" + NEWLINE + "destroy();" + NEWLINE
                + "var connectionCount = [];" + NEWLINE + "var nodes = [];" + NEWLINE + "var edges = [];"
                + NEWLINE + NEWLINE + "nodes = new vis.DataSet(nodesJson);" + NEWLINE
                + "edges = new vis.DataSet(edgesJson);" + NEWLINE
                + "var container = document.getElementById('mynetwork');" + NEWLINE + "var data = {" + NEWLINE
                + "nodes: nodes," + NEWLINE + "edges: edges" + NEWLINE + "};" + NEWLINE + "var options = {"
                + NEWLINE + "nodes:{" + NEWLINE + "shape: \"box\"" + NEWLINE + "}," + NEWLINE + "edges: {"
                + NEWLINE + "smooth: true," + NEWLINE + "arrows: {" + NEWLINE + "to: {" + NEWLINE
                + "enabled: true" + NEWLINE + "}" + NEWLINE + "}" + NEWLINE + "}," + NEWLINE + "interaction: {"
                + NEWLINE + "navigationButtons: true," + NEWLINE + "keyboard: true" + NEWLINE + "}," + NEWLINE
                + "layout: {" + NEWLINE + "hierarchical:{" + NEWLINE + "direction: directionInput.value"
                + NEWLINE + "}" + NEWLINE + "}," + NEWLINE + "physics: {" + NEWLINE + "hierarchicalRepulsion: {"
                + NEWLINE + "centralGravity: 0.8," + NEWLINE + "springLength: " + sprLength + "," + NEWLINE
                + "springConstant: " + sprConstant + "," + NEWLINE + "nodeDistance: nodeDist," + NEWLINE
                + "damping: 0.04" + NEWLINE + "}," + NEWLINE + "maxVelocity: 50," + NEWLINE + "minVelocity: 1,"
                + NEWLINE + "solver: 'hierarchicalRepulsion'," + NEWLINE + "timestep: 0.5," + NEWLINE
                + "stabilization: {" + NEWLINE + "iterations: 1000" + NEWLINE + "}" + NEWLINE + "}" + NEWLINE
                + "}" + NEWLINE + ";" + NEWLINE + "network = new vis.Network(container, data, options);"
                + NEWLINE);

        if (withPhysics == true) {
            xmlWriter.writeCharacters("network.on(\"stabilizationProgress\", function(params) {" + NEWLINE
                    + "var maxWidth = 496;" + NEWLINE + "var minWidth = 20;" + NEWLINE
                    + "var widthFactor = params.iterations/params.total;" + NEWLINE
                    + "var width = Math.max(minWidth,maxWidth * widthFactor);" + NEWLINE
                    + "document.getElementById('loadingBar').style.opacity = 1;" + NEWLINE
                    + "document.getElementById('bar').style.width = width + 'px';" + NEWLINE
                    + "document.getElementById('text').innerHTML = Math.round(widthFactor*100) + '%';" + NEWLINE
                    + "});" + NEWLINE + "network.on(\"stabilizationIterationsDone\", function() {" + NEWLINE
                    + "document.getElementById('text').innerHTML = '100%';" + NEWLINE
                    + "document.getElementById('bar').style.width = '496px';" + NEWLINE
                    + "document.getElementById('loadingBar').style.opacity = 0;" + NEWLINE + "});" + NEWLINE);
        }

        xmlWriter.writeCharacters("}" + NEWLINE);
        // script
        xmlWriter.writeEndElement();
        xmlWriter.writeCharacters(NEWLINE);

        // head
        xmlWriter.writeEndElement();
        xmlWriter.writeCharacters(NEWLINE);

        xmlWriter.writeStartElement(TAG_BODY);
        xmlWriter.writeAttribute("onload", "start();");
        xmlWriter.writeCharacters(NEWLINE);

        if (withPhysics == true) {
            xmlWriter.writeStartElement(TAG_DIV);
            xmlWriter.writeAttribute(ATT_ID, "wrapper");
            xmlWriter.writeCharacters(NEWLINE);

            xmlWriter.writeStartElement(TAG_DIV);
            xmlWriter.writeAttribute(ATT_ID, "loadingBar");
            xmlWriter.writeCharacters(NEWLINE);

            xmlWriter.writeStartElement(TAG_DIV);
            xmlWriter.writeAttribute(ATT_CLASS, "outerBorder");
            xmlWriter.writeCharacters(NEWLINE);

            xmlWriter.writeStartElement(TAG_DIV);
            xmlWriter.writeAttribute(ATT_ID, "text");
            xmlWriter.writeCharacters("0%");
            xmlWriter.writeEndElement();
            xmlWriter.writeCharacters(NEWLINE);

            xmlWriter.writeStartElement(TAG_DIV);
            xmlWriter.writeAttribute(ATT_ID, "border");
            xmlWriter.writeCharacters(NEWLINE);

            xmlWriter.writeStartElement(TAG_DIV);
            xmlWriter.writeAttribute(ATT_ID, "bar");
            xmlWriter.writeCharacters(NEWLINE);
            xmlWriter.writeEndElement();
            xmlWriter.writeCharacters(NEWLINE);

            xmlWriter.writeEndElement();
            xmlWriter.writeCharacters(NEWLINE);
            xmlWriter.writeEndElement();
            xmlWriter.writeCharacters(NEWLINE);
            xmlWriter.writeEndElement();
            xmlWriter.writeCharacters(NEWLINE);
        }

        xmlWriter.writeStartElement(TAG_H2);
        xmlWriter.writeCharacters("Dokument-Id: " + docId);
        xmlWriter.writeEndElement();
        xmlWriter.writeCharacters(NEWLINE);

        xmlWriter.writeStartElement(TAG_DIV);
        xmlWriter.writeAttribute(ATT_STYLE, TEXT_STYLE);
        xmlWriter.writeEndElement();
        xmlWriter.writeCharacters(NEWLINE);

        xmlWriter.writeStartElement("p");

        xmlWriter.writeEmptyElement(TAG_INPUT);
        xmlWriter.writeAttribute(ATT_TYPE, "button");
        xmlWriter.writeAttribute(ATT_ID, "btn-UD");
        xmlWriter.writeAttribute(ATT_VALUE, "Up-Down");
        xmlWriter.writeCharacters(NEWLINE);

        xmlWriter.writeEmptyElement(TAG_INPUT);
        xmlWriter.writeAttribute(ATT_TYPE, "button");
        xmlWriter.writeAttribute(ATT_ID, "btn-DU");
        xmlWriter.writeAttribute(ATT_VALUE, "Down-Up");
        xmlWriter.writeCharacters(NEWLINE);

        xmlWriter.writeEmptyElement(TAG_INPUT);
        xmlWriter.writeAttribute(ATT_TYPE, "hidden");
        // TODO check the apostrophes
        xmlWriter.writeAttribute(ATT_ID, "direction");
        xmlWriter.writeAttribute(ATT_VALUE, "UD");
        xmlWriter.writeCharacters(NEWLINE);

        // p
        xmlWriter.writeEndElement();
        xmlWriter.writeCharacters(NEWLINE);

        xmlWriter.writeStartElement(TAG_DIV);
        xmlWriter.writeAttribute(ATT_ID, "mynetwork");
        xmlWriter.writeCharacters(NEWLINE);
        xmlWriter.writeEndElement();
        xmlWriter.writeCharacters(NEWLINE);

        xmlWriter.writeStartElement(TAG_P);
        xmlWriter.writeAttribute(ATT_ID, "selection");
        xmlWriter.writeCharacters(NEWLINE);
        xmlWriter.writeEndElement();
        xmlWriter.writeCharacters(NEWLINE);

        xmlWriter.writeStartElement(TAG_SCRIPT);
        xmlWriter.writeAttribute(ATT_LANG, "JavaScript");
        xmlWriter.writeCharacters(NEWLINE);
        xmlWriter.writeCharacters("var directionInput = document.getElementById(\"direction\");" + NEWLINE
                + "var btnUD = document.getElementById(\"btn-UD\");" + NEWLINE + "btnUD.onclick = function() {"
                + NEWLINE + "directionInput.value = \"UD\";" + NEWLINE + "start();" + NEWLINE + "};" + NEWLINE
                + "var btnDU = document.getElementById(\"btn-DU\");" + NEWLINE + "btnDU.onclick = function() {"
                + NEWLINE + "directionInput.value = \"DU\";" + NEWLINE + "start();" + NEWLINE + "};" + NEWLINE);
        xmlWriter.writeEndElement();
        xmlWriter.writeCharacters(NEWLINE);

        // div wrapper
        if (withPhysics == true) {
            xmlWriter.writeEndElement();
            xmlWriter.writeCharacters(NEWLINE);
        }

        // body
        xmlWriter.writeEndElement();
        xmlWriter.writeCharacters(NEWLINE);

        // html
        xmlWriter.writeEndElement();
        xmlWriter.writeCharacters(NEWLINE);

        xmlWriter.writeEndDocument();
        xmlWriter.flush();
        xmlWriter.close();
        nodeWriter.close();
        edgeWriter.close();
    }

}

From source file:org.deegree.commons.xml.stax.FilteringXMLStreamWriterTest.java

private void writeDocument(XMLStreamWriter writer) throws XMLStreamException {
    writer.writeStartDocument();/* w ww.j  a  v  a 2s  .  co m*/
    writer.setPrefix("app", app);
    writer.setPrefix("nix", nix);
    writer.setPrefix("alles", alles);
    writer.writeStartElement(app, "a");
    writer.writeNamespace("app", app);
    writer.writeNamespace("nix", nix);
    writer.writeNamespace("alles", alles);
    writer.writeStartElement(app, "b");
    writer.writeStartElement(nix, "c");
    writer.writeStartElement(app, "d");
    writer.writeEndElement();
    writer.writeStartElement(alles, "e");
    writer.writeCharacters("sometext");
    writer.writeEndElement();
    writer.writeStartElement(app, "b");
    writer.writeStartElement(nix, "c");
    writer.writeEndElement();
    writer.writeEndElement();
    writer.writeEndElement();
    writer.writeEndElement();
    writer.writeEndElement();
    writer.close();
}

From source file:org.deegree.services.controller.AbstractOWS.java

/**
 * Finishes an OGC-SOAP response that has been initiated by {@link #beginSOAPResponse(HttpResponseBuffer)}.
 * /*from  w w w . ja  va 2  s  . c o  m*/
 * @see #beginSOAPResponse(HttpResponseBuffer)
 * 
 * @param response
 * @throws IOException
 * @throws XMLStreamException
 */
protected void endSOAPResponse(HttpResponseBuffer response) throws IOException, XMLStreamException {
    XMLStreamWriter xmlWriter = response.getXMLWriter();
    // "soapenv:Body"
    xmlWriter.writeEndElement();
    // "soapenv:Envelope"
    xmlWriter.writeEndElement();
}

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

private void export(XMLStreamWriter writer, Set<Sections> sections, ServiceIdentificationType identification,
        ServiceProviderType provider) throws XMLStreamException {
    writer.writeStartElement(WRS_PREFIX, "Capabilities", WRS_NS);
    writer.writeNamespace(WRS_PREFIX, WRS_NS);
    writer.writeNamespace(OWS_PREFIX, OWS_NS);
    writer.writeNamespace(OGC_PREFIX, OGCNS);
    writer.writeNamespace(XLINK_PREFIX, XLN_NS);
    writer.writeNamespace(XSINS, XSI_PREFIX);
    writer.writeAttribute("version", "2.0.2");
    writer.writeAttribute("schemaLocation", WRS_NS + " " + WRS_SCHEMA, XSINS);

    // ows:ServiceIdentification
    if (sections.isEmpty() || sections.contains(Sections.ServiceIdentification)) {
        gcHelper.exportServiceIdentification(writer, identification,
                "urn:ogc:serviceType:CatalogueService:2.0.2:HTTP:ebRIM", "2.0.2",
                "http://www.opengeospatial.org/ogcna");
    }/*from   w  w w  . ja v a 2  s .  c  om*/
    // ows:ServiceProvider
    if (sections.isEmpty() || sections.contains(Sections.ServiceProvider)) {
        exportServiceProvider100Old(writer, provider);
    }
    // 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.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
            }//from w  w w . ja  v a 2 s.c o m
        }
    }
    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 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);

    }//  ww  w .j a va2s.  c  o m

    // 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());
    }//from w w w  .  j  av a 2s  .  c  o  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

}