List of usage examples for org.w3c.dom Document setXmlStandalone
public void setXmlStandalone(boolean xmlStandalone) throws DOMException;
From source file:Main.java
public static void writeXMLObject(String path, String name, String tag, String model, double ry, String version, double x, double y, double z) { try {/*from w w w . j a v a2 s. co m*/ id++; DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); // Root elements Document doc = docBuilder.newDocument(); doc.setXmlStandalone(true); Element rootElement = doc.createElement(tag); doc.appendChild(rootElement); rootElement.setAttributeNode(addAttribut(doc, "action", "void")); rootElement.setAttributeNode(addAttribut(doc, "actionDist", "10.0")); rootElement.setAttributeNode(addAttribut(doc, "collidable", "true")); rootElement.setAttributeNode(addAttribut(doc, "id", id + "")); rootElement.setAttributeNode(addAttribut(doc, "model", model)); rootElement.setAttributeNode(addAttribut(doc, "pCameraFacing", "true")); rootElement.setAttributeNode(addAttribut(doc, "pControlFlow", "false")); rootElement.setAttributeNode(addAttribut(doc, "pEmitH", "1.0")); rootElement.setAttributeNode(addAttribut(doc, "pEmitInnerRadius", "0.0")); rootElement.setAttributeNode(addAttribut(doc, "pEmitOutterRadius", "1.0")); rootElement.setAttributeNode(addAttribut(doc, "pEmitType", "0")); rootElement.setAttributeNode(addAttribut(doc, "pEmitW", "1.0")); rootElement.setAttributeNode(addAttribut(doc, "pEndA", "1.0")); rootElement.setAttributeNode(addAttribut(doc, "pEndB", "1.0")); rootElement.setAttributeNode(addAttribut(doc, "pEndMass", "1.0")); rootElement.setAttributeNode(addAttribut(doc, "pEndR", "1.0")); rootElement.setAttributeNode(addAttribut(doc, "pEndSize", "1.0")); rootElement.setAttributeNode(addAttribut(doc, "pEndV", "1.0")); rootElement.setAttributeNode(addAttribut(doc, "pFactoryNumber", "500")); rootElement.setAttributeNode(addAttribut(doc, "pInitialVelocity", "0.0030")); rootElement.setAttributeNode(addAttribut(doc, "pMaxAngle", "10.0")); rootElement.setAttributeNode(addAttribut(doc, "pMaxLife", "2000.0")); rootElement.setAttributeNode(addAttribut(doc, "pMinAngle", "0.0")); rootElement.setAttributeNode(addAttribut(doc, "pMinLife", "1000.0")); rootElement.setAttributeNode(addAttribut(doc, "pParticulesPerSecVar", "1.0")); rootElement.setAttributeNode(addAttribut(doc, "pParticulesPerSeconds", "100")); rootElement.setAttributeNode(addAttribut(doc, "pSpeed", "1.0")); rootElement.setAttributeNode(addAttribut(doc, "pStartA", "1.0")); rootElement.setAttributeNode(addAttribut(doc, "pStartB", "1.0")); rootElement.setAttributeNode(addAttribut(doc, "pStartMass", "1.0")); rootElement.setAttributeNode(addAttribut(doc, "pStartR", "1.0")); rootElement.setAttributeNode(addAttribut(doc, "pStartSize", "1.0")); rootElement.setAttributeNode(addAttribut(doc, "pStartV", "1.0")); rootElement.setAttributeNode(addAttribut(doc, "rx", "0.0")); rootElement.setAttributeNode(addAttribut(doc, "ry", ry + "")); rootElement.setAttributeNode(addAttribut(doc, "rz", "0.0")); rootElement.setAttributeNode(addAttribut(doc, "s", "1.0")); rootElement.setAttributeNode(addAttribut(doc, "type", "basic")); rootElement.setAttributeNode(addAttribut(doc, "versionCode", version)); rootElement.setAttributeNode(addAttribut(doc, "x", x + "")); rootElement.setAttributeNode(addAttribut(doc, "y", y + "")); rootElement.setAttributeNode(addAttribut(doc, "z", z + "")); TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); DOMSource source = new DOMSource(doc); StreamResult result = new StreamResult(path + "\\" + name + id + ".xml"); transformer.transform(source, result); } catch (ParserConfigurationException pce) { pce.printStackTrace(); } catch (TransformerException tfe) { tfe.printStackTrace(); } }
From source file:eu.scidipes.toolkits.palibrary.utils.XMLUtils.java
/** * Transforms a collection of {@link FormField} objects into a simple XML document * /*from w w w. j ava2 s . c o m*/ * @param fields * a collection of form fields * @return an xml document representing the form fields, or null if the passed collection is null or empty, or all * form fields have an empty value */ public static Node formFieldsToMetadata(final Collection<? extends FormField> fields) { if (fields != null && !fields.isEmpty()) { try { final Document xml; synchronized (documentBuilderFactory) { xml = documentBuilderFactory.newDocumentBuilder().newDocument(); } xml.setXmlStandalone(true); final Element metaData = xml.createElement("metadata"); int completedFieldCount = 0; for (final FormField field : fields) { if (!StringUtils.isEmpty(field.getValue())) { completedFieldCount++; final Element metaDataEntry = xml.createElement("metadataentry"); final Element entryName = xml.createElement("entryname"); final Element entryValue = xml.createElement("entryvalue"); entryName.setTextContent(field.getDisplayName()); entryValue.setTextContent(field.getValue()); metaDataEntry.appendChild(entryName); metaDataEntry.appendChild(entryValue); metaData.appendChild(metaDataEntry); } } if (completedFieldCount > 0) { xml.appendChild(metaData); return xml; } else { return null; } } catch (final ParserConfigurationException e) { LOG.error(e.getMessage(), e); } } return null; }
From source file:Main.java
/** * Append application specific tags into xml signature document * @param document/*from w w w .ja v a 2 s .c om*/ * @return */ public static Document addUserInfoToSignature(Document document) { Element signature = document.getDocumentElement(); // initially it has no root-element, ... so we create it: Element root = document.createElement("digital-signature"); Element subjInfo = document.createElement("subject-information"); subjInfo.appendChild(document.createElement("subject")); subjInfo.appendChild(document.createElement("date")); subjInfo.appendChild(document.createElement("time")); subjInfo.appendChild(document.createElement("timestamp")); root.appendChild(subjInfo); root.appendChild(signature); // we can add an element to a document only once, // the following calls will raise exceptions: document.appendChild(root); document.setXmlStandalone(true); return document; }
From source file:com.moviejukebox.tools.DOMHelper.java
/** * Write the Document out to a file using nice formatting * * @param doc The document to save/*from w w w . j a va 2 s . c o m*/ * @param localFile The file to write to * @return */ public static boolean writeDocumentToFile(Document doc, File localFile) { try { Transformer trans = TransformerFactory.newInstance().newTransformer(); // Define the output properties trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no"); trans.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); trans.setOutputProperty(OutputKeys.INDENT, YES); trans.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4"); doc.setXmlStandalone(true); trans.transform(new DOMSource(doc), new StreamResult(localFile)); return true; } catch (IllegalArgumentException | DOMException | TransformerException error) { LOG.error("Error writing the document to {}", localFile); LOG.error("Message: {}", error.getMessage()); return false; } }
From source file:com.nebhale.gpxconverter.StandardRouteBuilder.java
@Override public Document build(String name, List<Point> points) { try {//from ww w. ja va 2 s . c om Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); document.setXmlStandalone(true); document.appendChild(gpx(document, name, points)); return document; } catch (ParserConfigurationException e) { throw new RuntimeException(e); } }
From source file:hu.bme.mit.sette.common.descriptors.eclipse.EclipseProjectDescriptor.java
/** * Creates the XML document for the .project file. * * @return The XML document./*from w w w .j a v a 2 s. c o m*/ * @throws ParserConfigurationException * If a DocumentBuilder cannot be created which satisfies the * configuration requested. */ public Document createXmlDocument() throws ParserConfigurationException { // create document object Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); document.setXmlVersion("1.0"); document.setXmlStandalone(true); // add root tag Element rootTag = document.createElement("projectDescription"); document.appendChild(rootTag); // add name and comment rootTag.appendChild(document.createElement("name")).setTextContent(name); rootTag.appendChild(document.createElement("comment")).setTextContent(comment); // add the projects tag rootTag.appendChild(document.createElement("projects")); // add the Java builder Element buildSpecTag = document.createElement("buildSpec"); rootTag.appendChild(buildSpecTag); Element buildCommandTag = document.createElement("buildCommand"); buildSpecTag.appendChild(buildCommandTag); buildCommandTag.appendChild(document.createElement("name")) .setTextContent(EclipseProjectDescriptor.JAVA_BUILDER); buildCommandTag.appendChild(document.createElement("arguments")); // add the Java nature Element naturesTag = document.createElement("natures"); rootTag.appendChild(naturesTag); naturesTag.appendChild(document.createElement("nature")) .setTextContent(EclipseProjectDescriptor.JAVA_NATURE); return document; }
From source file:hd3gtv.as5kpc.protocol.ProtocolHandler.java
private Document createDocument() { try {//from ww w .j a va2 s . c o m DocumentBuilderFactory fq = DocumentBuilderFactory.newInstance(); DocumentBuilder constructeur = fq.newDocumentBuilder(); Document document = constructeur.newDocument(); document.setXmlVersion("1.0"); document.setXmlStandalone(true); return document; } catch (Exception e) { log.error("Can't make XML document", e); } return null; }
From source file:edu.clemson.lph.civet.xml.StdeCviXmlBuilder.java
public StdeCviXmlBuilder(Document doc) { this.doc = doc; doc.setXmlStandalone(true); root = doc.getDocumentElement();//from w ww . ja va2 s. c om helper = new XMLDocHelper(doc); }
From source file:es.upm.fi.dia.oeg.sitemap4rdf.Generator.java
/** * Generates the sitemap.xml file//from w ww. j ava 2 s. c o m * @param result an existing ResultSet if we did cross the limit of URLs per sitemap.xml file * @param index of the current generation of the sitemap file, useful when we are creating sitemap_index.xml files */ protected void generateSiteMap(ResultSet result, int index) { try { DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = dbfac.newDocumentBuilder(); Document doc = docBuilder.newDocument(); Element root = doc.createElement(urlSetTag); root.setAttribute(XMLNS, namespace); if (!semanticSectionGenerated) { root.setAttribute(XMLNS + ":" + PREFIX_SEMANTIC_SITEMAP, NS_SEMANTIC_SITEMAP); } doc.appendChild(root); generateSemanticSection(doc, root); ResultSet rs = generateFromEndPoint(doc, root, result); doc.setXmlStandalone(true); String outputFileName = (index == 0) ? (outputFile + extensionOutputFile) : (outputFile + index + extensionOutputFile); //String outputFileNameDirIncluded = outputFileName; //if (outputDir!=null && !outputDir.isEmpty()) //outputFileNameDirIncluded = outputDir+outputFileName; if (files == null) files = new HashMap<String, Document>(); files.put(outputFileName, doc); if (rs != null) generateSiteMap(rs, ++index); } catch (ParserConfigurationException e) { logger.debug("ParserConfigurationException ", e); System.err.println(e.getMessage()); System.exit(3); } }
From source file:serverTools.java
public String createServerConfig(String node, String jsonString) { String result = node + "::"; try {//from www .ja v a 2s . c om String ret; JSONObject jo = new JSONObject(jsonString); UUID uid = UUID.randomUUID(); String varName = node; String varIP = jo.get("ip").toString(); String varHyp = jo.get("hypervisor").toString(); String varVmconfigs = jo.get("vmconfigs").toString(); String varTransport = jo.get("transport").toString(); String varDesc = jo.get("description").toString(); // make sure that remote directory exist // Get the JSONArray value associated with the Result key JSONArray storageArray = jo.getJSONArray("storages"); String configDir = this.makeRelativeDirs("/" + varName + "/config"); this.makeRelativeDirs("/" + varName + "/screenshots"); this.makeRelativeDirs("/" + varName + "/vm/configs"); // Cration d'un nouveau DOM DocumentBuilderFactory fabrique = DocumentBuilderFactory.newInstance(); DocumentBuilder constructeur = fabrique.newDocumentBuilder(); Document document = constructeur.newDocument(); // Proprits du DOM document.setXmlStandalone(true); // Cration de l'arborescence du DOM Element server = document.createElement("server"); document.appendChild(server); //racine.appendChild(document.createComment("Commentaire sous la racine")); Element name = document.createElement("name"); server.appendChild(name); name.setTextContent(varName); Element ip = document.createElement("ip"); server.appendChild(ip); ip.setTextContent(varIP); Element hypervisor = document.createElement("hypervisor"); server.appendChild(hypervisor); hypervisor.setTextContent(varHyp); Element transport = document.createElement("transport"); server.appendChild(transport); transport.setTextContent(varTransport); Element descEl = document.createElement("description"); server.appendChild(descEl); descEl.setTextContent(varDesc); Element vmconfigs = document.createElement("vmconfigs"); server.appendChild(vmconfigs); vmconfigs.setTextContent(varVmconfigs); JSONObject coordinatesObj = jo.getJSONObject("coordinates"); Element coordinatesEl = document.createElement("coordinates"); server.appendChild(coordinatesEl); coordinatesEl.setAttribute("building", coordinatesObj.get("building").toString()); coordinatesEl.setAttribute("street", coordinatesObj.get("street").toString()); coordinatesEl.setAttribute("city", coordinatesObj.get("city").toString()); coordinatesEl.setAttribute("latitude", coordinatesObj.get("latitude").toString()); coordinatesEl.setAttribute("longitude", coordinatesObj.get("longitude").toString()); //<storages> Element storages = document.createElement("storages"); server.appendChild(storages); int resultCount = storageArray.length(); for (int i = 0; i < resultCount; i++) { Element repository = document.createElement("repository"); storages.appendChild(repository); Element path = document.createElement("target"); repository.appendChild(path); JSONObject newStorage = storageArray.getJSONObject(i); String storageName = newStorage.get("name").toString(); String storagePath = newStorage.get("target").toString(); storageName = storageName.replaceAll(" ", "_"); storagePath = storagePath.replaceAll(" ", "_"); repository.setAttribute("type", newStorage.get("type").toString()); repository.setAttribute("name", storageName); path.setTextContent(storagePath); Element source = document.createElement("source"); repository.appendChild(source); String storageSource = newStorage.get("source").toString(); source.setTextContent(storageSource); String localStorageDir = this.makeRelativeDirs("/" + varName + "/vm/storages/" + storageName); if (localStorageDir == "Error") { return result + "Error: cannot create " + varName + "/vm/storages/" + storageName; } } //</storages> // Get network information (look for bridges) Element networks = document.createElement("networks"); server.appendChild(networks); JSONObject joAction = new JSONObject(); joAction.put("name", "add"); joAction.put("driver", varHyp); joAction.put("transport", varTransport); joAction.put("description", varDesc); ArrayList<String> optList = new ArrayList<String>(); optList.add("ip=" + varIP); String varPasswd = ""; varPasswd = jo.opt("password").toString(); if (varPasswd.length() > 0) { optList.add("exchange_keys=" + varPasswd); } joAction.put("options", optList); String msg = callOvnmanager(node, joAction.toString()); JSONObject joMsg = new JSONObject(msg); JSONObject joActionRes = joMsg.getJSONObject("action"); result += joActionRes.get("result").toString(); //write the content into xml file String pathToXml = configDir + "/" + varName + ".xml"; File xmlOutput = new File(pathToXml); TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); DOMSource source = new DOMSource(document); StreamResult streamRes = new StreamResult(xmlOutput); transformer.transform(source, streamRes); } catch (Exception e) { log(ERROR, "create xml file has failed", e); return result + "Error: " + e.toString(); } //ret = "done"; return result; }