Search in sources :

Example 6 with DetailedItem

use of de.geeksfactory.opacclient.objects.DetailedItem in project opacclient by opacapp.

the class WebOpacNet method parse_detail.

private DetailedItem parse_detail(String text) throws OpacErrorException {
    try {
        DetailedItem result = new DetailedItem();
        JSONObject json = new JSONObject(text);
        result.setTitle(json.getString("titel"));
        result.setCover(json.getString("imageurl"));
        result.setId(json.getString("medid"));
        // Details
        JSONArray info = json.getJSONArray("medium");
        for (int i = 0; i < info.length(); i++) {
            JSONObject detailJson = info.getJSONObject(i);
            String name = detailJson.getString("bez");
            String value = "";
            JSONArray values = detailJson.getJSONArray("values");
            for (int j = 0; j < values.length(); j++) {
                JSONObject valJson = values.getJSONObject(j);
                if (j != 0) {
                    value += ", ";
                }
                String content = valJson.getString("dval");
                content = content.replaceAll("<span[^>]*>", "");
                content = content.replaceAll("</span>", "");
                value += content;
            }
            Detail detail = new Detail(name, value);
            result.addDetail(detail);
        }
        // Copies
        JSONArray copies = json.getJSONArray("exemplare");
        for (int i = 0; i < copies.length(); i++) {
            JSONObject copyJson = copies.getJSONObject(i);
            Copy copy = new Copy();
            JSONArray values = copyJson.getJSONArray("rows");
            for (int j = 0; j < values.length(); j++) {
                JSONObject valJson = values.getJSONObject(j);
                String name = valJson.getString("bez");
                String value = valJson.getJSONArray("values").getJSONObject(0).getString("dval");
                if (!value.equals("")) {
                    switch(name) {
                        case "Exemplarstatus":
                            copy.setStatus(value);
                            break;
                        case "Signatur":
                            copy.setShelfmark(value);
                            break;
                        case "Standort":
                            copy.setLocation(value);
                            break;
                        case "Themenabteilung":
                            if (copy.getDepartment() != null) {
                                value = copy.getDepartment() + value;
                            }
                            copy.setDepartment(value);
                            break;
                        case "Themenbereich":
                            if (copy.getDepartment() != null) {
                                value = copy.getDepartment() + value;
                            }
                            copy.setDepartment(value);
                            break;
                    }
                }
            }
            result.addCopy(copy);
        }
        return result;
    } catch (JSONException e) {
        e.printStackTrace();
        throw new OpacErrorException(stringProvider.getFormattedString(StringProvider.INTERNAL_ERROR_WITH_DESCRIPTION, e.getMessage()));
    }
}
Also used : JSONObject(org.json.JSONObject) Copy(de.geeksfactory.opacclient.objects.Copy) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) DetailedItem(de.geeksfactory.opacclient.objects.DetailedItem) Detail(de.geeksfactory.opacclient.objects.Detail)

Example 7 with DetailedItem

use of de.geeksfactory.opacclient.objects.DetailedItem in project opacclient by opacapp.

the class Littera method getResultById.

