List of usage examples for org.w3c.dom Node appendChild
public Node appendChild(Node newChild) throws DOMException;
newChild
to the end of the list of children of this node. From source file:org.automagic.deps.doctor.editor.PomWriterImpl.java
private void addIndentedNode(final Node parent, Node newChild, int indent) { Optional<Node> insertionPoint = getInsertionPoint(parent); List<Node> indentedList = indent(newChild, indent); Collections.reverse(indentedList); Node point = insertionPoint.get(); for (Node node : indentedList) { if (insertionPoint.isPresent()) { parent.insertBefore(node, point); point = node;// www. j av a 2 s . com } else { parent.appendChild(node); } } }
From source file:org.automagic.deps.doctor.editor.PomWriterImpl.java
private List<Node> indent(Node node, int indent) { Node root = document.createElement("dummy"); StringBuilder sb = new StringBuilder(); Node wrapper = root; for (int i = 1; i < indent; i++) { Element element = document.createElement("dummy"); wrapper.appendChild(element); wrapper = element;//from w w w. ja v a2 s .c om sb.append("/dummy"); } wrapper.appendChild(node); Node prettyRoot = Utils.prettyFormat(root, indentationSize, indentWithTabs); if (sb.length() != 0) { String xpath = sb.substring(1); prettyRoot = Utils.getNode(xpath, prettyRoot).get(); } final Optional<Node> point = getInsertionPoint(prettyRoot); final List<Node> result = new ArrayList<>(); final NodeList childNodes = prettyRoot.getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { Node item = childNodes.item(i); if (point.isPresent() && point.get().equals(item)) { break; } result.add(item); } return result; }
From source file:org.automagic.deps.doctor.editor.PomWriterImpl.java
private void addDummyComment(Node dependenciesNode) { dependenciesNode.appendChild(document.createComment("dummy")); }
From source file:org.broad.igv.cbio.GeneNetwork.java
/** * Add the data specified by the score-types to our * network, using data from the tracks./*from w w w.j a v a 2 s. c om*/ * <p/> * * @param tracks * @param nodeAttributes */ public void annotate(List<Track> tracks, Collection<String> nodeAttributes) { Set<Node> nodes = this.vertexSet(); String name; for (Node node : nodes) { name = getNodeKeyData(node, LABEL); ScoreData data = this.collectScoreData(name, tracks, nodeAttributes); //Don't add annotation if gene has no alteration? float relData = data.getPercentAltered(); if (relData == 0 && !Globals.isTesting()) { continue; } for (String attr : nodeAttributes) { Element newData = node.getOwnerDocument().createElement("data"); newData.setAttribute(KEY, attr); newData.setTextContent("" + data.get(attr)); node.appendChild(newData); } //Set total Element newData = node.getOwnerDocument().createElement("data"); newData.setAttribute(KEY, PERCENT_ALTERED); newData.setTextContent("" + data.getPercentAltered()); node.appendChild(newData); } addSchema(Arrays.asList(PERCENT_ALTERED), "float", "node"); addSchema(nodeAttributes, "float", "node"); }
From source file:org.broadleafcommerce.common.extensibility.context.merge.handlers.InsertChildrenOf.java
public Node[] merge(List<Node> nodeList1, List<Node> nodeList2, List<Node> exhaustedNodes) { if (CollectionUtils.isEmpty(nodeList1) || CollectionUtils.isEmpty(nodeList2)) { return null; }//ww w . ja va 2 s. co m Node node1 = nodeList1.get(0); Node node2 = nodeList2.get(0); NodeList list2 = node2.getChildNodes(); for (int j = 0; j < list2.getLength(); j++) { node1.appendChild(node1.getOwnerDocument().importNode(list2.item(j).cloneNode(true), true)); } Node[] response = new Node[nodeList2.size()]; for (int j = 0; j < response.length; j++) { response[j] = nodeList2.get(j); } return response; }
From source file:org.broadleafcommerce.common.extensibility.context.merge.handlers.InsertItems.java
public Node[] merge(List<Node> nodeList1, List<Node> nodeList2, List<Node> exhaustedNodes) { if (CollectionUtils.isEmpty(nodeList1) || CollectionUtils.isEmpty(nodeList2)) { return null; }// www .j av a 2s . c om List<Node> usedNodes = new ArrayList<Node>(); Node node1Parent = nodeList1.get(0).getParentNode(); for (Node aNodeList2 : nodeList2) { Node tempNode = node1Parent.getOwnerDocument().importNode(aNodeList2.cloneNode(true), true); if (LOG.isDebugEnabled()) { StringBuffer sb = new StringBuffer(); sb.append("matching node for insertion: "); sb.append(tempNode.getNodeName()); int attrLength = tempNode.getAttributes().getLength(); for (int x = 0; x < attrLength; x++) { sb.append(" : ("); sb.append(tempNode.getAttributes().item(x).getNodeName()); sb.append("/"); sb.append(tempNode.getAttributes().item(x).getNodeValue()); sb.append(")"); } LOG.debug(sb.toString()); } if (LOG.isDebugEnabled()) { StringBuilder sb = new StringBuilder(); sb.append("inserting into parent: "); sb.append(node1Parent.getNodeName()); int attrLength = node1Parent.getAttributes().getLength(); for (int x = 0; x < attrLength; x++) { sb.append(" : ("); sb.append(node1Parent.getAttributes().item(x).getNodeName()); sb.append("/"); sb.append(node1Parent.getAttributes().item(x).getNodeValue()); sb.append(")"); } LOG.debug(sb.toString()); } node1Parent.appendChild(tempNode); usedNodes.add(tempNode); } Node[] response = { nodeList2.get(0).getParentNode() }; return response; }
From source file:org.broadleafcommerce.common.extensibility.context.merge.handlers.NodeReplaceInsert.java
private List<Node> matchNodes(List<Node> exhaustedNodes, Node[] primaryNodes, ArrayList<Node> list) { List<Node> usedNodes = new ArrayList<Node>(20); Iterator<Node> itr = list.iterator(); Node parentNode = primaryNodes[0].getParentNode(); Document ownerDocument = parentNode.getOwnerDocument(); while (itr.hasNext()) { Node node = itr.next();//from w w w .j a va 2 s. c o m if (Element.class.isAssignableFrom(node.getClass()) && !exhaustedNodesContains(exhaustedNodes, node)) { if (LOG.isDebugEnabled()) { StringBuffer sb = new StringBuffer(); sb.append("matching node for replacement: "); sb.append(node.getNodeName()); int attrLength = node.getAttributes().getLength(); for (int j = 0; j < attrLength; j++) { sb.append(" : ("); sb.append(node.getAttributes().item(j).getNodeName()); sb.append("/"); sb.append(node.getAttributes().item(j).getNodeValue()); sb.append(")"); } LOG.debug(sb.toString()); } if (!checkNode(usedNodes, primaryNodes, node)) { //simply append the node if all the above fails Node newNode = ownerDocument.importNode(node.cloneNode(true), true); parentNode.appendChild(newNode); usedNodes.add(node); } } } return usedNodes; }
From source file:org.carewebframework.ui.xml.ZK2XML.java
/** * Adds the root component to the XML document at the current level along with all bean * properties that return String or primitive types. Then, recurses over all of the root * component's children./*from www . j a v a2 s. co m*/ * * @param root The root component. * @param parent The parent XML node. */ private void toXML(Component root, Node parent) { TreeMap<String, String> properties = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER); Class<?> clazz = root.getClass(); ComponentDefinition def = root.getDefinition(); String cmpname = def.getName(); if (def.getImplementationClass() != clazz) { properties.put("use", clazz.getName()); } if (def.getApply() != null) { properties.put("apply", def.getApply()); } Node child = doc.createElement(cmpname); parent.appendChild(child); for (PropertyDescriptor propDx : PropertyUtils.getPropertyDescriptors(root)) { Method getter = propDx.getReadMethod(); Method setter = propDx.getWriteMethod(); String name = propDx.getName(); if (getter != null && setter != null && !isExcluded(name, cmpname, null) && !setter.isAnnotationPresent(Deprecated.class) && (getter.getReturnType() == String.class || getter.getReturnType().isPrimitive())) { try { Object raw = getter.invoke(root); String value = raw == null ? null : raw.toString(); if (StringUtils.isEmpty(value) || ("id".equals(name) && value.startsWith("z_")) || isExcluded(name, cmpname, value)) { continue; } properties.put(name, value.toString()); } catch (Exception e) { } } } for (Entry<String, String> entry : properties.entrySet()) { Attr attr = doc.createAttribute(entry.getKey()); child.getAttributes().setNamedItem(attr); attr.setValue(entry.getValue()); } properties = null; for (Component cmp : root.getChildren()) { toXML(cmp, child); } }
From source file:org.chiba.xml.xforms.ui.Repeat.java
private void initializePrototype(Node parent, Node prototype) { Node copy = prototype.cloneNode(false); if (copy.getNodeType() == Node.ELEMENT_NODE) { Element element = (Element) copy; if (element.getAttributeNS(null, "id").length() == 0) { element.setAttributeNS(null, "id", this.container.generateId()); }//w w w . j a v a 2 s . c o m NodeList children = prototype.getChildNodes(); for (int index = 0; index < children.getLength(); index++) { initializePrototype(element, children.item(index)); } } parent.appendChild(copy); }
From source file:org.company.processmaker.TreeFilesTopComponent.java
public TreeFilesTopComponent() { initComponents();/*from ww w . j a v a2s.c om*/ setName(Bundle.CTL_TreeFilesTopComponent()); setToolTipText(Bundle.HINT_TreeFilesTopComponent()); // new codes instance = this; MouseListener ml = new MouseAdapter() { public void mousePressed(MouseEvent e) { int selRow = jTree1.getRowForLocation(e.getX(), e.getY()); TreePath selPath = jTree1.getPathForLocation(e.getX(), e.getY()); if (selRow != -1) { if (e.getClickCount() == 1) { //mySingleClick(selRow, selPath); } else if (e.getClickCount() == 2) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) jTree1 .getLastSelectedPathComponent(); if (node == null) { return; } Object nodeInfo = node.getUserObject(); int node_level = node.getLevel(); if (node_level < 2) { return; } // for each dyna form if (node_level == 2) { Global gl_obj = Global.getInstance(); //myDoubleClick(selRow, selPath); conf = Config.getInstance(); DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent(); String parentName = (String) parent.getUserObject(); // handle triggers if (parentName.equals("Triggers")) { String filePath = ""; for (String[] s : res_trigger) { if (s[0].equals(nodeInfo.toString())) { // get path of dyna in xml forms filePath = conf.tmp + "triggers/" + s[3] + "/" + s[2] + ".php"; break; } } File toAdd = new File(filePath); try { DataObject dObject = DataObject.find(FileUtil.toFileObject(toAdd)); dObject.getLookup().lookup(OpenCookie.class).open(); // dont listen for exist listen files if (existFile(filePath)) { return; } dObject.addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { if (DataObject.PROP_MODIFIED.equals(evt.getPropertyName())) { //fire a dummy event if (!Boolean.TRUE.equals(evt.getNewValue())) { /*String msg = "Saved to" + evt.toString(); NotifyDescriptor nd = new NotifyDescriptor.Message(msg, NotifyDescriptor.INFORMATION_MESSAGE); DialogDisplayer.getDefault().notify(nd);*/ TopComponent activeTC = TopComponent.getRegistry() .getActivated(); DataObject dataLookup = activeTC.getLookup() .lookup(DataObject.class); String filePath = FileUtil.toFile(dataLookup.getPrimaryFile()) .getAbsolutePath(); File userFile = new File(filePath); String fileName = userFile.getName(); fileName = fileName.substring(0, fileName.lastIndexOf(".")); try { String content = new String( Files.readAllBytes(Paths.get(filePath))); // remote php tag and info "<?php //don't remove this tag! \n" content = content.substring(6, content.length()); String query = "update triggers set TRI_WEBBOT = '" + StringEscapeUtils.escapeSql(content) + "' where TRI_UID = '" + fileName + "'"; GooglePanel.updateQuery(query); } catch (Exception e) { //Exceptions.printStackTrace(e); String msg = "Can not update trigger"; NotifyDescriptor nd = new NotifyDescriptor.Message(msg, NotifyDescriptor.INFORMATION_MESSAGE); DialogDisplayer.getDefault().notify(nd); } } } } }); } catch (DataObjectNotFoundException ex) { //Exceptions.printStackTrace(ex); String msg = "Trigger not found"; NotifyDescriptor nd = new NotifyDescriptor.Message(msg, NotifyDescriptor.INFORMATION_MESSAGE); DialogDisplayer.getDefault().notify(nd); } return; } List<String[]> res_dyna = gl_obj.getDyna(); String FileDir = ""; for (String[] s : res_dyna) { if (s[1].equals(nodeInfo.toString())) { // get path of dyna in xml forms FileDir = s[3]; break; } } //String msg = "selRow" + nodeInfo.toString() + "|" + conf.getXmlForms() + FileDir; String filePath = conf.getXmlForms() + FileDir + ".xml"; if (conf.isRemote()) { String[] res = FileDir.split("/"); filePath = conf.get("local_tmp_for_remote") + "/" + FileDir + "/" + res[1] + ".xml"; } File toAdd = new File(filePath); //Result will be null if the user clicked cancel or closed the dialog w/o OK if (toAdd != null) { try { DataObject dObject = DataObject.find(FileUtil.toFileObject(toAdd)); dObject.getLookup().lookup(OpenCookie.class).open(); // dont listen for exist listen files if (existFile(filePath)) { return; } dObject.addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { if (DataObject.PROP_MODIFIED.equals(evt.getPropertyName())) { //fire a dummy event if (!Boolean.TRUE.equals(evt.getNewValue())) { /*String msg = "Saved to" + evt.toString(); NotifyDescriptor nd = new NotifyDescriptor.Message(msg, NotifyDescriptor.INFORMATION_MESSAGE); DialogDisplayer.getDefault().notify(nd);*/ TopComponent activeTC = TopComponent.getRegistry() .getActivated(); DataObject dataLookup = activeTC.getLookup() .lookup(DataObject.class); String filePath = FileUtil.toFile(dataLookup.getPrimaryFile()) .getAbsolutePath(); File userFile = new File(filePath); String fileName = userFile.getName(); fileName = fileName.substring(0, fileName.lastIndexOf(".")); Global gl_obj = Global.getInstance(); List<String[]> res_dyna = gl_obj.getDyna(); String FileDir = ""; for (String[] s : res_dyna) { if (filePath.contains(s[0])) { FileDir = s[3]; break; } } if (conf.isRemote()) { boolean res_Upload = SSH.getInstance().uplaodFile(FileDir); if (res_Upload) { String msg = "file upload Successfully!"; NotifyDescriptor nd = new NotifyDescriptor.Message(msg, NotifyDescriptor.INFORMATION_MESSAGE); DialogDisplayer.getDefault().notify(nd); } else { String msg = "error in uploading file!"; NotifyDescriptor nd = new NotifyDescriptor.Message(msg, NotifyDescriptor.INFORMATION_MESSAGE); DialogDisplayer.getDefault().notify(nd); } } } } } }); } catch (DataObjectNotFoundException ex) { //Exceptions.printStackTrace(ex); String msg = "Can not find xml file"; NotifyDescriptor nd = new NotifyDescriptor.Message(msg, NotifyDescriptor.INFORMATION_MESSAGE); DialogDisplayer.getDefault().notify(nd); } } } // for each js file if (node_level == 3) { TreeNode parentInfo = node.getParent(); Global gl_obj = Global.getInstance(); List<String[]> res_dyna = gl_obj.getDyna(); String FileDir = ""; for (String[] s : res_dyna) { if (s[1].equals(parentInfo.toString())) { // get path of dyna in xml forms FileDir = s[3]; break; } } //myDoubleClick(selRow, selPath); conf = Config.getInstance(); String filePath = conf.tmp + "xmlForms/" + FileDir + "/" + nodeInfo.toString() + ".js"; if (conf.isRemote()) { filePath = conf.get("local_tmp_for_remote") + FileDir + "/" + nodeInfo.toString() + ".js"; } File toAdd = new File(filePath); //Result will be null if the user clicked cancel or closed the dialog w/o OK if (toAdd != null) { try { DataObject dObject = DataObject.find(FileUtil.toFileObject(toAdd)); dObject.getLookup().lookup(OpenCookie.class).open(); // dont listen for exist listen files if (existFile(filePath)) { return; } dObject.addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { if (DataObject.PROP_MODIFIED.equals(evt.getPropertyName())) { //fire a dummy event if (!Boolean.TRUE.equals(evt.getNewValue())) { JTextComponent ed = EditorRegistry.lastFocusedComponent(); String jsDoc = ""; try { jsDoc = ed.getText(); } catch (Exception ex) { //Exceptions.printStackTrace(ex); String msg = "Can not get text from editor"; NotifyDescriptor nd = new NotifyDescriptor.Message(msg, NotifyDescriptor.INFORMATION_MESSAGE); DialogDisplayer.getDefault().notify(nd); } TopComponent activeTC = TopComponent.getRegistry() .getActivated(); DataObject dataLookup = activeTC.getLookup() .lookup(DataObject.class); String filePath = FileUtil.toFile(dataLookup.getPrimaryFile()) .getAbsolutePath(); File userFile = new File(filePath); String fileName = userFile.getName(); fileName = fileName.substring(0, fileName.lastIndexOf(".")); Global gl_obj = Global.getInstance(); List<String[]> res_dyna = gl_obj.getDyna(); String FileDir = ""; for (String[] s : res_dyna) { if (filePath.contains(s[0])) { FileDir = s[3]; break; } } String fullPath = conf.getXmlForms() + FileDir + ".xml"; if (conf.isRemote()) { String[] res = FileDir.split("/"); fullPath = conf.get("local_tmp_for_remote") + FileDir + "/" + res[1] + ".xml"; } try { DocumentBuilderFactory factory = DocumentBuilderFactory .newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document mainDoc = builder.parse(fullPath); XPath xPath = XPathFactory.newInstance().newXPath(); Node startDateNode = (Node) xPath .compile("//dynaForm/" + fileName) .evaluate(mainDoc, XPathConstants.NODE); Node cdata = mainDoc.createCDATASection(jsDoc); startDateNode.setTextContent(""); startDateNode.appendChild(cdata); /*String msg = evt.getPropertyName() + "-" + fileName; NotifyDescriptor nd = new NotifyDescriptor.Message(msg, NotifyDescriptor.INFORMATION_MESSAGE); DialogDisplayer.getDefault().notify(nd);*/ // write the content into xml file TransformerFactory transformerFactory = TransformerFactory .newInstance(); Transformer transformer = transformerFactory .newTransformer(); DOMSource source = new DOMSource(mainDoc); StreamResult result = new StreamResult(new File(fullPath)); transformer.transform(source, result); if (conf.isRemote()) { boolean res_Upload = SSH.getInstance() .uplaodFile(FileDir); if (res_Upload) { String msg = "file upload Successfully!"; NotifyDescriptor nd = new NotifyDescriptor.Message( msg, NotifyDescriptor.INFORMATION_MESSAGE); DialogDisplayer.getDefault().notify(nd); } else { String msg = "error in uploading file!"; NotifyDescriptor nd = new NotifyDescriptor.Message( msg, NotifyDescriptor.INFORMATION_MESSAGE); DialogDisplayer.getDefault().notify(nd); } } } catch (Exception ex) { //Exceptions.printStackTrace(ex); String msg = "Can not save to xml form"; NotifyDescriptor nd = new NotifyDescriptor.Message(msg, NotifyDescriptor.INFORMATION_MESSAGE); DialogDisplayer.getDefault().notify(nd); } } } } }); } catch (DataObjectNotFoundException ex) { //Exceptions.printStackTrace(ex); String msg = "Can not save to xml form"; NotifyDescriptor nd = new NotifyDescriptor.Message(msg, NotifyDescriptor.INFORMATION_MESSAGE); DialogDisplayer.getDefault().notify(nd); } } } } } } }; jTree1.addMouseListener(ml); jTree1.setModel(null); }