Search in sources :

Example 6 with AdditionalInfo

use of me.vertretungsplan.objects.AdditionalInfo in project substitution-schedule-parser by vertretungsplanme.

the class AmgRottweilMessagesParser method parse.

@NotNull
AdditionalInfo parse(String html) {
    Document doc = Jsoup.parse(html);
    Elements messages = doc.select("tr td:eq(1)");
    StringBuilder text = new StringBuilder();
    boolean first = true;
    for (Element message : messages) {
        if (first) {
            first = false;
        } else {
            text.append("<br><br>");
        }
        text.append(message.text());
    }
    AdditionalInfo info = new AdditionalInfo();
    info.setHasInformation(false);
    info.setTitle(getTitle());
    info.setText(text.toString());
    return info;
}
Also used : AdditionalInfo(me.vertretungsplan.objects.AdditionalInfo) Element(org.jsoup.nodes.Element) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with AdditionalInfo

use of me.vertretungsplan.objects.AdditionalInfo in project substitution-schedule-parser by vertretungsplanme.

the class BaseRSSFeedParser method parse.

@NotNull
private AdditionalInfo parse(String xml) {
    AdditionalInfo info = new AdditionalInfo();
    info.setTitle(getTitle());
    Document doc = Jsoup.parse(xml, "", Parser.xmlParser());
    StringBuilder content = new StringBuilder();
    int count = 0;
    for (Element item : doc.select("item")) {
        if (count >= MAX_ITEMS_COUNT) {
            break;
        } else if (count != 0) {
            content.append("<br><br>");
        }
        content.append("<b><a href=\"");
        content.append(item.select("link").text());
        content.append("\">");
        content.append(item.select("title").text());
        content.append("</a></b><br>");
        final String text = Jsoup.parse(item.select("description").text()).text();
        final String truncatedText = text.substring(0, Math.min(text.length(), MAX_LENGTH));
        content.append(truncatedText);
        if (truncatedText.length() < text.length())
            content.append("…");
        count++;
    }
    info.setText(content.toString());
    return info;
}
Also used : AdditionalInfo(me.vertretungsplan.objects.AdditionalInfo) Element(org.jsoup.nodes.Element) Document(org.jsoup.nodes.Document) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

AdditionalInfo (me.vertretungsplan.objects.AdditionalInfo)7 NotNull (org.jetbrains.annotations.NotNull)3 Document (org.jsoup.nodes.Document)3 BaseDemoTest (me.vertretungsplan.parser.BaseDemoTest)2 Element (org.jsoup.nodes.Element)2 Test (org.junit.Test)2 ICalendar (biweekly.ICalendar)1 VEvent (biweekly.component.VEvent)1 DateIterator (biweekly.util.com.google.ical.compat.javautil.DateIterator)1 Pattern (java.util.regex.Pattern)1 SubstitutionScheduleDay (me.vertretungsplan.objects.SubstitutionScheduleDay)1 DateTime (org.joda.time.DateTime)1 Duration (org.joda.time.Duration)1 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)1 Elements (org.jsoup.select.Elements)1