List of usage examples for org.w3c.dom Node getAttributes
public NamedNodeMap getAttributes();
NamedNodeMap
containing the attributes of this node (if it is an Element
) or null
otherwise. From source file:com.photon.phresco.framework.commons.QualityUtil.java
private static void appendTypeProp(Document document, Node parentProp, String tag, String nameAttr, String textContent) {/* w w w .ja v a2 s .c o m*/ Node typeProp = document.createElement(tag); NamedNodeMap attributes = typeProp.getAttributes(); attributes.setNamedItem(createAttribute(document, "name", nameAttr)); typeProp.setTextContent(textContent); parentProp.appendChild(typeProp); }
From source file:com.photon.phresco.framework.commons.QualityUtil.java
public static void changeTestName(String performancePath, String testName) throws Exception { File buildPathXml = null;// w ww . jav a 2s . c om S_LOGGER.debug("Entering Method QualityUtil.testSuite() performance path and TestName " + performancePath + " " + testName); buildPathXml = new File(performancePath + buildFileName); Document document = com.photon.phresco.framework.impl.util.FrameworkUtil.getDocument(buildPathXml); String fileNameNode = "project/target[@name='init']/property[@name='jmeter.result.file']"; NodeList nodelist = org.apache.xpath.XPathAPI.selectNodeList(document, fileNameNode); if (nodelist != null && nodelist.getLength() > 0) { Node stringProp = nodelist.item(0); NamedNodeMap attributes = stringProp.getAttributes(); Node valueAttr = attributes.getNamedItem("value"); String valueAttrTxt = valueAttr.getTextContent(); S_LOGGER.debug("Load test xml name " + valueAttrTxt.substring(0, valueAttrTxt.indexOf("/") + 1).concat(testName + ".xml")); valueAttr.setTextContent( valueAttrTxt.substring(0, valueAttrTxt.indexOf("/") + 1).concat(testName + ".xml")); } saveDocument(buildPathXml, document); }
From source file:Main.java
@SuppressWarnings("null") public static void copyInto(Node src, Node dest) throws DOMException { Document factory = dest.getOwnerDocument(); //Node start = src; Node parent = null;//ww w. j av a 2 s . c o m Node place = src; // traverse source tree while (place != null) { // copy this node Node node = null; int type = place.getNodeType(); switch (type) { case Node.CDATA_SECTION_NODE: { node = factory.createCDATASection(place.getNodeValue()); break; } case Node.COMMENT_NODE: { node = factory.createComment(place.getNodeValue()); break; } case Node.ELEMENT_NODE: { Element element = factory.createElement(place.getNodeName()); node = element; NamedNodeMap attrs = place.getAttributes(); int attrCount = attrs.getLength(); for (int i = 0; i < attrCount; i++) { Attr attr = (Attr) attrs.item(i); String attrName = attr.getNodeName(); String attrValue = attr.getNodeValue(); element.setAttribute(attrName, attrValue); /* if (domimpl && !attr.getSpecified()) { ((Attr) element.getAttributeNode(attrName)).setSpecified(false); } */ } break; } case Node.ENTITY_REFERENCE_NODE: { node = factory.createEntityReference(place.getNodeName()); break; } case Node.PROCESSING_INSTRUCTION_NODE: { node = factory.createProcessingInstruction(place.getNodeName(), place.getNodeValue()); break; } case Node.TEXT_NODE: { node = factory.createTextNode(place.getNodeValue()); break; } default: { throw new IllegalArgumentException( "can't copy node type, " + type + " (" + node.getNodeName() + ')'); } } dest.appendChild(node); // iterate over children if (place.hasChildNodes()) { parent = place; place = place.getFirstChild(); dest = node; } else if (parent == null) { place = null; } else { // advance place = place.getNextSibling(); while (place == null && parent != null && dest != null) { place = parent.getNextSibling(); parent = parent.getParentNode(); dest = dest.getParentNode(); } } } }
From source file:Main.java
public static void copyInto(Node src, Node dest) throws DOMException { Document factory = dest.getOwnerDocument(); //Node start = src; Node parent = null;/*from w ww .jav a2s. c om*/ Node place = src; // traverse source tree while (place != null) { // copy this node Node node = null; int type = place.getNodeType(); switch (type) { case Node.CDATA_SECTION_NODE: { node = factory.createCDATASection(place.getNodeValue()); break; } case Node.COMMENT_NODE: { node = factory.createComment(place.getNodeValue()); break; } case Node.ELEMENT_NODE: { Element element = factory.createElement(place.getNodeName()); node = element; NamedNodeMap attrs = place.getAttributes(); int attrCount = attrs.getLength(); for (int i = 0; i < attrCount; i++) { Attr attr = (Attr) attrs.item(i); String attrName = attr.getNodeName(); String attrValue = attr.getNodeValue(); element.setAttribute(attrName, attrValue); } break; } case Node.ENTITY_REFERENCE_NODE: { node = factory.createEntityReference(place.getNodeName()); break; } case Node.PROCESSING_INSTRUCTION_NODE: { node = factory.createProcessingInstruction(place.getNodeName(), place.getNodeValue()); break; } case Node.TEXT_NODE: { node = factory.createTextNode(place.getNodeValue()); break; } default: { throw new IllegalArgumentException( "can't copy node type, " + type + " (" + place.getNodeName() + ')'); } } dest.appendChild(node); // iterate over children if (place.hasChildNodes()) { parent = place; place = place.getFirstChild(); dest = node; } else if (parent == null) { place = null; } else { // advance place = place.getNextSibling(); while (place == null && parent != null) { place = parent.getNextSibling(); parent = parent.getParentNode(); dest = dest.getParentNode(); } } } }
From source file:com.photon.phresco.framework.commons.QualityUtil.java
private static Node appendHeaderManager(Document document, Map<String, String> headersMap) { Node headerManager = document.createElement("HeaderManager"); NamedNodeMap attributes = headerManager.getAttributes(); attributes.setNamedItem(createAttribute(document, "guiclass", "HeaderPanel")); attributes.setNamedItem(createAttribute(document, "testclass", "HeaderManager")); attributes.setNamedItem(createAttribute(document, "testname", "HTTP Header Manager")); attributes.setNamedItem(createAttribute(document, "enabled", "true")); appendHeaderManagerCollectionProp(document, headerManager, headersMap); return headerManager; }
From source file:com.photon.phresco.framework.commons.QualityUtil.java
private static void appendHeaderManagerCollectionProp(Document document, Node elementProp, Map<String, String> headersMap) { Node collectionProp = document.createElement("collectionProp"); NamedNodeMap attributes = collectionProp.getAttributes(); attributes.setNamedItem(createAttribute(document, "name", "HeaderManager.headers")); createHeaderElementProp(document, headersMap, collectionProp); elementProp.setTextContent(null);/*from w w w.ja va 2s.c om*/ elementProp.appendChild(collectionProp); }
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:com.photon.phresco.framework.commons.QualityUtil.java
private static Node appendJdbcSampler(Document document, Node hashTree, String name, String dataSource, String queryType, String query) { Node jdbcSampler = document.createElement("JDBCSampler"); NamedNodeMap attributes = jdbcSampler.getAttributes(); attributes.setNamedItem(createAttribute(document, "guiclass", "TestBeanGUI")); attributes.setNamedItem(createAttribute(document, "testclass", "JDBCSampler")); attributes.setNamedItem(createAttribute(document, "testname", name)); //url name attributes.setNamedItem(createAttribute(document, "enabled", "true")); appendTypeProp(document, jdbcSampler, "stringProp", "dataSource", dataSource); appendTypeProp(document, jdbcSampler, "stringProp", "queryType", queryType); appendTypeProp(document, jdbcSampler, "stringProp", "query", query); appendTypeProp(document, jdbcSampler, "stringProp", "queryArguments", null); appendTypeProp(document, jdbcSampler, "stringProp", "queryArgumentsTypes", null); appendTypeProp(document, jdbcSampler, "stringProp", "variableNames", null); appendTypeProp(document, jdbcSampler, "stringProp", "resultVariable", null); return jdbcSampler; }
From source file:moskitt4me.repositoryClient.core.util.RepositoryClientUtil.java
private static String getToolId(TechnicalFragment tf) { String type = tf.getType();/*ww w .jav a 2 s . c o m*/ if (type.equals("Others") || type.equals("Internal Tool")) { return ""; } if (type.equals("External Tool")) { ExternalToolFragment etf = (ExternalToolFragment) tf; String fileExtension = etf.getFileExtension(); if (!fileExtension.startsWith(".")) { fileExtension = "." + fileExtension; } return fileExtension; } List<IProject> plugins = tf.getPlugins(); for (IProject plugin : plugins) { String pluginLocation = plugin.getLocation().toString(); String pluginXMLLocation = pluginLocation + "/plugin.xml"; Document pluginXMLDocument = getDocument(pluginXMLLocation); if (pluginXMLDocument != null) { String extensionPointId = ""; String elementId = ""; String attribute = ""; if (type.equals("Graphical Editor") || type.equals("Meta-Model") || type.equals("Form-based Editor")) { extensionPointId = "org.eclipse.ui.newWizards"; elementId = "wizard"; attribute = "id"; } else if (type.equals("Model transformation")) { extensionPointId = "es.cv.gvcase.trmanager.transformation"; elementId = "transformation"; attribute = "id"; } else if (type.equals("Guidance")) { extensionPointId = "org.eclipse.epf.authoring.ui.helpcontextprovider"; elementId = "helpContextProviderDesc"; attribute = "idContext"; } if (!extensionPointId.equals("")) { NodeList extension = pluginXMLDocument.getElementsByTagName("extension"); int length = extension.getLength(); for (int i = 0; i < length; i++) { Node extensionNode = extension.item(i); if (extensionNode.getAttributes().getNamedItem("point").getNodeValue() .equals(extensionPointId) && extensionNode.getNodeType() == Node.ELEMENT_NODE) { Element extensionElement = (Element) extensionNode; NodeList elements = extensionElement.getElementsByTagName(elementId); if (elements.getLength() > 0) { Node element = elements.item(0); String attValue = element.getAttributes().getNamedItem(attribute).getNodeValue(); if (type.equals("Guidance")) { return plugin.getName() + "." + attValue; } else { return attValue; } } } } } } } return ""; }
From source file:com.photon.phresco.framework.commons.QualityUtil.java
private static void createHeaderElementProp(Document document, Map<String, String> headersMap, Node collectionProp) {/*w w w .j av a 2 s .c o m*/ for (Map.Entry<String, String> entry : headersMap.entrySet()) { Node subElementProp = document.createElement("elementProp"); NamedNodeMap subElementAttributes = subElementProp.getAttributes(); subElementAttributes.setNamedItem(createAttribute(document, "name", "")); subElementAttributes.setNamedItem(createAttribute(document, "elementType", "Header")); collectionProp.appendChild(subElementProp); appendTypeProp(document, subElementProp, "stringProp", "Header.name", entry.getKey()); appendTypeProp(document, subElementProp, "stringProp", "Header.value", entry.getValue()); } }