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:com.mediaworx.xmlutils.XmlHelper.java
/** * Appends a new child node to a parent node. * @param parent the parent node/*w w w .j a va 2 s . co m*/ * @param newChild the child node to be appended */ public void appendNode(Node parent, Node newChild) { Node toBeImported = newChild instanceof Document ? ((Document) newChild).getDocumentElement() : newChild; Node importedNode = parent.getOwnerDocument().importNode(toBeImported, true); parent.appendChild(importedNode); }
From source file:com.dinochiesa.edgecallouts.EditXmlNode.java
private void append(NodeList nodes, Node newNode, short newNodeType) { Node currentNode = nodes.item(0); switch (newNodeType) { case Node.ATTRIBUTE_NODE: Element parent = ((Attr) currentNode).getOwnerElement(); parent.setAttributeNode((Attr) newNode); break;//ww w . j a v a 2s. co m case Node.ELEMENT_NODE: currentNode.appendChild(newNode); break; case Node.TEXT_NODE: if (currentNode.getNodeType() != Node.TEXT_NODE) { throw new IllegalStateException("wrong source node type."); } String v = currentNode.getNodeValue(); currentNode.setNodeValue(v + newNode.getNodeValue()); break; } }
From source file:com.sonyericsson.hudson.plugins.gerrit.trigger.spec.DuplicateGerritListenersPreloadedProjectHudsonTestCase.java
/** * Adds a new gerritProject configuration to the gived XML document. * Assumes that the document is structured like the original project config.xml in the LocalData for this class. * * @param gerritProjectPattern the {@link GerritProject#pattern} to set. * @param document the config.xml * @return the new xml/*from w w w . jav a2s. c o m*/ * @throws Exception if so */ private String changeConfigXml(String gerritProjectPattern, Document document) throws Exception { Node projects = xPath(document, "/project/triggers/*[1]/gerritProjects"); String tagName = "com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.data.GerritProject"; Node newProject = document.createElement(tagName); setXmlConfig(document, newProject, "ANT", gerritProjectPattern); Node branches = document.createElement("branches"); tagName = "com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.data.Branch"; Node branch = document.createElement(tagName); setXmlConfig(document, branch, "ANT", "**"); branches.appendChild(branch); newProject.appendChild(branches); projects.appendChild(newProject); document.normalizeDocument(); return xmlToString(document); }
From source file:aurelienribon.gdxsetupui.ProjectUpdate.java
private void writeGwtDefinition(File gwtDefitionFile, List<GwtModule> modules) { try {/*w ww. j a v a2s .co m*/ Document doc = XmlUtils.createParser().parse(gwtDefitionFile); Node root = (Node) XmlUtils.xpath("module", doc, XPathConstants.NODE); NodeList nodes = (NodeList) XmlUtils.xpath("module/inherits", doc, XPathConstants.NODESET); for (int i = 0; i < nodes.getLength(); i++) { root.removeChild(nodes.item(i)); } for (GwtModule module : modules) { Element elem = doc.createElement("inherits"); root.appendChild(elem); elem.setAttribute("name", module.name); } XmlUtils.clean(doc); String str = XmlUtils.transform(doc); FileUtils.writeStringToFile(gwtDefitionFile, str); } catch (SAXException ex) { throw new RuntimeException(ex); } catch (IOException ex) { throw new RuntimeException(ex); } catch (TransformerException ex) { throw new RuntimeException(ex); } }
From source file:com.photon.phresco.framework.commons.QualityUtil.java
private static void appendElementProp(Document document, Node parentNode, String contextType, String contextPostData) { // eleme prop Node elementProp = document.createElement("elementProp"); NamedNodeMap attributes = elementProp.getAttributes(); attributes.setNamedItem(createAttribute(document, "name", "HTTPsampler.Arguments")); attributes.setNamedItem(createAttribute(document, "elementType", "Arguments")); attributes.setNamedItem(createAttribute(document, "guiclass", "HTTPArgumentsPanel")); attributes.setNamedItem(createAttribute(document, "testclass", "Arguments")); attributes.setNamedItem(createAttribute(document, "testname", "User Defined Variables")); attributes.setNamedItem(createAttribute(document, "enabled", "true")); appendCollectionProp(document, elementProp, contextType, contextPostData); //parentNode.setTextContent(null); parentNode.appendChild(elementProp); }
From source file:uk.co.markfrimston.tasktree.TaskTree.java
protected void makeConfigEl(Document doc, Node parent, String name, String description, Object value) { parent.appendChild(doc.createTextNode("\n\t")); parent.appendChild(doc.createComment(description)); parent.appendChild(doc.createTextNode("\n\t")); Element elParam = doc.createElement(name); if (value != null) { elParam.appendChild(doc.createTextNode(String.valueOf(value))); }/*from w w w . j av a 2 s . com*/ parent.appendChild(elParam); parent.appendChild(doc.createTextNode("\n")); }
From source file:de.rub.nds.burp.utilities.attacks.signatureFaking.SignatureFakingOracle.java
private void appendCertificate(Node keyInfo, String certificate) { String prefix = keyInfo.getPrefix(); if (replaceAll == true) { keyInfo.setTextContent(""); if (prefix == null) { prefix = ""; } else {//ww w . ja va2 s . c o m prefix = prefix + ":"; } Node data = keyInfo.getOwnerDocument().createElementNS(NamespaceConstants.URI_NS_DS, prefix + "X509Data"); keyInfo.appendChild(data); Node cert = keyInfo.getOwnerDocument().createElementNS(NamespaceConstants.URI_NS_DS, prefix + "X509Certificate"); data.appendChild(cert); cert.setTextContent(certificate); } else { List<Element> l = DomUtilities.findChildren(keyInfo, "X509Certificate", NamespaceConstants.URI_NS_DS, true); Node cert = l.get(0); cert.setTextContent(certificate); } Logging.getInstance().log(getClass(), "Appending Certificate \r\n" + certificate + "\r\nto the" + prefix + "X509Certificate element", Logging.DEBUG); }
From source file:com.amalto.core.history.accessor.UnaryFieldAccessor.java
private Element internalCreate() { parent.create();//w w w . j a va 2s.c o m Document domDocument = document.asDOM(); Element element = getElement(); if (element == null) { Element newElement = domDocument.createElementNS(domDocument.getNamespaceURI(), fieldName); Node parentNode = parent.getNode(); Node lastAccessedNode = document.getLastAccessedNode(); if (parentNode == lastAccessedNode) { parentNode.insertBefore(newElement, parentNode.getFirstChild()); } else if (lastAccessedNode != null && lastAccessedNode.getParentNode() == parentNode) { parentNode.insertBefore(newElement, lastAccessedNode.getNextSibling()); } else { parentNode.appendChild(newElement); } element = newElement; document.setLastAccessedNode(element); } return element; }
From source file:com.stratelia.webactiv.util.XMLConfigurationStore.java
public void appendChild(Node parent, Node child) { parent.appendChild(child); }
From source file:com.liferay.portal.editor.fckeditor.receiver.impl.BaseCommandReceiver.java
public void createFolder(CommandArgument commandArgument, HttpServletRequest request, HttpServletResponse response) {/*from www. j a va 2s . c o m*/ Document document = _createDocument(); Node rootNode = _createRoot(document, commandArgument.getCommand(), commandArgument.getType(), commandArgument.getCurrentFolder(), StringPool.BLANK); Element errorElement = document.createElement("Error"); rootNode.appendChild(errorElement); String returnValue = "0"; try { returnValue = createFolder(commandArgument); } catch (FCKException fcke) { Throwable cause = fcke.getCause(); returnValue = "110"; if (cause != null) { String causeString = GetterUtil.getString(cause.toString()); if (causeString.contains("DuplicateFolderNameException")) { returnValue = "101"; } else if (causeString.contains("FolderNameException")) { returnValue = "102"; } else if (causeString.contains("NoSuchGroupException") || causeString.contains("PrincipalException")) { returnValue = "103"; } else { throw fcke; } } } errorElement.setAttribute("number", returnValue); _writeDocument(document, response); }