use of de.geeksfactory.opacclient.objects.Volume in project opacclient by opacapp.
the class Open method parse_result.
protected DetailedItem parse_result(Document doc) {
DetailedItem item = new DetailedItem();
// Title and Subtitle
item.setTitle(doc.select("span[id$=LblShortDescriptionValue], span[id$=LblTitleValue]").text());
String subtitle = doc.select("span[id$=LblSubTitleValue]").text();
if (subtitle.equals("") && doc.select("span[id$=LblShortDescriptionValue]").size() > 0) {
// Subtitle detection for Bern
Element next = doc.select("span[id$=LblShortDescriptionValue]").first().parent().nextElementSibling();
if (next.select("span").size() == 0) {
subtitle = next.text().trim();
}
}
if (!subtitle.equals("")) {
item.addDetail(new Detail(stringProvider.getString(StringProvider.SUBTITLE), subtitle));
}
// Cover
if (doc.select("input[id$=mediumImage]").size() > 0) {
item.setCover(doc.select("input[id$=mediumImage]").attr("src"));
} else if (doc.select("img[id$=CoverView_Image]").size() > 0) {
assignBestCover(item, getCoverUrlList(doc.select("img[id$=CoverView_Image]").first()));
}
// ID
item.setId(doc.select("input[id$=regionmednr]").val());
// Description
if (doc.select("span[id$=ucCatalogueContent_LblAnnotation]").size() > 0) {
String name = doc.select("span[id$=lblCatalogueContent]").text();
String value = doc.select("span[id$=ucCatalogueContent_LblAnnotation]").text();
item.addDetail(new Detail(name, value));
}
// Parent
if (doc.select("a[id$=HyperLinkParent]").size() > 0) {
item.setCollectionId(doc.select("a[id$=HyperLinkParent]").first().attr("href"));
}
// Details
String DETAIL_SELECTOR = "div[id$=CatalogueDetailView] .spacingBottomSmall:has(span+span)," + "div[id$=CatalogueDetailView] .spacingBottomSmall:has(span+a), " + "div[id$=CatalogueDetailView] .oclc-searchmodule-detail-data div:has" + "(span+span), " + "div[id$=CatalogueDetailView] .oclc-searchmodule-detail-data div:has" + "(span+a)";
for (Element detail : doc.select(DETAIL_SELECTOR)) {
String name = detail.select("span").get(0).text().replace(": ", "");
String value = "";
if (detail.select("a").size() > 1) {
int i = 0;
for (Element a : detail.select("a")) {
if (i != 0) {
value += ", ";
}
value += a.text().trim();
i++;
}
} else {
value = detail.select("span, a").get(1).text();
if (value.contains("hier klicken") && detail.select("a").size() > 0) {
value = value + " " + detail.select("a").first().attr("href");
}
}
item.addDetail(new Detail(name, value));
}
// Description
if (doc.select("div[id$=CatalogueContent]").size() > 0) {
String name = doc.select("div[id$=CatalogueContent] .oclc-module-header").text();
String value = doc.select("div[id$=CatalogueContent] .oclc-searchmodule-detail-annotation").text();
item.addDetail(new Detail(name, value));
}
// Copies
Element table = doc.select("table[id$=grdViewMediumCopies]").first();
if (table != null) {
Elements trs = table.select("tr");
List<String> columnmap = new ArrayList<>();
for (Element th : trs.first().select("th")) {
columnmap.add(getCopyColumnKey(th.text()));
}
DateTimeFormatter fmt = DateTimeFormat.forPattern("dd.MM.yyyy").withLocale(Locale.GERMAN);
for (int i = 1; i < trs.size(); i++) {
Elements tds = trs.get(i).select("td");
Copy copy = new Copy();
for (int j = 0; j < tds.size(); j++) {
if (columnmap.get(j) == null)
continue;
String text = tds.get(j).text().replace("\u00a0", "");
if (tds.get(j).select(".oclc-module-label").size() > 0 && tds.get(j).select("span").size() == 2) {
text = tds.get(j).select("span").get(1).text();
}
if (text.equals(""))
continue;
copy.set(columnmap.get(j), text, fmt);
}
item.addCopy(copy);
}
}
// Dependent (e.g. Verden)
if (doc.select("div[id$=DivDependentCatalogue]").size() > 0) {
String url = opac_url + "/DesktopModules/OCLC.OPEN.PL.DNN.SearchModule/SearchService.asmx/GetDependantCatalogues";
JSONObject postData = new JSONObject();
// Determine portalID value
int portalId = 1;
for (Element scripttag : doc.select("script")) {
String scr = scripttag.html();
if (scr.contains("LoadCatalogueViewDependantCataloguesAsync")) {
Pattern portalIdPattern = Pattern.compile(".*LoadCatalogueViewDependantCataloguesAsync\\([^,]*,[^,]*," + "[^,]*,[^,]*,[^,]*,[^0-9,]*([0-9]+)[^0-9,]*,.*\\).*");
Matcher portalIdMatcher = portalIdPattern.matcher(scr);
if (portalIdMatcher.find()) {
portalId = Integer.parseInt(portalIdMatcher.group(1));
}
}
}
try {
postData.put("portalId", portalId).put("mednr", item.getId()).put("tabUrl", opac_url + "/" + data.getJSONObject("urls").getString("simple_search") + NO_MOBILE + "&id=").put("branchFilter", "");
RequestBody entity = RequestBody.create(MEDIA_TYPE_JSON, postData.toString());
String json = httpPost(url, entity, getDefaultEncoding());
JSONObject volumeData = new JSONObject(json);
JSONArray cat = volumeData.getJSONObject("d").getJSONArray("Catalogues");
for (int i = 0; i < cat.length(); i++) {
JSONObject obj = cat.getJSONObject(i);
Map<String, String> params = getQueryParamsFirst(obj.getString("DependantUrl"));
item.addVolume(new Volume(params.get("id"), obj.getString("DependantTitle")));
}
} catch (JSONException | IOException e) {
e.printStackTrace();
}
}
return item;
}
Aggregations