List of usage examples for org.w3c.dom NamedNodeMap item
public Node item(int index);
index
th item in the map. From source file:com.triompha.common.web.html.HtmlUtil.java
private boolean filterScript(Node node) throws MalformedURLException { if (node.getNodeType() == Node.ELEMENT_NODE) { NamedNodeMap attrs = node.getAttributes(); String target = null;/*from ww w . j a v a 2 s .co m*/ for (int i = 0; i < attrs.getLength(); i++) { Node attr = attrs.item(i); target = attr.getNodeValue(); if (target.toLowerCase().indexOf("javascript") > -1) { return true; } } } return false; }
From source file:com.naryx.tagfusion.cfm.document.cfDOCUMENT.java
private HashMap<String, String> extractTagAttributes(String _tagName, String _xhtml) { HashMap<String, String> attributes = new HashMap<String, String>(); try {//from w ww . ja va 2 s .c o m // Parse the XHTML body into an XML object cfXmlData content = cfXmlData.parseXml(_xhtml, true, null); // Find the node for the specified tag Node node = findNode(content.getXMLNode(), _tagName); if (node != null) { // Copy the node's attributes (if any) into the HashMap NamedNodeMap nodeAttributes = node.getAttributes(); if (nodeAttributes != null) { for (int i = 0; i < nodeAttributes.getLength(); i++) attributes.put(nodeAttributes.item(i).getNodeName(), nodeAttributes.item(i).getNodeValue()); } } } catch (Exception e) { } return attributes; }
From source file:com.photon.phresco.framework.actions.applications.Quality.java
private static TestCaseError getError(Node errorNode) throws TransformerException { S_LOGGER.debug("Entering Method Quality.getError(Node errorNode)"); S_LOGGER.debug("getError() Node = " + errorNode.getNodeName()); TestCaseError tcError = new TestCaseError(); try {/* w w w . ja v a 2 s . c om*/ tcError.setDescription(errorNode.getTextContent()); tcError.setErrorType(REQ_TITLE_ERROR); NamedNodeMap nameNodeMap = errorNode.getAttributes(); if (nameNodeMap != null && nameNodeMap.getLength() > 0) { for (int k = 0; k < nameNodeMap.getLength(); k++) { Node attribute = nameNodeMap.item(k); String attributeName = attribute.getNodeName(); String attributeValue = attribute.getNodeValue(); if (ATTR_TYPE.equals(attributeName)) { tcError.setErrorType(attributeValue); } } } } catch (Exception e) { S_LOGGER.error("Entered into catch block of Quality.getError()" + e); } return tcError; }
From source file:com.photon.phresco.framework.actions.applications.Quality.java
private static TestCaseFailure getFailure(Node failureNode) throws TransformerException { S_LOGGER.debug("Entering Method Quality.getFailure(Node failureNode)"); S_LOGGER.debug("getFailure() NodeName = " + failureNode.getNodeName()); TestCaseFailure failure = new TestCaseFailure(); try {/* w w w. ja v a2 s .c o m*/ failure.setDescription(failureNode.getTextContent()); failure.setFailureType(REQ_TITLE_EXCEPTION); NamedNodeMap nameNodeMap = failureNode.getAttributes(); if (nameNodeMap != null && nameNodeMap.getLength() > 0) { for (int k = 0; k < nameNodeMap.getLength(); k++) { Node attribute = nameNodeMap.item(k); String attributeName = attribute.getNodeName(); String attributeValue = attribute.getNodeValue(); if (ATTR_TYPE.equals(attributeName)) { failure.setFailureType(attributeValue); } } } } catch (Exception e) { S_LOGGER.error("Entered into catch block of Quality.getFailure()" + e); } return failure; }
From source file:edu.stanford.epad.epadws.aim.AIMUtil.java
private static Node renameNodeNS(Node node, String newName, String xmlns) { Element newNode = node.getOwnerDocument().createElementNS(xmlns, newName); NamedNodeMap map = node.getAttributes(); for (int i = 0; i < map.getLength(); i++) { newNode.setAttribute(map.item(i).getNodeName(), map.item(i).getNodeValue()); }/*from w w w . java 2s. c om*/ NodeList tempList = node.getChildNodes(); for (int i = 0; i < tempList.getLength(); i++) { newNode.appendChild(tempList.item(i).cloneNode(true)); } return newNode; }
From source file:jef.tools.XMLUtils.java
/** * ?// www .j a v a 2 s.c o m * * @param e * * @param subElementAsAttr * trueElement?<br> * * * <pre> * <Foo size="103" name="Karen"> * <dob>2012-4-12</dobh> * <dod>2052-4-12</dodh> * </Foo> * </pre> * * subElementAsAttr=falsedob,dod?true? * @return */ public static Map<String, String> getAttributesMap(Element e, boolean subElementAsAttr) { Map<String, String> attribs = new HashMap<String, String>(); if (e == null) return attribs; NamedNodeMap nmp = e.getAttributes(); for (int i = 0; i < nmp.getLength(); i++) { Attr child = (Attr) nmp.item(i); attribs.put(StringEscapeUtils.unescapeHtml(child.getName()), StringEscapeUtils.unescapeHtml(child.getValue())); } if (subElementAsAttr) { NodeList nds = e.getChildNodes(); for (int i = 0; i < nds.getLength(); i++) { Node node = nds.item(i); if (node.getNodeType() != Node.ELEMENT_NODE) continue; Element sub = (Element) node; String key = sub.getNodeName(); String value = nodeText(sub); if (attribs.containsKey(key)) { attribs.put(key, attribs.get(key) + "," + value); } else { attribs.put(key, value); } } } return attribs; }
From source file:jef.tools.XMLUtils.java
/** * NamedNodeMap?Node//from www .j a v a2s.c o m * * @param nds * NamedNodeMap * @return Node */ public static Node[] toArray(NamedNodeMap nds) { Node[] array = new Node[nds.getLength()]; for (int i = 0; i < nds.getLength(); i++) { array[i] = nds.item(i); } return array; }
From source file:edu.eurac.commul.pepperModules.mmax2.Salt2MMAXMapping.java
public static ArrayList<SAnnotationMapping> getSAnnotationMappingsFromFile(MMAX2ExporterProperties props) { ArrayList<SAnnotationMapping> mappings = new ArrayList<SAnnotationMapping>(); if (props.getSAnnotationMappingsFilePath() != null) { DocumentBuilder documentBuilder; try {/*from w w w . j a va2 s. co m*/ documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); } catch (ParserConfigurationException e) { throw new PepperModuleException(e.getMessage(), e); } File configurationFile = new File(props.getSAnnotationMappingsFilePath()); NodeList nodes = null; try { nodes = documentBuilder.parse(configurationFile).getDocumentElement().getChildNodes(); } catch (SAXException e) { throw new PepperModuleException(e.getMessage(), e); } catch (IOException e) { throw new PepperModuleException(e.getMessage(), e); } for (int i = 0; i < nodes.getLength(); i++) { Node xmlNode = nodes.item(i); if (xmlNode.getNodeType() != Node.ELEMENT_NODE) { continue; } String nodeName = xmlNode.getNodeName(); if (nodeName.equals(MAPPING_NODE_NAME)) { Node mapping_infos = null; Node condition_infos = null; NodeList sub_nodes = xmlNode.getChildNodes(); for (int j = 0; j < sub_nodes.getLength(); j++) { Node sub_xmlNode = sub_nodes.item(j); if (sub_xmlNode.getNodeType() != Node.ELEMENT_NODE) { continue; } String sub_nodeName = sub_xmlNode.getNodeName(); if (sub_nodeName.equals(MAPPING_INFOS_NODE_NAME)) { if (mapping_infos == null) { mapping_infos = sub_xmlNode; } else { throw new PepperModuleException( "More than one mapping infos defined on SAnnotation Mapping '" + xmlNode + "'"); } } else if (sub_nodeName.equals(CONDITION_NODE_NAME)) { if (condition_infos == null) { condition_infos = sub_xmlNode; } else { throw new PepperModuleException( "More than one match condition defined on SAnnotation Mapping '" + xmlNode + "'"); } } else { throw new PepperModuleException("Unknown type of Node '" + sub_xmlNode + "' with name '" + sub_nodeName + "' on SAnnotation Mapping '" + xmlNode + "'"); } } NamedNodeMap mapping_attributes = mapping_infos.getAttributes(); Node associatedSchemeNameAttribute = mapping_attributes.getNamedItem(SANN_MAPPING_ASS_SCHEME); if (associatedSchemeNameAttribute == null) { throw new PepperModuleException("associated scheme name '" + SANN_MAPPING_ASS_SCHEME + "' on SAnnotation Mapping infos Node '" + mapping_infos + "' is not defined..."); } String associatedSchemeName = associatedSchemeNameAttribute.getNodeValue(); mapping_attributes.removeNamedItem(SANN_MAPPING_ASS_SCHEME); Node associatedAttributeNameAttribute = mapping_attributes.getNamedItem(SANN_MAPPING_ASS_ATTR); if (associatedAttributeNameAttribute == null) { throw new PepperModuleException("associated attribute name '" + SANN_MAPPING_ASS_ATTR + "' on SAnnotation Mapping infos Node '" + mapping_infos + "' is not defined..."); } String associatedAttributeName = associatedAttributeNameAttribute.getNodeValue(); mapping_attributes.removeNamedItem(SANN_MAPPING_ASS_ATTR); SAnnotationMatchCondition condition = parseSAnnotationMatchCondition(condition_infos); if (mapping_attributes.getLength() != 0) { ArrayList<String> unknownAttributes = new ArrayList<String>(); for (int j = 0; j < mapping_attributes.getLength(); j++) { unknownAttributes.add(mapping_attributes.item(j).getNodeName()); } throw new PepperModuleException( "Unknown attributes '" + StringUtils.join(unknownAttributes, ",") + "' on SAnnotation Mapping infos Node '" + mapping_infos + "'"); } mappings.add(new SAnnotationMapping(condition, associatedSchemeName, associatedAttributeName)); } else if (xmlNode.getNodeType() == Node.ELEMENT_NODE) { throw new PepperModuleException("Unknown type of Node among Mapping nodes '" + xmlNode + "' with name '" + nodeName + "'"); } } } return mappings; }
From source file:iristk.flow.FlowCompiler.java
private Map<String, String> getParameters(Element elem) throws FlowCompilerException { NamedNodeMap attributes = elem.getAttributes(); NodeList childNodes = elem.getChildNodes(); Map<QName, String> otherAttributes = new HashMap<>(); for (int i = 0; i < attributes.getLength(); i++) { if (attributes.item(i).getNamespaceURI() == null || !attributes.item(i).getNamespaceURI().equals("http://www.w3.org/2000/xmlns/")) { otherAttributes.put(new QName("iristk.flow.param", attributes.item(i).getLocalName()), attributes.item(i).getNodeValue()); }/*from ww w .ja va 2 s. c om*/ } ArrayList<Object> content = new ArrayList<>(); for (int i = 0; i < childNodes.getLength(); i++) { content.add(childNodes.item(i)); } return getParameters(otherAttributes, content, elem); }