use of de.geeksfactory.opacclient.objects.Detail in project opacclient by opacapp.
the class TouchPoint method parse_result.
protected DetailedItem parse_result(String html) throws IOException {
Document doc = Jsoup.parse(html);
doc.setBaseUri(opac_url);
DetailedItem result = new DetailedItem();
result.setCover(findCoverUrl(doc, false));
if (doc.select("#permalink-link").size() > 0) {
String href = doc.select("#permalink-link").first().attr("href");
JSONObject id = new JSONObject();
try {
id.put("url", href);
result.setId(id.toString());
} catch (JSONException e) {
e.printStackTrace();
}
}
for (Element tr : doc.select(".titleinfo tr")) {
// Sometimes there is one th and one td, sometimes two tds
String detailName = tr.select("th, td").first().text().trim();
if (detailName.endsWith(":")) {
detailName = detailName.substring(0, detailName.length() - 1);
}
String detailValue = tr.select("td").last().text().trim();
result.addDetail(new Detail(detailName, detailValue));
if (detailName.contains("ID in diesem Katalog") && result.getId() == null) {
result.setId(detailValue);
}
if (detailName.equals("Titel")) {
result.setTitle(detailValue);
}
}
if (result.getDetails().size() == 0 && doc.select("#details").size() > 0) {
// e.g. Bayreuth_Uni
String dname = "";
String dval = "";
boolean in_value = true;
for (Node n : doc.select("#details").first().childNodes()) {
if (n instanceof Element && ((Element) n).tagName().equals("strong")) {
if (in_value) {
if (dname.length() > 0 && dval.length() > 0) {
result.addDetail(new Detail(dname, dval));
if (dname.equals("Titel")) {
result.setTitle(dval);
}
}
dname = ((Element) n).text();
in_value = false;
} else {
dname += ((Element) n).text();
}
} else {
String t = null;
if (n instanceof TextNode) {
t = ((TextNode) n).text();
} else if (n instanceof Element) {
t = ((Element) n).text();
}
if (t != null) {
if (in_value) {
dval += t;
} else {
in_value = true;
dval = t;
}
}
}
}
}
if (result.getTitle() == null) {
result.setTitle(doc.select("h1").first().text());
}
// Copies
String copiesParameter = doc.select("div[id^=ajax_holdings_url").attr("ajaxParameter").replace("&", "");
if (!"".equals(copiesParameter)) {
String copiesHtml = httpGet(opac_url + "/" + copiesParameter, ENCODING);
Document copiesDoc = Jsoup.parse(copiesHtml);
List<String> table_keys = new ArrayList<>();
for (Element th : copiesDoc.select(".data tr th")) {
if (th.text().contains("Zweigstelle")) {
table_keys.add("branch");
} else if (th.text().contains("Status")) {
table_keys.add("status");
} else if (th.text().contains("Signatur")) {
table_keys.add("signature");
} else {
table_keys.add(null);
}
}
for (Element tr : copiesDoc.select(".data tr:has(td)")) {
Copy copy = new Copy();
int i = 0;
for (Element td : tr.select("td")) {
if (table_keys.get(i) != null) {
copy.set(table_keys.get(i), td.text().trim());
}
i++;
}
result.addCopy(copy);
}
}
// Reservation Info, only works if the code above could find a URL
if (!"".equals(copiesParameter)) {
String reservationParameter = copiesParameter.replace("showHoldings", "showDocument");
try {
String reservationHtml = httpGet(opac_url + "/" + reservationParameter, ENCODING);
Document reservationDoc = Jsoup.parse(reservationHtml);
reservationDoc.setBaseUri(opac_url);
if (reservationDoc.select("a[href*=requestItem.do]").size() == 1) {
result.setReservable(true);
result.setReservation_info(reservationDoc.select("a").first().attr("abs:href"));
}
} catch (Exception e) {
e.printStackTrace();
// fail silently
}
}
try {
Element isvolume = null;
Map<String, String> volume = new HashMap<>();
Elements links = doc.select(".data td a");
int elcount = links.size();
for (int eli = 0; eli < elcount; eli++) {
List<NameValuePair> anyurl = URLEncodedUtils.parse(new URI(links.get(eli).attr("href")), "UTF-8");
for (NameValuePair nv : anyurl) {
if (nv.getName().equals("methodToCall") && nv.getValue().equals("volumeSearch")) {
isvolume = links.get(eli);
} else if (nv.getName().equals("catKey")) {
volume.put("catKey", nv.getValue());
} else if (nv.getName().equals("dbIdentifier")) {
volume.put("dbIdentifier", nv.getValue());
}
}
if (isvolume != null) {
volume.put("volume", "true");
result.setVolumesearch(volume);
break;
}
}
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
use of de.geeksfactory.opacclient.objects.Detail in project opacclient by opacapp.
the class VuFind method parseDetail.
static DetailedItem parseDetail(String id, Document doc, JSONObject data) throws OpacErrorException, JSONException {
if (doc.select("p.error, p.errorMsg, .alert-error").size() > 0) {
throw new OpacErrorException(doc.select("p.error, p.errorMsg, .alert-error").text());
}
DetailedItem res = new DetailedItem();
res.setId(id);
Elements title = doc.select(".record h1, .record [itemprop=name], .record [property=name]");
if (title.size() > 0) {
res.setTitle(title.first().text());
}
for (Element img : doc.select(".record img, #cover img")) {
String src = img.absUrl("src");
if (src.contains("over")) {
if (!src.contains("Unavailable")) {
res.setCover(src);
}
break;
}
}
String head = null;
StringBuilder value = new StringBuilder();
for (Element tr : doc.select(".record table").first().select("tr")) {
if (tr.children().size() == 1) {
if (tr.child(0).tagName().equals("th")) {
if (head != null) {
res.addDetail(new Detail(head, value.toString()));
value = new StringBuilder();
}
head = tr.child(0).text();
} else {
if (!value.toString().equals(""))
value.append("\n");
value.append(tr.child(0).text());
}
} else {
String text = tr.child(1).text();
if (tr.child(1).select("a").size() > 0) {
String href = tr.child(1).select("a").attr("href");
if (!href.startsWith("/") && !text.contains(data.getString("baseurl"))) {
text += " " + href;
}
}
res.addDetail(new Detail(tr.child(0).text(), text));
}
}
if (head != null)
res.addDetail(new Detail(head, value.toString()));
try {
if (doc.select("#Volumes").size() > 0) {
parseVolumes(res, doc, data);
} else {
parseCopies(res, doc, data);
}
} catch (JSONException e) {
e.printStackTrace();
}
return res;
}
use of de.geeksfactory.opacclient.objects.Detail in project opacclient by opacapp.
the class WinBiap method parse_result.
private DetailedItem parse_result(String html) {
Document doc = Jsoup.parse(html);
DetailedItem item = new DetailedItem();
if (doc.select(".cover").size() > 0) {
Element cover = doc.select(".cover").first();
if (cover.hasAttr("data-src")) {
item.setCover(cover.attr("data-src"));
} else if (cover.hasAttr("src") && !cover.attr("src").equals("images/empty.gif")) {
item.setCover(cover.attr("src"));
}
item.setMediaType(getMediaType(cover, data));
}
String permalink = doc.select(".PermalinkTextarea").text();
item.setId(getQueryParamsFirst(permalink).get("Id"));
Elements trs = doc.select(".DetailInformation").first().select("tr");
for (Element tr : trs) {
String name = tr.select(".DetailInformationEntryName").text().replace(":", "");
String value = tr.select(".DetailInformationEntryContent").text();
switch(name) {
case "Titel":
item.setTitle(value);
break;
case "Stücktitel":
item.setTitle(item.getTitle() + " " + value);
break;
default:
item.addDetail(new Detail(name, value));
break;
}
}
DateTimeFormatter fmt = DateTimeFormat.forPattern("dd.MM.yyyy").withLocale(Locale.GERMAN);
trs = doc.select(".detailCopies .tableCopies > tbody > tr:not(.headerCopies)");
for (Element tr : trs) {
Copy copy = new Copy();
copy.setBarcode(tr.select(".mediaBarcode").text().replace("#", ""));
copy.setStatus(tr.select(".mediaStatus").text());
if (tr.select(".DateofReturn .borrowUntil").size() > 0) {
String returntime = tr.select(".DateofReturn .borrowUntil").text();
try {
copy.setReturnDate(fmt.parseLocalDate(returntime));
} catch (IllegalArgumentException e) {
e.printStackTrace();
}
}
if (tr.select(".mediaBranch").size() > 0) {
copy.setBranch(tr.select(".mediaBranch").text());
}
copy.setLocation(tr.select(".cellMediaItemLocation span").text());
if (tr.select("#HyperLinkReservation").size() > 0) {
copy.setResInfo(tr.select("#HyperLinkReservation").attr("href"));
item.setReservable(true);
item.setReservation_info("reservable");
}
item.addCopy(copy);
}
return item;
}
use of de.geeksfactory.opacclient.objects.Detail in project opacclient by opacapp.
the class Zones method parse_result.
private DetailedItem parse_result(String id, String html) {
Document doc = Jsoup.parse(html);
DetailedItem result = new DetailedItem();
result.setTitle("");
boolean title_is_set = false;
result.setId(id);
String detailTrsQuery = version18 ? ".inRoundBox1 table table tr" : ".DetailDataCell table table:not(.inRecordHeader) tr";
Elements detailtrs1 = doc.select(detailTrsQuery);
for (int i = 0; i < detailtrs1.size(); i++) {
Element tr = detailtrs1.get(i);
int s = tr.children().size();
if (tr.child(0).text().trim().equals("Titel") && !title_is_set) {
result.setTitle(tr.child(s - 1).text().trim());
title_is_set = true;
} else if (s > 1) {
Element valchild = tr.child(s - 1);
if (valchild.select("table").isEmpty()) {
String val = valchild.text().trim();
if (val.length() > 0) {
result.addDetail(new Detail(tr.child(0).text().trim(), val));
}
}
}
}
for (Element a : doc.select("a.SummaryActionLink")) {
if (a.text().contains("Vormerken")) {
result.setReservable(true);
result.setReservation_info(a.attr("href"));
}
}
Elements detaildiv = doc.select("div.record-item-new");
if (!detaildiv.isEmpty()) {
for (int i = 0; i < detaildiv.size(); i++) {
Element dd = detaildiv.get(i);
String text = "";
for (Node node : dd.childNodes()) {
if (node instanceof TextNode) {
String snip = ((TextNode) node).text();
if (snip.length() > 0) {
text += snip;
}
} else if (node instanceof Element) {
if (((Element) node).tagName().equals("br")) {
text += "\n";
} else {
String snip = ((Element) node).text().trim();
if (snip.length() > 0) {
text += snip;
}
}
}
}
result.addDetail(new Detail("", text));
}
}
if (doc.select("span.z3988").size() > 0) {
// Sometimes there is a <span class="Z3988"> item which provides
// data in a standardized format.
String z3988data = doc.select("span.z3988").first().attr("title").trim();
for (String pair : z3988data.split("&")) {
String[] nv = pair.split("=", 2);
if (nv.length == 2) {
if (!nv[1].trim().equals("")) {
if (nv[0].equals("rft.btitle") && result.getTitle().length() == 0) {
result.setTitle(nv[1]);
} else if (nv[0].equals("rft.atitle") && result.getTitle().length() == 0) {
result.setTitle(nv[1]);
} else if (nv[0].equals("rft.au")) {
result.addDetail(new Detail("Author", nv[1]));
}
}
}
}
}
// Cover
if (doc.select(".BookCover, .LargeBookCover").size() > 0) {
result.setCover(doc.select(".BookCover, .LargeBookCover").first().attr("src"));
}
Elements copydivs = doc.select("div[id^=stock_]");
String pop = "";
for (int i = 0; i < copydivs.size(); i++) {
Element div = copydivs.get(i);
if (div.attr("id").startsWith("stock_head")) {
pop = div.text().trim();
continue;
}
Copy copy = new Copy();
DateTimeFormatter fmt = DateTimeFormat.forPattern("dd.MM.yyyy").withLocale(Locale.GERMAN);
// This is getting very ugly - check if it is valid for libraries which are not Hamburg.
// Seems to also work in Kiel (Zones 1.8, checked 10.10.2015)
int j = 0;
for (Node node : div.childNodes()) {
try {
if (node instanceof Element) {
if (((Element) node).tag().getName().equals("br")) {
copy.setBranch(pop);
result.addCopy(copy);
j = -1;
} else if (((Element) node).tag().getName().equals("b") && j == 1) {
copy.setLocation(((Element) node).text());
} else if (((Element) node).tag().getName().equals("b") && j > 1) {
copy.setStatus(((Element) node).text());
}
j++;
} else if (node instanceof TextNode) {
if (j == 0) {
copy.setDepartment(((TextNode) node).text());
}
if (j == 2) {
copy.setBarcode(((TextNode) node).getWholeText().trim().split("\n")[0].trim());
}
if (j == 6) {
String text = ((TextNode) node).text().trim();
String date = text.substring(text.length() - 10);
try {
copy.setReturnDate(fmt.parseLocalDate(date));
} catch (IllegalArgumentException e) {
e.printStackTrace();
}
}
j++;
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
return result;
}
use of de.geeksfactory.opacclient.objects.Detail in project opacclient by opacapp.
the class DetailsAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
Detail detail = details.get(position);
holder.desc.setText(detail.getDesc());
holder.content.setText(detail.getContent());
Linkify.addLinks(holder.content, Linkify.WEB_URLS);
}
Aggregations