List of usage examples for javax.xml.stream XMLOutputFactory createXMLStreamWriter
public abstract XMLStreamWriter createXMLStreamWriter(java.io.OutputStream stream, String encoding) throws XMLStreamException;
From source file:com.marklogic.client.impl.CombinedQueryBuilderImpl.java
private XMLStreamWriter makeXMLSerializer(OutputStream out) { XMLOutputFactory factory = XMLOutputFactory.newInstance(); factory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, true); try {/*from w w w . ja v a2 s .com*/ XMLStreamWriter serializer = factory.createXMLStreamWriter(out, "UTF-8"); serializer.setDefaultNamespace("http://marklogic.com/appservices/search"); serializer.setPrefix("xs", XMLConstants.W3C_XML_SCHEMA_NS_URI); return serializer; } catch (Exception e) { throw new MarkLogicIOException(e); } }
From source file:de.codesourcery.eve.skills.util.XMLMapper.java
public void write(Collection<?> beans, IFieldConverters converters, OutputStream outstream) throws XMLStreamException, IntrospectionException, IllegalArgumentException, IllegalAccessException { final XMLOutputFactory factory = XMLOutputFactory.newInstance(); final XMLStreamWriter writer = factory.createXMLStreamWriter(outstream, OUTPUT_ENCODING); try {// w w w . j ava 2s.c o m writer.writeStartDocument(OUTPUT_ENCODING, "1.0"); writer.writeStartElement("rows"); if (beans.isEmpty()) { writer.writeEndDocument(); return; } final Class<?> beanClass = beans.iterator().next().getClass(); final BeanDescription desc = createBeanDescription(beanClass); final Collection<Field> fields = desc.getFields(); if (fields.isEmpty()) { writer.writeEndDocument(); return; } for (Object bean : beans) { writer.writeStartElement("row"); for (Field f : fields) { final Object fieldValue = f.get(bean); final String[] values = converters.getConverter(f).toString(fieldValue); final String attrName = this.propertyNameMappings.get(f.getName()); if (values == null) { writer.writeAttribute(f.getName(), NIL); } else if (attrName == null) { writer.writeAttribute(f.getName(), toAttributeValue(values)); } else { writer.writeAttribute(attrName, toAttributeValue(values)); } } writer.writeEndElement(); } writer.writeEndDocument(); } finally { writer.close(); } }
From source file:de.codesourcery.eve.skills.dao.impl.FileShoppingListDAO.java
protected void writeToFile() { XMLStreamWriter writer = null; try {/* ww w .ja v a2 s .c o m*/ if (!dataFile.exists()) { final File parent = dataFile.getParentFile(); if (parent != null && !parent.exists()) { if (!parent.mkdirs()) { log.error("writeToFile(): Failed to create parent directory " + parent.getAbsolutePath()); } else { log.info("writeToFile(): Created parent directory " + parent.getAbsolutePath()); } } } final XMLOutputFactory factory = XMLOutputFactory.newInstance(); log.info("writeToFile(): Writing to " + dataFile.getAbsolutePath()); final FileOutputStream outStream = new FileOutputStream(dataFile); writer = factory.createXMLStreamWriter(outStream, OUTPUT_ENCODING); writer.writeStartDocument(OUTPUT_ENCODING, "1.0"); writer.writeStartElement("shoppinglists"); // <shoppinglists> synchronized (this.entries) { for (ShoppingList list : this.entries) { writer.writeStartElement("shoppinglist"); writer.writeAttribute("title", list.getTitle()); if (!StringUtils.isBlank(list.getDescription())) { writer.writeStartElement("description"); writer.writeCharacters(list.getDescription()); writer.writeEndElement(); // </description> } writer.writeStartElement("entries"); for (ShoppingListEntry entry : list.getEntries()) { writer.writeStartElement("entry"); writer.writeAttribute("itemId", Long.toString(entry.getType().getId())); writer.writeAttribute("totalQuantity", Long.toString(entry.getQuantity())); writer.writeAttribute("purchasedQuantity", Long.toString(entry.getPurchasedQuantity())); writer.writeEndElement(); // </entry> } writer.writeEndElement(); // </entries> writer.writeEndElement(); // </shoppinglist> } } writer.writeEndElement(); // </shoppinglists> writer.writeEndDocument(); writer.flush(); writer.close(); } catch (FileNotFoundException e) { log.error("writeToFile(): Caught ", e); throw new RuntimeException("Unable to save shopping list to " + dataFile, e); } catch (XMLStreamException e) { log.error("writeToFile(): Caught ", e); throw new RuntimeException("Unable to save shopping list to " + dataFile, e); } finally { if (writer != null) { try { writer.close(); } catch (XMLStreamException e) { log.error("writeToFile(): Caught ", e); } } } }
From source file:microsoft.exchange.webservices.data.core.EwsServiceXmlWriter.java
/** * Initializes a new instance./*from ww w . j a v a 2s.c o m*/ * * @param service the service * @param stream the stream * @throws XMLStreamException the XML stream exception */ public EwsServiceXmlWriter(ExchangeServiceBase service, OutputStream stream) throws XMLStreamException { this.service = service; XMLOutputFactory xmlof = XMLOutputFactory.newInstance(); xmlWriter = xmlof.createXMLStreamWriter(stream, "utf-8"); }
From source file:com.concursive.connect.web.modules.api.services.BackupService.java
public boolean process(TransactionItem transactionItem, Connection db) throws Exception { LOG.debug("Backup requested..."); // TODO: Fix cyclical/endless backups; need to keep an array of ids already archived // TODO: Fix if lookup value is -1, then a lookup is not needed DataRecordFactory factory = DataRecordFactory.INSTANCE; // Override the default response packet so that the returned data records // can be replayed using the RestoreService; stream the output PacketContext packetContext = transactionItem.getPacketContext(); packetContext.setReturnType(PacketContext.RETURN_DATARECORDS); // Start with the original record(s) being backed up LOG.debug("Performing buildList query"); Object object = transactionItem.getObject(); if (object instanceof java.util.AbstractList || object instanceof java.util.AbstractMap) { Object result = TransactionItem.doExecute(transactionItem.getObject(), db, TransactionItem.SELECT, packetContext, "buildList"); // TODO: check result } else {/* w w w . j av a 2 s . co m*/ Object newObject = ObjectUtils.constructObject(object.getClass(), db, ObjectUtils.getParamAsInt(object, factory.retrieveUniqueField(transactionItem.getName() + "List"))); transactionItem.setObject(newObject); } // Start backup recursion... // Consider lower-memory options to stream records without holding in memory // option 1: use pagedList to get x record(s) at a time // option 2: consider queue for limiting backup requests and asynchronous backups XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); OutputStream outputStream = null; if (packetContext.getOutputStream() == null) { outputStream = packetContext.getResponse().getOutputStream(); } else { outputStream = packetContext.getOutputStream(); } XMLStreamWriter writer = outputFactory.createXMLStreamWriter(outputStream, "utf-8"); writer.writeStartDocument(); writer.writeCharacters(System.getProperty("line.separator")); writer.writeStartElement("concursive"); writer.writeCharacters(System.getProperty("line.separator")); ArrayList<String> addedRecords = new ArrayList<String>(); addRecords(writer, transactionItem.getObject(), transactionItem, packetContext, db, addedRecords); writer.writeEndElement(); writer.writeCharacters(System.getProperty("line.separator")); writer.flush(); writer.close(); return true; }
From source file:de.uzk.hki.da.model.ObjectPremisXmlWriter.java
/** * Note: On its way writing the PREMIS file all the previously created jhove files get integrated into the resulting file. This * can't be done outside and passed as object attributes because it can be potentially very big and cause memory issues. * * @param object the object/*from ww w .ja va 2 s . c o m*/ * @param f the f * @throws IOException Signals that an I/O exception has occurred. */ public void serialize(Object object, File f, Path jhoveDataPath) throws IOException { if ((object.getPackages() == null) || (object.getPackages().isEmpty())) throw new IllegalStateException("No Packages set"); if (object.getIdentifier() == null) throw new IllegalStateException("object identifier is null"); if (object.getContractor() == null) throw new IllegalStateException("object has no contractor"); if (object.getOrig_name() == null) throw new IllegalStateException("object has no orig name"); this.jhoveDataPath = jhoveDataPath; agents = new HashSet<Agent>(); XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); FileOutputStream outputStream = new FileOutputStream(f); try { writer = outputFactory.createXMLStreamWriter(outputStream, C.ENCODING_UTF_8); } catch (XMLStreamException e) { throw new IOException("Failed to create XMLStreamWriter", e); } try { writer.writeStartDocument(C.ENCODING_UTF_8, "1.0"); writer.setPrefix("xsi", C.XSI_NS); createOpenElement("premis", 0); createAttribute(C.XSI_NS, "schemaLocation", "info:lc/xmlns/premis-v2 http://www.loc.gov/standards/premis/v2/premis-v2-2.xsd"); createAttribute("version", "2.2"); createAttribute("xmlns", "info:lc/xmlns/premis-v2"); createAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); createObjectElement(object.getIdentifier(), object.getUrn(), object.getOrig_name()); for (Package pkg : object.getPackages()) createPackageElement(object, pkg); // generate files for (Package pkg : object.getPackages()) for (DAFile fi : pkg.getFiles()) createFileElement(fi, object, pkg); generateEvents(object); for (Agent a : agents) createAgentElement(object, a); createOpenElement("rights", 1); generateRightsStatementElement(object.getRights()); createOpenElement("rightsExtension", 2); generateRightsGrantedElement(object, object.getRights()); createCloseElement(2); createCloseElement(1); createCloseElement(0); writer.writeDTD("\n"); writer.writeEndDocument(); writer.close(); outputStream.close(); } catch (XMLStreamException e) { throw new RuntimeException("Failed to serialize premis.xml", e); } }
From source file:org.apache.axiom.om.util.StAXUtils.java
public static XMLStreamWriter createXMLStreamWriter(StAXWriterConfiguration configuration, final OutputStream out) throws XMLStreamException { final XMLOutputFactory outputFactory = getXMLOutputFactory(configuration); try {// w ww . ja va 2s . c o m XMLStreamWriter writer = (XMLStreamWriter) AccessController .doPrivileged(new PrivilegedExceptionAction() { public Object run() throws XMLStreamException { return outputFactory.createXMLStreamWriter(out, OMConstants.DEFAULT_CHAR_SET_ENCODING); } }); if (isDebugEnabled) { log.debug("XMLStreamWriter is " + writer.getClass().getName()); } return writer; } catch (PrivilegedActionException pae) { throw (XMLStreamException) pae.getException(); } }
From source file:org.apache.axiom.om.util.StAXUtils.java
public static XMLStreamWriter createXMLStreamWriter(StAXWriterConfiguration configuration, final OutputStream out, final String encoding) throws XMLStreamException { final XMLOutputFactory outputFactory = getXMLOutputFactory(configuration); try {/*ww w. j ava 2 s . co m*/ XMLStreamWriter writer = (XMLStreamWriter) AccessController .doPrivileged(new PrivilegedExceptionAction() { public Object run() throws XMLStreamException { return outputFactory.createXMLStreamWriter(out, encoding); } }); if (isDebugEnabled) { log.debug("XMLStreamWriter is " + writer.getClass().getName()); } return writer; } catch (PrivilegedActionException pae) { throw (XMLStreamException) pae.getException(); } }
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 w ww .j a v a 2s. c o m 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.protocol.wps.client.wps100.ExecuteResponse100Reader.java
/** * <ul>//from w w w . ja v a 2 s.co m * <li>Precondition: cursor must point at the <code>START_ELEMENT</code> event (<wps:ComplexData>)</li> * <li>Postcondition: cursor points at the corresponding <code>END_ELEMENT</code> event (</wps:ComplexData>)</li> * </ul> * * @return * @throws XMLStreamException * @throws IOException */ private ExecutionOutput parseComplexOutput(CodeType id) throws XMLStreamException { ComplexFormat attribs = parseComplexAttributes(); StreamBufferStore tmpSink = new StreamBufferStore(); try { if (attribs.getMimeType().startsWith("text/xml") || attribs.getMimeType().startsWith("application/xml")) { XMLOutputFactory fac = XMLOutputFactory.newInstance(); fac.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, true); XMLStreamWriter xmlWriter = fac.createXMLStreamWriter(tmpSink, "UTF-8"); XMLStreamUtils.nextElement(reader); xmlWriter.writeStartDocument("UTF-8", "1.0"); if (reader.getEventType() == START_ELEMENT) { XMLAdapter.writeElement(xmlWriter, reader); XMLStreamUtils.nextElement(reader); } else { LOG.debug("Response document contains empty complex data output '" + id + "'"); } xmlWriter.writeEndDocument(); xmlWriter.close(); } else { if ("base64".equals(attribs.getEncoding())) { String base64String = reader.getElementText(); byte[] bytes = Base64.decodeBase64(base64String); tmpSink.write(bytes); } else { LOG.warn("The encoding of binary data (found at response location " + reader.getLocation() + ") is not base64. Currently only for this format the decoding can be performed. Skipping the data."); } } tmpSink.close(); } catch (IOException e) { LOG.error(e.getMessage()); } return new ComplexOutput(id, tmpSink, attribs.getMimeType(), attribs.getEncoding(), attribs.getEncoding()); }