List of usage examples for org.jsoup.nodes Document children
public Elements children()
From source file:com.hp.test.framework.htmparse.UpdateTestCaseDesciption.java
public static void replaceDetailsTable(String path) throws IOException { File source = new File(path); Document report = null; try {//from ww w . j ava 2 s .com report = Jsoup.parse(source, "UTF-8"); } catch (IOException e) { System.out.println("Unable to open [" + source.getAbsolutePath() + "] for parsing!"); } Elements dom = report.children(); Elements tds = report.select("table[id=tableStyle] td"); // select the tds from your table String temp_key = ""; for (Element td : tds) { // loop through them String[] temp_ar = td.toString().split("\""); String Key = temp_ar[1]; String Status = ""; if (td.toString().contains("pass.png")) { Status = "pass"; } if (td.toString().contains("fail.png")) { Status = "fail"; } if (td.toString().contains("skip.png")) { Status = "skip"; } if (TestCaseDesMap.containsKey(temp_key) && Status.length() > 1) { TestcaseStatusMap.put(temp_key, Status); temp_key = ""; } if (td.text().contains("Test Method")) { // found the one you want String TestcaseDes; if (!TestCaseDesMap.containsKey(Key)) { TestcaseDes = " --------- "; TestCaseDesMap.put(Key, TestcaseDes); temp_key = Key; } else { TestcaseDes = TestCaseDesMap.get(Key); temp_key = Key; // TestcaseStatusMap.put(Key, Status); } td.text(TestcaseDes); // Replace with your text } } Elements ths = report.select("table[id=tableStyle] th"); // select the tds from your table for (Element th : ths) { // loop through them if (th.text().contains("Method Type")) { // found the one you want th.text("TestCase Description"); } if (th.text().contains("Test Case Name")) { // found the one you want th.text("Testng Method"); } } if (!source.canWrite()) { System.out.println("Can't write this file!");//Just check if the file is writable or not } BufferedWriter bw = new BufferedWriter(new FileWriter(source)); bw.write(dom.toString()); //toString will give all the elements as a big string bw.close(); //Close to apply the changes // genarateFailureReport(new File("C:\\Users\\yanamalp\\Desktop\\Gen_jelly\\HTML_Design_Files\\CSS\\HtmlReport.html"), "c:\\"); }
From source file:org.tinymediamanager.scraper.anidb.AniDBMetadataProvider.java
@Override public MediaMetadata getTvShowMetadata(MediaScrapeOptions options) throws Exception { MediaMetadata md = new MediaMetadata(providerInfo.getId()); String id = ""; String langu = options.getLanguage().name(); // id from result if (options.getResult() != null) { id = options.getResult().getId(); }/*w w w .j av a 2s . co m*/ // do we have an id from the options? if (StringUtils.isEmpty(id)) { id = options.getId(providerInfo.getId()); } if (StringUtils.isEmpty(id)) { return md; } trackConnections(); // call API http://api.anidb.net:9001/httpapi?request=anime&client=tinymediamanager&clientver=2&protover=1&aid=4242 String url = "http://api.anidb.net:9001/httpapi?request=anime&client=tinymediamanager&clientver=2&protover=1&aid=" + id; Document doc = null; try { CachedUrl cachedUrl = new CachedUrl(url); doc = Jsoup.parse(cachedUrl.getInputStream(), "UTF-8", "", Parser.xmlParser()); } catch (Exception e) { LOGGER.error("failed to get TV show metadata: " + e.getMessage()); // clear cache CachedUrl.removeCachedFileForUrl(url); } if (doc == null || doc.children().size() == 0) { return md; } md.setId(providerInfo.getId(), id); Element anime = doc.child(0); for (Element e : anime.children()) { if ("startdate".equalsIgnoreCase(e.tagName())) { md.storeMetadata(MediaMetadata.RELEASE_DATE, e.text()); try { Date date = org.tinymediamanager.scraper.util.StrgUtils.parseDate(e.text()); md.storeMetadata(MediaMetadata.YEAR, new SimpleDateFormat("yyyy").format(date)); } catch (Exception ex) { } } if ("titles".equalsIgnoreCase(e.tagName())) { parseTitle(md, langu, e); } if ("description".equalsIgnoreCase(e.tagName())) { md.storeMetadata(MediaMetadata.PLOT, e.text()); } if ("ratings".equalsIgnoreCase(e.tagName())) { getRating(md, e); } if ("picture".equalsIgnoreCase(e.tagName())) { md.storeMetadata(MediaMetadata.POSTER_URL, IMAGE_SERVER + e.text()); } if ("characters".equalsIgnoreCase(e.tagName())) { getActors(md, e); } } // add static "Anime" genre md.addGenre(MediaGenres.ANIME); return md; }
From source file:org.tinymediamanager.scraper.anidb.AniDBMetadataProvider.java
@Override public MediaMetadata getEpisodeMetadata(MediaScrapeOptions options) throws Exception { MediaMetadata md = new MediaMetadata(providerInfo.getId()); String id = ""; String langu = options.getLanguage().name(); // id from result if (options.getResult() != null) { id = options.getResult().getId(); }/* w ww .j a va 2s . c om*/ // do we have an id from the options? if (StringUtils.isEmpty(id)) { id = options.getId(providerInfo.getId()); } if (StringUtils.isEmpty(id)) { return md; } // get episode number and season number int seasonNr = -1; int episodeNr = -1; try { seasonNr = Integer.parseInt(options.getId(MediaMetadata.SEASON_NR)); episodeNr = Integer.parseInt(options.getId(MediaMetadata.EPISODE_NR)); } catch (Exception e) { LOGGER.warn("error parsing season/episode number"); } if (seasonNr == -1 || episodeNr == -1) { return md; } trackConnections(); String url = "http://api.anidb.net:9001/httpapi?request=anime&client=tinymediamanager&clientver=2&protover=1&aid=" + id; Document doc = null; try { CachedUrl cachedUrl = new CachedUrl(url); doc = Jsoup.parse(cachedUrl.getInputStream(), "UTF-8", "", Parser.xmlParser()); } catch (Exception e) { LOGGER.error("failed to get episode metadata: " + e.getMessage()); // clear cache CachedUrl.removeCachedFileForUrl(url); } if (doc == null || doc.children().size() == 0) { return md; } md.setId(providerInfo.getId(), id); List<Episode> episodes = parseEpisodes(doc); Episode episode = null; // filter out the episode for (Episode ep : episodes) { if (ep.season == seasonNr && ep.episode == episodeNr) { episode = ep; break; } } if (episode == null) { return md; } String title = episode.titles.get(langu); if (StringUtils.isBlank(title)) { title = episode.titles.get("en"); } if (StringUtils.isBlank(title)) { title = episode.titles.get("x-jat"); } md.storeMetadata(MediaMetadata.TITLE, title); md.storeMetadata(MediaMetadata.PLOT, episode.summary); md.storeMetadata(MediaMetadata.RATING, episode.rating); md.storeMetadata(MediaMetadata.RELEASE_DATE, episode.airdate); md.storeMetadata(MediaMetadata.RUNTIME, episode.runtime); md.setId(providerInfo.getId(), episode.id); return md; }
From source file:org.tinymediamanager.scraper.anidb.AniDBMetadataProvider.java
@Override public List<MediaEpisode> getEpisodeList(MediaScrapeOptions options) throws Exception { List<MediaEpisode> episodes = new ArrayList<MediaEpisode>(); String id = ""; String langu = options.getLanguage().name(); // id from result if (options.getResult() != null) { id = options.getResult().getId(); }/* w ww . java 2 s . c om*/ // do we have an id from the options? if (StringUtils.isEmpty(id)) { id = options.getId(providerInfo.getId()); } if (StringUtils.isEmpty(id)) { return episodes; } trackConnections(); String url = "http://api.anidb.net:9001/httpapi?request=anime&client=tinymediamanager&clientver=2&protover=1&aid=" + id; Document doc = null; try { CachedUrl cachedUrl = new CachedUrl(url); doc = Jsoup.parse(cachedUrl.getInputStream(), "UTF-8", "", Parser.xmlParser()); } catch (Exception e) { LOGGER.error("error getting episode list: " + e.getMessage()); // clear cache CachedUrl.removeCachedFileForUrl(url); } if (doc == null || doc.children().size() == 0) { return episodes; } // filter out the episode for (Episode ep : parseEpisodes(doc)) { MediaEpisode episode = new MediaEpisode(getProviderInfo().getId()); episode.title = ep.titles.get(langu); episode.season = ep.season; episode.episode = ep.episode; if (StringUtils.isBlank(episode.title)) { episode.title = ep.titles.get("en"); } if (StringUtils.isBlank(episode.title)) { episode.title = ep.titles.get("x-jat"); } episode.plot = ep.summary; episode.rating = ep.rating; episode.firstAired = ep.airdate; episode.ids.put(providerInfo.getId(), ep.id); } return episodes; }