Skip to content

Commit

Permalink
feat: some upgrades, vpo adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
to-kn committed Aug 14, 2024
1 parent 5960f21 commit b34f90f
Show file tree
Hide file tree
Showing 33 changed files with 164 additions and 556 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ Below you find the currently supported substitution schedule softwares and the c
* svPlan ([example](http://bls.infoboard-schleswig.de/dav/schueler1.html)) `"svplan"`
* DaVinci ([example](http://hochtaunusschule.de/Vertretungsplan/)) `"davinci"`
* ESchool ([example](http://eschool.topackt.com/?wp=d7406384445ce1fc9409bc90f95ccef5&go=vplan&content=x1)) `"eschool"`
* [LegionBoard](https://legionboard.dorfbrunnen.eu/) `"legionboard"`
* Indiware
* XML export ([example](https://francisceum.de/vertretung/mo.xml)) `"indiware"`
* XML export converted to HTML ([example](http://v-plan.gymnasium-nossen.de/v_plan_komplett/vplan_sch_html.html)) `"indiware"`
Expand Down
6 changes: 3 additions & 3 deletions parser/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ compileTestJava.options.encoding = 'UTF-8'

dependencies {
compile 'joda-time:joda-time:2.8.1'
compile 'org.jsoup:jsoup:1.9.2'
compile 'org.jsoup:jsoup:1.15.3'
compile 'org.apache.httpcomponents:fluent-hc:4.5.3'
compile 'org.apache.httpcomponents:httpmime:4.5.3'
compile 'org.json:json:20090211'
compile 'org.json:json:20231013'
compile 'org.apache.commons:commons-lang3:3.4'
compile 'org.jetbrains:annotations:13.0'
compile 'commons-io:commons-io:2.5'
compile 'commons-io:commons-io:2.7'
compile 'com.github.mifmif:generex:1.0.2'
compile 'net.sf.biweekly:biweekly:0.6.1'
compile 'com.googlecode.juniversalchardet:juniversalchardet:1.0.3'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
/**
* Parser information about cancellation of classes caused by snow or other extreme weather conditions provided as an
* RSS feed by the Ministry of Education of Schleswig-Holstein, Germany.
* Same as http://www.schleswig-holstein.de/DE/Landesregierung/III/Service/winterhotline/Winterhotline.html
* Same as <a href="http://www.schleswig-holstein.de/DE/Landesregierung/III/Service/winterhotline/Winterhotline.html">...</a>
* Can be used for all public and vocational schools in Schleswig-Holstein.
*/
public class WinterShParser extends BaseAdditionalInfoParser {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public void setClasses(Set<String> classes) {

/**
* Get the lesson which this substitution is for.
*
* <p>
* Keep it short, the recommended format is e.g. "1" for single lessons and "5-6" for multiple lessons. But some
* schools use different ways to name their lessons.
*
Expand All @@ -117,7 +117,7 @@ public String getLesson() {

/**
* Set the lesson which this substitution is for.
*
* <p>
* Keep it short, the recommended format is e.g. "1" for single lessons and "5-6" for multiple lessons. But some
* schools use different ways to name their lessons. Required.
*
Expand Down Expand Up @@ -190,7 +190,7 @@ public void setPreviousSubject(String previousSubject) {
* @return the teacher
*/
public String getTeacher() {
return teachers.size() > 0 ? SubstitutionTextUtils.joinTeachers(teachers) : null;
return !teachers.isEmpty() ? SubstitutionTextUtils.joinTeachers(teachers) : null;
}

/**
Expand Down Expand Up @@ -231,7 +231,7 @@ public void setTeachers(Set<String> teachers) {
* @return the previous teacher
*/
public String getPreviousTeacher() {
return previousTeachers.size() > 0 ? SubstitutionTextUtils.joinTeachers(previousTeachers) : null;
return !previousTeachers.isEmpty() ? SubstitutionTextUtils.joinTeachers(previousTeachers) : null;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -454,11 +454,11 @@ public String toString() {
builder.append("website: ").append(website).append("\n");

if (classes != null) {
builder.append("classes: ").append(classes.toString()).append("\n");
builder.append("classes: ").append(classes).append("\n");
}

if (teachers != null) {
builder.append("teachers: ").append(teachers.toString()).append("\n");
builder.append("teachers: ").append(teachers).append("\n");
}

builder.append("\n\n");
Expand All @@ -467,7 +467,7 @@ public String toString() {

for (SubstitutionScheduleDay day : days) builder.append(day.toString(type)).append("\n\n");

if (additionalInfos.size() > 0) {
if (!additionalInfos.isEmpty()) {
builder.append("Additional Infos\n");
builder.append("----------------\n\n");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ public String getApi() {
* <li>{@code "davinci"}</li>
* <li>{@code "turbovertretung"}</li>
* <li>{@code "csv"}</li>
* <li>{@code "legionboard"}</li>
* </ul>
*
* @param api the type of parser to use
Expand All @@ -86,7 +85,7 @@ public void setApi(String api) {
* {@link me.vertretungsplan.additionalinfo.BaseAdditionalInfoParser#getInstance(String)} to create a suitable
* parser instance.
*
* @return the set of additional info types
* @return the list of additional info types
*/
public List<String> getAdditionalInfos() {
return additionalInfos;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public interface Credential {
* This can be used to differentiate between two credentials or to allow a user to authenticate to an application
* which uses this parser. <b>It should not be used by {@link me.vertretungsplan.parser.SubstitutionScheduleParser}
* implementations, especially not if they depend on a specific hashing algorithm.</b>
*
* <p>
* For two Credential objects a and b, the following relation should apply:
* a.getHash().equals(b.getHash()) if and only if a.getLoginData().equals(b.getLoginData())
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,6 @@ public static BaseParser getInstance(SubstitutionScheduleData data, @Nullable Co
case "csv":
parser = new CSVParser(data, cookieProvider);
break;
case "legionboard":
parser = new LegionBoardParser(data, cookieProvider);
break;
case "iphis":
parser = new IphisParser(data, cookieProvider);
break;
Expand Down Expand Up @@ -248,7 +245,7 @@ private static X509TrustManager trustManagerFromKeystore(

for (final TrustManager tm : tms) {
if (tm instanceof X509TrustManager) {
return X509TrustManager.class.cast(tm);
return (X509TrustManager) tm;
}
}
throw new IllegalStateException("Could not locate X509TrustManager!");
Expand Down Expand Up @@ -577,7 +574,7 @@ public void setLocalSource(Path localSource) {
this.localSource = localSource;
}

private class CustomHostnameVerifier implements HostnameVerifier {
private static class CustomHostnameVerifier implements HostnameVerifier {
private String host;
private DefaultHostnameVerifier defaultHostnameVerifier;

Expand All @@ -596,7 +593,7 @@ public boolean isPersonal() {
return false;
}

private class NoOpDebuggingDataHandler implements DebuggingDataHandler {
private static class NoOpDebuggingDataHandler implements DebuggingDataHandler {
@Override public void columnTitles(List<String> columnTitles) {

}
Expand Down
9 changes: 4 additions & 5 deletions parser/src/main/java/me/vertretungsplan/parser/CSVParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,9 @@
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.security.GeneralSecurityException;
import java.util.*;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;

/**
Expand Down Expand Up @@ -127,7 +126,7 @@ public SubstitutionSchedule getSubstitutionSchedule() throws IOException, JSONEx
schedule.setLastChange(modified);
}
InputStream stream = client.get(new URI(httpUrl).resolve(file.getHref()).toString());
parseCSV(IOUtils.toString(stream, "UTF-8"), schedule);
parseCSV(IOUtils.toString(stream, StandardCharsets.UTF_8), schedule);
}
}
} catch (GeneralSecurityException | URISyntaxException e) {
Expand All @@ -154,7 +153,7 @@ public SubstitutionSchedule getSubstitutionSchedule() throws IOException, JSONEx
schedule.setLastChange(modified);
}
InputStream stream = client.get(new URI(httpUrl).resolve(file.getHref()).toString());
schedule = parseCSVAdditionalInfos(IOUtils.toString(stream, "UTF-8"), schedule);
schedule = parseCSVAdditionalInfos(IOUtils.toString(stream, StandardCharsets.UTF_8), schedule);
}
}
} catch (GeneralSecurityException | URISyntaxException e) {
Expand Down Expand Up @@ -208,7 +207,7 @@ SubstitutionSchedule parseCSVAdditionalInfos(String response, SubstitutionSchedu
}
j++;
}
if (info.getText() != null && !info.getText().trim().equals("")) {
if (info.getText() != null && !info.getText().trim().isEmpty()) {
Boolean isDayMessage = false;
for (SubstitutionScheduleDay day : schedule.getDays()) {
if (day.getDate().equals(ParserUtils.parseDate(info.getTitle()))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
Expand All @@ -26,7 +27,7 @@ public class ColumnTypeDetector {
public ColumnTypeDetector() throws IOException, JSONException {
columns = new HashMap<>();
InputStream is = getClass().getClassLoader().getResourceAsStream("column_headers.json");
String content = IOUtils.toString(is, "UTF-8");
String content = IOUtils.toString(is, StandardCharsets.UTF_8);
JSONObject json = new JSONObject(content);
for (Iterator it = json.keys(); it.hasNext(); ) {
String type = (String) it.next();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ static void parseDaVinciTable(Element table, SubstitutionSchedule v, String klas
for (Element header : table.select("thead tr th")) {
headers.add(header.text());
}
if (headers.size() == 0) {
if (headers.isEmpty()) {
skipRow = true;
for (Element header : table.select(" tr:first-child td")) {
headers.add(header.text());
Expand Down Expand Up @@ -321,27 +321,27 @@ public SubstitutionSchedule getSubstitutionSchedule() throws IOException, JSONEx
static List<String> getDayUrls(String url, Document doc)
throws IOException {
List<String> dayUrls = new ArrayList<>();
if (doc.select("ul.classes").size() > 0) {
if (!doc.select("ul.classes").isEmpty()) {
// List of classes
Elements classes = doc.select("ul.classes li a");
for (Element klasse : classes) {
dayUrls.add(new URL(new URL(url), klasse.attr("href")).toString());
}
} else if (doc.select("ul.month").size() > 0) {
} else if (!doc.select("ul.month").isEmpty()) {
// List of days in calendar view
Elements days = doc.select("ul.month li input[onclick]");
for (Element day : days) {
String urlFromOnclick = urlFromOnclick(day.attr("onclick"));
if (urlFromOnclick == null) continue;
dayUrls.add(new URL(new URL(url), urlFromOnclick).toString());
}
} else if (doc.select("ul.day-index").size() > 0) {
} else if (!doc.select("ul.day-index").isEmpty()) {
// List of days in list view
Elements days = doc.select("ul.day-index li a");
for (Element day : days) {
dayUrls.add(new URL(new URL(url), day.attr("href")).toString());
}
} else if (doc.select("table td[align=left] a").size() > 0) {
} else if (!doc.select("table td[align=left] a").isEmpty()) {
// Table of classes (DaVinci 5)
Elements classes = doc.select("table td[align=left] a");
for (Element klasse : classes) {
Expand Down Expand Up @@ -369,7 +369,7 @@ static void parsePage(Element doc, SubstitutionSchedule schedule, ColorProvider
SubstitutionScheduleDay day = new SubstitutionScheduleDay();

Element titleElem;
if (doc.select("h1.list-table-caption").size() > 0) {
if (!doc.select("h1.list-table-caption").isEmpty()) {
titleElem = doc.select("h1.list-table-caption").first();
} else {
// DaVinci 5
Expand Down Expand Up @@ -454,7 +454,7 @@ static void parsePage(Element doc, SubstitutionSchedule schedule, ColorProvider
}
}

if (doc.select(".list-table").size() > 0 || !doc.select(".callout").text().contains("Es liegen keine")) {
if (!doc.select(".list-table").isEmpty() || !doc.select(".callout").text().contains("Es liegen keine")) {
Element table = doc.select(".list-table, table").first();
parseDaVinciTable(table, schedule, klasse, day, colorProvider);
}
Expand All @@ -471,7 +471,7 @@ public List<String> getAllClasses() throws IOException, JSONException, Credentia
Document doc = Jsoup.parse(httpGet(scheduleData.getData().getString("classesSource"), ENCODING));
List<String> classes = new ArrayList<>();
Elements elems = doc.select("li.Class");
if (elems.size() == 0) {
if (elems.isEmpty()) {
// daVinci 5
elems = doc.select("td[align=left] a");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public SubstitutionSchedule getSubstitutionSchedule()
String url = BASE_URL + "?" + URLEncodedUtils.format(nvps, "UTF-8");

Document doc = Jsoup.parse(httpGet(url, ENCODING));
if (doc.select("form[name=loginform]").size() > 0
if (!doc.select("form[name=loginform]").isEmpty()
&& scheduleData.getAuthenticationData() instanceof PasswordAuthenticationData) {
// Login required
List<NameValuePair> formParams = new ArrayList<>();
Expand Down Expand Up @@ -150,7 +150,7 @@ private void parseTable(Element table, SubstitutionScheduleDay day) {

// skip over table headers
Element row = th.parent().nextElementSibling().nextElementSibling();
while (row != null && row.select("th").size() == 0) {
while (row != null && row.select("th").isEmpty()) {
Substitution subst = new Substitution();
subst.setLesson(lesson);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public IndiwareMobileParser(SubstitutionScheduleData scheduleData, CookieProvide
lastException = e;
}
}
if (docs.size() == 0 && lastException != null) {
if (docs.isEmpty() && lastException != null) {
throw lastException;
}

Expand Down Expand Up @@ -121,7 +121,7 @@ static SubstitutionScheduleDay parseDay(Document doc, ColorProvider colorProvide
HashSet<String> classes = new HashSet<>();
classes.add(className);
for (Element lesson:klasse.select("Pl > Std")) {
if (lesson.select("If:not(:empty), Le[LeAe], Ra[RaAe], Fa[FaAe]").size() == 0) {
if (lesson.select("If:not(:empty), Le[LeAe], Ra[RaAe], Fa[FaAe]").isEmpty()) {
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ void parseIndiwarePage(SubstitutionSchedule v, String response) throws JSONExcep
if (html && data.has(PARAM_EMBEDDED_CONTENT_SELECTOR)) {
String selector = data.getString(PARAM_EMBEDDED_CONTENT_SELECTOR);
Elements elems = doc.select(selector);
if (elems.size() == 0) throw new IOException("No elements found using " + selector);
if (elems.isEmpty()) throw new IOException("No elements found using " + selector);
for (Element elem : elems) {
v.addDay(parseIndiwareDay(elem, true));
}
Expand Down Expand Up @@ -340,7 +340,7 @@ SubstitutionScheduleDay parseIndiwareDay(Element doc, boolean html) throws IOExc
day.setLastChange(DateTimeFormat.forPattern("dd.MM.yyyy, HH:mm")
.withLocale(Locale.GERMAN).parseLocalDateTime(lastChange));

if (ds.kopfinfos().size() > 0) {
if (!ds.kopfinfos().isEmpty()) {
for (Element kopfinfo : ds.kopfinfos()) {
String title = html ? kopfinfo.select("th").text() : kopfinfoTitle(kopfinfo.tagName()) + ":";

Expand Down Expand Up @@ -420,7 +420,7 @@ SubstitutionScheduleDay parseIndiwareDay(Element doc, boolean html) throws IOExc
case "fach":
String subject = subjectAndCourse(course, value);
if (html ? columnTypes.contains("vfach") :
aktion.getElementsByTag("vfach").size() > 0) {
!aktion.getElementsByTag("vfach").isEmpty()) {
substitution.setPreviousSubject(subject);
} else {
substitution.setSubject(subject);
Expand All @@ -434,7 +434,7 @@ SubstitutionScheduleDay parseIndiwareDay(Element doc, boolean html) throws IOExc
value = bracesMatcher.group(1);
substitution.setPreviousTeachers(splitTeachers(value, splitTeachers));
} else if (html ? columnTypes.contains("vlehrer") :
aktion.getElementsByTag("vlehrer").size() > 0) {
!aktion.getElementsByTag("vlehrer").isEmpty()) {
substitution.setPreviousTeachers(splitTeachers(value, splitTeachers));
} else {
substitution.setTeachers(splitTeachers(value, splitTeachers));
Expand Down
Loading

0 comments on commit b34f90f

Please sign in to comment.