use of me.vertretungsplan.objects.AdditionalInfo in project substitution-schedule-parser by vertretungsplanme.
the class WinterShParser method handleXML.
@NotNull
static AdditionalInfo handleXML(String xml) {
AdditionalInfo info = new AdditionalInfo();
info.setTitle(TITLE);
Document doc = Jsoup.parse(xml, "", Parser.xmlParser());
doc.outputSettings(new Document.OutputSettings().prettyPrint(false));
String text = doc.select("item description").first().html().replace("\r\n", "<br>").trim();
if (text.startsWith("Zurzeit gibt es keine Hinweise auf witterungsbedingten Unterrichtsausfall.")) {
info.setHasInformation(false);
}
if (text.endsWith("<br>")) {
text = text.substring(0, text.length() - 4);
}
info.setTitle(TITLE + " (Stand: " + doc.select("pubDate").first().text() + ")");
info.setText(text);
return info;
}
use of me.vertretungsplan.objects.AdditionalInfo in project substitution-schedule-parser by vertretungsplanme.
the class AmgRottweilMessagesParserTest method test.
@Test
public void test() {
String html = readResource("/amgrottweil/messages.html");
AdditionalInfo info = new AmgRottweilStudentMessagesParser().parse(html);
assertEquals("Nachrichten für Schüler", info.getTitle());
assertEquals("Kunst-Kurse KS1 und KS2 / Hageloch : Foto-Projekt findet erst am 17.3.statt !" + "(Unterricht am 10.3. fällt aus.) /Ha<br><br>USA-Austausch: Bewerbungsschluss Mi, 8.03.! " + "AJ<br><br>JtfO Fußball Mädchen WK III: Schülerinnen der Klassen 6+7, Treff Montag, 6.03., 2. gr. " + "Pause, R. 111! AJ<br><br>Mysterienspiel-AG: Mittwoch,8.März, 1.gr.Pause vor 005-Treffen zur Planung " + "-WICHTIG! / Ha<br><br>Kletter-AG fällt diese Woche aus! AJ", info.getText());
}
use of me.vertretungsplan.objects.AdditionalInfo in project substitution-schedule-parser by vertretungsplanme.
the class WinterShParserTest method testNoInfo.
@Test
public void testNoInfo() throws Exception {
String xml = readResource("/winter-sh/no-info.xml");
AdditionalInfo info = WinterShParser.handleXML(xml);
assertFalse(info.hasInformation());
assertEquals("Witterungsbedingter Unterrichtsausfall (Stand: 23.11.2015 14:15)", info.getTitle());
}
use of me.vertretungsplan.objects.AdditionalInfo in project substitution-schedule-parser by vertretungsplanme.
the class SubstitutionScheduleDiff method compare.
/**
* Constructs a {@link SubstitutionScheduleDiff} from two {@link SubstitutionSchedule}s
* @param a Old substitution schedule
* @param b New substitution schedule
* @return difference between the two schedules
*/
public static SubstitutionScheduleDiff compare(SubstitutionSchedule a, SubstitutionSchedule b) {
SubstitutionScheduleDiff diff = new SubstitutionScheduleDiff();
diff.newAdditionalInfos = new ArrayList<>();
diff.removedAdditionalInfos = new ArrayList<>();
diff.newDays = new ArrayList<>();
diff.editedDays = new ArrayList<>();
diff.removedDays = new ArrayList<>();
for (AdditionalInfo newInfo : b.getAdditionalInfos()) {
if (!a.getAdditionalInfos().contains(newInfo)) {
diff.newAdditionalInfos.add(newInfo);
}
}
for (AdditionalInfo oldInfo : a.getAdditionalInfos()) {
if (!b.getAdditionalInfos().contains(oldInfo)) {
diff.removedAdditionalInfos.add(oldInfo);
}
}
for (SubstitutionScheduleDay newDay : b.getDays()) {
SubstitutionScheduleDay oldDay = findSameDateDay(newDay, a.getDays());
if (oldDay != null) {
SubstitutionScheduleDayDiff dayDiff = SubstitutionScheduleDayDiff.compare(oldDay, newDay);
if (dayDiff.isNotEmpty())
diff.editedDays.add(dayDiff);
} else {
diff.newDays.add(newDay);
}
}
for (SubstitutionScheduleDay oldDay : a.getDays()) {
SubstitutionScheduleDay newDay = findSameDateDay(oldDay, b.getDays());
if (newDay == null) {
diff.removedDays.add(oldDay);
}
}
return diff;
}
use of me.vertretungsplan.objects.AdditionalInfo in project substitution-schedule-parser by vertretungsplanme.
the class BaseIcalParser method getAdditionalInfo.
@Override
public AdditionalInfo getAdditionalInfo() throws IOException {
AdditionalInfo info = new AdditionalInfo();
info.setTitle(getTitle());
String rawdata = httpGet(getIcalUrl(), "UTF-8");
if (shouldStripTimezoneInfo()) {
Pattern pattern = Pattern.compile("BEGIN:VTIMEZONE.*END:VTIMEZONE", Pattern.DOTALL);
rawdata = pattern.matcher(rawdata).replaceAll("");
}
DateTime now = DateTime.now().withTimeAtStartOfDay();
List<ICalendar> icals = Biweekly.parse(rawdata).all();
List<Event> events = new ArrayList<>();
for (ICalendar ical : icals) {
for (VEvent event : ical.getEvents()) {
Event item = new Event();
TimeZone timezoneStart = getTimeZoneStart(ical, event);
if (event.getDescription() != null) {
item.description = event.getDescription().getValue();
}
if (event.getSummary() != null) {
item.summary = event.getSummary().getValue();
}
if (event.getDateStart() != null) {
item.startDate = new DateTime(event.getDateStart().getValue());
item.startHasTime = event.getDateStart().getValue().hasTime();
} else {
continue;
}
if (event.getDateEnd() != null) {
item.endDate = new DateTime(event.getDateEnd().getValue());
item.endHasTime = event.getDateEnd().getValue().hasTime();
}
if (event.getLocation() != null) {
item.location = event.getLocation().getValue();
}
if (event.getUrl() != null) {
item.url = event.getUrl().getValue();
}
if (event.getRecurrenceRule() == null && item.endDate != null && (item.endDate.compareTo(now) < 0)) {
continue;
} else if (event.getRecurrenceRule() == null && (item.startDate.compareTo(now) < 0)) {
continue;
}
if (event.getRecurrenceRule() != null && event.getRecurrenceRule().getValue().getUntil() != null && event.getRecurrenceRule().getValue().getUntil().compareTo(now.toDate()) < 0) {
continue;
}
if (event.getRecurrenceRule() != null) {
Duration duration = null;
if (event.getDateEnd() != null) {
duration = new Duration(new DateTime(event.getDateStart().getValue()), new DateTime(event.getDateEnd().getValue()));
}
DateIterator iterator = event.getDateIterator(timezoneStart);
while (iterator.hasNext()) {
Date date = iterator.next();
Event reccitem = item.clone();
reccitem.startDate = new DateTime(date);
reccitem.endDate = reccitem.startDate.plus(duration);
if (item.startDate.equals(reccitem.startDate))
continue;
if (item.endDate != null && (item.endDate.compareTo(now) < 0)) {
continue;
} else if (item.endDate == null && (item.startDate.compareTo(now) < 0)) {
continue;
}
events.add(reccitem);
}
}
if (item.endDate != null && (item.endDate.compareTo(now) < 0)) {
continue;
} else if (item.endDate == null && (item.startDate.compareTo(now) < 0)) {
continue;
}
events.add(item);
}
}
Collections.sort(events, new Comparator<Event>() {
@Override
public int compare(Event o1, Event o2) {
return o1.startDate.compareTo(o2.startDate);
}
});
StringBuilder content = new StringBuilder();
int count = 0;
DateTimeFormatter fmtDt = DateTimeFormat.shortDateTime().withLocale(Locale.GERMANY);
DateTimeFormatter fmtD = DateTimeFormat.shortDate().withLocale(Locale.GERMANY);
for (Event item : events) {
if (count >= getMaxItemsCount()) {
break;
} else if (count != 0) {
content.append("<br><br>\n\n");
}
DateTime start = item.startDate;
if (item.endDate != null) {
DateTime end = item.endDate;
if (!item.endHasTime) {
end = end.minusDays(1);
}
content.append((item.startHasTime ? fmtDt : fmtD).print(start));
if (!end.equals(start)) {
content.append(" - ");
content.append((item.endHasTime ? fmtDt : fmtD).print(end));
}
} else {
content.append(fmtDt.print(start));
}
content.append("<br>\n");
content.append("<b>");
content.append(item.summary);
content.append("</b>");
count++;
}
info.setText(content.toString());
return info;
}
Aggregations