List of usage examples for org.w3c.dom NamedNodeMap getNamedItem
public Node getNamedItem(String name);
From source file:org.energy_home.jemma.ah.internal.hac.lib.HacService.java
private Object traversePropertyNode(Node node) { int nodeType = node.getNodeType(); switch (nodeType) { // print element with attributes case Node.ELEMENT_NODE: NamedNodeMap attrs = node.getAttributes(); String tag = node.getNodeName(); Node item = attrs.getNamedItem("type"); String type = null;//w ww. j av a2 s. c om if (item != null) { type = item.getNodeValue(); } if (tag.equals("item") || tag.equals("property")) { if (type == null) { return getTextContent(node); } else if (type.equals("java.lang.String")) { return getTextContent(node); } else if (type.equals("java.util.Vector")) { NodeList children = node.getChildNodes(); int len = children.getLength(); Vector container = new Vector(); for (int i = 0; i < len; i++) { Object res = traversePropertyNode(children.item(i)); if (res != null) { container.add(res); LOG.debug("added to vector " + res.toString()); } } return container; } } } return null; }
From source file:org.entrystore.repository.impl.converters.OAI_DC2RDFGraphConverter.java
/** * Converts an oai_dc xml document tag metadata to a graph. * //from www . j av a 2s .c o m * @param from * An XML NodeList. * * @param resourceURI * Root URI of the resource's metadata. * * @return the new metadata graph. */ public Object convert(Object from, java.net.URI resourceURI, java.net.URI metadataURI) { NodeList metadataList = null; if (from instanceof NodeList) { metadataList = (NodeList) from; } else if (from instanceof Node) { metadataList = ((Node) from).getChildNodes(); } else { log.warn("Unable to convert object, class type not supported"); return null; } Graph graph = new GraphImpl(); ValueFactory vf = graph.getValueFactory(); org.openrdf.model.URI root = vf.createURI(resourceURI.toString()); for (int i = 0; i < metadataList.getLength(); i++) { Node n = metadataList.item(i); if (n == null || "#text".equals(n.getNodeName())) { continue; } String nodeNS = n.getNamespaceURI(); String nodeName = n.getNodeName(); String predicate = null; if (nodeName.contains(":") && (nodeNS != null)) { nodeName = nodeName.substring(nodeName.indexOf(":") + 1); predicate = nodeNS + nodeName; } else { predicate = nodeName; } String nodeContent = n.getTextContent(); if (nodeContent == null) { continue; } nodeContent = nodeContent.trim(); // fix to create a valid language literal with a 2-letter ISO code // this is about the language value as a literal, attributes are treated further down if ("language".equalsIgnoreCase(nodeName)) { // convert 3-letter to 2-letter ISO code if (nodeContent.length() == 3) { nodeContent = getISO2Language(nodeContent); } } // <- fix // fix to convert ISO 3-letter lang codes to 2-letter codes // this is about LangStrings in general NamedNodeMap nodeAttributes = n.getAttributes(); String lang = null; if (nodeAttributes != null) { Node langNode = nodeAttributes.getNamedItem("xml:lang"); if (langNode != null) { lang = langNode.getNodeValue(); if (lang != null) { lang = lang.trim(); if (lang.length() == 3) { lang = getISO2Language(lang.toLowerCase()); } } } } // <- fix Literal lit; if (lang != null) { lit = vf.createLiteral(nodeContent, lang); } else { lit = vf.createLiteral(nodeContent); } graph.add(root, new org.openrdf.model.impl.URIImpl(predicate), lit); } return graph; }
From source file:org.exoplatform.rest.client.openfire.ExoGroupProvider.java
/** * Create List of group names from given XML document. * @param d Document./*from ww w.j a va 2s .c o m*/ * @return List of group names. */ private List<String> createGroupList(Document d) { List<String> groupnames = new ArrayList<String>(); NodeList u = d.getDocumentElement().getElementsByTagName("group"); for (int i = 0; i < u.getLength(); i++) { Node descendantGroup = u.item(i); NamedNodeMap attribs = descendantGroup.getAttributes(); String groupName = attribs.getNamedItem("groupId").getNodeValue(); String getGroups = getGroupNameWithDescendants(groupName); for (String _group : getGroups.split(":")) { if (_group.startsWith("/")) _group = _group.substring(1); groupnames.add(_group); } } return groupnames; }
From source file:org.exoplatform.rest.client.openfire.ExoGroupProvider.java
private String getGroupNameWithDescendants(String group) { String url = getGroupsAllURL_; String method = getGroupsAllMethod_; Response resp = null;/* w w w . j av a 2s.com*/ HashMap<String, String> params = new HashMap<String, String>(); params.put("parentId", group); try { if ("POST".equalsIgnoreCase(method)) { resp = Utils.doPost(new URL(url), params); } else if ("GET".equalsIgnoreCase(method)) { resp = Utils.doGet(new URL(url), params); } else throw new IllegalStateException( "Configuration error, only HTTP methods 'POST' or 'GET' are allowed, " + "but found '" + method + "'."); } catch (Exception e) { e.printStackTrace(); return null; } if (resp.getStatus() == HttpStatus.SC_OK) { Document d = resp.getResponseDoc(); NodeList groupList = d.getDocumentElement().getElementsByTagName("group"); // recursion break if (groupList.getLength() == 0) return group; String compositeGroupName = group; for (int i = 0; i < groupList.getLength(); i++) { Node descendantGroup = groupList.item(i); NamedNodeMap attribs = descendantGroup.getAttributes(); String groupId = attribs.getNamedItem("groupId").getNodeValue(); compositeGroupName += ":" + getGroupNameWithDescendants(groupId); } return compositeGroupName; } else if (resp.getStatus() == HttpStatus.SC_NOT_FOUND) { throw new IllegalStateException("Group not found"); } throw new IllegalStateException("Unknown response status : " + resp.getStatus()); }
From source file:org.fcrepo.server.security.servletfilters.pubcookie.FilterPubcookie.java
private final String getAction(Node parent, String pubcookieLoginpageFormName) { String method = "getAction()"; if (logger.isDebugEnabled()) { logger.debug(enter(method));//from w ww .j a v a2 s. c o m } String action = ""; NodeList children = parent.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); String tag = child.getNodeName(); if ("form".equalsIgnoreCase(tag)) { NamedNodeMap attributes = child.getAttributes(); Node nameNode = attributes.getNamedItem("name"); String name = nameNode.getNodeValue(); Node actionNode = attributes.getNamedItem("action"); if (pubcookieLoginpageFormName.equalsIgnoreCase(name) && actionNode != null) { action = actionNode.getNodeValue(); break; } } action = getAction(child, pubcookieLoginpageFormName); if (!"".equals(action)) { break; } } if (logger.isDebugEnabled()) { logger.debug(exit(method)); } return action; }
From source file:org.fcrepo.server.security.servletfilters.pubcookie.FilterPubcookie.java
private final void getFormFields(Node parent, Map formfields) { String method = "getFormFields(Node parent, Map formfields)"; if (logger.isDebugEnabled()) { logger.debug(enter(method));// w ww.ja v a2s .co m } NodeList children = parent.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); String tag = child.getNodeName(); if ("input".equalsIgnoreCase(tag)) { NamedNodeMap attributes = child.getAttributes(); Node typeNode = attributes.getNamedItem("type"); String type = typeNode.getNodeValue(); Node nameNode = attributes.getNamedItem("name"); String name = nameNode.getNodeValue(); Node valueNode = attributes.getNamedItem("value"); String value = ""; if (valueNode != null) { value = valueNode.getNodeValue(); } if ("hidden".equalsIgnoreCase(type) && value != null) { if (logger.isDebugEnabled()) { logger.debug(format("capturing hidden fields", name, value)); } formfields.put(name, value); } } getFormFields(child, formfields); } if (logger.isDebugEnabled()) { logger.debug(exit(method)); } }
From source file:org.geotools.coverage.io.util.Utilities.java
/** * Simple method returning the value (as {@code String}) of the attribute with name {@code attributeName} from the input attributes map. * /* w w w .ja v a 2 s . c om*/ * @param attributes the attributes map * @param attributeName the requested attribute * @return the value of the requested attribute as a {@code String}. Returns {@code null} in case of no attribute found. * */ public static String getAttributeValue(NamedNodeMap attributes, String attributeName) { String attributeValue = null; Node attribute = attributes.getNamedItem(attributeName); if (attribute != null) { attributeValue = attribute.getNodeValue(); } return attributeValue; }
From source file:org.geotools.geometry.jts.spatialschema.geometry.GeometryTestParser.java
private String getNodeAttribute(Node node, String attrName) { String emptyString = ""; NamedNodeMap attrs = node.getAttributes(); if (attrs == null) { return emptyString; }/* www. j a v a 2s. c o m*/ Node attrNode = attrs.getNamedItem(attrName); if (attrNode == null) { return emptyString; } return attrNode.getNodeValue(); }
From source file:org.hyperic.hq.plugin.jboss.JBossConfig.java
private String getAttribute(Node node, String name) { NamedNodeMap attrs = node.getAttributes(); if (attrs == null) { return null; }// w w w.j ava 2 s. co m Node item = attrs.getNamedItem(name); if (item == null) { return null; } return item.getNodeValue(); }
From source file:org.jasig.portal.layout.dlm.FragmentDefinition.java
private void loadAudienceEvaluators(NodeList nodes) { final String evaluatorFactoryAtt = "evaluatorFactory"; for (int i = 0; i < nodes.getLength(); i++) { Node audience = nodes.item(i); NamedNodeMap atts = audience.getAttributes(); Node att = atts.getNamedItem(evaluatorFactoryAtt); if (att == null || att.getNodeValue().equals("")) throw new RuntimeException( "Required attibute '" + evaluatorFactoryAtt + "' " + "is missing or empty on 'audience' " + " element in\n'" + XmlUtilitiesImpl.toString(audience) + "'"); String className = att.getNodeValue(); EvaluatorFactory factory = loadEvaluatorFactory(className, audience); addEvaluator(factory, audience); }//from www . j a va2 s . c o m }