List of usage examples for javax.xml.stream XMLStreamWriter writeCharacters
public void writeCharacters(String text) throws XMLStreamException;
From source file:org.corpus_tools.salt.util.internal.persistence.SaltXML10Writer.java
/** * Writes a salt project to the xml stream. * // w w w . j a va 2 s . c o m * @param xml * A pre-configured {@link XMLStreamWriter} * @param project */ public void writeSaltProject(XMLStreamWriter xml, SaltProject project) { try { xml.writeStartElement(NS_SALTCOMMON, TAG_SALT_PROJECT, NS_VALUE_SALTCOMMON); xml.writeNamespace(NS_SCORPUSSTRUCTURE, NS_VALUE_SCORPUSSTRUCTURE); xml.writeNamespace(NS_XMI, NS_VALUE_XMI); xml.writeNamespace(NS_XSI, NS_VALUE_XSI); xml.writeNamespace(NS_SALTCORE, NS_VALUE_SALTCORE); xml.writeNamespace(NS_SALTCOMMON, NS_VALUE_SALTCOMMON); xml.writeAttribute(NS_VALUE_XMI, ATT_XMI_VERSION, "2.0"); Iterator<SCorpusGraph> cGraphs = project.getCorpusGraphs().iterator(); while (cGraphs.hasNext()) { if (isPrettyPrint) { xml.writeCharacters("\n"); xml.writeCharacters("\t"); } writeCorpusGraph(xml, cGraphs.next(), true); } if (isPrettyPrint) { xml.writeCharacters("\n"); } xml.writeEndElement(); } catch (XMLStreamException e) { throw new SaltResourceException("Cannot store salt project to file '" + getLocationStr() + "'. ", e); } }
From source file:org.corpus_tools.salt.util.internal.persistence.SaltXML10Writer.java
/** * Writes a corpus graph to the xml stream * //from w w w . j a v a 2s .co m * @param graph * the corpus graph to be written * @param embedded * determines whether this corpus graph is part of a saltProject * @param xml * xml stream to write corpus graph to, if the passed one is * null, a new one will be created */ public void writeCorpusGraph(XMLStreamWriter xml, SCorpusGraph graph, boolean embedded) { try { if (!embedded) { xml.writeStartDocument("1.0"); if (isPrettyPrint) { xml.writeCharacters("\n"); xml.writeStartElement(NS_SALTCOMMON, TAG_SCORPUSGRAPH, NS_VALUE_SALTCOMMON); xml.writeNamespace(NS_SCORPUSSTRUCTURE, NS_VALUE_SCORPUSSTRUCTURE); xml.writeNamespace(NS_XMI, NS_VALUE_XMI); xml.writeNamespace(NS_XSI, NS_VALUE_XSI); xml.writeNamespace(NS_SALTCORE, NS_VALUE_SALTCORE); xml.writeNamespace(NS_SALTCOMMON, NS_VALUE_SALTCOMMON); xml.writeAttribute(NS_VALUE_XMI, ATT_XMI_VERSION, "2.0"); } } else { xml.writeStartElement(TAG_SCORPUSGRAPH); } // write all labels if (graph.getLabels() != null) { Iterator<Label> labelIt = graph.getLabels().iterator(); while (labelIt.hasNext()) { if (isPrettyPrint) { xml.writeCharacters("\n"); xml.writeCharacters("\t"); } writeLabel(xml, labelIt.next()); } } // stores the position of a single node in the list of nodes to // refer them in a relation Map<SNode, Integer> nodePositions = new HashMap<>(); // write all nodes if (graph.getNodes() != null) { Iterator<SNode> nodeIt = graph.getNodes().iterator(); Integer position = 0; while (nodeIt.hasNext()) { SNode node = nodeIt.next(); writeNode(xml, node, null); nodePositions.put(node, position); position++; } } // write all relations if (graph.getRelations() != null) { Iterator<SRelation<SNode, SNode>> relIt = graph.getRelations().iterator(); while (relIt.hasNext()) { SRelation<SNode, SNode> rel = relIt.next(); writeRelation(xml, rel, nodePositions, null); } } if (isPrettyPrint) { xml.writeCharacters("\n"); xml.writeCharacters("\t"); } xml.writeEndElement(); } catch (XMLStreamException e) { throw new SaltResourceException( "Cannot store salt project to file '" + getLocationStr() + "'. " + e.getMessage(), e); } finally { if (!embedded) { if (xml != null) { try { xml.flush(); xml.close(); } catch (XMLStreamException e) { throw new SaltResourceException("Cannot store salt project to file '" + getLocationStr() + "', because the opened stream is not closable. ", e); } } } } }
From source file:org.corpus_tools.salt.util.internal.persistence.SaltXML10Writer.java
/** * Writes a document graph to the file given by {@link #getPath()}. * /* w ww . j av a 2s . c o m*/ * @param graph */ public void writeDocumentGraph(SDocumentGraph graph) { XMLStreamWriter xml = null; try (OutputStream output = new FileOutputStream(path)) { xml = xmlFactory.createXMLStreamWriter(output, "UTF-8"); xml.writeStartDocument("1.0"); if (isPrettyPrint) { xml.writeCharacters("\n"); } writeDocumentGraph(xml, graph); xml.writeEndDocument(); } catch (XMLStreamException | IOException e) { throw new SaltResourceException("Cannot store document graph to file '" + getLocationStr() + "'. ", e); } finally { if (xml != null) { try { xml.flush(); xml.close(); } catch (XMLStreamException e) { throw new SaltResourceException("Cannot store document graph to file '" + getLocationStr() + "', because the opened stream is not closable. ", e); } } } }
From source file:org.corpus_tools.salt.util.internal.persistence.SaltXML10Writer.java
/** * Writes a document graph to the xml stream. * // www . j a v a2 s .c o m * @param xml * A pre-configured {@link XMLStreamWriter} * @param graph */ public void writeDocumentGraph(XMLStreamWriter xml, SDocumentGraph graph) { try { xml.writeStartElement(NS_SDOCUMENTSTRUCTURE, TAG_SDOCUMENTSTRUCTURE_SDOCUMENTGRAPH, NS_VALUE_SDOCUMENTSTRUCTURE); xml.writeNamespace(NS_SDOCUMENTSTRUCTURE, NS_VALUE_SDOCUMENTSTRUCTURE); xml.writeNamespace(NS_XMI, NS_VALUE_XMI); xml.writeNamespace(NS_XSI, NS_VALUE_XSI); xml.writeNamespace(NS_SALTCORE, NS_VALUE_SALTCORE); xml.writeAttribute(NS_VALUE_XMI, ATT_XMI_VERSION, "2.0"); // write all labels Iterator<Label> labelIt = graph.getLabels().iterator(); while (labelIt.hasNext()) { if (isPrettyPrint) { xml.writeCharacters("\n"); xml.writeCharacters("\t"); } writeLabel(xml, labelIt.next()); } // stores the position of a single layer in the list of layers to // refer them in a relation Map<SLayer, Integer> layerPositions = new HashMap<>(); Iterator<SLayer> layerIt = graph.getLayers().iterator(); Integer position = 0; while (layerIt.hasNext()) { layerPositions.put(layerIt.next(), position); position++; } // stores the position of a single node in the list of nodes to // refer them in a relation Map<SNode, Integer> nodePositions = new HashMap<>(); // write all nodes Iterator<SNode> nodeIt = graph.getNodes().iterator(); position = 0; while (nodeIt.hasNext()) { SNode node = nodeIt.next(); writeNode(xml, node, layerPositions); nodePositions.put(node, position); position++; } // stores the position of a single relation in the list of relations // to refer them later Map<SRelation<SNode, SNode>, Integer> relPositions = new HashMap<>(); { // write all relations Iterator<SRelation<SNode, SNode>> relIt = graph.getRelations().iterator(); position = 0; while (relIt.hasNext()) { SRelation<SNode, SNode> rel = relIt.next(); writeRelation(xml, rel, nodePositions, layerPositions); relPositions.put(rel, position); position++; } } // write layers layerIt = graph.getLayers().iterator(); while (layerIt.hasNext()) { writeLayer(xml, layerIt.next(), nodePositions, relPositions); } if (isPrettyPrint) { xml.writeCharacters("\n"); } xml.writeEndElement(); } catch (XMLStreamException e) { throw new SaltResourceException("Cannot store document graph to file '" + getLocationStr() + "'. ", e); } }
From source file:org.corpus_tools.salt.util.internal.persistence.SaltXML10Writer.java
/** * Writes the passed node object to the passed {@link XMLStreamWriter}. * //from w w w.ja v a2s . c om * @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}. * //from w ww .java 2 s . 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 w w w .jav a 2s . c om * @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.internal.persistence.SaltXML10Writer.java
/** * Writes an Salt XMI header to the {@link XMLStreamWriter}. * Salt XMI has a certain header structure (including the namespaces). * This helper function writes this header to an existing * {@link XMLStreamWriter}./*from w w w. j av a2 s . co m*/ * @param xml * @throws XMLStreamException */ public void writeXMIRootElement(XMLStreamWriter xml) throws XMLStreamException { xml.writeStartElement(NS_XMI, "XMI", NS_VALUE_XMI); xml.writeNamespace(NS_SDOCUMENTSTRUCTURE, NS_VALUE_SDOCUMENTSTRUCTURE); xml.writeNamespace(NS_XMI, NS_VALUE_XMI); xml.writeNamespace(NS_XSI, NS_VALUE_XSI); xml.writeNamespace(NS_SALTCORE, NS_VALUE_SALTCORE); xml.writeAttribute(NS_VALUE_XMI, ATT_XMI_VERSION, "2.0"); if (isPrettyPrint) { xml.writeCharacters("\n"); } }
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 av a2 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();/*from w ww . ja va2 s . 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(); }