@Override
public DetailedItem getResultById(String id, String homebranch) throws IOException, OpacErrorException {
    if (!initialised) {
        start();
    }
    final String html = httpGet(getApiUrl() + "&view=detail&id=" + id, getDefaultEncoding());
    final Document doc = Jsoup.parse(html);
    final Element detailData = doc.select(".detailData").first();
    final Element detailTable = detailData.select("table.titel").first();
    final Element availabilityTable = doc.select(".bibliothek table").first();
    final DetailedItem result = new DetailedItem();
    final Copy copy = new Copy();
    result.addCopy(copy);
    result.setId(id);
    result.setCover(getCover(doc));
    result.setTitle(detailData.select("h3").first().text());
    result.setMediaType(MEDIA_TYPES.get(getCellContent(detailTable, "Medienart|Type of media")));
    copy.setStatus(getCellContent(availabilityTable, "Verfügbar|Available"));
    copy.setReturnDate(parseCopyReturn(getCellContent(availabilityTable, "Exemplare verliehen|Copies lent")));
    copy.setReservations(getCellContent(availabilityTable, "Reservierungen|Reservations"));
    for (final Element tr : detailTable.select("tr")) {
        final String desc = tr.child(0).text();
        final String content = tr.child(1).text();
        if (desc != null && !desc.trim().equals("")) {
            result.addDetail(new Detail(desc, content));
        } else if (!result.getDetails().isEmpty()) {
            final Detail lastDetail = result.getDetails().get(result.getDetails().size() - 1);
            lastDetail.setHtml(true);
            lastDetail.setContent(lastDetail.getContent() + "\n" + content);
        }
    }
    return result;
}
Also used : Copy(de.geeksfactory.opacclient.objects.Copy) Element(org.jsoup.nodes.Element) DetailedItem(de.geeksfactory.opacclient.objects.DetailedItem) Document(org.jsoup.nodes.Document) Detail(de.geeksfactory.opacclient.objects.Detail)

Example 8 with DetailedItem

use of de.geeksfactory.opacclient.objects.DetailedItem in project opacclient by opacapp.

the class Pica method parse_result.

protected DetailedItem parse_result(String html) {
    Document doc = Jsoup.parse(html);
    doc.setBaseUri(opac_url);
    DetailedItem result = new DetailedItem();
    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("img[title=Titelbild]").size() > 0) {
        result.setCover(doc.select("img[title=Titelbild]").first().absUrl("src"));
    } else if (doc.select("td.preslabel:contains(ISBN) + td.presvalue").size() > 0) {
        Element isbnElement = doc.select("td.preslabel:contains(ISBN) + td.presvalue").first();
        String isbn = isbnElement.text().trim();
        if (!isbn.equals("")) {
            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 || element.text().trim().equals("")) // after the separator we get the copies
        {
            break;
        }
        if (detail.length() == 0 && title.length() == 0) {
            line++;
            continue;
        }
        if (title.contains(":")) {
            // remove colon
            title = title.substring(0, title.indexOf(":"));
        }
        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++;
    }
    // next line after separator
    line++;
    // 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.text().trim().equals("")) {
            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("Sachgebiete") || title.contains("Subject")) {
                copy.setDepartment(detail);
            } else if (title.contains("Fachnummer") || title.contains("locationnumber") || title.contains("Schlagwörter")) {
                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));
                        reservation.put("desc", location);
                        reservationInfo.put(reservation);
                    } catch (JSONException e1) {
                        e1.printStackTrace();
                    }
                    result.setReservable(true);
                }
            }
        } else {
            copy.setBranch(location);
            if (copy.notEmpty()) {
                result.addCopy(copy);
            }
            location = "";
            copy = new Copy();
        }
        line++;
    }
    if (copy.notEmpty()) {
        copy.setBranch(location);
        result.addCopy(copy);
    }
    if (reservationInfo.length() == 0) {
        // 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));
                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;
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) HashMap(java.util.HashMap) Element(org.jsoup.nodes.Element) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements) JSONObject(org.json.JSONObject) Copy(de.geeksfactory.opacclient.objects.Copy) DetailedItem(de.geeksfactory.opacclient.objects.DetailedItem) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) Detail(de.geeksfactory.opacclient.objects.Detail)

Example 9 with DetailedItem

use of de.geeksfactory.opacclient.objects.DetailedItem in project opacclient by opacapp.

the class SISIS method parseDetail.

