List of usage examples for javax.xml.stream XMLStreamWriter writeStartElement
public void writeStartElement(String localName) throws XMLStreamException;
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 av a2 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}. // 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);//from ww w . ja v a 2 s . c om 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.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 ww w . j a va2 s . c o m*/ 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.dita.dost.module.GenMapAndTopicListModule.java
private void writeExportAnchors() throws DITAOTException { if (INDEX_TYPE_ECLIPSEHELP.equals(transtype)) { // Output plugin id final File pluginIdFile = new File(job.tempDir, FILE_NAME_PLUGIN_XML); final DelayConrefUtils delayConrefUtils = new DelayConrefUtils(); delayConrefUtils.writeMapToXML(exportAnchorsFilter.getPluginMap(), pluginIdFile); XMLStreamWriter export = null; try (OutputStream exportStream = new FileOutputStream(new File(job.tempDir, FILE_NAME_EXPORT_XML))) { export = XMLOutputFactory.newInstance().createXMLStreamWriter(exportStream, "UTF-8"); export.writeStartDocument(); export.writeStartElement("stub"); for (final ExportAnchor e : exportAnchorsFilter.getExportAnchors()) { export.writeStartElement("file"); export.writeAttribute("name", tempFileNameScheme.generateTempFileName(toFile(e.file).toURI()).toString()); for (final String t : sort(e.topicids)) { export.writeStartElement("topicid"); export.writeAttribute("name", t); export.writeEndElement(); }/*ww w .j a v a 2 s. c o m*/ for (final String i : sort(e.ids)) { export.writeStartElement("id"); export.writeAttribute("name", i); export.writeEndElement(); } for (final String k : sort(e.keys)) { export.writeStartElement("keyref"); export.writeAttribute("name", k); export.writeEndElement(); } export.writeEndElement(); } export.writeEndElement(); export.writeEndDocument(); } catch (final IOException e) { throw new DITAOTException("Failed to write export anchor file: " + e.getMessage(), e); } catch (final XMLStreamException e) { throw new DITAOTException("Failed to serialize export anchor file: " + e.getMessage(), e); } finally { if (export != null) { try { export.close(); } catch (final XMLStreamException e) { logger.error("Failed to close export anchor file: " + e.getMessage(), e); } } } } }
From source file:org.dita.dost.reader.ChunkMapReader.java
/** * Create the new topic stump./*from w ww . j a v a2 s . c o m*/ */ private void createTopicStump(final File newFile) { OutputStream newFileWriter = null; try { newFileWriter = new FileOutputStream(newFile); final XMLStreamWriter o = XMLOutputFactory.newInstance().createXMLStreamWriter(newFileWriter, UTF8); o.writeStartDocument(); o.writeProcessingInstruction(PI_WORKDIR_TARGET, UNIX_SEPARATOR + newFile.getParentFile().getAbsolutePath()); o.writeProcessingInstruction(PI_WORKDIR_TARGET_URI, newFile.getParentFile().toURI().toString()); o.writeStartElement(ELEMENT_NAME_DITA); o.writeEndElement(); o.writeEndDocument(); o.close(); newFileWriter.flush(); } catch (final RuntimeException e) { throw e; } catch (final Exception e) { logger.error(e.getMessage(), e); } finally { try { if (newFileWriter != null) { newFileWriter.close(); } } catch (final Exception e) { logger.error(e.getMessage(), e); } } }
From source file:org.eclipse.gyrex.logback.config.model.Appender.java
@Override public void toXml(final XMLStreamWriter writer) throws XMLStreamException { final boolean wrapIntoSiftingAppender = canSift() && isSeparateLogOutputsPerMdcProperty(); writer.writeStartElement("appender"); writer.writeAttribute("name", getName()); if (wrapIntoSiftingAppender) { writer.writeAttribute("class", SiftingAppender.class.getName()); } else {/*from w ww. j a va2 s . co m*/ writer.writeAttribute("class", getAppenderClassName()); } final Level threshold = getThreshold(); if (null != threshold) { writer.writeStartElement("filter"); writer.writeAttribute("class", ThresholdFilter.class.getName()); writer.writeStartElement("level"); writer.writeCharacters(threshold.toString()); writer.writeEndElement(); writer.writeEndElement(); } if (wrapIntoSiftingAppender) { // start discriminator and wrap regular appender into <sift><appender> writer.writeStartElement("discriminator"); writer.writeAttribute("class", MDCBasedDiscriminator.class.getName()); writer.writeStartElement("key"); writer.writeCharacters(getSiftingMdcPropertyName()); writer.writeEndElement(); writer.writeStartElement("defaultValue"); writer.writeCharacters(getSiftingMdcPropertyDefaultValue()); writer.writeEndElement(); writer.writeEndElement(); writer.writeStartElement("sift"); writer.writeStartElement("appender"); writer.writeAttribute("name", String.format("%s-${%s}", getName(), getSiftingMdcPropertyName())); } writeAppenderContent(writer); writeEncoder(writer); if (wrapIntoSiftingAppender) { // finish <sift><appender> writer.writeEndElement(); writer.writeEndElement(); } writer.writeEndElement(); }
From source file:org.eclipse.gyrex.logback.config.model.Appender.java
private void writeEncoder(final XMLStreamWriter writer) throws XMLStreamException { writer.writeStartElement("encoder"); writer.writeStartElement("pattern"); String text = getPattern();//from w w w . j a v a2 s . c om if (StringUtils.isBlank(text)) { text = preferShortPattern() ? "${PATTERN_SHORT}" : "${PATTERN_LONG}"; } else if (StringUtils.containsIgnoreCase(text, "PATTERN_LONG")) { text = "${PATTERN_LONG}"; } else if (StringUtils.containsIgnoreCase(text, "PATTERN_SHORT")) { text = "${PATTERN_SHORT}"; } writer.writeCharacters(text); writer.writeEndElement(); writer.writeEndElement(); }
From source file:org.eclipse.gyrex.logback.config.model.FileAppender.java
@Override protected void writeAppenderContent(final XMLStreamWriter writer) throws XMLStreamException { writer.writeStartElement("file"); writer.writeCharacters(String.format("${BASE_PATH}/%s", getFileName())); writer.writeEndElement();// w w w . j a v a 2 s .c o m writeRotation(writer); }
From source file:org.eclipse.gyrex.logback.config.model.FileAppender.java
private void writeSizeBasedRotation(final XMLStreamWriter writer) throws XMLStreamException { writer.writeStartElement("rollingPolicy"); writer.writeAttribute("class", FixedWindowRollingPolicy.class.getName()); {/*from ww w.j av a 2s . c o m*/ writer.writeStartElement("fileNamePattern"); writer.writeCharacters(StringUtils.substringBeforeLast(getFileName(), ".")); writer.writeCharacters(".%i"); final String extension = StringUtils.substringAfter(getFileName(), "."); if (StringUtils.isNotBlank(extension)) { writer.writeCharacters("."); writer.writeCharacters(extension); } if (isCompressRotatedLogs()) { writer.writeCharacters(".gz"); } writer.writeEndElement(); writer.writeStartElement("minIndex"); writer.writeCharacters("1"); writer.writeEndElement(); writer.writeStartElement("maxIndex"); writer.writeCharacters("3"); writer.writeEndElement(); } writer.writeEndElement(); writer.writeStartElement("triggeringPolicy"); writer.writeAttribute("class", SizeBasedTriggeringPolicy.class.getName()); { String maxFileSize = getMaxFileSize(); if (StringUtils.isBlank(maxFileSize)) { maxFileSize = "1MB"; } writer.writeStartElement("maxFileSize"); writer.writeCharacters(maxFileSize); writer.writeEndElement(); } writer.writeEndElement(); }