List of usage examples for org.w3c.dom Document getElementsByTagName
public NodeList getElementsByTagName(String tagname);
NodeList
of all the Elements
in document order with a given tag name and are contained in the document. From source file:org.earthtime.archivingTools.IEDACredentialsValidator.java
/** * * http://www.geochronportal.org/post_to_credentials_service.html * * @param username/*from w ww . j av a2 s .c o m*/ * @param password * @param isVerbose * @return */ public static String validateGeochronCredentials(String username, String password, boolean isVerbose) { String geochronCredentialsService = "http://www.geochron.org/credentials_service.php"; boolean valid = false; // Feb 2015 userCode is prefix for IGSN String userCode = ""; // using geochron as identifier since both are same and need backward compartibility for serialization ReduxPersistentState.getExistingPersistentState().getReduxPreferences().setGeochronUserName(username); ReduxPersistentState.getExistingPersistentState().getReduxPreferences().setGeochronPassWord(password); Document doc = HTTP_PostAndResponse(username, password, geochronCredentialsService); if (doc != null) { if (doc.getElementsByTagName("valid").getLength() > 0) { valid = doc.getElementsByTagName("valid").item(0).getTextContent().trim().equalsIgnoreCase("yes"); if (valid) { userCode = doc.getElementsByTagName("user_code").item(0).getTextContent().trim(); } } if (isVerbose) { JOptionPane.showMessageDialog(null, new String[] { valid ? "GeoChron credentials are VALID!\n" : "GeoChron credentials NOT valid!\n" }); } } else { if (isVerbose) { JOptionPane.showMessageDialog(null, new String[] { "Credentials Server " + geochronCredentialsService + " cannot be located.\n" }); } } return userCode; }
From source file:com.photon.phresco.impl.WindowsApplicationProcessor.java
private static List<Node> getItemGroup(Document doc) { NodeList projects = doc.getElementsByTagName(PROJECT); List<Node> itemGroupList = new ArrayList<Node>(); for (int i = 0; i < projects.getLength(); i++) { Element project = (Element) projects.item(i); NodeList itemGroups = project.getElementsByTagName(ITEMGROUP); for (int j = 0; j < itemGroups.getLength(); j++) { Element itemGroup = (Element) itemGroups.item(j); itemGroupList.add(itemGroup); }/*from w w w. j av a2 s . com*/ } return itemGroupList; }
From source file:com.photon.phresco.impl.WindowsApplicationProcessor.java
private static boolean referenceCheck(Document doc) { NodeList project = doc.getElementsByTagName(PROJECT); Boolean flag = false;/* ww w . ja v a2s . c om*/ for (int i = 0; i < project.getLength(); i++) { Element PROEJCT = (Element) project.item(i); NodeList ITEMGROUPs = PROEJCT.getElementsByTagName(ITEMGROUP); for (int j = 0; j < ITEMGROUPs.getLength(); j++) { Element ITEMGROUP = (Element) ITEMGROUPs.item(j); NodeList references = ITEMGROUP.getElementsByTagName(REFERENCE); for (int k = 0; k < references.getLength(); k++) { Element reference = (Element) references.item(k); if (reference.getTagName().equalsIgnoreCase(REFERENCE)) { flag = true; } else { flag = false; } } } } return flag; }
From source file:com.github.anba.es6draft.chakra.ChakraTest.java
private static Map<String, TestSetting> readSettings(Path dir) { Path settingsFile = dir.resolve("rlexe.xml"); if (Files.isRegularFile(settingsFile)) { try (Reader reader = bomReader(Files.newInputStream(settingsFile))) { Document doc = Resources.xml(reader); NodeList elements = doc.getElementsByTagName("default"); HashMap<String, TestSetting> settingMap = new HashMap<>(); for (int i = 0, length = elements.getLength(); i < length; ++i) { Element element = (Element) elements.item(i); String files = element.getElementsByTagName("files").item(0).getTextContent(); TestSetting setting = new TestSetting(); NodeList baseline = element.getElementsByTagName("baseline"); if (baseline.getLength() > 0) { setting.baseline = baseline.item(0).getTextContent(); }//from w w w. ja v a 2 s . c o m NodeList compileFlags = element.getElementsByTagName("compile-flags"); if (compileFlags.getLength() > 0) { String flags = compileFlags.item(0).getTextContent(); setting.disabled = flags.contains("-verbose") || flags.contains("-dump:") || flags.contains("-trace:") || flags.contains("-testtrace:") || flags.contains("-testTrace:"); } settingMap.putIfAbsent(files, setting); } return settingMap; } catch (IOException e) { throw new UncheckedIOException(e); } } return Collections.emptyMap(); }
From source file:com.enioka.jqm.tools.ResourceParser.java
private static void importXml() throws NamingException { InputStream is = ResourceParser.class.getClassLoader().getResourceAsStream(Helpers.resourceFile); DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); try {/* ww w . j av a 2s . c o m*/ DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(is); doc.getDocumentElement().normalize(); NodeList nList = doc.getElementsByTagName("resource"); String jndiAlias = null, resourceClass = null, description = "no description", scope = null, auth = "Container", factory = null; boolean singleton = false; for (int i = 0; i < nList.getLength(); i++) { Node n = nList.item(i); Map<String, String> otherParams = new HashMap<String, String>(); NamedNodeMap attrs = n.getAttributes(); for (int j = 0; j < attrs.getLength(); j++) { Node attr = attrs.item(j); String key = attr.getNodeName(); String value = attr.getNodeValue(); if ("name".equals(key)) { jndiAlias = value; } else if ("type".equals(key)) { resourceClass = value; } else if ("description".equals(key)) { description = value; } else if ("factory".equals(key)) { factory = value; } else if ("auth".equals(key)) { auth = value; } else if ("singleton".equals(key)) { singleton = Boolean.parseBoolean(value); } else { otherParams.put(key, value); } } if (resourceClass == null || jndiAlias == null || factory == null) { throw new NamingException("could not load the resource.xml file"); } JndiResourceDescriptor jrd = new JndiResourceDescriptor(resourceClass, description, scope, auth, factory, singleton); for (Map.Entry<String, String> prm : otherParams.entrySet()) { jrd.add(new StringRefAddr(prm.getKey(), prm.getValue())); } xml.put(jndiAlias, jrd); } } catch (Exception e) { NamingException pp = new NamingException("could not initialize the JNDI local resources"); pp.setRootCause(e); throw pp; } finally { IOUtils.closeQuietly(is); } }
From source file:resources.XmlToAnime.java
public static void ReadXml() { animes.clear();/*from w ww. jav a2 s. co m*/ if (sUrl.isEmpty() || sUrl == null) { throw new InternalError("Url should not be empty!"); } try { DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); //Document doc = (Document) dBuilder.parse(new URL(sUrl).openStream()); //Document doc = (Document) dBuilder.parse InputStream input = getInput(); if (input.available() > 0) { Document doc = (Document) dBuilder.parse(input); doc.getDocumentElement().normalize(); NodeList nList = doc.getElementsByTagName("entry"); for (int i = 0; i < nList.getLength(); i++) { Node nNode = nList.item(i); if (nNode.getNodeType() == Node.ELEMENT_NODE) { Anime anime = new Anime(); Element eElement = (Element) nNode; anime.setId(Integer.parseInt(eElement.getElementsByTagName("id").item(0).getTextContent())); anime.setTitle(eElement.getElementsByTagName("title").item(0).getTextContent()); anime.setDescription(eElement.getElementsByTagName("synopsis").item(0).getTextContent()); anime.setEpisodes(Integer .parseInt(eElement.getElementsByTagName("episodes").item(0).getTextContent())); anime.setImageUrl(eElement.getElementsByTagName("image").item(0).getTextContent()); anime.setStartDate(eElement.getElementsByTagName("start_date").item(0).getTextContent()); anime.setEndDate(eElement.getElementsByTagName("end_date").item(0).getTextContent()); String temp = eElement.getElementsByTagName("status").item(0).getTextContent(); if (temp.toLowerCase().contains("finished")) { anime.setStatus(AnimeStatus.FINISHED); } else if (temp.toLowerCase().contains("currently")) { anime.setStatus(AnimeStatus.CURRENTLY_AIRING); } anime.setAirDay(CalculateNextRelease.getAirDay(anime)); anime.setType( Anime.TYPE.valueOf(eElement.getElementsByTagName("type").item(0).getTextContent())); animes.add(anime); } } } } catch (SAXException | IOException | ParserConfigurationException e) { status = STATUS.ERROR; e.printStackTrace(); } }
From source file:de.jaetzold.philips.hue.HueBridgeComm.java
static List<HueBridge> discover() { final Logger log = Logger.getLogger(HueBridge.class.getName()); final SimpleServiceDiscovery serviceDiscovery = new SimpleServiceDiscovery(); int attempted = 0; int maxAttempts = Math.min(4, Math.max(1, HueBridge.discoveryAttempts)); Map<String, URL> foundBriges = new HashMap<>(); // if nothing is found the first time try up to maxAttempts times with increasing timeouts while (foundBriges.isEmpty() && attempted < maxAttempts) { serviceDiscovery.setSearchMx(1 + attempted); serviceDiscovery.setSocketTimeout(500 + attempted * 1500); final List<? extends SimpleServiceDiscovery.Response> responses = serviceDiscovery .discover(SimpleServiceDiscovery.SEARCH_TARGET_ROOTDEVICE); try {/*from ww w. j a v a 2s.c o m*/ for (SimpleServiceDiscovery.Response response : responses) { String urlBase = null; final String usn = response.getHeader("USN"); if (usn != null && usn.matches("uuid:[-\\w]+")) { if (!foundBriges.containsKey(usn)) { final String server = response.getHeader("SERVER"); if (server != null && server.contains("IpBridge")) { final String location = response.getHeader("LOCATION"); if (location != null && location.endsWith(".xml")) { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.parse(new URL(location).openStream()); final NodeList modelNames = doc.getElementsByTagName("modelName"); for (int i = 0; i < modelNames.getLength(); i++) { final Node item = modelNames.item(i); if (item.getParentNode().getNodeName().equals("device") && item .getTextContent().matches("(?i).*philips\\s+hue\\s+bridge.*")) { final NodeList urlBases = doc.getElementsByTagName("URLBase"); if (urlBases.getLength() > 0) { urlBase = urlBases.item(0).getTextContent(); break; } } } } } } } if (urlBase != null) { foundBriges.put(usn, new URL(urlBase)); } } } catch (Exception e) { HueBridge.lastDiscoveryException = e; log.log(Level.INFO, "Exception when dicovering devices", e); } attempted++; } List<HueBridge> result = new ArrayList<>(); for (Map.Entry<String, URL> entry : foundBriges.entrySet()) { final HueBridge bridge = new HueBridge(entry.getValue(), null); bridge.UDN = entry.getKey(); result.add(bridge); } return result; }
From source file:org.wise.vle.domain.webservice.crater.CRaterHttpClient.java
/** * Gets and Returns the Score from the CRater response XML string, * or -1 if it does not exist./*from www . ja v a 2 s .c om*/ * @param cRaterResponseXML response XML from the CRater. Looks like this: * <crater-results> * <tracking id="1013701"/> * <client id="WISETEST"/> * <items> * <item id="Photo_Sun"> * <responses> * <response id="testID" score="4" concepts="1,2,3,4,5"/> * </responses> * </item> * </items> * * @return integer score returned from the CRater. In the case above, this method will return 4. */ public static int getScore(String cRaterResponseXML) { try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db; db = dbf.newDocumentBuilder(); Document doc = db.parse(new ByteArrayInputStream(cRaterResponseXML.getBytes())); NodeList responseList = doc.getElementsByTagName("response"); Node response = responseList.item(0); String score = response.getAttributes().getNamedItem("score").getNodeValue(); return Integer.valueOf(score); } catch (ParserConfigurationException e) { e.printStackTrace(); } catch (SAXException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return -1; }
From source file:com.ibm.rpe.web.service.docgen.impl.GenerateBaseTemplate.java
private static void createTemplateXmls(String inputFile, BaseTemplateInput data) throws ParserConfigurationException, SAXException, IOException { String directory = (new File(inputFile)).getParent() + File.separator; DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = null; builder = factory.newDocumentBuilder(); Document document = builder.parse(new File(inputFile)); NodeList nlist = document.getElementsByTagName("element"); if (nlist != null && nlist.getLength() > 0) { for (int i = 0; i < nlist.getLength(); i++) { Node node = nlist.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { Element ele = (Element) node; String attr = ele.getAttribute("id"); if (attr.contentEquals(data.getElementId())) { Node newNode = document.createTextNode(data.getReplacement()); node.getParentNode().insertBefore(newNode, node); try { } catch (Exception e1) { e1.printStackTrace(); }/* w w w .ja v a 2 s .c om*/ Node removedNode = node.getParentNode().removeChild(node); // System.out.println(nodeToString(removedNode)); String removed = nodeToString(removedNode); removed = replace(removed, data.getReplaceMap()); if (data.isReplaceElementId()) { removed = replaceElementId(removed); } document.normalize(); FileUtils.writeFile(directory + data.getOutputFile(), removed); System.out.println("Removed : " + ((Element) removedNode).getAttribute("id")); try { // prettyPrint(document); } catch (Exception e) { e.printStackTrace(); } break; } } } FileUtils.writeFile(inputFile, transformToString(document)); } }
From source file:org.wise.vle.domain.webservice.crater.CRaterHttpClient.java
/** * Gets and Returns the Concepts from the CRater response XML string, * or "" if it does not exist.//from ww w. ja va2 s .co m * @param cRaterResponseXML response XML from the CRater. Looks like this: * <crater-results> * <tracking id="1013701"/> * <client id="WISETEST"/> * <items> * <item id="Photo_Sun"> * <responses> * <response id="testID" score="4" concepts="1,2,3,4,5"/> * </responses> * </item> * </items> * * @return String concepts returned from the CRater. In the case above, this method will return "1,2,3,4,5". */ public static String getConcepts(String cRaterResponseXML) { try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db; db = dbf.newDocumentBuilder(); Document doc = db.parse(new ByteArrayInputStream(cRaterResponseXML.getBytes())); NodeList responseList = doc.getElementsByTagName("response"); Node response = responseList.item(0); if (response.getAttributes().getNamedItem("concepts") != null) { return response.getAttributes().getNamedItem("concepts").getNodeValue(); } else { return ""; } } catch (ParserConfigurationException e) { e.printStackTrace(); } catch (SAXException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return ""; }