List of usage examples for org.w3c.dom Node getAttributes
public NamedNodeMap getAttributes();
NamedNodeMap
containing the attributes of this node (if it is an Element
) or null
otherwise. From source file:org.ensembl.gti.seqstore.database.cramstore.EnaCramSubmitter.java
protected static String getElemAttrib(Document doc, String tag, String attr) { try {/*from ww w. java 2s. c o m*/ XPathExpression acc = xpath.compile("//" + tag + "[@" + attr + "]"); Node nl = (Node) acc.evaluate(doc, XPathConstants.NODE); if (nl == null) { return null; } Node attrN = nl.getAttributes().getNamedItem(attr); if (attrN == null) { return null; } else { return attrN.getTextContent(); } } catch (XPathExpressionException e) { throw new EnaSubmissionException("Could not parse submission receipt", e); } }
From source file:Main.java
private static String docNodeToXMLString(Node root) { StringBuilder result = new StringBuilder(); if (root.getNodeType() == 3) { // TEXT_NODE result.append(root.getNodeValue()); } else {//from w ww. j ava 2s .c om if (root.getNodeType() != 9) { // not DOCUMENT_NODE StringBuffer attrs = new StringBuffer(); for (int k = 0; k < root.getAttributes().getLength(); ++k) { attrs.append(" ").append(root.getAttributes().item(k).getNodeName()).append("=\"") .append(root.getAttributes().item(k).getNodeValue()).append("\" "); } result.append("<").append(root.getNodeName()).append(" ").append(attrs).append(">"); } else { result.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); } NodeList nodes = root.getChildNodes(); for (int i = 0, j = nodes.getLength(); i < j; i++) { Node node = nodes.item(i); result.append(docNodeToXMLString(node)); } if (root.getNodeType() != 9) { // not DOCUMENT_NODE result.append("</").append(root.getNodeName()).append(">"); } } return result.toString(); }
From source file:Main.java
private static String getMetaScriptType(List metaNodeList) { Node meta = null; NamedNodeMap attributes = null; boolean httpEquiv = false; String contentScriptType = null; for (int i = metaNodeList.size() - 1; i >= 0; i--) { meta = (Node) metaNodeList.get(i); attributes = meta.getAttributes(); httpEquiv = false;//from w w w . j ava 2 s. c o m contentScriptType = null; for (int j = 0; j < attributes.getLength(); j++) { if (attributes.item(j).getNodeName().equalsIgnoreCase(HTTP_EQUIV)) { httpEquiv = attributes.item(j).getNodeValue().equalsIgnoreCase(CONTENT_SCRIPT_TYPE); } else if (attributes.item(j).getNodeName().equalsIgnoreCase(CONTENT)) { contentScriptType = attributes.item(j).getNodeValue(); } } if (httpEquiv && (contentScriptType != null)) { return contentScriptType; } } return null; }
From source file:com.mingo.parser.xml.dom.DomUtil.java
/** * Transform node attributes to map.// w ww.j ava 2 s . com * * @param node {@link Node} * @return map : key - attribute name; value - attribute value */ public static Map<String, String> getAttributes(Node node) { Map<String, String> attributes = ImmutableMap.of(); if (node.hasAttributes()) { ImmutableMap.Builder builder = ImmutableMap.builder(); // get attributes names and values NamedNodeMap nodeMap = node.getAttributes(); for (int i = 0; i < nodeMap.getLength(); i++) { Node currentNode = nodeMap.item(i); builder.put(currentNode.getNodeName(), currentNode.getNodeValue()); } attributes = builder.build(); } return attributes; }
From source file:edu.ku.brc.util.thumbnails.Thumbnailer.java
/** * //from w w w . jav a 2s.co m */ private static void readIconMap() { availableIcons = new HashMap<String, String>(); fallbackIcons = new HashMap<String, String>(); File mimeTypeFile = XMLHelper.getConfigDir("mime_icons.xml"); if (mimeTypeFile.exists()) { try { Document registry = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(mimeTypeFile); NodeList mimeNodes = registry.getElementsByTagName("mimetype"); for (int i = 0; i < mimeNodes.getLength(); ++i) { Node mimeNode = mimeNodes.item(i); Node iconNameNode = mimeNode.getAttributes().getNamedItem("icon"); Node fallbackNode = mimeNode.getAttributes().getNamedItem("fallback"); String iconName = iconNameNode.getNodeValue(); String fbStr = fallbackNode != null ? fallbackNode.getNodeValue() : null; boolean isFallBack = StringUtils.isNotEmpty(fbStr) && fbStr.equals("true"); NodeList extNodes = mimeNode.getChildNodes(); for (int j = 0; j < extNodes.getLength(); ++j) { Node extNode = extNodes.item(j); String ext = extNode.getTextContent().trim(); if (StringUtils.isNotEmpty(ext)) { if (isFallBack) { fallbackIcons.put(ext, iconName); } else { availableIcons.put(ext, iconName); } } } } } catch (SAXException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (ParserConfigurationException e) { e.printStackTrace(); } } }
From source file:org.eclipse.lyo.testsuite.oslcv2.OAuthTests.java
public static Collection<Object[]> getReferencedUrls(ArrayList<Node> capabilityDOMNodesUsingXML, String base) throws IOException, XPathException, ParserConfigurationException, SAXException { //ArrayList to contain the urls from all SPCs Collection<Object[]> data = new ArrayList<Object[]>(); String requestTokenUri = ""; String authorizationUri = ""; String accessTokenUri = ""; for (Node node : capabilityDOMNodesUsingXML) { NodeList oAuthChildren = node.getChildNodes(); requestTokenUri = null;//from w w w.ja v a2 s .co m authorizationUri = null; accessTokenUri = null; for (int j = 0; j < oAuthChildren.getLength(); j++) { Node oAuthNode = oAuthChildren.item(j); if (oAuthNode.getLocalName() == null) continue; NamedNodeMap attribs = oAuthNode.getAttributes(); if (oAuthNode.getNamespaceURI().equals(OSLCConstants.OSLC_V2)) { if (oAuthNode.getLocalName().equals("oauthRequestTokenURI")) { requestTokenUri = attribs.getNamedItemNS(OSLCConstants.RDF, "resource").getNodeValue(); } else if (oAuthNode.getLocalName().equals("authorizationURI")) { authorizationUri = attribs.getNamedItemNS(OSLCConstants.RDF, "resource").getNodeValue(); } else if (oAuthNode.getLocalName().equals("oauthAccessTokenURI")) { accessTokenUri = attribs.getNamedItemNS(OSLCConstants.RDF, "resource").getNodeValue(); } } } if (requestTokenUri != null && authorizationUri != null && accessTokenUri != null) data.add(new Object[] { base, requestTokenUri, authorizationUri, accessTokenUri }); } // If service provider didn't provide OAuth parameters, see if they // were provided in test configuration parameters. if (data.isEmpty()) { requestTokenUri = setupProps.getProperty("OAuthRequestTokenUrl"); authorizationUri = setupProps.getProperty("OAuthAuthorizationUrl"); accessTokenUri = setupProps.getProperty("OAuthAccessTokenUrl"); if (requestTokenUri != null && authorizationUri != null && accessTokenUri != null) data.add(new Object[] { base, requestTokenUri, authorizationUri, accessTokenUri }); } return data; }
From source file:Main.java
private static String logXMLSubNode(Node node, int deepth) { int i;/*from w w w . j a v a 2s . com*/ String nodeStr = new String(); String interStr = new String(); for (i = 0; i < deepth; i++) interStr += "\t"; nodeStr += interStr + "<" + node.getNodeName() + internal; if (node.hasAttributes()) { NamedNodeMap attrs = node.getAttributes(); // add the attrubite name-value pairs for (i = 0; i < attrs.getLength(); i++) { Node a = attrs.item(i); nodeStr += a.getNodeName() + "=" + a.getNodeValue() + internal; } } if (node.hasChildNodes()) { nodeStr += ">\n"; NodeList ns = node.getChildNodes(); for (i = 0; i < ns.getLength(); i++) { nodeStr += logXMLSubNode(ns.item(i), deepth + 1); } nodeStr += interStr + "</" + node.getNodeName() + ">\n"; } else { if (node.getNodeValue() != null) { nodeStr += ">" + node.getNodeValue() + "<" + node.getNodeName(); } nodeStr += "/>\n"; } return nodeStr; }
From source file:com.ewcms.common.io.HtmlStringUtil.java
public static String getPureText(Node node) { if (!node.hasChildNodes() && isTextNode(node)) return node.getNodeValue(); if (isFiltered(node)) return ""; if (node.hasAttributes()) { Node a = node.getAttributes().getNamedItem("style"); if (a != null) { String style = a.getNodeValue(); Pattern p = Pattern.compile("display\\s*\\:\\s*none", 2); if (p.matcher(style).find()) return ""; }//from w w w . j a v a 2 s .co m } StringBuffer sb = new StringBuffer(); NodeList list = node.getChildNodes(); for (int i = 0; i < list.getLength(); i++) { Node child = list.item(i); String name = child.getNodeName(); sb.append(getPureText(child)); sb.append(" "); if (name.equals("TR") || name.equals("P") || name.equals("DIV")) sb.append("\n"); } return sb.toString(); }
From source file:curam.molsa.test.customfunctions.MOLSADOMReader.java
/** * Get attribute value from node, when node is not Element. * /*from w w w . jav a 2 s.co m*/ * @param node * @param name * @return * @return null */ public static String attributeValue(final Node node, final String name) { final Node att = node.getAttributes().getNamedItem(name); if (att != null) { return att.getNodeValue(); } else { return null; } }
From source file:com.jaspersoft.jasperserver.ws.xml.Unmarshaller.java
private static ListItem readResourceParameter(Node rpNode) { ListItem rp = new ListItem(); NamedNodeMap nodeAttributes = rpNode.getAttributes(); if (nodeAttributes.getNamedItem("name") != null) rp.setLabel(nodeAttributes.getNamedItem("name").getNodeValue()); if (nodeAttributes.getNamedItem("isListItem") != null) rp.setIsListItem(nodeAttributes.getNamedItem("isListItem").getNodeValue().equals("true")); rp.setValue(readPCDATA(rpNode));//from w w w .ja v a2s . co m return rp; }