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.icesoft.jasper.xmlparser.ParserUtils.java
/** * Create and return a TreeNode that corresponds to the specified Node, * including processing all of the attributes and children nodes. * * @param parent The parent TreeNode (if any) for the new TreeNode * @param node The XML document Node to be converted *///www.j a v a 2 s . co m protected TreeNode convert(TreeNode parent, Node node) { // Construct a new TreeNode for this node TreeNode treeNode = new TreeNode(node.getNodeName(), parent); // Convert all attributes of this node NamedNodeMap attributes = node.getAttributes(); if (attributes != null) { int n = attributes.getLength(); for (int i = 0; i < n; i++) { Node attribute = attributes.item(i); treeNode.addAttribute(attribute.getNodeName(), attribute.getNodeValue()); } } // Create and attach all children of this node NodeList children = node.getChildNodes(); if (children != null) { int n = children.getLength(); for (int i = 0; i < n; i++) { Node child = children.item(i); if (child instanceof Comment) continue; if (child instanceof Text) { String body = ((Text) child).getData(); if (body != null) { body = body.trim(); if (body.length() > 0) treeNode.setBody(body); } } else { TreeNode treeChild = convert(treeNode, child); } } } // Return the completed TreeNode graph return (treeNode); }
From source file:com.founder.fix.fixwpe.wpeformdesigner.jst.pagedesigner.properties.FixPropertySourceProvider.java
/** * tag/*from ww w .j ava 2s . c om*/ */ public void refleshTagProperty() { NamedNodeMap attributes = impl.getAttributes(); // ? JSONObject attributeJsonTag = new JSONObject(); for (int i = 0; i < attributes.getLength(); i++) { try { attributeJsonTag.put(attributes.item(i).getNodeName(), attributes.item(i).getNodeValue()); if (fixImpl.getObjectJson() == null) { fixImpl.setObjectJson(new JSONObject()); fixImpl.getObjectJson().put(ConstantVariable.childJsonAttributeTag, attributeJsonTag); } else { fixImpl.getObjectJson().put(ConstantVariable.childJsonAttributeTag, attributeJsonTag); } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
From source file:com.sun.faces.config.rules.DescriptionTextRule.java
/** * <p>Append the serialized version of the specified node to the * string buffer being accumulated.</p> * * @param sb StringBuffer to which serialized text is appended * @param node Node to be serialized/*from w w w . j ava2 s . c o m*/ * * @exception Exception if any processing exception occurs */ private void serialize(StringBuffer sb, Node node) throws Exception { // Processing depends on the node type switch (node.getNodeType()) { case Node.ELEMENT_NODE: if (digester.getLogger().isDebugEnabled()) { digester.getLogger().debug(" Processing element node '" + node.getNodeName() + "'"); } // Open the element and echo the attributes sb.append("<"); sb.append(node.getNodeName()); NamedNodeMap attrs = node.getAttributes(); int n = attrs.getLength(); for (int i = 0; i < n; i++) { Node attr = attrs.item(i); sb.append(" "); sb.append(attr.getNodeName()); sb.append("=\""); sb.append(attr.getNodeValue()); sb.append("\""); } // Does this element have any children? NodeList kids = node.getChildNodes(); int m = kids.getLength(); if (m > 0) { // Yes -- serialize child elements and close parent element sb.append(">"); for (int j = 0; j < m; j++) { serialize(sb, kids.item(j)); } sb.append("</"); sb.append(node.getNodeName()); sb.append(">"); } else { // No -- shorthand close of the parent element sb.append(" />"); } break; case Node.TEXT_NODE: if (digester.getLogger().isDebugEnabled()) { digester.getLogger().debug(" Processing text node '" + node.getNodeValue() + "'"); } // Append the text to our accumulating buffer sb.append(node.getNodeValue()); break; default: throw new IllegalArgumentException( "Cannot process node '" + node.getNodeName() + "' of type '" + node.getNodeType()); } }
From source file:ar.com.zauber.commons.web.transformation.sanitizing.impl.AbstractElementNodeSanitizer.java
/** * Recursive tree traversal//from w w w . j av a 2 s . com * @param node * @param invalidElements */ private void sanitizeNode(final Node node, final List<Element> invalidElements) { if (node.getNodeType() == Node.ELEMENT_NODE) { final Element element = (Element) node; if (!tagSecurityStrategy.isTagAllowed(element.getNodeName())) { invalidElements.add(element); return; } else { final NamedNodeMap attributes = node.getAttributes(); if (attributes.getLength() > 0) { final List<Attr> invalidAttributes = new ArrayList<Attr>(); for (int i = 0; i < attributes.getLength(); ++i) { final Attr attribute = (Attr) attributes.item(i); if (!tagSecurityStrategy.isAttributeAllowedForTag(attribute.getNodeName(), element.getNodeName()) || !tagSecurityStrategy.isAttributeValueValidForTag(attribute.getNodeValue(), attribute.getNodeName(), element.getNodeName())) { invalidAttributes.add(attribute); } } processInvalidElementAttributes(element, invalidAttributes); } } } final NodeList children = node.getChildNodes(); for (int i = 0; i < children.getLength(); ++i) { sanitizeNode(children.item(i), invalidElements); } }
From source file:channellistmaker.dataextractor.AbstractEPGFileExtractor.java
/** * trace??????????????/*from w w w. j ava 2 s . c om*/ * @param node * @return trace?????????????????????????? */ protected final String dumpNode(final Node node) { if (LOG.isTraceEnabled()) { if (node == null) { //???? return ""; } else { final StringBuilder sb = new StringBuilder(); final String nodeName_t; if (node.getNodeName() != null && !"".equals(node.getNodeName())) { nodeName_t = node.getNodeName(); } else { nodeName_t = "no_Name"; } sb.append(nodeName_t).append(" [ "); /* ? */ sb.append("Node_type = ").append(node.getNodeType()).append(" "); sb.append(" "); /*(??)*/ NamedNodeMap attrs = node.getAttributes(); // NamedNodeMap?? if (attrs != null) { sb.append("Attribute [ "); for (int index = 0; index < attrs.getLength(); index++) { Node attr = attrs.item(index); // sb.append("( "); sb.append("Attribute_name = ").append(attr.getNodeName()).append(" "); // ???? sb.append("Attribute_value = ").append(attr.getNodeValue()).append(" "); // ? sb.append(")"); } sb.append(" ] "); } /* ? sb.append("] "); */ sb.append("Node_value = ").append(node.getNodeValue()).append(" "); /*(??)?? */ if (node.hasChildNodes()) { sb.append(" \n"); NodeList Children = node.getChildNodes(); int Nodes = Children.getLength(); for (int i = 0; i < Nodes; i++) { Node child = Children.item(i); sb.append(dumpNode(child)); } } sb.append("] "); return sb.toString(); } } else { return ""; } }
From source file:org.dozer.eclipse.plugin.sourcepage.contentassist.DozerContentAssistProcessor.java
@Override @SuppressWarnings("restriction") protected ContentAssistRequest computeAttributeValueProposals(int documentPosition, String matchString, ITextRegion completionRegion, IDOMNode nodeAtOffset, IDOMNode node) { if ("field".equals(node.getNodeName()) || "a".equals(node.getNodeName()) || "b".equals(node.getNodeName())) { NamedNodeMap attrs = nodeAtOffset.getAttributes(); for (int i = 0; i < attrs.getLength(); i++) { AttrImpl existingAttr = (AttrImpl) attrs.item(i); ITextRegion valueRegion = existingAttr.getValueRegion(); String attrName = existingAttr.getName(); if (completionRegion.getStart() >= valueRegion.getStart() && completionRegion.getEnd() <= valueRegion.getEnd()) { //the first " in matchstring must be deleted for search if ("custom-converter".equals(attrName)) { return computeDozerClassContentProposals(documentPosition, matchString.substring(1), completionRegion, existingAttr, node); } else if ("custom-converter-id".equals(attrName)) { return computeDozerBeanContentProposals(documentPosition, matchString.substring(1), completionRegion, existingAttr, node); } else if ("get-method".equals(attrName) || "set-method".equals(attrName) || "map-get-method".equals(attrName) || "map-set-method".equals(attrName)) { return computeDozerMethodContentProposals(documentPosition, matchString.substring(1), completionRegion, existingAttr, node, attrName.substring(0, 3).equals("set")); }/*from ww w. j a v a 2 s. c o m*/ } } } return super.computeAttributeValueProposals(documentPosition, matchString, completionRegion, nodeAtOffset, node); }
From source file:org.solmix.runtime.support.spring.AbstractBeanDefinitionParser.java
/**?Element,?Container*/ protected boolean parseAttributes(Element element, ParserContext ctx, BeanDefinitionBuilder bean) { NamedNodeMap atts = element.getAttributes(); boolean setBus = false; for (int i = 0; i < atts.getLength(); i++) { Attr node = (Attr) atts.item(i); String val = node.getValue(); String pre = node.getPrefix(); String name = node.getLocalName(); String prefix = node.getPrefix(); // Don't process namespaces if (isNamespace(name, prefix)) { continue; }// w w w . j a v a 2 s . co m if ("createdFromAPI".equals(name)) { bean.setAbstract(true); } else if ("abstract".equals(name)) { bean.setAbstract(true); } else if ("depends-on".equals(name)) { bean.addDependsOn(val); } else if ("name".equals(name)) { parseNameAttribute(element, ctx, bean, val); } else if ("container".equals(name)) { setBus = parseContainerAttribute(element, ctx, bean, val); } else if ("id".equals(name)) { parseIdAttribute(bean, element, name, val, ctx); } else if (isAttribute(pre, name)) { parseAttribute(bean, element, name, val, ctx); } } return setBus; }
From source file:com.evolveum.midpoint.util.DOMUtil.java
private static Attr findAttributeByQName(NamedNodeMap attrs, QName qname) { for (int i = 0; i < attrs.getLength(); i++) { Node aItem = attrs.item(i); Attr aAttr = (Attr) aItem; if (aAttr.getLocalName() == null) { continue; }//from w ww . j a v a 2 s.c o m QName aQname = new QName(aAttr.getNamespaceURI(), aAttr.getLocalName()); if (aQname.equals(qname)) { return aAttr; } } return null; }
From source file:com.jaeksoft.searchlib.analysis.ClassFactory.java
final protected void addProperties(final NamedNodeMap nnm) throws SearchLibException { if (nnm == null) return;/*from ww w .ja v a 2 s.co m*/ int l = nnm.getLength(); for (int i = 0; i < l; i++) { Node attr = nnm.item(i); addProperty(attr.getNodeName(), StringEscapeUtils.unescapeXml(attr.getNodeValue())); } }
From source file:org.joy.config.Configuration.java
private Properties parseAttributes(Node node) { Properties attributes = new Properties(); NamedNodeMap nnm = node.getAttributes(); for (int i = 0; i < nnm.getLength(); i++) { Node attribute = nnm.item(i); String value = attribute.getNodeValue(); attributes.put(attribute.getNodeName(), value); }/*from ww w .j a v a 2 s .co m*/ return attributes; }