List of usage examples for org.w3c.dom NamedNodeMap getLength
public int getLength();
From source file:com.nridge.core.base.io.xml.DSCriteriaXML.java
/** * Parses an XML DOM element and loads it into a criteria. * * @param anElement DOM element.//from w w w . j av a 2 s. c o m * * @throws java.io.IOException I/O related exception. */ @Override public void load(Element anElement) throws IOException { Node nodeItem; Attr nodeAttr; Element nodeElement; DataField dataField; String nodeName, nodeValue, logicalOperator; String className = mDSCriteria.getClass().getName(); String attrValue = anElement.getAttribute("type"); if ((StringUtils.isNotEmpty(attrValue)) && (!IO.isTypesEqual(attrValue, className))) throw new IOException("Unsupported type: " + attrValue); attrValue = anElement.getAttribute("name"); if (StringUtils.isNotEmpty(attrValue)) mDSCriteria.setName(attrValue); NamedNodeMap namedNodeMap = anElement.getAttributes(); int attrCount = namedNodeMap.getLength(); for (int attrOffset = 0; attrOffset < attrCount; attrOffset++) { nodeAttr = (Attr) namedNodeMap.item(attrOffset); nodeName = nodeAttr.getNodeName(); nodeValue = nodeAttr.getNodeValue(); if (StringUtils.isNotEmpty(nodeValue)) { if ((StringUtils.equalsIgnoreCase(nodeName, "name")) || (StringUtils.equalsIgnoreCase(nodeName, "type"))) continue; else mDSCriteria.addFeature(nodeName, nodeValue); } } NodeList nodeList = anElement.getChildNodes(); for (int i = 0; i < nodeList.getLength(); i++) { nodeItem = nodeList.item(i); if (nodeItem.getNodeType() != Node.ELEMENT_NODE) continue; nodeName = nodeItem.getNodeName(); if (nodeName.equalsIgnoreCase(IO.XML_FIELD_NODE_NAME)) { nodeElement = (Element) nodeItem; dataField = mDataFieldXML.load(nodeElement); if (dataField != null) { logicalOperator = dataField.getFeature("operator"); if (StringUtils.isEmpty(logicalOperator)) logicalOperator = Field.operatorToString(Field.Operator.EQUAL); mDSCriteria.add(dataField, Field.stringToOperator(logicalOperator)); } } } }
From source file:com.streamsets.pipeline.stage.processor.xmlflattener.XMLFlatteningProcessor.java
private void addAttrs(Record record, Element element, String elementPrefix) { if (!ignoreAttrs) { NamedNodeMap attrs = element.getAttributes(); for (int j = 0; j < attrs.getLength(); j++) { Node attr = attrs.item(j); String attrName = attr.getNodeName(); if (attrName.equals("xmlns")) { //handled separately. continue; }/*from w w w . ja va2 s . com*/ record.set(getPathPrefix() + elementPrefix + attrDelimiter + attr.getNodeName(), Field.create(attr.getNodeValue())); } } if (!ignoreNamespace) { String namespaceURI = element.getNamespaceURI(); if (namespaceURI != null) { record.set(getPathPrefix() + elementPrefix + attrDelimiter + "xmlns", Field.create(namespaceURI)); } } }
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 w ww . j av a2 s. co m*/ } } } return super.computeAttributeValueProposals(documentPosition, matchString, completionRegion, nodeAtOffset, node); }
From source file:net.algart.simagis.imageio.IIOMetadataToJsonConverter.java
private JSONObject compactTIFFSimilarNodes(Node node, String childrenName) throws JSONException { assert node != null; assert childrenName != null; long count = 0; for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling(), count++) { if (!childrenName.equals(child.getNodeName())) { return null; }/*from ww w .j a va 2s . c om*/ // so, a child has the name, equal to childrenName if (child.getFirstChild() != null) { return null; } // so, a child has no own children final NamedNodeMap childAttributes = child.getAttributes(); if (childAttributes == null || childAttributes.getLength() != 1) { return null; } Node childAttr = childAttributes.item(0); String attrName = childAttr.getNodeName(); String attrValue = childAttr.getNodeValue(); if (!("value".equals(attrName)) || attrValue == null || attrValue.contains(",")) { return null; } // so, a child has only 1 attribute "value", which is a string, not containing "," } if (count <= MAX_NON_COMPACTED_SIMILAR_CHILDREN) { return null; } StringBuilder sb = new StringBuilder(); count = 0; for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling(), count++) { Node childAttr = child.getAttributes().item(0); if (count > 0) { sb.append(","); } sb.append(childAttr.getNodeValue()); } JSONObject result = new JSONObject(); result.put("childrenName", childrenName); result.put("childrenValue", sb.toString()); return result; }
From source file:com.nridge.core.base.io.xml.DataBagXML.java
/** * Parses an XML DOM element and loads it into a bag/table. * * @param anElement DOM element./* ww w.ja va 2 s .c o m*/ * @throws java.io.IOException I/O related exception. */ @Override public void load(Element anElement) throws IOException { Node nodeItem; Attr nodeAttr; Element nodeElement; DataField dataField; String nodeName, nodeValue; String className = mBag.getClass().getName(); String attrValue = anElement.getAttribute("type"); if ((StringUtils.isNotEmpty(attrValue)) && (!IO.isTypesEqual(attrValue, className))) throw new IOException("Unsupported type: " + attrValue); attrValue = anElement.getAttribute("name"); if (StringUtils.isNotEmpty(attrValue)) mBag.setName(attrValue); attrValue = anElement.getAttribute("title"); if (StringUtils.isNotEmpty(attrValue)) mBag.setTitle(attrValue); NamedNodeMap namedNodeMap = anElement.getAttributes(); int attrCount = namedNodeMap.getLength(); for (int attrOffset = 0; attrOffset < attrCount; attrOffset++) { nodeAttr = (Attr) namedNodeMap.item(attrOffset); nodeName = nodeAttr.getNodeName(); nodeValue = nodeAttr.getNodeValue(); if (StringUtils.isNotEmpty(nodeValue)) { if ((StringUtils.equalsIgnoreCase(nodeName, "name")) || (StringUtils.equalsIgnoreCase(nodeName, "type")) || (StringUtils.equalsIgnoreCase(nodeName, "count")) || (StringUtils.equalsIgnoreCase(nodeName, "title")) || (StringUtils.equalsIgnoreCase(nodeName, "version"))) continue; else mBag.addFeature(nodeName, nodeValue); } } NodeList nodeList = anElement.getChildNodes(); for (int i = 0; i < nodeList.getLength(); i++) { nodeItem = nodeList.item(i); if (nodeItem.getNodeType() != Node.ELEMENT_NODE) continue; nodeName = nodeItem.getNodeName(); if (nodeName.equalsIgnoreCase(IO.XML_FIELD_NODE_NAME)) { nodeElement = (Element) nodeItem; dataField = mDataFieldXML.load(nodeElement); if (dataField != null) mBag.add(dataField); } } }
From source file:channellistmaker.dataextractor.AbstractEPGFileExtractor.java
/** * trace??????????????/*from w w w . ja v a 2 s.c o m*/ * @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:com.jaeksoft.searchlib.analysis.ClassFactory.java
final protected void addProperties(final NamedNodeMap nnm) throws SearchLibException { if (nnm == null) return;/*from w ww . j a v a2 s . c om*/ 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:net.algart.simagis.imageio.IIOMetadataToJsonConverter.java
private JSONObject treeToJson(Node node) throws JSONException { JSONObject result = new JSONObject(); result.put("name", node.getNodeName()); result.put("value", node.getNodeValue()); final NamedNodeMap nodeAttributes = node.getAttributes(); if (nodeAttributes != null) { final int length = nodeAttributes.getLength(); if (length > 0) { JSONObject attributes = new JSONObject(); for (int k = 0; k < length; k++) { final Node nodeAttr = nodeAttributes.item(k); attributes.put(nodeAttr.getNodeName(), nodeAttr.getNodeValue()); }//w w w.j av a 2s . c o m result.put("attributes", attributes); } } JSONObject compactChildren = null; for (String childrenName : COMPACTED_SIMILAR_CHILDREN_NAMES) { compactChildren = compactTIFFSimilarNodes(node, childrenName); if (compactChildren != null) { break; } } if (compactChildren != null) { result.put("joinedNodes", compactChildren); } else { Node child = node.getFirstChild(); if (child != null) { JSONArray nodes = new JSONArray(); do { nodes.put(treeToJson(child)); child = child.getNextSibling(); } while (child != null); result.put("nodes", nodes); } } if (node instanceof IIOMetadataNode) { result.put("userObject", iioNodeUserObjectToJson((IIOMetadataNode) node)); } return result; }
From source file:jp.igapyon.selecrawler.SeleCrawlerWebContentAnalyzer.java
public void processFile(final File file, final String urlString) throws IOException { final List<String> anchorList = new ArrayList<String>(); final List<String> headList = new ArrayList<String>(); final List<String> scriptSrcList = new ArrayList<String>(); final String contents = FileUtils.readFileToString( new File(file.getParentFile(), file.getName() + SeleCrawlerConstants.EXT_SC_NORMAL), "UTF-8"); final Document document = SimpleMyXmlUtil.string2Document(contents); {/* ww w.j a v a 2s .c om*/ final String title = SimpleMyXmlUtil.getXPathString(document, "/html/head/title/text()"); if (title != null && title.trim().length() > 0) { headList.add("title: " + title); } } { final NodeList nodes = SimpleMyXmlUtil.getXPathNodeList(document, "/html/head/meta"); for (int index = 0; index < nodes.getLength(); index++) { if (nodes.item(index) instanceof Element) { final Element eleMeta = (Element) nodes.item(index); headList.add("meta:"); final NamedNodeMap nnm = eleMeta.getAttributes(); for (int indexNnm = 0; indexNnm < nnm.getLength(); indexNnm++) { final Attr attr = (Attr) nnm.item(indexNnm); headList.add(" " + attr.getName() + " [" + attr.getValue() + "]"); } } } } { final NodeList nodes = SimpleMyXmlUtil.getXPathNodeList(document, "/html/head/link"); for (int index = 0; index < nodes.getLength(); index++) { if (nodes.item(index) instanceof Element) { final Element eleMeta = (Element) nodes.item(index); headList.add("link:"); final NamedNodeMap nnm = eleMeta.getAttributes(); for (int indexNnm = 0; indexNnm < nnm.getLength(); indexNnm++) { final Attr attr = (Attr) nnm.item(indexNnm); headList.add(" " + attr.getName() + " [" + attr.getValue() + "]"); } } } } { // search anchor with href final NodeList nodes = SimpleMyXmlUtil.getXPathNodeList(document, "//a"); for (int index = 0; index < nodes.getLength(); index++) { if (nodes.item(index) instanceof Element) { final Element eleAnchor = (Element) nodes.item(index); String href = eleAnchor.getAttribute("href"); href = adjustAnchorUrl(href, urlString); if (href == null) { continue; } anchorList.add(href); } } } { // search script final NodeList nodes = SimpleMyXmlUtil.getXPathNodeList(document, "//script"); for (int index = 0; index < nodes.getLength(); index++) { if (nodes.item(index) instanceof Element) { final Element eleScript = (Element) nodes.item(index); String srcString = eleScript.getAttribute("src"); srcString = adjustAnchorUrl(srcString, urlString); if (srcString == null) { continue; } scriptSrcList.add(srcString); } } } { final File fileMetaAnchor = new File(file.getParentFile(), file.getName() + SeleCrawlerConstants.EXT_SC_ANCHOR); FileUtils.writeLines(fileMetaAnchor, "UTF-8", anchorList); } { final File fileMetaHead = new File(file.getParentFile(), file.getName() + SeleCrawlerConstants.EXT_SC_HEAD); FileUtils.writeLines(fileMetaHead, "UTF-8", headList); } { final File fileScriptSrc = new File(file.getParentFile(), file.getName() + SeleCrawlerConstants.EXT_SC_SCRIPTSRC); FileUtils.writeLines(fileScriptSrc, "UTF-8", scriptSrcList); } }
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; }//from ww w . jav a 2 s . c o 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; }