List of usage examples for org.w3c.dom NamedNodeMap getLength
public int getLength();
From source file:cc.siara.csv_ml.ParsedObject.java
/** * Performas any pending activity against an element to finalize it. In this * case, it adds any pending attributes needing namespace mapping. * //from w w w .j ava 2 s . c o m * Also if the node has a namespace attached, it recreates the node with * specific URI. */ public void finalizeElement() { // Add all remaining attributes for (String col_name : pendingAttributes.keySet()) { String value = pendingAttributes.get(col_name); int cIdx = col_name.indexOf(':'); String ns = col_name.substring(0, cIdx); String nsURI = nsMap.get(ns); if (nsURI == null) nsURI = generalNSURI; Attr attr = doc.createAttributeNS(nsURI, col_name.substring(cIdx + 1)); attr.setPrefix(ns); attr.setValue(value); ((Element) cur_element).setAttributeNodeNS(attr); } // If the element had a namespace prefix, it has to be recreated. if (!currentElementNS.equals("") && !doc.getDocumentElement().equals(cur_element)) { Node parent = cur_element.getParentNode(); Element cur_ele = (Element) parent.removeChild(cur_element); String node_name = cur_ele.getNodeName(); String nsURI = nsMap.get(currentElementNS); if (nsURI == null) nsURI = generalNSURI; Element new_node = doc.createElementNS(nsURI, currentElementNS + ":" + node_name); parent.appendChild(new_node); // Add all attributes NamedNodeMap attrs = cur_ele.getAttributes(); while (attrs.getLength() > 0) { Attr attr = (Attr) attrs.item(0); cur_ele.removeAttributeNode(attr); nsURI = attr.getNamespaceURI(); new_node.setAttributeNodeNS(attr); } // Add all CData sections NodeList childNodes = cur_ele.getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { Node node = childNodes.item(i); if (node.getNodeType() == Node.CDATA_SECTION_NODE) new_node.appendChild(node); } cur_element = new_node; } pendingAttributes = new Hashtable<String, String>(); }
From source file:edu.eurac.commul.pepperModules.mmax2.Salt2MMAXMapping.java
public static SAnnotationNameSpaceMatchCondition parseSAnnotationNameSpaceMatchCondition(Node node) { NamedNodeMap attributes = node.getAttributes(); Node nsAttributeNode = attributes.getNamedItem(SANN_NS_REGEXP); String nsRegExp = null;//from ww w. ja v a 2 s . co m if (nsAttributeNode != null) { nsRegExp = nsAttributeNode.getNodeValue(); attributes.removeNamedItem(SANN_NS_REGEXP); } else { throw new PepperModuleException("'" + SANN_NS_REGEXP + "' attribute not found on SAnnotation NameSpace Match Condition '" + node + "'"); } if (attributes.getLength() != 0) { throw new PepperModuleException( "Additional unexpected attributes found on SAnnotation NameSpace Match Condition '" + node + "'"); } return new SAnnotationNameSpaceMatchCondition(Pattern.compile(nsRegExp)); }
From source file:edu.eurac.commul.pepperModules.mmax2.Salt2MMAXMapping.java
public static SRelationSNameMatchCondition parseSRelationSNameMatchCondition(Node node) { NamedNodeMap attributes = node.getAttributes(); Node snameAttributeNode = attributes.getNamedItem(SREL_SNAME_REGEXP); String snameRegExp = null;//from w w w . java 2s. c o m if (snameAttributeNode != null) { snameRegExp = snameAttributeNode.getNodeValue(); attributes.removeNamedItem(SREL_SNAME_REGEXP); } else { throw new PepperModuleException("'" + SREL_SNAME_REGEXP + " attribute not found on SRelation SName Match Condition '" + node + "'"); } if (attributes.getLength() != 0) { throw new PepperModuleException( "Additional unexpected attributes found on SRelation SName Match Condition '" + node + "'"); } return new SRelationSNameMatchCondition(Pattern.compile(snameRegExp)); }
From source file:edu.eurac.commul.pepperModules.mmax2.Salt2MMAXMapping.java
public static SRelationSTypeMatchCondition parseSRelationSTypeMatchCondition(Node node) { NamedNodeMap attributes = node.getAttributes(); Node stypeAttributeNode = attributes.getNamedItem(SREL_STYPE_REGEXP); String stypeRegExp = null;/*from w ww .ja va2s .com*/ if (stypeAttributeNode != null) { stypeRegExp = stypeAttributeNode.getNodeValue(); attributes.removeNamedItem(SREL_STYPE_REGEXP); } else { throw new PepperModuleException("'" + SREL_STYPE_REGEXP + " attribute not found on SRelation SType Match Condition '" + node + "'"); } if (attributes.getLength() != 0) { throw new PepperModuleException( "Additional unexpected attributes found on SRelation SType Match Condition '" + node + "'"); } return new SRelationSTypeMatchCondition(Pattern.compile(stypeRegExp)); }
From source file:edu.eurac.commul.pepperModules.mmax2.Salt2MMAXMapping.java
public static SAnnotationSNameMatchCondition parseSAnnotationSNameMatchCondition(Node node) { NamedNodeMap attributes = node.getAttributes(); Node snameAttributeNode = attributes.getNamedItem(SANN_SNAME_REGEXP); String nameRegExp = null;/*from w w w . j a v a 2s.c o m*/ if (snameAttributeNode != null) { nameRegExp = snameAttributeNode.getNodeValue(); attributes.removeNamedItem(SANN_SNAME_REGEXP); } else { throw new PepperModuleException("'" + SANN_SNAME_REGEXP + "' attribute not found on SAnnotation SName Match Condition '" + node + "'"); } if (attributes.getLength() != 0) { throw new PepperModuleException( "Additional unexpected attributes found on SAnnotation SName Match Condition '" + node + "'"); } return new SAnnotationSNameMatchCondition(Pattern.compile(nameRegExp)); }
From source file:eionet.gdem.conversion.odf.ODFSpreadsheetAnalyzer.java
/** * Finds the namespace prefixes associated with OpenDocument, Dublin Core, and OpenDocument meta elements. * This function presumes that all the namespaces are in the root element. If they aren't, this breaks. * * @param rootElement// www .ja v a 2s . c om * the root element of the document. */ protected void findNamespaces(Element rootElement) { NamedNodeMap attributes; Node node; String value; attributes = rootElement.getAttributes(); for (int i = 0; i < attributes.getLength(); i++) { node = attributes.item(i); value = node.getNodeValue(); if (value.equals(DC_URI)) { dcNamespace = extractNamespace(node.getNodeName()); } else if (value.equals(TABLE_URI)) { tableNamespace = extractNamespace(node.getNodeName()); } else if (value.equals(TEXT_URI)) { textNamespace = extractNamespace(node.getNodeName()); } else if (value.equals(OPENDOCUMENT_URI)) { officeNamespace = extractNamespace(node.getNodeName()); } } }
From source file:edu.eurac.commul.pepperModules.mmax2.Salt2MMAXMapping.java
public static SRelationSLayerMatchCondition parseSRelationSLayerMatchCondition(Node node) { NamedNodeMap attributes = node.getAttributes(); Node slayerAttributeNode = attributes.getNamedItem(SREL_SLAYER_REGEXP); String slayerRegExp = null;/*w w w . j av a2 s . c o m*/ if (slayerAttributeNode != null) { slayerRegExp = slayerAttributeNode.getNodeValue(); attributes.removeNamedItem(SREL_SLAYER_REGEXP); } else { throw new PepperModuleException("'" + SREL_SLAYER_REGEXP + " attribute not found on SRelation SLayer Match Condition '" + node + "'"); } if (attributes.getLength() != 0) { throw new PepperModuleException( "Additional unexpected attributes found on SRelation SLayer Match Condition '" + node + "'"); } return new SRelationSLayerMatchCondition(Pattern.compile(slayerRegExp)); }
From source file:edu.eurac.commul.pepperModules.mmax2.Salt2MMAXMapping.java
public static SAnnotationSLayerMatchCondition parseSAnnotationSLayerMatchCondition(Node node) { NamedNodeMap attributes = node.getAttributes(); Node slayerAttributeNode = attributes.getNamedItem(SANN_SLAYER_REGEXP); String slayerRegExp = null;//from ww w. j a va 2s . c om if (slayerAttributeNode != null) { slayerRegExp = slayerAttributeNode.getNodeValue(); attributes.removeNamedItem(SANN_SLAYER_REGEXP); } else { throw new PepperModuleException("'" + SANN_SLAYER_REGEXP + " attribute not found on SAnnotation SLayer Match Condition '" + node + "'"); } if (attributes.getLength() != 0) { throw new PepperModuleException( "Additional unexpected attributes found on SAnnnotation SLayer Match Condition '" + node + "'"); } return new SAnnotationSLayerMatchCondition(Pattern.compile(slayerRegExp)); }
From source file:hudson.plugins.plot.XMLSeries.java
/*** * This is a fallback strategy for nodesets that include non numeric content * enabling users to create lists by selecting them such that names and * values share a common parent. If a node has attributes and is empty that * node will be re-enqueued as a parent to its attributes. * /*from w w w .ja v a 2s. c o m*/ * @param buildNumber * the build number * * @returns a list of PlotPoints where the label is the last non numeric * text content and the value is the last numeric text content for * each set of nodes under a given parent. ***/ private List<PlotPoint> coalesceTextnodesAsLabelsStrategy(NodeList nodeList, int buildNumber) { Map<Node, List<Node>> parentNodeMap = new HashMap<Node, List<Node>>(); for (int i = 0; i < nodeList.getLength(); i++) { Node node = nodeList.item(i); if (!parentNodeMap.containsKey(node.getParentNode())) { parentNodeMap.put(node.getParentNode(), new ArrayList<Node>()); } parentNodeMap.get(node.getParentNode()).add(node); } List<PlotPoint> retval = new ArrayList<PlotPoint>(); Queue<Node> parents = new ArrayDeque<Node>(parentNodeMap.keySet()); while (!parents.isEmpty()) { Node parent = parents.poll(); Double value = null; String label = null; for (Node child : parentNodeMap.get(parent)) { if (null == child.getTextContent() || child.getTextContent().trim().isEmpty()) { NamedNodeMap attrmap = child.getAttributes(); List<Node> attrs = new ArrayList<Node>(); for (int i = 0; i < attrmap.getLength(); i++) { attrs.add(attrmap.item(i)); } parentNodeMap.put(child, attrs); parents.add(child); } else if (new Scanner(child.getTextContent().trim()).hasNextDouble()) { value = new Scanner(child.getTextContent().trim()).nextDouble(); } else { label = child.getTextContent().trim(); } } if ((label != null) && (value != null)) { addValueToList(retval, new String(label), String.valueOf(value), buildNumber); } } return retval; }
From source file:com.nridge.core.base.io.xml.DocumentOpXML.java
private void loadOperation(Element anElement) throws IOException { Attr nodeAttr;/*from w w w .j a v a 2s .c o m*/ Node nodeItem; Document document; Element nodeElement; DocumentXML documentXML; DSCriteriaXML criteriaXML; String nodeName, nodeValue; mCriteria = null; mDocumentList.clear(); mField.clearFeatures(); String attrValue = anElement.getAttribute(Doc.FEATURE_OP_NAME); if (StringUtils.isNotEmpty(attrValue)) { mField.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, Doc.FEATURE_OP_NAME)) && (!StringUtils.equalsIgnoreCase(nodeName, Doc.FEATURE_OP_COUNT))) mField.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_CRITERIA_NODE_NAME)) { nodeElement = (Element) nodeItem; criteriaXML = new DSCriteriaXML(); criteriaXML.load(nodeElement); mCriteria = criteriaXML.getCriteria(); } else if (StringUtils.startsWithIgnoreCase(nodeName, IO.XML_DOCUMENT_NODE_NAME)) { nodeElement = (Element) nodeItem; documentXML = new DocumentXML(); documentXML.load(nodeElement); document = documentXML.getDocument(); if (document != null) mDocumentList.add(document); } } }