List of usage examples for org.w3c.dom Node getTextContent
public String getTextContent() throws DOMException;
From source file:com.arcusys.liferay.vaadinplugin.util.ControlPanelPortletUtil.java
private static String getPomVaadinVersion(JarFile jarFile) { try {/*w ww. jav a 2s. c om*/ JarEntry pomEntry = null; // find pom.xml file in META-INF/maven and sub folders Enumeration<JarEntry> enumerator = jarFile.entries(); while (enumerator.hasMoreElements()) { JarEntry entry = enumerator.nextElement(); if (entry.getName().startsWith("META-INF/maven/") && entry.getName().endsWith("/pom.xml")) { pomEntry = entry; break; } } // read project version from pom.xml if (pomEntry != null) { Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder() .parse(jarFile.getInputStream(pomEntry)); NodeList children = document.getDocumentElement().getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node node = children.item(i + 1); if (node.getNodeName().equals("version")) { return node.getTextContent(); } } } return null; } catch (Exception exception) { return null; } }
From source file:Main.java
private static Object getElementValue(Node node) { NodeList nodes = node.getChildNodes(); int childCount = nodes.getLength(); int childElementCount = 0; for (int i = 0; i < childCount; i++) { Node child = nodes.item(i); if (child.getNodeType() == Node.ELEMENT_NODE) { childElementCount++;/* w w w .j a v a2s. co m*/ } } if (childElementCount == 0) { return node.getTextContent(); } Map<String, Object> map = new LinkedHashMap<>(childElementCount); for (int i = 0; i < childCount; i++) { Node child = nodes.item(i); if (child.getNodeType() != Node.ELEMENT_NODE) { continue; } String childName = child.getNodeName(); Object childValue = child.hasChildNodes() ? toObject(child) : null; // auto detect repeating elements if (map.containsKey(childName)) { Object temp = map.get(childName); if (temp instanceof List) { List list = (List) temp; list.add(childValue); } else { List list = new ArrayList(childCount); map.put(childName, list); list.add(temp); list.add(childValue); } } else { map.put(childName, childValue); } } return map; }
From source file:Main.java
private static Element copyNode(Document destDocument, Element dest, Element src) { NamedNodeMap namedNodeMap = src.getAttributes(); for (int i = 0; i < namedNodeMap.getLength(); i++) { Attr attr = (Attr) namedNodeMap.item(i); dest.setAttribute(attr.getName(), attr.getValue()); }/*from w w w. jav a 2 s . com*/ NodeList childNodeList = src.getChildNodes(); for (int i = 0; i < childNodeList.getLength(); i++) { Node child = childNodeList.item(i); if (child.getNodeType() == Node.TEXT_NODE) { Text text = destDocument.createTextNode(child.getTextContent()); dest.appendChild(text); } else if (child.getNodeType() == Node.ELEMENT_NODE) { Element element = destDocument.createElement(((Element) child).getTagName()); element = copyNode(destDocument, element, (Element) child); dest.appendChild(element); } } return dest; }
From source file:org.pentaho.support.cmd.CommandLineUtility.java
/** * parses web.xml file the get pentaho-solution path if installation is * manual/* w w w . j av a 2s. c o m*/ * * @param server * @param webxml * @return */ private static String getSolutionPath(String server, String webxml) { String pentahoSolPath = null; String os = System.getProperty(CMDConstant.OS).toLowerCase().substring(0, 3); DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); File xmlFile = new File(webxml); try { DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(xmlFile); NodeList paramValueList = doc.getElementsByTagName(CMDConstant.XML_PARAM_VALUE); for (int i = 0; i < paramValueList.getLength(); i++) { Node paramNode = paramValueList.item(i); if (paramNode.getTextContent().contains(CMDConstant.PENTAHO_SOL_DIR)) { if (os.equals("win")) { pentahoSolPath = paramNode.getTextContent().replace("/", "\\"); } else { pentahoSolPath = paramNode.getTextContent(); } } } } catch (Exception e) { e.printStackTrace(); } return pentahoSolPath; }
From source file:Main.java
public static List<String> getValuesFromDocumentByTagAndAttribute(Node parentNode, String tagName, String attributeName, String attributeValue) { ArrayList<String> values = new ArrayList<String>(); for (int i = 0; i < parentNode.getChildNodes().getLength(); i++) { Node childNode = parentNode.getChildNodes().item(i); if (childNode != null) { if (childNode.hasAttributes()) { for (int j = 0; j < childNode.getAttributes().getLength(); j++) { Node attribute = childNode.getAttributes().item(j); if (attribute.getNodeName().equals(attributeName) && attribute.getNodeValue().equals(attributeValue)) { values.add(childNode.getTextContent().trim()); }// ww w . jav a 2s. c o m } } if (childNode.hasChildNodes()) { values.addAll(getValuesFromDocumentByTagAndAttribute(childNode, tagName, attributeName, attributeValue)); } } } return values; }
From source file:com.wso2telco.identity.application.authentication.endpoint.util.TenantDataManager.java
private static void refreshActiveTenantDomainsList() { try {/* w ww.j a v a 2 s . co m*/ String url = "https://" + getPropertyValue(HOST) + ":" + getPropertyValue(PORT) + "/services/TenantMgtAdminService/retrieveTenants"; String xmlString = getServiceResponse(url); if (xmlString != null && !"".equals(xmlString)) { XPathFactory xpf = XPathFactory.newInstance(); XPath xpath = xpf.newXPath(); InputSource inputSource = new InputSource(new StringReader(xmlString)); String xPathExpression = "/*[local-name() = '" + RETRIEVE_TENANTS_RESPONSE + "']/*[local-name() = '" + RETURN + "']"; NodeList nodeList = (NodeList) xpath.evaluate(xPathExpression, inputSource, XPathConstants.NODESET); tenantDomainList = new ArrayList<String>(); for (int i = 0; i < nodeList.getLength(); i++) { Node node = nodeList.item(i); if (node != null && node.getNodeType() == Node.ELEMENT_NODE) { Element element = (Element) node; NodeList tenantData = element.getChildNodes(); boolean activeChecked = false; boolean domainChecked = false; boolean isActive = false; String tenantDomain = null; for (int j = 0; j < tenantData.getLength(); j++) { Node dataItem = tenantData.item(j); String localName = dataItem.getLocalName(); if (ACTIVE.equals(localName)) { activeChecked = true; if ("true".equals(dataItem.getTextContent())) { isActive = true; } } if (TENANT_DOMAIN.equals(localName)) { domainChecked = true; tenantDomain = dataItem.getTextContent(); } if (activeChecked && domainChecked) { if (isActive) { tenantDomainList.add(tenantDomain); } break; } } } } Collections.sort(tenantDomainList); } } catch (Exception e) { if (log.isDebugEnabled()) { log.debug("Retrieving Active Tenant Domains Failed. Ignore this if there are no tenants : ", e); } } }
From source file:com.vmware.o11n.plugin.powershell.model.RemotePsType.java
/** * Returns child element containing attribute 'N' maching provided name. * @param node Child nodes to be searched * @param name Search name/* ww w .j a v a2s.com*/ * @return maching element. */ private static Node getChildByNameAttr(final Node node, final String name) { ; NodeList childs = node.getChildNodes(); for (int i = 0; i < childs.getLength(); i++) { Node child = childs.item(i); if (child.getNodeType() == Node.ELEMENT_NODE) { Node nodeName = child.getAttributes().getNamedItem("N"); if (nodeName != null && nodeName.getTextContent().equals(name)) { return child; } } } return null; }
From source file:Main.java
private static Node copyNodeExceptNamespace(Document document, Node srcNode, Set<String> namespace, List<String> exceptNamespaces) { if (srcNode.getNodeType() == Node.ELEMENT_NODE) { String nodeName = srcNode.getNodeName(); nodeName = nodeName.substring(nodeName.indexOf(":") + 1); Element element = document.createElement(nodeName); for (int i = 0; i < srcNode.getAttributes().getLength(); i++) { Attr attr = (Attr) srcNode.getAttributes().item(i); String name = attr.getName(); if (name.startsWith("xmlns:")) { String suffix = name.substring(6); if (!exceptNamespaces.contains(suffix)) { namespace.add(suffix); }//from w w w . ja v a 2s .c om continue; } } for (int i = 0; i < srcNode.getAttributes().getLength(); i++) { Attr attr = (Attr) srcNode.getAttributes().item(i); String name = attr.getName(); if (name.startsWith("xmlns:")) { continue; } int semi = name.indexOf(":"); if (semi > 0) { if (namespace.contains(name.substring(0, semi))) { name = name.substring(semi + 1); } } element.setAttribute(name, attr.getValue()); } NodeList nodeList = srcNode.getChildNodes(); for (int i = 0; i < nodeList.getLength(); i++) { Node childNode = nodeList.item(i); if (childNode.getNodeType() == Node.TEXT_NODE) { element.appendChild(document.createTextNode(childNode.getTextContent())); } else if (childNode.getNodeType() == Node.ELEMENT_NODE) { Node node = copyNodeExceptNamespace(document, childNode, namespace, exceptNamespaces); element.appendChild(node); } } return element; } if (srcNode.getNodeType() == Node.TEXT_NODE) { Text text = document.createTextNode(srcNode.getTextContent()); return text; } return null; }
From source file:Main.java
public static Object xmlToBean(Node beanNode) throws ClassNotFoundException, IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException { String className = beanNode.getNodeName(); System.out.println(className); Class clazz = Class.forName(className); Object bean = clazz.newInstance(); NodeList fieldNodeList = beanNode.getChildNodes(); for (int i = 0; i < fieldNodeList.getLength(); i++) { Node fieldNode = fieldNodeList.item(i); if (fieldNode.getNodeType() == Node.ELEMENT_NODE) { String fieldName = fieldNode.getNodeName(); if (!fieldName.contains(".")) { String getName = analyzeMethodName(fieldName, "get"); String setName = analyzeMethodName(fieldName, "set"); System.out.println(setName); clazz.getMethod(setName, clazz.getMethod(getName).getReturnType()).invoke(bean, fieldNode.getTextContent()); }//from w w w.j a v a2s . c o m } } System.out.println(bean); return bean; }
From source file:eidassaml.starterkit.EidasMetadataNode.java
/** * Parse an metadata.xml//from w w w.j a v a 2s.c o m * * @param is * @return * @throws XMLParserException * @throws UnmarshallingException * @throws CertificateException * @throws IOException * @throws ErrorCodeException * @throws DOMException */ public static EidasMetadataNode Parse(InputStream is) throws XMLParserException, UnmarshallingException, CertificateException, IOException, DOMException, ErrorCodeException { EidasMetadataNode eidasMetadataService = new EidasMetadataNode(); BasicParserPool ppMgr = new BasicParserPool(); Document inCommonMDDoc = ppMgr.parse(is); Element metadataRoot = inCommonMDDoc.getDocumentElement(); UnmarshallerFactory unmarshallerFactory = Configuration.getUnmarshallerFactory(); Unmarshaller unmarshaller = unmarshallerFactory.getUnmarshaller(metadataRoot); EntityDescriptor metaData = (EntityDescriptor) unmarshaller.unmarshall(metadataRoot); eidasMetadataService.setId(metaData.getID()); eidasMetadataService.setEntityId(metaData.getEntityID()); eidasMetadataService.setValidUntil(metaData.getValidUntil().toDate()); if (metaData.getExtensions() != null) { Element extension = metaData.getExtensions().getDOM(); for (int i = 0; i < extension.getChildNodes().getLength(); i++) { Node n = extension.getChildNodes().item(i); if ("SPType".equals(n.getLocalName())) { eidasMetadataService.spType = EidasRequestSectorType.GetValueOf(n.getTextContent()); break; } } } SPSSODescriptor ssoDescriptor = metaData.getSPSSODescriptor("urn:oasis:names:tc:SAML:2.0:protocol"); ssoDescriptor.getAssertionConsumerServices().forEach(s -> { String bindString = s.getBinding(); if ("urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST".equals(bindString)) { eidasMetadataService.setPostEndpoint(s.getLocation()); } }); for (KeyDescriptor k : ssoDescriptor.getKeyDescriptors()) { if (k.getUse() == UsageType.ENCRYPTION) { eidasMetadataService.encCert = GetFirstCertFromKeyDescriptor(k); } else if (k.getUse() == UsageType.SIGNING) { eidasMetadataService.sigCert = GetFirstCertFromKeyDescriptor(k); } } return eidasMetadataService; }