List of usage examples for org.w3c.dom Element getElementsByTagName
public NodeList getElementsByTagName(String name);
NodeList
of all descendant Elements
with a given tag name, in document order. From source file:com.persistent.cloudninja.controller.AuthFilterUtils.java
/** * Get Certificate thumb print and Issuer Name from the ACS token. * @param acsToken the acs token// w w w .j a v a2 s. com * @return returnData the Map containing Thumb print and issuer name of X509Certiificate * @throws NoSuchAlgorithmException * @throws CertificateEncodingException */ public static Map<String, String> getCertificateThumbPrintAndIssuerName(String acsToken) throws NoSuchAlgorithmException, CertificateEncodingException { byte[] acsTokenByteArray = null; Map<String, String> returnData = new HashMap<String, String>(); try { acsTokenByteArray = acsToken.getBytes("UTF-8"); } catch (UnsupportedEncodingException e) { return null; } DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); builderFactory.setNamespaceAware(true); DocumentBuilder docBuilder; String issuerName = null; StringBuffer thumbprint = null; try { docBuilder = builderFactory.newDocumentBuilder(); Document resultDoc = docBuilder.parse(new ByteArrayInputStream(acsTokenByteArray)); Element keyInfo = (Element) resultDoc.getDocumentElement() .getElementsByTagNameNS("http://www.w3.org/2000/09/xmldsig#", "KeyInfo").item(0); NodeList x509CertNodeList = keyInfo.getElementsByTagName("X509Certificate"); Element x509CertNode = (Element) x509CertNodeList.item(0); if (x509CertNode == null) { return null; } //generating Certificate to retrieve its detail. String x509CertificateData = x509CertNode.getTextContent(); InputStream inStream = new Base64InputStream(new ByteArrayInputStream(x509CertificateData.getBytes())); CertificateFactory x509CertificateFactory = CertificateFactory.getInstance("X.509"); X509Certificate x509Certificate = (X509Certificate) x509CertificateFactory .generateCertificate(inStream); String issuerDN = x509Certificate.getIssuerDN().toString(); String[] issuerDNData = issuerDN.split("="); issuerName = issuerDNData[1]; MessageDigest md = MessageDigest.getInstance("SHA-1"); byte[] der = x509Certificate.getEncoded(); md.update(der); thumbprint = new StringBuffer(); thumbprint.append(Hex.encodeHex(md.digest())); } catch (Exception e) { e.printStackTrace(); } returnData.put("IssuerName", issuerName); returnData.put("Thumbprint", thumbprint.toString().toUpperCase()); return returnData; }
From source file:com.photon.phresco.impl.DrupalApplicationProcessor.java
private static String getTagValue(String sTag, Element eElement) { String tagValue = ""; NodeList elementsByTagName = eElement.getElementsByTagName(sTag); if (elementsByTagName != null) { NodeList nlList = eElement.getElementsByTagName(sTag).item(0).getChildNodes(); if (nlList.getLength() > 0) { Node nValue = (Node) nlList.item(0); if (nValue != null) { tagValue = nValue.getNodeValue(); }// w ww.j av a2 s. c om } } return tagValue; }
From source file:edu.lternet.pasta.portal.search.BrowseGroup.java
public static BrowseGroup generateKeywordCache() { BrowseGroup controlledVocabulary = new BrowseGroup("Controlled Vocabulary"); BrowseGroup lterSiteCache = generateLterSiteCache(); controlledVocabulary.addBrowseGroup(lterSiteCache); try {/*from ww w . j av a 2s. co m*/ String topTermsXML = ControlledVocabularyClient.webServiceFetchTopTerms(); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); InputStream inputStream = IOUtils.toInputStream(topTermsXML, "UTF-8"); Document document = documentBuilder.parse(inputStream); Element documentElement = document.getDocumentElement(); NodeList documentNodeList = documentElement.getElementsByTagName("term"); for (int i = 0; i < documentNodeList.getLength(); i++) { Node documentNode = documentNodeList.item(i); NodeList childNodes = documentNode.getChildNodes(); String termId = null; String value = null; for (int j = 0; j < childNodes.getLength(); j++) { Node childNode = childNodes.item(j); if (childNode instanceof Element) { Element childElement = (Element) childNode; if (childElement.getTagName().equals("term_id")) { Text text = (Text) childElement.getFirstChild(); termId = text.getData().trim(); } else if (childElement.getTagName().equals("string")) { Text text = (Text) childElement.getFirstChild(); value = text.getData().trim(); } } } BrowseGroup topTerm = new BrowseGroup(value); controlledVocabulary.addBrowseGroup(topTerm); topTerm.setTermId(termId); topTerm.setHasMoreDown("1"); topTerm.addFetchDownElements(); } } catch (Exception e) { logger.error("Exception:\n" + e.getMessage()); e.printStackTrace(); /* * By returning null, we let callers know that there was a problem * refreshing the browse cache, so callers will know not to * overwrite the previous results. */ controlledVocabulary = null; } return controlledVocabulary; }
From source file:ching.icecreaming.action.ResourceDescriptors.java
private static String getTagValue(String tagName1, Element element1) { String tagValue1 = null;// w w w . ja va 2s . com Node node1 = null; Element element2 = null; NodeList nodeList1 = element1.getElementsByTagName(tagName1); if (nodeList1 != null && nodeList1.getLength() > 0) { node1 = nodeList1.item(0); if (node1.hasChildNodes()) { if (node1.getNodeType() == Node.ELEMENT_NODE) { element2 = (Element) node1; tagValue1 = element2.getFirstChild().getNodeValue(); } } } return tagValue1; }
From source file:com.msopentech.odatajclient.engine.data.Deserializer.java
private static XMLLinkCollection toLinkCollectionFromXML(final InputStream input) { final Element root = toDOM(input); final NodeList uris = root.getOwnerDocument().getElementsByTagName(ODataConstants.ELEM_URI); final List<URI> links = new ArrayList<URI>(); for (int i = 0; i < uris.getLength(); i++) { links.add(URI.create(uris.item(i).getTextContent())); }/* w w w . j a va 2s. co m*/ final NodeList next = root.getElementsByTagName(ODataConstants.NEXT_LINK_REL); final XMLLinkCollection linkCollection = next.getLength() > 0 ? new XMLLinkCollection(URI.create(next.item(0).getTextContent())) : new XMLLinkCollection(); linkCollection.setLinks(links); return linkCollection; }
From source file:com.moviejukebox.tools.DOMHelper.java
/** * Gets the string value from a list of tag element names passed * * @param element//from w w w. j av a 2 s . c o m * @param tagNames * @return */ public static String getValueFromElement(Element element, String... tagNames) { String returnValue = DEFAULT_RETURN; NodeList nlElement; Element tagElement; NodeList tagNodeList; for (String tagName : tagNames) { try { nlElement = element.getElementsByTagName(tagName); if (nlElement != null) { tagElement = (Element) nlElement.item(0); if (tagElement != null) { tagNodeList = tagElement.getChildNodes(); if (tagNodeList != null && tagNodeList.getLength() > 0) { returnValue = tagNodeList.item(0).getNodeValue(); } } } } catch (DOMException ex) { LOG.trace("DOM processing exception, error: {}", ex.getMessage()); } catch (NullPointerException ex) { // Shouldn't really catch null pointer exceptions, but there you go. LOG.trace("Null pointer exception, error: {}", ex.getMessage()); } } return returnValue; }
From source file:es.juntadeandalucia.panelGestion.negocio.utiles.PanelSettings.java
private static String getStringNodeValue(String nodeName, Element node) { String value = null;//from w w w .jav a2s .c o m NodeList nodeChildren = node.getElementsByTagName(nodeName); for (int i = 0; i < nodeChildren.getLength(); i++) { Node child = nodeChildren.item(i); if (child instanceof Element) { Element childElem = (Element) child; value = childElem.getTextContent(); break; } } return value; }
From source file:es.juntadeandalucia.panelGestion.negocio.utiles.PanelSettings.java
private static void readProjections(Document xmlConfiguration) { projections = new LinkedList<String>(); Element doc = xmlConfiguration.getDocumentElement(); NodeList nodesProjection = doc.getElementsByTagName("projection"); // iterate over the data base types for (int i = 0; i < nodesProjection.getLength(); i++) { // get the data base type node Node projectionNode = nodesProjection.item(i); if (projectionNode instanceof Element) { Element projectionElem = (Element) projectionNode; String projection = projectionElem.getTextContent(); projections.add(projection); }//from w w w . j a v a 2s. c om } }
From source file:es.juntadeandalucia.panelGestion.negocio.utiles.PanelSettings.java
private static void readPoolProperties(Document xmlConfiguration) { poolProperties = new HashMap<String, String>(); Element doc = xmlConfiguration.getDocumentElement(); NodeList jdbcPoolNodes = doc.getElementsByTagName("jdbc-pool"); Node jdbcPoolNode = jdbcPoolNodes.item(0); if (jdbcPoolNode != null) { NodeList poolPropertiesNodes = jdbcPoolNode.getChildNodes(); // iterate over the properties for (int i = 0; i < poolPropertiesNodes.getLength(); i++) { // get the pool property node Node poolPropertiesNode = poolPropertiesNodes.item(i); if (poolPropertiesNode instanceof Element) { Element poolPropertiesElement = (Element) poolPropertiesNode; String name = poolPropertiesElement.getLocalName(); String value = poolPropertiesElement.getTextContent(); if (!StringUtils.isEmpty(value)) { poolProperties.put(name, value); }//from w ww .j ava 2 s .c o m } } } }
From source file:es.juntadeandalucia.panelGestion.negocio.utiles.PanelSettings.java
private static void readPredefinedRepositories(Document xmlConfiguration) { predefinedRepositories = new LinkedList<Repository>(); Element doc = xmlConfiguration.getDocumentElement(); NodeList repositories = doc.getElementsByTagName("repository"); // iterate over the repositories for (int i = 0; i < repositories.getLength(); i++) { // get the repository node Node repositoryNode = repositories.item(i); if (repositoryNode instanceof Element) { Element repositoryElem = (Element) repositoryNode; // get alias and url from the repository node String repositoryAlias = getStringNodeValue("alias", repositoryElem); String repositoryUrl = getStringNodeValue("url", repositoryElem); String repositoryUser = getStringNodeValue("user", repositoryElem); String repositoryPass = getStringNodeValue("password", repositoryElem); // create a repository Repository repository = new Repository(); repository.setAlias(repositoryAlias); repository.setUrl(repositoryUrl); repository.setUser(repositoryUser); repository.setPassword(repositoryPass); predefinedRepositories.add(repository); }//from ww w .jav a2s . c o m } }