use of org.jsoup.nodes.Comment in project flow by vaadin.
the class DefaultTemplateParser method removeCommentsRecursively.
private static void removeCommentsRecursively(Node node) {
int i = 0;
while (i < node.childNodes().size()) {
Node child = node.childNode(i);
if (child instanceof Comment) {
child.remove();
} else {
removeCommentsRecursively(child);
i++;
}
}
}
use of org.jsoup.nodes.Comment in project opacclient by opacapp.
the class Bibliotheca method parseSearch.
public static SearchRequestResult parseSearch(String html, int page, JSONObject data) throws OpacErrorException {
Document doc = Jsoup.parse(html);
doc.setBaseUri(data.optString("baseurl"));
Elements table = doc.select(".resulttab tr.result_trefferX, .resulttab tr.result_treffer");
List<SearchResult> results = new ArrayList<>();
for (int i = 0; i < table.size(); i++) {
Element tr = table.get(i);
SearchResult sr = new SearchResult();
int contentindex = 1;
if (tr.select("td a img").size() > 0) {
String[] fparts = tr.select("td a img").get(0).attr("src").split("/");
String fname = fparts[fparts.length - 1];
if (data.has("mediatypes")) {
try {
sr.setType(MediaType.valueOf(data.getJSONObject("mediatypes").getString(fname)));
} catch (JSONException | IllegalArgumentException e) {
sr.setType(defaulttypes.get(fname.toLowerCase(Locale.GERMAN).replace(".jpg", "").replace(".gif", "").replace(".png", "")));
}
} else {
sr.setType(defaulttypes.get(fname.toLowerCase(Locale.GERMAN).replace(".jpg", "").replace(".gif", "").replace(".png", "")));
}
} else {
if (tr.children().size() == 3) {
contentindex = 2;
}
}
sr.setInnerhtml(tr.child(contentindex).child(0).html());
sr.setNr(i);
Element link = tr.child(contentindex).select("a").first();
try {
if (link != null && link.attr("href").contains("detmediennr")) {
Map<String, String> params = getQueryParamsFirst(link.attr("abs:href"));
String nr = params.get("detmediennr");
if (Integer.parseInt(nr) > i + 1) {
// Seems to be an ID…
if (params.get("detDB") != null) {
sr.setId("&detmediennr=" + nr + "&detDB=" + params.get("detDB"));
} else {
sr.setId("&detmediennr=" + nr);
}
}
}
} catch (Exception e) {
}
try {
if (tr.child(1).childNode(0) instanceof Comment) {
Comment c = (Comment) tr.child(1).childNode(0);
String comment = c.getData().trim();
String id = comment.split(": ")[1];
sr.setId(id);
}
} catch (Exception e) {
e.printStackTrace();
}
results.add(sr);
}
int results_total = -1;
if (doc.select(".result_gefunden").size() > 0) {
try {
results_total = Integer.parseInt(doc.select(".result_gefunden").text().trim().replaceAll(".*[^0-9]+([0-9]+).*", "$1"));
} catch (NumberFormatException e) {
e.printStackTrace();
results_total = -1;
}
} else if (doc.select(".resultzeile").size() > 0) {
throw new OpacErrorException(doc.select(".resultzeile").text());
}
return new SearchRequestResult(results, results_total, page);
}
Aggregations