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.diversityarrays.dalclient.DalUtil.java
public static Map<String, String> asRowdata(Node node) { Map<String, String> result = null; NamedNodeMap attributes = node.getAttributes(); if (attributes != null) { int nAttributes = attributes.getLength(); result = new LinkedHashMap<>(nAttributes); for (int ai = 0; ai < nAttributes; ++ai) { Node attr = attributes.item(ai); result.put(attr.getNodeName(), attr.getNodeValue()); }/*from www . ja v a2 s . c o m*/ } return result; }
From source file:com.doculibre.constellio.lang.html.HtmlLangDetector.java
private List<String> parse(Node node) { List<String> langs = new ArrayList<String>(); if (node.getNodeType() == Node.ELEMENT_NODE) { // Check for the lang HTML attribute final String htmlLang = parseLanguage(((Element) node).getAttribute("lang")); if (StringUtils.isNotBlank(htmlLang)) { langs.add(htmlLang);/*from w w w . j a v a 2 s .co m*/ } // Check for Meta if ("meta".equalsIgnoreCase(node.getNodeName())) { NamedNodeMap attrs = node.getAttributes(); // Check for the dc.language Meta for (int i = 0; i < attrs.getLength(); i++) { Node attrnode = attrs.item(i); if ("name".equalsIgnoreCase(attrnode.getNodeName())) { if ("dc.language".equalsIgnoreCase(attrnode.getNodeValue())) { Node valueattr = attrs.getNamedItem("content"); if (valueattr != null) { final String dublinCore = parseLanguage(valueattr.getNodeValue()); if (StringUtils.isNotBlank(dublinCore)) { langs.add(dublinCore); } } } } } // Check for the http-equiv content-language for (int i = 0; i < attrs.getLength(); i++) { Node attrnode = attrs.item(i); if ("http-equiv".equalsIgnoreCase(attrnode.getNodeName())) { if ("content-language".equalsIgnoreCase(attrnode.getNodeValue().toLowerCase())) { Node valueattr = attrs.getNamedItem("content"); if (valueattr != null) { final String httpEquiv = parseLanguage(valueattr.getNodeValue()); if (StringUtils.isNotBlank(httpEquiv)) { langs.add(httpEquiv); } } } } } // Check for the <meta name="language" content="xyz" /> tag for (int i = 0; i < attrs.getLength(); i++) { Node attrnode = attrs.item(i); if ("name".equalsIgnoreCase(attrnode.getNodeName())) { if ("language".equalsIgnoreCase(attrnode.getNodeValue().toLowerCase())) { Node valueattr = attrs.getNamedItem("content"); if (valueattr != null) { final String metaLanguage = parseLanguage(valueattr.getNodeValue()); if (StringUtils.isNotBlank(metaLanguage)) { langs.add(metaLanguage); } } } } } } } if (langs.isEmpty()) { // Recurse NodeList children = node.getChildNodes(); for (int i = 0; children != null && i < children.getLength(); i++) { langs.addAll(parse(children.item(i))); if (!langs.isEmpty()) { break; } } } return langs; }
From source file:com.nortal.jroad.endpoint.AbstractXTeeBaseEndpoint.java
private void copyParing(Document paring, Node response) throws Exception { Node paringElement = response.appendChild(response.getOwnerDocument().createElement("paring")); Node kehaNode = response.getOwnerDocument().importNode(paring.getDocumentElement(), true); NamedNodeMap attrs = kehaNode.getAttributes(); for (int i = 0; i < attrs.getLength(); i++) { paringElement.getAttributes().setNamedItem(attrs.item(i).cloneNode(true)); }//from w ww . j a v a 2s .co m while (kehaNode.hasChildNodes()) { paringElement.appendChild(kehaNode.getFirstChild()); } }
From source file:net.di2e.ecdr.search.transform.atom.security.impl.XmlMetadataSecurityMarkingHandler.java
@Override public SecurityData getSecurityData(Metacard metacard) { String metadata = metacard.getMetadata(); if (StringUtils.isNotBlank(metadata)) { XPathHelper helper = new XPathHelper(metacard.getMetadata()); Document document = helper.getDocument(); NodeList nodeList = document.getElementsByTagNameNS("*", "security"); if (nodeList != null && nodeList.getLength() > 0) { Element element = (Element) nodeList.item(0); NamedNodeMap nodeNameMap = element.getAttributes(); int length = nodeNameMap.getLength(); Map<String, List<String>> securityProps = new HashMap<String, List<String>>(); String securityNamespace = null; for (int i = 0; i < length; i++) { Attr attr = (Attr) nodeNameMap.item(i); String value = attr.getValue(); if (!attr.getName().startsWith(XMLNS_PREFIX) && StringUtils.isNotBlank(value)) { securityProps.put(attr.getLocalName(), SecurityMarkingParser.getValues(value)); if (securityNamespace == null) { securityNamespace = attr.getNamespaceURI(); }//from w w w. ja v a 2s . c o m } } if (!securityProps.isEmpty()) { return new SecurityDataImpl(securityProps, securityNamespace); } } } return null; }
From source file:com.predic8.membrane.annot.parser.BlueprintElementParser.java
protected void setProperties(ParserContext context, String springPropertyName, Element element, MutableBeanMetadata mcm) {/*w ww .j a va 2s .c o m*/ NamedNodeMap attributes = element.getAttributes(); HashMap<String, String> attrs = new HashMap<String, String>(); for (int i = 0; i < attributes.getLength(); i++) { Attr item = (Attr) attributes.item(i); if (item.getLocalName() != null) attrs.put(item.getLocalName(), item.getValue()); } MutablePassThroughMetadata pt = context.createMetadata(MutablePassThroughMetadata.class); pt.setObject(attrs); mcm.addProperty(springPropertyName, pt); }
From source file:edu.illinois.cs.cogcomp.temporal.normalizer.main.TemporalNormalizerBenchmark.java
/** * Setting up TemporalChunkerAnnotator, prepare dataset * @param fullFolderName folder name of the dataset * @param useHeidelTime boolean whether use HeidelTime for normalization or not * @throws IOException//from w ww . ja v a 2 s . c o m * @throws ParserConfigurationException * @throws SAXException */ public void setUp(String fullFolderName, boolean useHeidelTime) throws IOException, ParserConfigurationException, SAXException { testText = new ArrayList<>(); DCTs = new ArrayList<>(); docIDs = new ArrayList<>(); te3inputText = new ArrayList<>(); Properties rmProps = new TemporalChunkerConfigurator().getDefaultConfig().getProperties(); rmProps.setProperty("useHeidelTime", useHeidelTime ? "True" : "False"); tca = new TemporalChunkerAnnotator(new ResourceManager(rmProps)); File folder = new File(fullFolderName); File[] listOfFiles = folder.listFiles(); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); for (File file : listOfFiles) { if (file.isFile()) { String testFile = fullFolderName + "/" + file.getName(); byte[] encoded = Files.readAllBytes(Paths.get(testFile)); String fileContent = new String(encoded, StandardCharsets.UTF_8); te3inputText.add(fileContent); Document document = builder.parse(new InputSource(new StringReader(fileContent))); Element rootElement = document.getDocumentElement(); NodeList nodeList = rootElement.getChildNodes(); for (int i = 0; i < nodeList.getLength(); i++) { Node currentNode = nodeList.item(i); if (currentNode.getNodeName().equals("TEXT")) { testText.add(currentNode.getTextContent()); } if (currentNode.getNodeName().indexOf("DOCID") != -1) { docIDs.add(currentNode.getTextContent()); } if (currentNode.getNodeName().indexOf("DCT") != -1) { Node dctNode = currentNode.getChildNodes().item(0); NamedNodeMap dctAttrs = dctNode.getAttributes(); for (int j = 0; j < dctAttrs.getLength(); j++) { if (dctAttrs.item(j).getNodeName().equals("value")) { DCTs.add(dctAttrs.item(j).getNodeValue()); } } } } } } }
From source file:com.sqewd.os.maracache.core.Config.java
private ConfigPath load(ConfigNode parent, Element elm) throws ConfigException { if (parent instanceof ConfigPath) { // Check if there are any attributes. // Attributes are treated as Value nodes. if (elm.hasAttributes()) { NamedNodeMap map = elm.getAttributes(); if (map.getLength() > 0) { for (int ii = 0; ii < map.getLength(); ii++) { Node n = map.item(ii); ((ConfigPath) parent).addValueNode(n.getNodeName(), n.getNodeValue()); }//from w w w . j a va 2s. c o m } } if (elm.hasChildNodes()) { NodeList children = elm.getChildNodes(); for (int ii = 0; ii < children.getLength(); ii++) { Node cn = children.item(ii); if (cn.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) cn; if (e.hasChildNodes()) { int nc = 0; for (int jj = 0; jj < e.getChildNodes().getLength(); jj++) { Node ccn = e.getChildNodes().item(jj); // Read the text node if there is any. if (ccn.getNodeType() == Node.TEXT_NODE) { String n = e.getNodeName(); String v = ccn.getNodeValue(); if (!StringUtils.isEmpty(v.trim())) ((ConfigPath) parent).addValueNode(n, v); nc++; } } // Make sure this in not a text only node. if (e.getChildNodes().getLength() > nc) { // Check if this is a parameter node. Parameters are treated differently. if (e.getNodeName().compareToIgnoreCase(ConfigParams.NODE_NAME) == 0) { ConfigParams cp = ((ConfigPath) parent).addParamNode(); setParams(cp, e); } else { ConfigPath cp = ((ConfigPath) parent).addPathNode(e.getNodeName()); load(cp, e); } } } } } } } return (ConfigPath) parent; }
From source file:com.gargoylesoftware.htmlunit.javascript.host.xml.XMLSerializer.java
private void toXml(final int indent, final DomNode node, final StringBuilder buffer, final String foredNamespace) { final String nodeName = node.getNodeName(); buffer.append('<').append(nodeName); String optionalPrefix = ""; final String namespaceURI = node.getNamespaceURI(); final String prefix = node.getPrefix(); if (namespaceURI != null && prefix != null) { boolean sameNamespace = false; for (DomNode parentNode = node .getParentNode(); parentNode instanceof DomElement; parentNode = parentNode.getParentNode()) { if (namespaceURI.equals(parentNode.getNamespaceURI())) { sameNamespace = true;// ww w . j a v a2s .com } } if (node.getParentNode() == null || !sameNamespace) { ((DomElement) node).setAttribute("xmlns:" + prefix, namespaceURI); } } else if (foredNamespace != null) { buffer.append(" xmlns=\"").append(foredNamespace).append('"'); optionalPrefix = " "; } final NamedNodeMap attributesMap = node.getAttributes(); for (int i = 0; i < attributesMap.getLength(); i++) { final DomAttr attrib = (DomAttr) attributesMap.item(i); buffer.append(' ').append(attrib.getQualifiedName()).append('=').append('"').append(attrib.getValue()) .append('"'); } boolean startTagClosed = false; for (final DomNode child : node.getChildren()) { if (!startTagClosed) { buffer.append(optionalPrefix).append('>'); startTagClosed = true; } switch (child.getNodeType()) { case Node.ELEMENT_NODE: toXml(indent + 1, child, buffer, null); break; case Node.TEXT_NODE: String value = child.getNodeValue(); value = StringUtils.escapeXmlChars(value); buffer.append(value); break; case Node.CDATA_SECTION_NODE: case Node.COMMENT_NODE: buffer.append(child.asXml()); break; default: } } if (!startTagClosed) { final String tagName = nodeName.toLowerCase(Locale.ROOT); final boolean nonEmptyTagsSupported = getBrowserVersion().hasFeature(JS_XML_SERIALIZER_NON_EMPTY_TAGS); if (nonEmptyTagsSupported && NON_EMPTY_TAGS.contains(tagName)) { buffer.append('>'); buffer.append("</").append(nodeName).append('>'); } else { buffer.append(optionalPrefix); if (buffer.charAt(buffer.length() - 1) != ' ' && getBrowserVersion().hasFeature(JS_XML_SERIALIZER_BLANK_BEFORE_SELF_CLOSING)) { buffer.append(" "); } buffer.append("/>"); } } else { buffer.append('<').append('/').append(nodeName).append('>'); } }
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; }// w w w. j a v a 2 s.co m 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.solmix.runtime.support.spring.AbstractRootBeanDefinitionParser.java
protected void parseAttributes(Element element, ParserContext parserContext, String id, RootBeanDefinition beanDefinition) { Set<String> props = new HashSet<String>(); ManagedMap<String, Object> parameters = null; for (Method setter : this.type.getMethods()) { String name = setter.getName(); if (name.length() > 3 && name.startsWith("set") && Modifier.isPublic(setter.getModifiers()) && setter.getParameterTypes().length == 1) { Class<?> type = setter.getParameterTypes()[0]; String property = StringUtils .camelToSplitName(name.substring(3, 4).toLowerCase() + name.substring(4), "-"); props.add(property);/*www. j a v a 2s . c o m*/ Method getter = null; try { getter = this.type.getMethod("get" + name.substring(3), new Class<?>[0]); } catch (NoSuchMethodException e) { try { getter = this.type.getMethod("is" + name.substring(3), new Class<?>[0]); } catch (NoSuchMethodException e2) { } } if (getter == null || !Modifier.isPublic(getter.getModifiers()) || !type.equals(getter.getReturnType())) { continue; } if ("properties".equals(property)) { parameters = parseProperties(element.getChildNodes(), beanDefinition); } else if ("arguments".equals(property)) { parseArguments(id, element.getChildNodes(), beanDefinition, parserContext); } else { String value = element.getAttribute(property); if (value != null && value.trim().length() > 0) { value = value.trim(); parserValue(beanDefinition, property, type, value, parserContext); } } } } NamedNodeMap attributes = element.getAttributes(); int len = attributes.getLength(); for (int i = 0; i < len; i++) { Node node = attributes.item(i); String name = node.getLocalName(); if (!props.contains(name)) { if (parameters == null) { parameters = new ManagedMap<String, Object>(); } String value = node.getNodeValue(); parameters.put(name, new TypedStringValue(value, String.class)); } } if (parameters != null) { beanDefinition.getPropertyValues().addPropertyValue("properties", parameters); } }