List of usage examples for org.jsoup.nodes Element text
public String text()
From source file:de.luhmer.owncloudnewsreader.reader.GoogleReaderApi.GoogleReaderMethods.java
public static ArrayList<String[]> getTagList(String _USERNAME, String _PASSWORD) { Log.d(GoogleReaderConstants.APP_NAME, "METHOD: getTagList()"); ArrayList<String[]> _TAGTITLE_ARRAYLIST = new ArrayList<String[]>(); String _TAG_LABEL = null;//from w w w . ja va2 s.co m try { _TAG_LABEL = "user/" + AuthenticationManager.getGoogleUserID(_USERNAME, _PASSWORD) + "/label/"; } catch (IOException e) { e.printStackTrace(); } Document doc = null; try { doc = Jsoup.connect(GoogleReaderConstants._TAG_LIST_URL) .header("Authorization", GoogleReaderConstants._AUTHPARAMS + AuthenticationManager.getGoogleAuthKey(_USERNAME, _PASSWORD)) .userAgent(GoogleReaderConstants.APP_NAME).timeout(6000).get(); } catch (IOException e) { e.printStackTrace(); } Elements links = doc.select("string"); for (Element link : links) { //String tagAttrib = link.attr("name"); String tagText = link.text(); if (Func_Strings.FindWordInString(tagText, _TAG_LABEL)) { _TAGTITLE_ARRAYLIST.add(new String[] { tagText.substring(32), tagText }); } } //String[] _TAGTITLE_ARRAY = new String[_TAGTITLE_ARRAYLIST.size()]; //_TAGTITLE_ARRAYLIST.toArray(_TAGTITLE_ARRAY); //return _TAGTITLE_ARRAY; return _TAGTITLE_ARRAYLIST; }
From source file:io.jari.geenstijl.API.API.java
/** * Get article and comments (note that getArticles doesn't get the comments) * * @param url The direct url to the geenstijl article * @return Artikel The fetched article//from w w w. ja va 2 s . c o m * @throws IOException * @throws ParseException */ public static Artikel getArticle(String url, Context context) throws IOException, ParseException { ensureCookies(); domain = context.getSharedPreferences("geenstijl", 0).getString("gsdomain", "www.geenstijl.nl"); Artikel artikel; Log.i(TAG, "GETARTICLE STEP 1/2: Getting/parsing article page & images... " + url); Document document = Jsoup.connect(url).get(); Element artikel_el = document.select("#content>article").first(); artikel = parseArtikel(artikel_el, context); Log.i(TAG, "GETARTICLE STEP 2/2: Parsing comments..."); ArrayList<Comment> comments = new ArrayList<Comment>(); int i = 0; Elements comments_el = document.select("#comments article"); for (Element comment_el : comments_el) { i++; Comment comment = new Comment(); comment.id = Integer.parseInt(comment_el.attr("id").substring(1)); Element footer = comment_el.select("footer").first(); StringTokenizer footer_items = new StringTokenizer(footer.text(), "|"); comment.auteur = footer_items.nextToken().trim(); try { SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd-MM-yyHH:mm", Locale.US); comment.datum = simpleDateFormat .parse(footer_items.nextToken().trim() + footer_items.nextToken().trim()); } catch (ParseException parseEx) { //fuck gebruikers met pipe chars in hun naam, pech, gehad. continue; } comment.inhoud = comment_el.select("p").first().html(); Log.d(TAG + ".perf", "CommentParser: Parsed " + comment.id + ": " + i + "/" + comments_el.size()); comments.add(comment); } Comment[] comm = new Comment[comments.size()]; comments.toArray(comm); artikel.comments = comm; Log.i(TAG, "GETARTICLE: DONE"); return artikel; }
From source file:de.luhmer.owncloudnewsreader.reader.GoogleReaderApi.GoogleReaderMethods.java
@SuppressWarnings("unused") public static ArrayList<FolderSubscribtionItem> getSubList(String _USERNAME, String _PASSWORD) throws UnsupportedEncodingException, IOException { ArrayList<FolderSubscribtionItem> _SUBTITLE_ARRAYLIST = new ArrayList<FolderSubscribtionItem>(); Document doc = Jsoup.connect(GoogleReaderConstants._SUBSCRIPTION_LIST_URL) .header("Authorization", GoogleReaderConstants._AUTHPARAMS + AuthenticationManager.getGoogleAuthKey(_USERNAME, _PASSWORD)) .userAgent(GoogleReaderConstants.APP_NAME).timeout(5000).get(); Elements objects = doc.select("object"); Element element = objects.get(0); Node childTemp = element.childNodes().get(0); List<Node> childs = childTemp.childNodes(); for (Node node : childs) { Elements links = ((Element) node).select("string"); String idFeed = null;/* w w w.j a v a 2s .c o m*/ String feedName; String parentSubscriptionName; for (Element link : links) { String tagAttrib = link.attr("name"); String tagText = link.text(); if (tagAttrib.equals("id") && idFeed == null) idFeed = tagText; else if (tagAttrib.equals("title")) feedName = tagText; else if (tagAttrib.equals("label")) parentSubscriptionName = tagText; } //String idFeed = node.attr("id"); //String name = node.attr("title"); //_SUBTITLE_ARRAYLIST.add(new FolderSubscribtionItem(feedName, -1, idFeed, parentSubscriptionName));//TODO implements this again... ? Update FolderSubscribtionItem } //String[] _SUBTITLE_ARRAY = new String[_SUBTITLE_ARRAYLIST.size()]; //_SUBTITLE_ARRAYLIST.toArray(_SUBTITLE_ARRAY); return _SUBTITLE_ARRAYLIST; }
From source file:io.apiman.tools.i18n.TemplateScanner.java
/** * Scan the given html template using jsoup and find all strings that require translation. This is * done by finding all elements with a "apiman-i18n-key" attribute. * @param file//from w w w . j a v a 2 s . c o m * @param strings * @throws IOException */ private static void scanFile(File file, TreeMap<String, String> strings) throws IOException { Document doc = Jsoup.parse(file, "UTF-8"); // First, scan for elements with the 'apiman-i18n-key' attribute. These require translating. Elements elements = doc.select("*[apiman-i18n-key]"); for (Element element : elements) { String i18nKey = element.attr("apiman-i18n-key"); boolean isNecessary = false; // Process the element text (if the element has no children) if (strings.containsKey(i18nKey)) { if (hasNoChildren(element)) { isNecessary = true; String elementVal = element.text(); if (elementVal.trim().length() > 0 && !elementVal.contains("{{")) { String currentValue = strings.get(i18nKey); if (!currentValue.equals(elementVal)) { throw new IOException("Duplicate i18n key found with different default values. Key=" + i18nKey + " Value1=" + elementVal + " Value2=" + currentValue); } } } } else { if (hasNoChildren(element)) { String elementVal = element.text(); if (elementVal.trim().length() > 0 && !elementVal.contains("{{")) { isNecessary = true; strings.put(i18nKey, elementVal); } } } // Process the translatable attributes for (String tattr : TRANSLATABLE_ATTRIBUTES) { if (element.hasAttr(tattr)) { String attrValue = element.attr(tattr); if (attrValue.contains("{{")) { continue; } String attrI18nKey = i18nKey + '.' + tattr; String currentAttrValue = strings.get(attrI18nKey); if (currentAttrValue == null) { isNecessary = true; strings.put(attrI18nKey, attrValue); } else if (!currentAttrValue.equals(attrValue)) { throw new IOException( "Duplicate i18n key found with different default values (for attribute '" + tattr + "'). Key=" + attrI18nKey + " Value1=" + attrValue + " Value2=" + currentAttrValue); } else { isNecessary = true; } } } if (!isNecessary) { throw new IOException("Detected an unnecessary apiman-i18n-key attribute in file '" + file.getName() + "' on element: " + element); } } // Next, scan all elements to see if the element *should* be marked for translation elements = doc.select("*"); for (Element element : elements) { if (element.hasAttr("apiman-i18n-key") || element.hasAttr("apiman-i18n-skip")) { continue; } if (hasNoChildren(element)) { String value = element.text(); if (value != null && value.trim().length() > 0) { if (!value.contains("{{")) { throw new IOException("Found an element in '" + file.getName() + "' that should be translated: " + element); } } } } // Next scan elements with a translatable attribute and fail if any of those elements // are missing the apiman-i18n-key attribute. for (String tattr : TRANSLATABLE_ATTRIBUTES) { elements = doc.select("*[" + tattr + "]"); for (Element element : elements) { if (element.hasAttr("apiman-i18n-key") || element.hasAttr("apiman-i18n-skip") || element.attr(tattr).contains("{{")) { continue; } else { throw new IOException("In template '" + file.getName() + "', found an element with a '" + tattr + "' attribute but missing 'apiman-i18n-key': " + element); } } } }
From source file:com.kantenkugel.discordbot.jdocparser.JDocParser.java
private static List<DocBlock> getDocBlock(String jdocBase, Element elem, ClassDocumentation reference) { if (elem != null) { String baseLink = JDocUtil.getLink(jdocBase, reference); List<DocBlock> blocks = new ArrayList<>(10); String hashLink = null;/* w w w .j a va 2s. co m*/ for (elem = elem.nextElementSibling(); elem != null; elem = elem.nextElementSibling()) { if (elem.tagName().equals("a")) { hashLink = '#' + elem.attr("name"); } else if (elem.tagName().equals("ul")) { Element tmp = elem.getElementsByTag("h4").first(); String title = JDocUtil.fixSpaces(tmp.text().trim()); String description = "", signature = ""; OrderedMap<String, List<String>> fields = new ListOrderedMap<>(); for (; tmp != null; tmp = tmp.nextElementSibling()) { if (tmp.tagName().equals("pre")) { //contains full signature signature = JDocUtil.fixSpaces(tmp.text().trim()); } else if (tmp.tagName().equals("div") && tmp.className().equals("block")) { //main block of content (description or deprecation) Element deprecationElem = tmp.getElementsByClass("deprecationComment").first(); if (deprecationElem != null) { //deprecation block fields.put("Deprecated:", Collections .singletonList(JDocUtil.formatText(deprecationElem.html(), baseLink))); } else { //description block description = JDocUtil.formatText(tmp.html(), baseLink); } } else if (tmp.tagName().equals("dl")) { //a field String fieldName = null; List<String> fieldValues = new ArrayList<>(); for (Element element : tmp.children()) { if (element.tagName().equals("dt")) { if (fieldName != null) { fields.put(fieldName, fieldValues); fieldValues = new ArrayList<>(); } fieldName = JDocUtil.fixSpaces(element.text().trim()); } else if (element.tagName().equals("dd")) { fieldValues.add(JDocUtil.formatText(element.html(), baseLink)); } } if (fieldName != null) { fields.put(fieldName, fieldValues); } } } blocks.add(new DocBlock(title, hashLink, signature, description, fields)); } } return blocks; } return null; }
From source file:me.vertretungsplan.parser.DaVinciParser.java
static void parseDaVinciTable(Element table, SubstitutionSchedule v, String klasse, SubstitutionScheduleDay day, ColorProvider colorProvider) {//from www. java 2 s . com List<String> headers = new ArrayList<>(); for (Element header : table.select("thead tr th, tr td[bgcolor=#9999FF]")) { headers.add(header.text()); } // These three variables can Set<String> classes = new HashSet<>(); String lesson = null; LocalDate currentDate = null; Pattern previousCurrentPattern = Pattern.compile("\\+([^\\s]+) \\(([^)]+)\\)"); Pattern previousPattern = Pattern.compile("\\(([^)]+)\\)"); for (Element row : table.select("tr:not(thead tr, tr:has(td[bgcolor=#9999FF]))")) { Substitution subst = new Substitution(); LocalDate substDate = null; Elements columns = row.select("td"); for (int i = 0; i < headers.size(); i++) { String value = columns.get(i).text().replace("\u00a0", ""); String header = headers.get(i); if (value.isEmpty()) { if (header.equals("Klasse")) subst.setClasses(classes); if (header.equals("Pos") || header.equals("Stunde") || header.equals("Std.")) { subst.setLesson(lesson); } if (header.equals("Art") || header.equals("Merkmal")) subst.setType("Vertretung"); if (header.equals("Datum")) substDate = currentDate; continue; } Matcher previousCurrentMatcher = previousCurrentPattern.matcher(value); Matcher previousMatcher = previousPattern.matcher(value); switch (header) { case "Klasse": String classesStr = value; if (previousMatcher.find()) { classesStr = previousMatcher.group(1); } classes = new HashSet<>(Arrays.asList(classesStr.split(", "))); subst.setClasses(classes); break; case "Pos": case "Stunde": case "Std.": lesson = value; subst.setLesson(lesson); break; case "VLehrer Krzel": case "VLehrer": case "Vertreter": case "Vertretungslehrkraft": if (!value.startsWith("*")) { subst.setTeacher(value); } else { subst.setType(value.substring(1)); } break; case "Lehrer": case "Lehrer Krzel": case "Lehrer Name": case "Lehrkraft": if (previousCurrentMatcher.find()) { subst.setTeacher(previousCurrentMatcher.group(1)); subst.setPreviousTeacher(previousCurrentMatcher.group(2)); } else if (previousMatcher.find()) { subst.setPreviousTeacher(previousMatcher.group(1)); } else { subst.setPreviousTeacher(value); } break; case "VFach": case "V Fach": subst.setSubject(value); break; case "Fach": case "Original Fach": if (previousCurrentMatcher.find()) { subst.setSubject(previousCurrentMatcher.group(1)); subst.setPreviousSubject(previousCurrentMatcher.group(2)); } else { subst.setPreviousSubject(value); } break; case "VRaum": case "V Raum": subst.setRoom(value); break; case "Raum": case "Original Raum": if (previousCurrentMatcher.find()) { subst.setRoom(previousCurrentMatcher.group(1)); subst.setPreviousRoom(previousCurrentMatcher.group(2)); } else { subst.setPreviousRoom(value); } break; case "Art": case "Merkmal": subst.setType(value); break; case "Info": case "Mitteilung": subst.setDesc(value); break; case "Datum": substDate = ParserUtils.parseDate(value); currentDate = substDate; break; } } if (klasse != null) { Set<String> fixedClasses = new HashSet<>(); fixedClasses.add(klasse); subst.setClasses(fixedClasses); } if (subst.getType() == null) { String recognizedType = null; if (subst.getDesc() != null) recognizedType = recognizeType(subst.getDesc()); subst.setType(recognizedType != null ? recognizedType : "Vertretung"); } subst.setColor(colorProvider.getColor(subst.getType())); if (substDate == null && day == null) continue; if (day == null || substDate != null && !substDate.equals(day.getDate())) { day = null; for (SubstitutionScheduleDay d : v.getDays()) { if (d.getDate().equals(substDate)) { day = d; } } if (day == null) { day = new SubstitutionScheduleDay(); day.setDate(substDate); v.addDay(day); } } day.addSubstitution(subst); } }
From source file:com.kantenkugel.discordbot.jdocparser.JDocParser.java
private static Map<String, String> getInheritedMethods(Element summaryAnchor) { Map<String, String> inherited = new HashMap<>(); if (summaryAnchor == null) return inherited; summaryAnchor = summaryAnchor.parent(); Elements inheritAnchors = summaryAnchor.select("a[name^=\"methods.inherited.from.class\"]"); for (Element inheritAnchor : inheritAnchors) { if (inheritAnchor.siblingElements().size() != 2) throw new RuntimeException("Got unexpected html while parsing inherited methods from class " + inheritAnchor.attr("name")); Element next = inheritAnchor.nextElementSibling(); if (!next.tagName().equals("h3")) throw new RuntimeException("Got unexpected html while parsing inherited methods from class " + inheritAnchor.attr("name")); Element sub = next.children().last(); if (sub == null || !sub.tagName().equals("a")) continue; String parent = sub.text().toLowerCase(); next = next.nextElementSibling(); if (!next.tagName().equals("code")) throw new RuntimeException("Got unexpected html while parsing inherited methods from class " + inheritAnchor.attr("name")); for (sub = next.children().first(); sub != null; sub = sub.nextElementSibling()) { if (sub.tagName().equals("a")) { inherited.putIfAbsent(sub.text().toLowerCase(), parent); }//w w w . j a va2 s.c om } } return inherited; }
From source file:net.sf.texprinter.utils.StringUtils.java
/** * Escapes HTML entities and tags to a TeX format. This method tries to * replace HTML code by the TeX equivalent macros. * * @param text The input text./* w w w . j a v a2 s .c o m*/ * @return A new text formatted from HTML to TeX. */ public static String escapeHTMLtoTeX(String text) { // replace bold tags String newText = text.replaceAll("<b>", "\\\\textbf{"); newText = newText.replaceAll("</b>", "}"); // replace bold tags newText = newText.replaceAll("<strong>", "\\\\textbf{"); newText = newText.replaceAll("</strong>", "}"); // replace italic tags newText = newText.replaceAll("<i>", "\\\\textit{"); newText = newText.replaceAll("</i>", "}"); // replace emphasized tags newText = newText.replaceAll("<em>", "\\\\emph{"); newText = newText.replaceAll("</em>", "}"); // replace paragraphs tags newText = newText.replaceAll("<p>", ""); newText = newText.replaceAll("</p>", "\n\n"); // replace ordered lists tags newText = newText.replaceAll("<ol>", "\\\\begin{enumerate}\n"); newText = newText.replaceAll("</ol>", "\\\\end{enumerate}\n"); // replace unordered lists tags newText = newText.replaceAll("<ul>", "\\\\begin{itemize}\n"); newText = newText.replaceAll("</ul>", "\\\\end{itemize}\n"); // replace item tags newText = newText.replaceAll("<li>", "\\\\item "); newText = newText.replaceAll("</li>", "\n"); // replace blockquote tags newText = newText.replaceAll("<blockquote>", "\\\\begin{quotation}\n"); newText = newText.replaceAll("</blockquote>", "\\\\end{quotation}\n"); // replace code tags newText = newText.replaceAll("<pre><code>", "\\\\begin{TeXPrinterListing}\n"); newText = newText.replaceAll("<pre class=.*\"><code>", "\\\\begin{TeXPrinterListing}\n"); newText = newText.replaceAll("</code></pre>", "\\\\end{TeXPrinterListing}\n\n"); // replace inline code tags newText = newText.replaceAll("<code>", "\\\\lstinline|"); newText = newText.replaceAll("</code>", "|"); // replace links tags newText = newText.replaceAll("alt=\".*\" ", ""); // parse the text Document docLinks = Jsoup.parse(newText); // get all the links Elements links = docLinks.getElementsByTag("a"); // if there are links if (links.size() > 0) { // for every link for (Element link : links) { // get the outer HTML String temp = link.outerHtml(); // replace it newText = newText.replaceFirst(Pattern.quote(temp), "\\\\href{" + link.attr("href") + "}{" + link.text() + "}"); } } // create a list of images ArrayList<ImageGroup> images = new ArrayList<ImageGroup>(); // parse the current text Document doc = Jsoup.parse(text); // fetch all the media found Elements media = doc.select("[src]"); // for all media found for (Element m : media) { // if it's an image tag if (m.tagName().equals("img")) { // create a new image group with the image link ImageGroup image = new ImageGroup(m.attr("abs:src")); // add to the list of images images.add(image); // set the current image to null image = null; } } // create a new loop saver LoopSaver lps = null; // for every image in the list of images for (ImageGroup img : images) { // create a new object lps = new LoopSaver(); // while there are references for that image in the text while (newText.indexOf(img.getURL()) != -1) { // tick loop lps.tick(); // replace the occurrence of that image newText = newText.replaceFirst("<img src=\"" + img.getURL() + "\" />", "\\\\begin{figure}[h!]\n\\\\centering\n\\\\includegraphics[scale=0.5]{" + img.getName() + "}\n\\\\end{figure}"); } // lets try try { // finally, download the image to the current directory Downloader.download(img.getURL(), img.getName()); } catch (Exception exception) { // log message log.log(Level.WARNING, "An error occurred while getting the current image. Trying to set the replacement image instead. MESSAGE: {0}", StringUtils.printStackTrace(exception)); // image could not be downloaded for any reason try { // open a file stream FileOutputStream f = new FileOutputStream(img.getName()); // write a replacement image f.write(Base64.decode( "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")); // close the file f.close(); } catch (IOException ioexception) { // log message log.log(Level.SEVERE, "An IO exception occured while trying to create the image replacement. MESSAGE: {0}", StringUtils.printStackTrace(ioexception)); } catch (Exception except) { // log message log.log(Level.SEVERE, "An error occured while trying to create the image replacement. MESSAGE: {0}", StringUtils.printStackTrace(except)); } } } // unescape all HTML entities newText = StringEscapeUtils.unescapeHtml(newText); // return new text return newText; }
From source file:com.kantenkugel.discordbot.jdocparser.JDocParser.java
static void parse(final String jdocBase, final String name, final InputStream inputStream, Map<String, ClassDocumentation> docs) { final String[] pathSplits = name.split("/"); final String fileName = pathSplits[pathSplits.length - 1]; if (!Character.isUpperCase(fileName.charAt(0))) { //ignore jdoc structure html return;//from ww w . j av a 2s. c om } final String[] nameSplits = fileName.split("\\."); final String className = nameSplits[nameSplits.length - 2]; final String fullName = fileName.substring(0, fileName.length() - nameSplits[nameSplits.length - 1].length() - 1); try (BufferedReader buffer = new BufferedReader(new InputStreamReader(inputStream))) { //create dom Document final String content = buffer.lines().collect(Collectors.joining("\n")); Document document = Jsoup.parse(content); //classDocument (classname, package, description) Element titleElem = getSingleElementByClass(document, "title"); final String classSig = JDocUtil.fixSpaces(titleElem.text()); Element packageElem = titleElem.previousElementSibling(); if (packageElem.children().size() > 1) { packageElem = packageElem.children().last(); } final String pack = JDocUtil.fixSpaces(packageElem.text()); final String link = JDocUtil.getLink(jdocBase, pack, fullName); Element descriptionElement = null; Elements descriptionCandidates = document.select(".description .block"); if (descriptionCandidates.size() > 1) { List<Element> removed = descriptionCandidates.stream().map(elem -> elem.child(0)) .filter(child -> child != null && !child.className().startsWith("deprecat")) .map(Element::parent).collect(Collectors.toList()); if (removed.size() != 1) throw new RuntimeException("Found too many description candidates"); descriptionElement = removed.get(0); } else if (descriptionCandidates.size() == 1) { descriptionElement = descriptionCandidates.get(0); } final String description = descriptionElement == null ? "" : JDocUtil.formatText(descriptionElement.html(), link); final ClassDocumentation classDoc = new ClassDocumentation(pack, fullName, classSig, description, classSig.startsWith("Enum")); //methods, fields final Element details = document.getElementsByClass("details").first(); if (details != null) { //methods Element tmp = getSingleElementByQuery(details, "a[name=\"method.detail\"]"); List<DocBlock> docBlock = getDocBlock(jdocBase, tmp, classDoc); if (docBlock != null) { for (DocBlock block : docBlock) { Set<MethodDocumentation> mdocs = classDoc.methodDocs .computeIfAbsent(block.title.toLowerCase(), key -> new HashSet<>()); mdocs.add(new MethodDocumentation(classDoc, block.signature, block.hashLink, block.description, block.fields)); } } //vars tmp = getSingleElementByQuery(details, "a[name=\"field.detail\"]"); docBlock = getDocBlock(jdocBase, tmp, classDoc); if (docBlock != null) { for (DocBlock block : docBlock) { classDoc.classValues.put(block.title.toLowerCase(), new ValueDocumentation(classDoc, block.title, block.hashLink, block.signature, block.description)); } } //enum-values tmp = getSingleElementByQuery(details, "a[name=\"enum.constant.detail\"]"); docBlock = getDocBlock(jdocBase, tmp, classDoc); if (docBlock != null) { for (DocBlock block : docBlock) { classDoc.classValues.put(block.title.toLowerCase(), new ValueDocumentation(classDoc, block.title, block.hashLink, block.signature, block.description)); } } } final Element methodSummary = getSingleElementByQuery(document, "a[name=\"method.summary\"]"); classDoc.inheritedMethods.putAll(getInheritedMethods(methodSummary)); //storing if (nameSplits.length > 2) { if (!docs.containsKey(nameSplits[0].toLowerCase())) docs.put(nameSplits[0].toLowerCase(), new ClassDocumentation(null, null, null, null, false)); ClassDocumentation parent = docs.get(nameSplits[0].toLowerCase()); for (int i = 1; i < nameSplits.length - 2; i++) { if (!parent.subClasses.containsKey(nameSplits[i].toLowerCase())) parent.subClasses.put(nameSplits[i].toLowerCase(), new ClassDocumentation(null, null, null, null, false)); parent = parent.subClasses.get(nameSplits[i].toLowerCase()); } if (parent.subClasses.containsKey(className.toLowerCase())) classDoc.subClasses.putAll(parent.subClasses.get(className.toLowerCase()).subClasses); parent.subClasses.put(className.toLowerCase(), classDoc); } if (docs.containsKey(fullName.toLowerCase())) { ClassDocumentation current = docs.get(fullName.toLowerCase()); if (current.classSig != null) throw new RuntimeException("Got a class-name conflict with classes " + classDoc.classSig + "(" + classDoc.className + ") AND " + current.classSig + "(" + current.className + ")"); classDoc.subClasses.putAll(current.subClasses); } docs.put(fullName.toLowerCase(), classDoc); } catch (final IOException | NullPointerException ex) { JDocUtil.LOG.error("Got excaption for element {}", fullName, ex); } try { inputStream.close(); } catch (final IOException e) { JDocUtil.LOG.error("Error closing inputstream", e); } }
From source file:me.vertretungsplan.parser.UntisInfoParser.java
private static List<Substitution> parseTimetableCell(Element cell, String lesson, String klasse, JSONArray cellFormat, ColorProvider colorProvider) throws JSONException { List<Substitution> substitutions = new ArrayList<>(); if (cell.text().trim().equals("")) { return substitutions; }/* w ww.ja v a 2 s. co m*/ final Elements rows = cell.select("table").first().select("tr"); int cols = rows.get(0).select("td").size(); int courseCount = cols / cellFormat.getJSONArray(0).length(); for (int course = 0; course < courseCount; course++) { Substitution s = new Substitution(); s.setLesson(lesson); final HashSet<String> classes = new HashSet<>(); classes.add(klasse); s.setClasses(classes); boolean isChange = false; for (int row = 0; row < cellFormat.length() && row < rows.size(); row++) { JSONArray rowData = cellFormat.getJSONArray(row); Element tr = rows.get(row); for (int col = 0; col < rowData.length(); col++) { if (rowData.getString(col) == null) continue; String type = rowData.getString(col); try { Element td = tr.select("td").get(col + course * cellFormat.getJSONArray(0).length()); if (td.select("font[color=#FF0000]").size() > 0) { isChange = true; } parseTimetableCellContent(s, type, td); } catch (IndexOutOfBoundsException e) { if (course == 0) throw e; } } } if (s.getSubject() == null && s.getTeacher() == null && s.getRoom() == null) { s.setType("Entfall"); } else { s.setType("Vertretung"); } s.setColor(colorProvider.getColor(s.getType())); if (isChange) { substitutions.add(s); } } return substitutions; }