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:de.itomig.itoplib.GetItopData.java
private static ArrayList<Person> parsePersonDoc(Document doc) { // get the root elememt Element root = doc.getDocumentElement(); NodeList items = root.getElementsByTagName("Person"); persons.clear();/*www .j av a 2 s. com*/ for (int i = 0; i < items.getLength(); i++) { Node item = items.item(i); String person_id = ((Element) items.item(i)).getAttribute("id"); NodeList properties = item.getChildNodes(); String person_first = ""; String person_name = ""; String phone = ""; String org = "0"; for (int j = 0; j < properties.getLength(); j++) { Node property = properties.item(j); String name = property.getNodeName(); if (name.equalsIgnoreCase("name")) { person_name = getConcatNodeValues(property); } else if (name.equalsIgnoreCase("first_name")) { person_first = getConcatNodeValues(property); } else if (name.equalsIgnoreCase("phone")) { phone = getConcatNodeValues(property); } else if (name.equalsIgnoreCase("org_id")) { org = getConcatNodeValues(property); } } // there should ALLWAYS be an id. int id, org_id; try { id = Integer.parseInt(person_id); org_id = Integer.parseInt(org); persons.add(new Person(id, person_first + " " + person_name, phone, org_id)); } catch (NumberFormatException e) { // should never happen Log.e("TAG", "id of person not parseable"); } } return persons; }
From source file:de.itomig.itoplib.GetItopData.java
private static ArrayList<ItopTicket> parseTicketDoc(Document doc) { // assemble new ArrayList of tickets. tickets.clear();//w ww . j av a2s.c o m Element root = doc.getDocumentElement(); // look for UserRequest NodeList items = root.getElementsByTagName("UserRequest"); for (int i = 0; i < items.getLength(); i++) { tickets.add(parseTicketNode("UserRequest", items.item(i))); } // look for Incident items = root.getElementsByTagName("Incident"); for (int i = 0; i < items.getLength(); i++) { tickets.add(parseTicketNode("Incident", items.item(i))); } return tickets; // UserRequests and Incidents }
From source file:de.akra.idocit.wsdl.services.DocumentationParser.java
/** * Searches for the first documentation element in <code>docElems</code> with docpart * elements as children.//w ww.java 2 s . c o m * * @param docElems * List of documentation {@link Element}s. * @return The first documentation {@link Element} with docpart elements as children. * If no element was found, <code>null</code> is returned. */ public static Element findElementWithName(List<Element> docElems, String elementName) { if (docElems != null && !docElems.isEmpty()) { // search for the first <documentation> element with <docpart> // elements boolean bFoundDocParts = false; Iterator<Element> it = docElems.iterator(); while (it.hasNext() && !bFoundDocParts) { Element docElem = it.next(); NodeList docParts = docElem.getElementsByTagName(elementName); if (docParts.getLength() > 0) { logger.log(Level.FINE, "Number of <docpart> elements = " + docParts.getLength()); return docElem; } } } return null; }
From source file:com.wallellen.wechat.common.util.crypto.WxCryptUtil.java
static String extractEncryptPart(String xml) { try {// w w w. j a v a2s . c o m DocumentBuilder db = builderLocal.get(); Document document = db.parse(new InputSource(new StringReader(xml))); Element root = document.getDocumentElement(); return root.getElementsByTagName("Encrypt").item(0).getTextContent(); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:com.codebutler.farebot.card.felica.FelicaCard.java
public static FelicaCard fromXml(byte[] tagId, Date scannedAt, Element element) { Element systemsElement = (Element) element.getElementsByTagName("systems").item(0); NodeList systemElements = systemsElement.getElementsByTagName("system"); FeliCaLib.IDm idm = new FeliCaLib.IDm( Base64.decode(element.getElementsByTagName("idm").item(0).getTextContent(), Base64.DEFAULT)); FeliCaLib.PMm pmm = new FeliCaLib.PMm( Base64.decode(element.getElementsByTagName("pmm").item(0).getTextContent(), Base64.DEFAULT)); FelicaSystem[] systems = new FelicaSystem[systemElements.getLength()]; for (int x = 0; x < systemElements.getLength(); x++) { Element systemElement = (Element) systemElements.item(x); int systemCode = Integer.parseInt(systemElement.getAttribute("code")); Element servicesElement = (Element) systemElement.getElementsByTagName("services").item(0); NodeList serviceElements = servicesElement.getElementsByTagName("service"); FelicaService[] services = new FelicaService[serviceElements.getLength()]; for (int y = 0; y < serviceElements.getLength(); y++) { Element serviceElement = (Element) serviceElements.item(y); int serviceCode = Integer.parseInt(serviceElement.getAttribute("code")); Element blocksElement = (Element) serviceElement.getElementsByTagName("blocks").item(0); NodeList blockElements = blocksElement.getElementsByTagName("block"); FelicaBlock[] blocks = new FelicaBlock[blockElements.getLength()]; for (int z = 0; z < blockElements.getLength(); z++) { Element blockElement = (Element) blockElements.item(z); byte address = Byte.parseByte(blockElement.getAttribute("address")); byte[] data = Base64.decode(blockElement.getTextContent(), Base64.DEFAULT); blocks[z] = new FelicaBlock(address, data); }// w w w.jav a 2 s .co m services[y] = new FelicaService(serviceCode, blocks); } systems[x] = new FelicaSystem(systemCode, services); } return new FelicaCard(tagId, scannedAt, idm, pmm, systems); }
From source file:Main.java
public static Map<String, Element> getMBeanAttributes(Document document, String mbeanCode) { Map<String, Element> attrs = new HashMap<String, Element>(); NodeList nlist = document.getElementsByTagName("mbean"); Element beanNode = null; for (int i = 0; i < nlist.getLength(); i++) { Element elem = (Element) nlist.item(i); String attr = elem.getAttribute("code"); if (mbeanCode.equals(attr)) { beanNode = elem;/* w ww .j av a 2 s.com*/ break; } } if (beanNode != null) { nlist = beanNode.getElementsByTagName("attribute"); for (int i = 0; i < nlist.getLength(); i++) { Element attrElem = (Element) nlist.item(i); String attrName = attrElem.getAttribute("name"); attrs.put(attrName, attrElem); } } return attrs; }
From source file:de.codesourcery.utils.xml.XmlHelper.java
public static Element getElement(Element parent, String tagName, boolean isRequired) throws ParseException { NodeList list = parent.getElementsByTagName(tagName); if (list.getLength() == 0) { if (isRequired) { log.error("getElement(): XML is lacking required tag <" + tagName + ">"); throw new ParseException("XML is lacking required tag <" + tagName + ">", -1); }//from w w w . j a va 2 s . c om return null; } if (list.getLength() > 1) { log.error("getElement(): XML is contains multiple <" + tagName + "> tags, expected only one"); throw new ParseException("XML is contains multiple <" + tagName + "> tags, expected only one", -1); } Node n = list.item(0); if (!(n instanceof Element)) { log.error("getElement(): Internal error, expected Element but got Node"); throw new ParseException("Internal error, expected Element but got Node", -1); } return (Element) n; }
From source file:eu.eidas.configuration.ConfigurationReader.java
/** * Generate parameters./*www . j a v a 2 s . c om*/ * * @param configurationNode the configuration node * * @return the map< string, string> */ private static Map<String, String> generateParam(final Element configurationNode) { final Map<String, String> parameters = new HashMap<String, String>(); final NodeList parameterNodes = configurationNode.getElementsByTagName(NODE_PARAMETER); String parameterName; String parameterValue; for (int k = 0; k < parameterNodes.getLength(); ++k) { // for every parameter find, process. final Element parameterNode = (Element) parameterNodes.item(k); parameterName = parameterNode.getAttribute(NODE_PARAM_NAME); parameterValue = parameterNode.getAttribute(NODE_PARAM_VALUE); // verified the content. if (StringUtils.isBlank(parameterName) || StringUtils.isBlank(parameterValue)) { throw new EIDASSAMLEngineRuntimeException("Error reader parameters (name - value)."); } else { parameters.put(parameterName.trim(), parameterValue.trim()); } } return parameters; }
From source file:com.concursive.connect.web.modules.admin.utils.AdminPortalUtils.java
public static DashboardPage retrieveDashboardPage(AdminPortalBean portalBean) throws Exception { // Use the admin-portal-config.xml to determine the dashboard page to use for the current url URL resource = AdminPortalUtils.class.getResource("/portal/admin-portal-config.xml"); LOG.debug("portal config file: " + resource.toString()); XMLUtils library = new XMLUtils(resource); // The nodes are listed under the <module> tag Element portal = XMLUtils.getFirstChild(library.getDocumentElement(), "portal", "type", "controller"); String moduleLayout = null;/*from w w w . j a v a2 s . c o m*/ String page = null; // Look through the modules NodeList moduleNodeList = portal.getElementsByTagName("module"); for (int i = 0; i < moduleNodeList.getLength(); i++) { Node thisModule = moduleNodeList.item(i); NodeList urlNodeList = ((Element) thisModule).getElementsByTagName("url"); for (int j = 0; j < urlNodeList.getLength(); j++) { Element urlElement = (Element) urlNodeList.item(j); // Construct a AdminPortalURL and add to the list for retrieving String name = urlElement.getAttribute("name"); // <url name="/show" object="/" page="default"/> if (name.equals("/" + portalBean.getAction())) { String object = urlElement.getAttribute("object"); if (object.equals("/" + portalBean.getDomainObject())) { // Set the module for tab highlighting portalBean.setModule(((Element) thisModule).getAttribute("name")); // Set the page for looking up page = urlElement.getAttribute("page"); // Set the layout filename to find the referenced page moduleLayout = ((Element) thisModule).getAttribute("layout"); break; } } } } URL moduleResource = AdminPortalUtils.class.getResource("/portal/" + moduleLayout); LOG.debug("module config file: " + moduleResource.toString()); XMLUtils module = new XMLUtils(moduleResource); Element moduleElement = XMLUtils.getFirstChild(module.getDocumentElement(), "controller"); NodeList pageNodeList = moduleElement.getElementsByTagName("page"); if (pageNodeList.getLength() == 0) { LOG.warn("No pages found in moduleLayout: " + moduleLayout); } for (int j = 0; j < pageNodeList.getLength(); j++) { Node thisPage = pageNodeList.item(j); String pageName = ((Element) thisPage).getAttribute("name"); if (pageName.equals(page)) { LOG.debug("Found page " + pageName); // Find a portal template to use LOG.debug("Trying a specific portal: " + page); DashboardPage dashboardPage = DashboardUtils.loadDashboardPage( DashboardTemplateList.TYPE_CONTROLLER, (portalBean.isPopup() ? page + "-popup" : page), moduleLayout); if (dashboardPage == null) { LOG.warn("Page not found: " + page); return null; } return dashboardPage; } } return null; }
From source file:com.mirth.connect.server.launcher.MirthLauncher.java
private static void addExtensionsToClasspath(List<URL> urls, String currentVersion) throws Exception { FileFilter extensionFileFilter = new NameFileFilter( new String[] { "plugin.xml", "source.xml", "destination.xml" }, IOCase.INSENSITIVE); FileFilter directoryFilter = FileFilterUtils.directoryFileFilter(); File extensionPath = new File(EXTENSIONS_DIR); Properties extensionProperties = new Properties(); File extensionPropertiesFile = new File(appDataDir, EXTENSION_PROPERTIES); /*/*w ww. j a va2s. com*/ * If the file does not exist yet, an empty Properties object will be used, returning the * default of true for all extensions. */ if (extensionPropertiesFile.exists()) { extensionProperties.load(new FileInputStream(extensionPropertiesFile)); } if (extensionPath.exists() && extensionPath.isDirectory()) { File[] directories = extensionPath.listFiles(directoryFilter); for (File directory : directories) { File[] extensionFiles = directory.listFiles(extensionFileFilter); for (File extensionFile : extensionFiles) { try { Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder() .parse(extensionFile); Element rootElement = document.getDocumentElement(); boolean enabled = extensionProperties .getProperty(rootElement.getElementsByTagName("name").item(0).getTextContent(), "true") .equalsIgnoreCase("true"); boolean compatible = isExtensionCompatible( rootElement.getElementsByTagName("mirthVersion").item(0).getTextContent(), currentVersion); // Only add libraries from extensions that are not disabled and are compatible with the current version if (enabled && compatible) { NodeList libraries = rootElement.getElementsByTagName("library"); for (int i = 0; i < libraries.getLength(); i++) { Element libraryElement = (Element) libraries.item(i); String type = libraryElement.getAttribute("type"); if (type.equalsIgnoreCase("server") || type.equalsIgnoreCase("shared")) { File pathFile = new File(directory, libraryElement.getAttribute("path")); if (pathFile.exists()) { logger.trace("adding library to classpath: " + pathFile.getAbsolutePath()); urls.add(pathFile.toURI().toURL()); } else { logger.error("could not locate library: " + pathFile.getAbsolutePath()); } } } } } catch (Exception e) { logger.error("failed to parse extension metadata: " + extensionFile.getAbsolutePath(), e); } } } } else { logger.warn("no extensions found"); } }