use of me.vertretungsplan.exception.CredentialInvalidException in project substitution-schedule-parser by vertretungsplanme.
the class UntisMonitorParser method loadUrl.
private void loadUrl(String url, String encoding, boolean following, List<Document> docs, String startUrl, int recursionDepth) throws IOException, CredentialInvalidException {
String html;
if (url.equals(VALUE_URL_LOGIN_RESPONSE)) {
html = loginResponse;
} else {
try {
html = httpGet(url, encoding).replace(" ", "");
} catch (HttpResponseException e) {
if (docs.size() == 0) {
throw e;
} else {
// ignore if first page was loaded and redirect didn't work
return;
}
}
}
Document doc = Jsoup.parse(html);
doc.setBaseUri(url);
if (doc.select(".mon_title").size() == 0) {
// inside a frame?
if (doc.select("frameset frame[name").size() > 0) {
for (Element frame : doc.select("frameset frame")) {
if (frame.attr("src").matches(".*subst_\\d\\d\\d.html?") && recursionDepth < MAX_RECURSION_DEPTH) {
String frameUrl = frame.absUrl("src");
loadUrl(frame.absUrl("src"), encoding, following, docs, frameUrl, recursionDepth + 1);
}
}
} else if (doc.text().contains("registriert")) {
throw new CredentialInvalidException();
} else {
if (docs.size() == 0) {
// ignore if first page was loaded and redirect didn't work
throw new IOException("Could not find .mon-title, seems like there is no Untis " + "schedule here");
}
}
} else {
findSubDocs(docs, html, doc);
if (following && doc.select("meta[http-equiv=refresh]").size() > 0) {
Element meta = doc.select("meta[http-equiv=refresh]").first();
String attr = meta.attr("content").toLowerCase();
String redirectUrl = url.substring(0, url.lastIndexOf("/") + 1) + attr.substring(attr.indexOf("url=") + 4);
if (!redirectUrl.equals(startUrl) && recursionDepth < MAX_RECURSION_DEPTH) {
loadUrl(redirectUrl, encoding, true, docs, startUrl, recursionDepth + 1);
}
}
}
}
Aggregations