static DetailedItem 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);
    Document doc2 = Jsoup.parse(html2);
    doc2.setBaseUri(opac_url);
    Document doc3 = Jsoup.parse(html3);
    doc3.setBaseUri(opac_url);
    DetailedItem result = new DetailedItem();
    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 (result.getId() == null && doc.select("#permalink_link").size() > 0) {
        result.setId(doc.select("#permalink_link").text());
    }
    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")));
        }
    }
    if (doc3.select("#tab-content .textrot").size() > 0) {
        result.addDetail(new Detail(stringProvider.getString(StringProvider.STATUS), doc3.select("#tab-content .textrot").text()));
    }
    Map<String, Integer> copy_columnmap = new HashMap<>();
    // Default values
    copy_columnmap.put("barcode", 1);
    copy_columnmap.put("branch", 3);
    copy_columnmap.put("status", 4);
    Element table = doc.select("#tab-content .data").first();
    Elements copy_columns = table != null ? table.select("tr#bg2 th") : new Elements();
    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 = table != null ? table.select("tr").not("#bg2") : new Elements();
    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.trim().replace(" Wegweiser", ""));
            }
            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;
}
Also used : Pattern(java.util.regex.Pattern) NameValuePair(org.apache.http.NameValuePair) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) Matcher(java.util.regex.Matcher) HashMap(java.util.HashMap) Element(org.jsoup.nodes.Element) Node(org.jsoup.nodes.Node) TextNode(org.jsoup.nodes.TextNode) ArrayList(java.util.ArrayList) TextNode(org.jsoup.nodes.TextNode) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements) URI(java.net.URI) URISyntaxException(java.net.URISyntaxException) JSONException(org.json.JSONException) NotReachableException(de.geeksfactory.opacclient.networking.NotReachableException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ClientProtocolException(org.apache.http.client.ClientProtocolException) IOException(java.io.IOException) Copy(de.geeksfactory.opacclient.objects.Copy) DetailedItem(de.geeksfactory.opacclient.objects.DetailedItem) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) Detail(de.geeksfactory.opacclient.objects.Detail)

Example 10 with DetailedItem

use of de.geeksfactory.opacclient.objects.DetailedItem in project opacclient by opacapp.

the class SRU method parse_detail.

private DetailedItem parse_detail(Element record) {
    String title = getDetail(record, "titleInfo title");
    String firstName = getDetail(record, "name > namePart[type=given]");
    String lastName = getDetail(record, "name > namePart[type=family]");
    String year = getDetail(record, "dateIssued");
    String desc = getDetail(record, "abstract");
    String isbn = getDetail(record, "identifier[type=isbn]");
    String coverUrl = getDetail(record, "url[displayLabel=C Cover]");
    DetailedItem item = new DetailedItem();
    item.setTitle(title);
    item.addDetail(new Detail("Autor", firstName + " " + lastName));
    item.addDetail(new Detail("Jahr", year));
    item.addDetail(new Detail("Beschreibung", desc));
    if (coverUrl.equals("") && isbn.length() > 0) {
        item.setCover(ISBNTools.getAmazonCoverURL(isbn, true));
    } else if (!coverUrl.equals("")) {
        item.setCover(coverUrl);
    }
    if (isbn.length() > 0) {
        item.addDetail(new Detail("ISBN", isbn));
    }
    return item;
}
Also used : DetailedItem(de.geeksfactory.opacclient.objects.DetailedItem) Detail(de.geeksfactory.opacclient.objects.Detail)

Aggregations

DetailedItem (de.geeksfactory.opacclient.objects.DetailedItem)27 Detail (de.geeksfactory.opacclient.objects.Detail)18 Copy (de.geeksfactory.opacclient.objects.Copy)17 Element (org.jsoup.nodes.Element)15 Document (org.jsoup.nodes.Document)12 Elements (org.jsoup.select.Elements)12 JSONException (org.json.JSONException)11 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)10 IOException (java.io.IOException)8 JSONObject (org.json.JSONObject)7 NotReachableException (de.geeksfactory.opacclient.networking.NotReachableException)6 HashMap (java.util.HashMap)6 UnsupportedEncodingException (java.io.UnsupportedEncodingException)5 ArrayList (java.util.ArrayList)5 Matcher (java.util.regex.Matcher)5 Pattern (java.util.regex.Pattern)5 NameValuePair (org.apache.http.NameValuePair)5 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)5 Node (org.jsoup.nodes.Node)5 TextNode (org.jsoup.nodes.TextNode)5