List of usage examples for org.w3c.dom Document appendChild
public Node appendChild(Node newChild) throws DOMException;
newChild
to the end of the list of children of this node. From source file:com.connexta.arbitro.utils.policy.PolicyBuilder.java
public String build(PolicySetElementDTO policyElementDTO) throws PolicyBuilderException { Document doc = null; try {//from ww w. j a va 2 s. c om doc = Utils.createNewDocument(); } catch (ParserConfigurationException e) { throw new PolicyBuilderException("While creating Document Object", e); } if (doc != null) { doc.appendChild(PolicyUtils.createPolicySetElement(policyElementDTO, doc)); try { return Utils.getStringFromDocument(doc); } catch (TransformerException e) { throw new PolicyBuilderException("Error while converting Policy element to String", e); } } return null; }
From source file:com.alvexcore.share.ShareExtensionRegistry.java
public ExtensionUpdateInfo checkForUpdates(String extensionId, String shareId, Map<String, String> shareHashes, String shareVersion, String repoId, Map<String, String> repoHashes, String repoVersion, String licenseId) throws Exception { // search for extension DocumentBuilderFactory xmlFact = DocumentBuilderFactory.newInstance(); xmlFact.setNamespaceAware(true);//w ww.jav a 2s . com xmlBuilder = xmlFact.newDocumentBuilder(); // build query Document queryXML = xmlBuilder.newDocument(); Element rootElement = queryXML.createElement("extension"); queryXML.appendChild(rootElement); Element el = queryXML.createElement("license-id"); el.appendChild(queryXML.createTextNode(licenseId)); rootElement.appendChild(el); el = queryXML.createElement("id"); el.appendChild(queryXML.createTextNode(extensionId)); rootElement.appendChild(el); el = queryXML.createElement("share-version"); el.appendChild(queryXML.createTextNode(shareVersion)); rootElement.appendChild(el); el = queryXML.createElement("repo-version"); el.appendChild(queryXML.createTextNode(repoVersion)); rootElement.appendChild(el); el = queryXML.createElement("share-id"); el.appendChild(queryXML.createTextNode(shareId)); rootElement.appendChild(el); el = queryXML.createElement("repo-id"); el.appendChild(queryXML.createTextNode(repoId)); rootElement.appendChild(el); el = queryXML.createElement("share-files"); rootElement.appendChild(el); for (String fileName : shareHashes.keySet()) { Element fileElem = queryXML.createElement("file"); fileElem.setAttribute("md5hash", shareHashes.get(fileName)); fileElem.appendChild(queryXML.createTextNode(fileName)); el.appendChild(fileElem); } el = queryXML.createElement("repo-files"); rootElement.appendChild(el); for (String fileName : repoHashes.keySet()) { Element fileElem = queryXML.createElement("file"); fileElem.setAttribute("md5hash", repoHashes.get(fileName)); fileElem.appendChild(queryXML.createTextNode(fileName)); el.appendChild(fileElem); } // query server try { URL url = new URL( "https://update.alvexhq.com:443/alfresco/s/api/alvex/extension/" + extensionId + "/update"); HttpsURLConnection conn = (HttpsURLConnection) url.openConnection(); // disable host verification conn.setHostnameVerifier(new HostnameVerifier() { @Override public boolean verify(String arg0, SSLSession arg1) { return true; } }); conn.setDoOutput(true); conn.setDoInput(true); conn.connect(); OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream()); TransformerFactory.newInstance().newTransformer().transform(new DOMSource(queryXML), new StreamResult(wr)); wr.close(); // get response Document responseXML = xmlBuilder.parse(conn.getInputStream()); XPath xpath = XPathFactory.newInstance().newXPath(); // get version String repoLatestVersion = ((Node) xpath.evaluate("/extension/repo-version/text()", responseXML, XPathConstants.NODE)).getNodeValue(); String shareLatestVersion = ((Node) xpath.evaluate("/extension/share-version/text()", responseXML, XPathConstants.NODE)).getNodeValue(); NodeList nl = (NodeList) xpath.evaluate("/extension/repo-files/file", responseXML, XPathConstants.NODESET); Map<String, Boolean> repoFiles = new HashMap<String, Boolean>(nl.getLength()); for (int i = 0; i < nl.getLength(); i++) repoFiles.put(nl.item(i).getTextContent(), "ok".equals(nl.item(i).getAttributes().getNamedItem("status").getNodeValue())); nl = (NodeList) xpath.evaluate("/extension/share-files/file", responseXML, XPathConstants.NODESET); Map<String, Boolean> shareFiles = new HashMap<String, Boolean>(nl.getLength()); for (int i = 0; i < nl.getLength(); i++) shareFiles.put(nl.item(i).getTextContent(), "ok".equals(nl.item(i).getAttributes().getNamedItem("status").getNodeValue())); String motd = ((Node) xpath.evaluate("/extension/motd/text()", responseXML, XPathConstants.NODE)) .getNodeValue(); return new ExtensionUpdateInfo(extensionId, repoVersion, shareVersion, repoLatestVersion, shareLatestVersion, repoFiles, shareFiles, motd); } catch (Exception e) { return new ExtensionUpdateInfo(extensionId, repoVersion, shareVersion, "", "", new HashMap<String, Boolean>(), new HashMap<String, Boolean>(), ""); } }
From source file:com.connexta.arbitro.utils.policy.PolicyBuilder.java
/** * * @param requestElementDTO// w w w.java2s .c o m * @return * @throws PolicyBuilderException */ public String buildRequest(RequestElementDTO requestElementDTO) throws PolicyBuilderException { Document doc = null; try { doc = Utils.createNewDocument(); } catch (ParserConfigurationException e) { throw new PolicyBuilderException("While creating Document Object", e); } if (doc != null) { doc.appendChild(PolicyUtils.createRequestElement(requestElementDTO, doc)); try { return Utils.getStringFromDocument(doc); } catch (TransformerException e) { throw new PolicyBuilderException("Error while converting request element to String", e); } } return null; }
From source file:com.action.ExportAction.java
public String exportXMLAction() { try {/* ww w . j a v a2 s. c o m*/ //document DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.newDocument(); Element reportsElement = document.createElement("project");// reportsElement.setAttribute("date", (new Date()).toString()); document.appendChild(reportsElement); System.out.println("exportXMLAction:" + tableCode); String[] ids = tableCode.split(","); for (String id : ids) { System.out.println("id:" + id); List<JQ_zhibiao_entity> list = Export.getDuizhaoByJqTbCode(id); document = Export.exportXML(reportsElement, document, list, id); } TransformerFactory tf = TransformerFactory.newInstance(); Transformer transformer = tf.newTransformer(); DOMSource source = new DOMSource(document); transformer.setOutputProperty(OutputKeys.ENCODING, "GB2312"); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); PrintWriter pw = new PrintWriter(new FileOutputStream(realPath + "test.xml")); StreamResult result = new StreamResult(pw); transformer.transform(source, result); pw.close(); } catch (Exception e) { ActionContext.getContext().put("message", "??" + e); return ERROR; } return SUCCESS; }
From source file:eu.apenet.dpt.standalone.gui.hgcreation.LevelTreeActions.java
public File createXML(TreeModel model, HashMap<String, String> paramMap, String countryCode, String globalIdentifier) { CLevelTreeObject obj = (CLevelTreeObject) ((DefaultMutableTreeNode) model.getRoot()).getUserObject(); try {/* www . j a v a 2s.c o m*/ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); DOMImplementation domImplementation = builder.getDOMImplementation(); Document doc = domImplementation.createDocument(null, null, null); Element root = createArchdesc(doc, model, model.getRoot(), paramMap, obj.getId(), obj.getName()); doc.appendChild(root); TransformerFactory tf = TransformerFactory.newInstance(); Transformer output = tf.newTransformer(); output.setOutputProperty(javax.xml.transform.OutputKeys.INDENT, "yes"); output.setOutputProperty(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes"); output.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); output.transform(new DOMSource(doc.getFirstChild()), new StreamResult(new File(Utilities.TEMP_DIR + ".hg_creation.xml"))); File outputFile = new File(Utilities.TEMP_DIR + "temp_HG.xml"); File finalFile = new File( Utilities.TEMP_DIR + "Holdings_Guide_" + globalIdentifier + "_" + obj.getId() + ".xml"); finalFile.deleteOnExit(); FileUtils.writeStringToFile(outputFile, HoldingsGuideCreationUtils.eadDeclaration(obj.getName(), obj.getId(), countryCode, globalIdentifier, DataPreparationToolGUI.VERSION_NB), "UTF-8"); fileUtil.writeToFile(fileUtil.readFileAsString_linebreak(Utilities.TEMP_DIR + ".hg_creation.xml"), Utilities.TEMP_DIR + outputFile.getName(), true); fileUtil.writeToFile(HoldingsGuideCreationUtils.endDeclaration(), Utilities.TEMP_DIR + outputFile.getName(), true); TransformationTool.createTransformation(fileUtil.readFileAsInputStream(outputFile), finalFile, Utilities.BEFORE_XSL_FILE, null, true, true, null, true, null); outputFile.delete(); return finalFile; } catch (Exception e) { LOG.error("Error", e); } return null; }
From source file:hd3gtv.as5kpc.protocol.ProtocolHandler.java
public ServerResponseAbout initialize() throws IOException { Document document = createDocument(); Element root_ams_element = document.createElement("AMS"); document.appendChild(root_ams_element); Element last_order_element = document.createElement("Configuration"); Element init = document.createElement("Initialize"); last_order_element.appendChild(init); root_ams_element.appendChild(last_order_element); return (ServerResponseAbout) send(document, new ServerResponseAbout()); }
From source file:hd3gtv.as5kpc.protocol.ProtocolHandler.java
public ServerResponseOk record() throws IOException { Document document = createDocument(); Element root_ams_element = document.createElement("AMS"); document.appendChild(root_ams_element); Element last_order_element = document.createElement("TransportControl"); Element rec = document.createElement("Record"); last_order_element.appendChild(rec); root_ams_element.appendChild(last_order_element); return (ServerResponseOk) send(document, new ServerResponseOk()); }
From source file:hd3gtv.as5kpc.protocol.ProtocolHandler.java
public ServerResponseOk eject() throws IOException { Document document = createDocument(); Element root_ams_element = document.createElement("AMS"); document.appendChild(root_ams_element); Element last_order_element = document.createElement("TransportControl"); Element ej = document.createElement("Eject"); last_order_element.appendChild(ej);//from ww w. j a v a 2 s. c om root_ams_element.appendChild(last_order_element); return (ServerResponseOk) send(document, new ServerResponseOk()); }
From source file:hd3gtv.as5kpc.protocol.ProtocolHandler.java
public ServerResponseOk stop() throws IOException { Document document = createDocument(); Element root_ams_element = document.createElement("AMS"); document.appendChild(root_ams_element); Element last_order_element = document.createElement("TransportControl"); Element stop = document.createElement("Stop"); last_order_element.appendChild(stop); root_ams_element.appendChild(last_order_element); return (ServerResponseOk) send(document, new ServerResponseOk()); }
From source file:de.dentrassi.pm.maven.internal.MavenRepositoryChannelAggregator.java
/** * Create the repository meta data file, for scraping * * @param context/*from w w w . j av a2 s . com*/ * @return the document */ private Document makeRepoMetaData(final AggregationContext context) { final Document doc = this.xml.create(); // create document final Element root = doc.createElement("repository-metadata"); doc.appendChild(root); addElement(root, "version", "1.0.0"); addElement(root, "id", context.getChannelId()); addElement(root, "name", context.getChannelNameOrId()); addElement(root, "layout", "maven2"); addElement(root, "policy", "mixed"); addElement(root, "url", makeUrl(context.getChannelId())); return doc; }