List of usage examples for org.joda.time.format DateTimeFormatter parseLocalDate
public LocalDate parseLocalDate(String text)
From source file:de.geeksfactory.opacclient.apis.IOpac.java
License:MIT License
static void parseResList(List<ReservedItem> media, Document doc, JSONObject data) { if (doc.select("a[name=RES]").size() == 0) return;/*from w ww. j av a 2 s. c o m*/ Elements copytrs = doc.select("a[name=RES] ~ table:contains(Titel)").first().select("tr"); doc.setBaseUri(data.optString("baseurl")); DateTimeFormatter fmt = DateTimeFormat.forPattern("dd.MM.yyyy").withLocale(Locale.GERMAN); int trs = copytrs.size(); if (trs < 2) { return; } assert (trs > 0); for (int i = 1; i < trs; i++) { Element tr = copytrs.get(i); ReservedItem item = new ReservedItem(); item.setTitle(tr.child(0).text().trim().replace("\u00a0", "")); item.setAuthor(tr.child(1).text().trim().replace("\u00a0", "")); try { item.setReadyDate(fmt.parseLocalDate(tr.child(4).text().trim().replace("\u00a0", ""))); } catch (IllegalArgumentException e) { item.setStatus(tr.child(4).text().trim().replace("\u00a0", "")); } if (tr.select("a").size() > 0) { item.setCancelData(tr.select("a").last().attr("href")); } media.add(item); } assert (media.size() == trs - 1); }
From source file:de.geeksfactory.opacclient.apis.Littera.java
License:MIT License
static LocalDate parseCopyReturn(String str) { if (str == null) return null; DateTimeFormatter fmt = DateTimeFormat.forPattern("dd.MM.yyyy").withLocale(Locale.GERMAN); final Matcher matcher = Pattern.compile("[0-9.-]{4,}").matcher(str); if (matcher.find()) { return fmt.parseLocalDate(matcher.group()); } else {//from w w w .j a v a2 s . c om return null; } }
From source file:de.geeksfactory.opacclient.apis.Pica.java
License:MIT License
protected DetailledItem parse_result(String html) { Document doc = Jsoup.parse(html); doc.setBaseUri(opac_url);//from ww w .j a v a 2s. com DetailledItem result = new DetailledItem(); for (Element a : doc.select("a[href*=PPN")) { Map<String, String> hrefq = getQueryParamsFirst(a.absUrl("href")); String ppn = hrefq.get("PPN"); result.setId(ppn); break; } // GET COVER if (doc.select("td.preslabel:contains(ISBN) + td.presvalue").size() > 0) { Element isbnElement = doc.select("td.preslabel:contains(ISBN) + td.presvalue").first(); String isbn = ""; for (Node child : isbnElement.childNodes()) { if (child instanceof TextNode) { isbn = ((TextNode) child).text().trim(); break; } } result.setCover(ISBNTools.getAmazonCoverURL(isbn, true)); } // GET TITLE AND SUBTITLE String titleAndSubtitle; Element titleAndSubtitleElem = null; String titleRegex = ".*(Titel|Aufsatz|Zeitschrift|Gesamttitel" + "|Title|Article|Periodical|Collective\\stitle" + "|Titre|Article|P.riodique|Titre\\sg.n.ral).*"; String selector = "td.preslabel:matches(" + titleRegex + ") + td.presvalue"; if (doc.select(selector).size() > 0) { titleAndSubtitleElem = doc.select(selector).first(); titleAndSubtitle = titleAndSubtitleElem.text().trim(); int slashPosition = Math.min(titleAndSubtitle.indexOf("/"), titleAndSubtitle.indexOf(":")); String title; if (slashPosition > 0) { title = titleAndSubtitle.substring(0, slashPosition).trim(); String subtitle = titleAndSubtitle.substring(slashPosition + 1).trim(); result.addDetail(new Detail(stringProvider.getString(StringProvider.SUBTITLE), subtitle)); } else { title = titleAndSubtitle; } result.setTitle(title); } else { result.setTitle(""); } // Details int line = 0; Elements lines = doc.select("td.preslabel + td.presvalue"); if (titleAndSubtitleElem != null) { lines.remove(titleAndSubtitleElem); } for (Element element : lines) { Element titleElem = element.firstElementSibling(); String detail = ""; if (element.select("div").size() > 1 && element.select("div").text().equals(element.text())) { boolean first = true; for (Element div : element.select("div")) { if (!div.text().replace("\u00a0", " ").trim().equals("")) { if (!first) { detail += "\n" + div.text().replace("\u00a0", " ").trim(); } else { detail += div.text().replace("\u00a0", " ").trim(); first = false; } } } } else { detail = element.text().replace("\u00a0", " ").trim(); } String title = titleElem.text().replace("\u00a0", " ").trim(); if (element.select("hr").size() > 0) // after the separator we get the copies { break; } if (detail.length() == 0 && title.length() == 0) { line++; continue; } if (title.contains(":")) { title = title.substring(0, title.indexOf(":")); // remove colon } result.addDetail(new Detail(title, detail)); if (element.select("a").size() == 1 && !element.select("a").get(0).text().trim().equals("")) { String url = element.select("a").first().absUrl("href"); if (!url.startsWith(opac_url)) { result.addDetail(new Detail(stringProvider.getString(StringProvider.LINK), url)); } } line++; } line++; // next line after separator // Copies Copy copy = new Copy(); String location = ""; // reservation info will be stored as JSON JSONArray reservationInfo = new JSONArray(); while (line < lines.size()) { Element element = lines.get(line); if (element.select("hr").size() == 0) { Element titleElem = element.firstElementSibling(); String detail = element.text().trim(); String title = titleElem.text().replace("\u00a0", " ").trim(); if (detail.length() == 0 && title.length() == 0) { line++; continue; } if (title.contains("Standort") || title.contains("Vorhanden in") || title.contains("Location")) { location += detail; } else if (title.contains("Sonderstandort")) { location += " - " + detail; } else if (title.contains("Systemstelle") || title.contains("Subject")) { copy.setDepartment(detail); } else if (title.contains("Fachnummer") || title.contains("locationnumber")) { copy.setLocation(detail); } else if (title.contains("Signatur") || title.contains("Shelf mark")) { copy.setShelfmark(detail); } else if (title.contains("Anmerkung")) { location += " (" + detail + ")"; } else if (title.contains("Link")) { result.addDetail(new Detail(title.replace(":", "").trim(), detail)); } else if (title.contains("Status") || title.contains("Ausleihinfo") || title.contains("Ausleihstatus") || title.contains("Request info")) { // Find return date Pattern pattern = Pattern.compile("(till|bis) (\\d{2}-\\d{2}-\\d{4})"); Matcher matcher = pattern.matcher(detail); if (matcher.find()) { DateTimeFormatter fmt = DateTimeFormat.forPattern("dd-MM-yyyy").withLocale(Locale.GERMAN); try { copy.setStatus(detail.substring(0, matcher.start() - 1).trim()); copy.setReturnDate(fmt.parseLocalDate(matcher.group(2))); } catch (IllegalArgumentException e) { e.printStackTrace(); copy.setStatus(detail); } } else { copy.setStatus(detail); } // Get reservation info if (element.select("a:has(img[src*=inline_arrow])").size() > 0) { Element a = element.select("a:has(img[src*=inline_arrow])").first(); boolean multipleCopies = a.text().matches(".*(Exemplare|Volume list).*"); JSONObject reservation = new JSONObject(); try { reservation.put("multi", multipleCopies); reservation.put("link", _extract_url(a.absUrl("href"))); reservation.put("desc", location); reservationInfo.put(reservation); } catch (JSONException e1) { e1.printStackTrace(); } result.setReservable(true); } } } else { copy.setBranch(location); result.addCopy(copy); location = ""; copy = new Copy(); } line++; } if (copy.notEmpty()) { copy.setBranch(location); result.addCopy(copy); } if (reservationInfo.length() == 0) { // No reservation info found yet, because we didn't find any copies. // If there is a reservation link somewhere in the rows we interpreted // as details, we still want to use it. if (doc.select("td a:has(img[src*=inline_arrow])").size() > 0) { Element a = doc.select("td a:has(img[src*=inline_arrow])").first(); boolean multipleCopies = a.text().matches(".*(Exemplare|Volume list).*"); JSONObject reservation = new JSONObject(); try { reservation.put("multi", multipleCopies); reservation.put("link", _extract_url(a.attr("href"))); reservation.put("desc", location); reservationInfo.put(reservation); } catch (JSONException e1) { e1.printStackTrace(); } result.setReservable(true); } } result.setReservation_info(reservationInfo.toString()); // Volumes if (doc.select("a[href^=FAM?PPN=]").size() > 0) { String href = doc.select("a[href^=FAM?PPN=]").attr("href"); String ppn = getQueryParamsFirst(href).get("PPN"); Map<String, String> data = new HashMap<>(); data.put("ppn", ppn); result.setVolumesearch(data); } return result; }
From source file:de.geeksfactory.opacclient.apis.SISIS.java
License:MIT License
static DetailledItem parseDetail(String html, String html2, String html3, String coverJs, JSONObject data, StringProvider stringProvider) throws IOException { Document doc = Jsoup.parse(html); String opac_url = data.optString("baseurl", ""); doc.setBaseUri(opac_url);/*from w w w.j a v a2s . co m*/ Document doc2 = Jsoup.parse(html2); doc2.setBaseUri(opac_url); Document doc3 = Jsoup.parse(html3); doc3.setBaseUri(opac_url); DetailledItem result = new DetailledItem(); try { result.setId(doc.select("#bibtip_id").text().trim()); } catch (Exception ex) { ex.printStackTrace(); } List<String> reservationlinks = new ArrayList<>(); for (Element link : doc3.select("#vormerkung a, #tab-content a")) { String href = link.absUrl("href"); Map<String, String> hrefq = getQueryParamsFirst(href); if (result.getId() == null) { // ID retrieval String key = hrefq.get("katkey"); if (key != null) { result.setId(key); break; } } // Vormerken if (hrefq.get("methodToCall") != null) { if (hrefq.get("methodToCall").equals("doVormerkung") || hrefq.get("methodToCall").equals("doBestellung")) { reservationlinks.add(href.split("\\?")[1]); } } } if (reservationlinks.size() == 1) { result.setReservable(true); result.setReservation_info(reservationlinks.get(0)); } else if (reservationlinks.size() == 0) { result.setReservable(false); } else { // TODO: Multiple options - handle this case! } if (coverJs != null) { Pattern srcPattern = Pattern.compile("<img .* src=\"([^\"]+)\">"); Matcher matcher = srcPattern.matcher(coverJs); if (matcher.find()) { result.setCover(matcher.group(1)); } } else if (doc.select(".data td img").size() == 1) { result.setCover(doc.select(".data td img").first().attr("abs:src")); } if (doc.select(".aw_teaser_title").size() == 1) { result.setTitle(doc.select(".aw_teaser_title").first().text().trim()); } else if (doc.select(".data td strong").size() > 0) { result.setTitle(doc.select(".data td strong").first().text().trim()); } else { result.setTitle(""); } if (doc.select(".aw_teaser_title_zusatz").size() > 0) { result.addDetail(new Detail("Titelzusatz", doc.select(".aw_teaser_title_zusatz").text().trim())); } String title = ""; String text = ""; boolean takeover = false; Element detailtrs = doc2.select(".box-container .data td").first(); for (Node node : detailtrs.childNodes()) { if (node instanceof Element) { Element element = (Element) node; if (element.tagName().equals("strong")) { if (element.hasClass("c2")) { if (!title.equals("")) { result.addDetail(new Detail(title, text.trim())); } title = element.text().trim(); text = ""; } else { text = text + element.text(); } } else { if (element.tagName().equals("a")) { if (element.text().trim().contains("hier klicken") || title.contains("Link")) { text = text + node.attr("href"); takeover = true; break; } else { text = text + element.text(); } } } } else if (node instanceof TextNode) { text = text + ((TextNode) node).text(); } } if (!takeover) { text = ""; title = ""; } detailtrs = doc2.select("#tab-content .data td").first(); if (detailtrs != null) { for (Node node : detailtrs.childNodes()) { if (node instanceof Element) { if (((Element) node).tagName().equals("strong")) { if (!text.equals("") && !title.equals("")) { result.addDetail(new Detail(title.trim(), text.trim())); if (title.equals("Titel:")) { result.setTitle(text.trim()); } text = ""; } title = ((Element) node).text().trim(); } else { if (((Element) node).tagName().equals("a") && (((Element) node).text().trim().contains("hier klicken") || title.equals("Link:"))) { text = text + node.attr("href"); } else { text = text + ((Element) node).text(); } } } else if (node instanceof TextNode) { text = text + ((TextNode) node).text(); } } } else { if (doc2.select("#tab-content .fulltitle tr").size() > 0) { Elements rows = doc2.select("#tab-content .fulltitle tr"); for (Element tr : rows) { if (tr.children().size() == 2) { Element valcell = tr.child(1); String value = valcell.text().trim(); if (valcell.select("a").size() == 1) { value = valcell.select("a").first().absUrl("href"); } result.addDetail(new Detail(tr.child(0).text().trim(), value)); } } } else { result.addDetail(new Detail(stringProvider.getString(StringProvider.ERROR), stringProvider.getString(StringProvider.COULD_NOT_LOAD_DETAIL))); } } if (!text.equals("") && !title.equals("")) { result.addDetail(new Detail(title.trim(), text.trim())); if (title.equals("Titel:")) { result.setTitle(text.trim()); } } for (Element link : doc3.select("#tab-content a")) { Map<String, String> hrefq = getQueryParamsFirst(link.absUrl("href")); if (result.getId() == null) { // ID retrieval String key = hrefq.get("katkey"); if (key != null) { result.setId(key); break; } } } for (Element link : doc3.select(".box-container a")) { if (link.text().trim().equals("Download")) { result.addDetail( new Detail(stringProvider.getString(StringProvider.DOWNLOAD), link.absUrl("href"))); } } Map<String, Integer> copy_columnmap = new HashMap<>(); // Default values copy_columnmap.put("barcode", 1); copy_columnmap.put("branch", 3); copy_columnmap.put("status", 4); Elements copy_columns = doc.select("#tab-content .data tr#bg2 th"); for (int i = 0; i < copy_columns.size(); i++) { Element th = copy_columns.get(i); String head = th.text().trim(); if (head.contains("Status")) { copy_columnmap.put("status", i); } if (head.contains("Zweigstelle")) { copy_columnmap.put("branch", i); } if (head.contains("Mediennummer")) { copy_columnmap.put("barcode", i); } if (head.contains("Standort")) { copy_columnmap.put("location", i); } if (head.contains("Signatur")) { copy_columnmap.put("signature", i); } } Pattern status_lent = Pattern.compile( "^(entliehen) bis ([0-9]{1,2}.[0-9]{1,2}.[0-9]{2," + "4}) \\(gesamte Vormerkungen: ([0-9]+)\\)$"); Pattern status_and_barcode = Pattern.compile("^(.*) ([0-9A-Za-z]+)$"); Elements exemplartrs = doc.select("#tab-content .data tr").not("#bg2"); DateTimeFormatter fmt = DateTimeFormat.forPattern("dd.MM.yyyy").withLocale(Locale.GERMAN); for (Element tr : exemplartrs) { try { Copy copy = new Copy(); Element status = tr.child(copy_columnmap.get("status")); Element barcode = tr.child(copy_columnmap.get("barcode")); String barcodetext = barcode.text().trim().replace(" Wegweiser", ""); // STATUS String statustext; if (status.getElementsByTag("b").size() > 0) { statustext = status.getElementsByTag("b").text().trim(); } else { statustext = status.text().trim(); } if (copy_columnmap.get("status").equals(copy_columnmap.get("barcode"))) { Matcher matcher1 = status_and_barcode.matcher(statustext); if (matcher1.matches()) { statustext = matcher1.group(1); barcodetext = matcher1.group(2); } } Matcher matcher = status_lent.matcher(statustext); if (matcher.matches()) { copy.setStatus(matcher.group(1)); copy.setReservations(matcher.group(3)); copy.setReturnDate(fmt.parseLocalDate(matcher.group(2))); } else { copy.setStatus(statustext); } copy.setBarcode(barcodetext); if (status.select("a[href*=doVormerkung]").size() == 1) { copy.setResInfo(status.select("a[href*=doVormerkung]").attr("href").split("\\?")[1]); } String branchtext = tr.child(copy_columnmap.get("branch")).text().trim().replace(" Wegweiser", ""); copy.setBranch(branchtext); if (copy_columnmap.containsKey("location")) { copy.setLocation( tr.child(copy_columnmap.get("location")).text().trim().replace(" Wegweiser", "")); } if (copy_columnmap.containsKey("signature")) { copy.setShelfmark( tr.child(copy_columnmap.get("signature")).text().trim().replace(" Wegweiser", "")); } result.addCopy(copy); } catch (Exception ex) { ex.printStackTrace(); } } 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; }
From source file:de.geeksfactory.opacclient.apis.SISIS.java
License:MIT License
public static void parse_medialist(List<LentItem> media, Document doc, int offset, JSONObject data) { Elements copytrs = doc.select(".data tr"); doc.setBaseUri(data.optString("baseurl")); DateTimeFormatter fmt = DateTimeFormat.forPattern("dd.MM.yyyy").withLocale(Locale.GERMAN); int trs = copytrs.size(); if (trs == 1) { return;// w w w .j av a 2 s . c om } assert (trs > 0); for (int i = 1; i < trs; i++) { Element tr = copytrs.get(i); LentItem item = new LentItem(); if (tr.text().contains("keine Daten") || (trs == 2 && tr.children().size() == 1)) { // Dresden: Konto entlt keine <Ausleihen>. [sic!] return; } item.setTitle(tr.child(1).select("strong").text().trim()); try { item.setAuthor(tr.child(1).html().split("<br[ /]*>")[1].trim()); String[] col2split = tr.child(2).html().split("<br[ /]*>"); String deadline = col2split[0].trim(); if (deadline.contains("-")) { deadline = deadline.split("-")[1].trim(); } try { item.setDeadline(fmt.parseLocalDate(deadline).toString()); } catch (IllegalArgumentException e1) { e1.printStackTrace(); } if (col2split.length > 1) { item.setHomeBranch(col2split[1].trim()); } if (tr.select("a").size() > 0) { for (Element link : tr.select("a")) { String href = link.attr("abs:href"); Map<String, String> hrefq = getQueryParamsFirst(href); if (hrefq.get("methodToCall").equals("renewalPossible")) { item.setProlongData(offset + "$" + href.split("\\?")[1]); item.setRenewable(true); break; } } } else if (tr.select(".textrot, .textgruen, .textdunkelblau").size() > 0) { item.setProlongData("" + tr.select(".textrot, .textgruen, .textdunkelblau").text()); item.setRenewable(false); } } catch (Exception ex) { ex.printStackTrace(); } media.add(item); } assert (media.size() == trs - 1); }
From source file:de.geeksfactory.opacclient.apis.TouchPoint.java
License:MIT License
static List<LentItem> parse_medialist(Document doc) { List<LentItem> media = new ArrayList<>(); Elements copytrs = doc.select(".data tr"); DateTimeFormatter fmt = DateTimeFormat.forPattern("dd.MM.yyyy").withLocale(Locale.GERMAN); int trs = copytrs.size(); if (trs == 1) { return null; }/*ww w.j a va 2 s . co m*/ assert (trs > 0); for (int i = 1; i < trs; i++) { Element tr = copytrs.get(i); LentItem item = new LentItem(); if (tr.text().contains("keine Daten")) { return null; } item.setTitle(tr.select(".account-display-title").select("b, strong").text().trim()); try { item.setRenewable(false); if (tr.select("a").size() > 0) { for (Element link : tr.select("a")) { String href = link.attr("abs:href"); Map<String, String> hrefq = getQueryParamsFirst(href); if (hrefq.containsKey("q")) { item.setId(extractIdFromQ(hrefq.get("q"))); } else if ("renewal".equals(hrefq.get("methodToCall"))) { item.setProlongData(href.split("\\?")[1]); item.setRenewable(true); link.remove(); break; } } } String[] lines = tr.select(".account-display-title").html().split("<br[ /]*>"); if (lines.length == 4 || lines.length == 5) { // Winterthur item.setAuthor(Jsoup.parse(lines[1]).text().trim()); item.setBarcode(Jsoup.parse(lines[2]).text().trim()); if (lines.length == 5) { // Chemnitz item.setStatus(Jsoup.parse(lines[3] + " " + lines[4]).text().trim()); } else { // Winterthur item.setStatus(Jsoup.parse(lines[3]).text().trim()); } } else if (lines.length == 3) { // We can't really tell the difference between missing author and missing // shelfmark. However, all items have shelfmarks, not all have authors. item.setBarcode(Parser.unescapeEntities(lines[1].trim(), false)); item.setStatus(Parser.unescapeEntities(lines[2].trim(), false)); } else if (lines.length == 2) { item.setAuthor(Parser.unescapeEntities(lines[1].trim(), false)); } String[] col3split = tr.select(".account-display-state").html().split("<br[ /]*>"); String deadline = Jsoup.parse(col3split[0].trim()).text().trim(); if (deadline.contains(":")) { // BSB Munich: <span class="hidden-sm hidden-md hidden-lg">Flligkeitsdatum : // </span>26.02.2016<br> deadline = deadline.split(":")[1].trim(); } if (deadline.contains("-")) { // Chemnitz: 22.07.2015 - 20.10.2015<br> deadline = deadline.split("-")[1].trim(); } try { item.setDeadline(fmt.parseLocalDate(deadline).toString()); } catch (IllegalArgumentException e1) { e1.printStackTrace(); } if (col3split.length > 1) item.setHomeBranch(col3split[1].trim()); } catch (Exception ex) { ex.printStackTrace(); } media.add(item); } return media; }
From source file:de.geeksfactory.opacclient.apis.WebOpacAt.java
License:MIT License
static LocalDate parseCopyReturn(String str) { DateTimeFormatter fmt = DateTimeFormat.forPattern("dd.MM.yyyy").withLocale(Locale.GERMAN); final Matcher matcher = Pattern.compile("[0-9.-]{4,}").matcher(str); if (matcher.find()) { return fmt.parseLocalDate(matcher.group()); } else {/*from w w w . java 2s.c om*/ return null; } }
From source file:de.geeksfactory.opacclient.apis.WebOpacNet.java
License:MIT License
static void parseAccount(JSONObject response, AccountData data) throws JSONException { data.setValidUntil(ifNotEmpty(response.getString("gueltigbis"))); data.setPendingFees(ifNotEmpty(response.getString("gebuehren"))); DateTimeFormatter format = DateTimeFormat.forPattern("dd.MM.yyyy"); List<LentItem> lent = new ArrayList<>(); JSONArray ausleihen = response.getJSONArray("ausleihen"); for (int i = 0; i < ausleihen.length(); i++) { LentItem item = new LentItem(); JSONObject json = ausleihen.getJSONObject(i); item.setAuthor(json.getString("urheber")); item.setTitle(json.getString("titelkurz").replace(item.getAuthor() + " : ", "")); item.setCover(json.getString("imageurl")); item.setMediaType(getMediaType(json.getString("iconurl"))); item.setStatus(ifNotEmpty(json.getString("hinweis"))); item.setProlongData(json.getString("exemplarid")); JSONArray felder = json.getJSONArray("felder"); for (int j = 0; j < felder.length(); j++) { String value = felder.getJSONObject(j).getString("display"); if (value.startsWith("Leihfrist: ")) { String dateStr = value.replace("Leihfrist: ", ""); item.setDeadline(format.parseLocalDate(dateStr)); break; }/*from ww w . j a v a 2 s . c o m*/ } lent.add(item); } data.setLent(lent); List<ReservedItem> reservations = new ArrayList<>(); JSONArray reservationen = response.getJSONArray("reservationen"); for (int i = 0; i < reservationen.length(); i++) { ReservedItem item = new ReservedItem(); JSONObject json = reservationen.getJSONObject(i); item.setAuthor(json.getString("urheber")); item.setTitle(json.getString("titelkurz").replace(item.getAuthor() + " : ", "")); item.setCover(json.getString("imageurl")); item.setMediaType(getMediaType(json.getString("iconurl"))); item.setStatus(ifNotEmpty(json.getString("hinweis"))); if (!json.getString("abholdat").equals("")) { item.setExpirationDate(format.parseLocalDate(json.getString("abholdat"))); } if (json.getString("status").equals("1")) { item.setCancelData(json.getString("exemplarid")); } reservations.add(item); } data.setLent(lent); data.setReservations(reservations); }
From source file:de.geeksfactory.opacclient.apis.Zones.java
License:MIT License
private DetailledItem parse_result(String id, String html) { Document doc = Jsoup.parse(html); DetailledItem result = new DetailledItem(); result.setTitle(""); boolean title_is_set = false; result.setId(id);// www .j ava2s. co m 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; }
From source file:de.geeksfactory.opacclient.apis.Zones.java
License:MIT License
static List<LentItem> parseMediaList(Document doc) { List<LentItem> lent = new ArrayList<>(); DateTimeFormatter fmt = DateTimeFormat.forPattern("dd/MM/yyyy").withLocale(Locale.GERMAN); Pattern id_pat = Pattern.compile("javascript:renewItem\\('[0-9]+','(.*)'\\)"); Pattern cannotrenew_pat = Pattern.compile("javascript:CannotRenewLoan\\('[0-9]+','(.*)','[0-9]+'\\)"); for (Element table : doc .select(".LoansBrowseItemDetailsCellStripe table, " + ".LoansBrowseItemDetailsCell " + "table")) { LentItem item = new LentItem(); for (Element tr : table.select("tr")) { String desc = tr.select(".LoanBrowseFieldNameCell").text().trim(); String value = tr.select(".LoanBrowseFieldDataCell").text().trim(); if (desc.equals("Titel")) { item.setTitle(value);/*from w ww . j a v a 2 s .co m*/ if (tr.select(".LoanBrowseFieldDataCell a[href]").size() > 0) { String href = tr.select(".LoanBrowseFieldDataCell a[href]").attr("href"); Map<String, String> params = getQueryParamsFirst(href); if (params.containsKey("BACNO")) { item.setId(params.get("BACNO")); } } } if (desc.equals("Verfasser")) item.setAuthor(value); if (desc.equals("Mediennummer")) item.setBarcode(value); if (desc.equals("ausgeliehen in")) item.setHomeBranch(value); if (desc.matches("F.+lligkeits.*datum")) { value = value.split(" ")[0]; try { item.setDeadline(fmt.parseLocalDate(value)); } catch (IllegalArgumentException e) { e.printStackTrace(); } } } if (table.select(".button[Title~=Zum]").size() == 1) { Matcher matcher1 = id_pat.matcher(table.select(".button[Title~=Zum]").attr("href")); if (matcher1.matches()) item.setProlongData(matcher1.group(1)); } else if (table.select(".CannotRenewLink").size() == 1) { Matcher matcher = cannotrenew_pat.matcher(table.select(".CannotRenewLink").attr("href").trim()); if (matcher.matches()) { item.setProlongData("cannotrenew|" + matcher.group(1)); } item.setRenewable(false); } lent.add(item); } return lent; }