Search in sources :

Example 11 with DetailedItem

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

the class TestApi method makeSearchResult.

private void makeSearchResult(String name, String url, boolean reservable) {
    SearchResult res = new SearchResult();
    res.setNr(list.size());
    res.setInnerhtml("<b>" + name + "</b><br/>Lorem ipsum <i>dolor</i> sit amet.");
    res.setCover(url);
    res.setType(SearchResult.MediaType.BOOK);
    list.add(res);
    DetailedItem item = new DetailedItem();
    item.setTitle(name);
    item.setReservable(reservable);
    item.setCover(url);
    item.addDetail(new Detail("Autor", "Max Mustermann"));
    item.addDetail(new Detail("Beschreibung", "Weit hinten, hinter den Wortbergen, " + "fern der Länder Vokalien und Konsonantien leben die Blindtexte. Abgeschieden " + "wohnen sie in Buchstabhausen an der Küste des Semantik, " + "eines großen Sprachozeans. Ein kleines Bächlein namens Duden fließt durch ihren " + "Ort und versorgt sie mit den nötigen Regelialien. Es ist ein paradiesmatisches " + "Land, in dem einem gebratene Satzteile in den Mund fliegen.\n" + "\n" + "Nicht einmal von der allmächtigen Interpunktion werden die Blindtexte beherrscht" + " – ein geradezu unorthographisches Leben. Eines Tages aber beschloß eine kleine " + "Zeile Blindtext, ihr Name war Lorem Ipsum, hinaus zu gehen in die weite " + "Grammatik. Der große Oxmox riet ihr davon ab, da es dort wimmele von bösen " + "Kommata, wilden Fragezeichen und hinterhältigen Semikoli, " + "doch das Blindtextchen ließ sich nicht beirren.\n" + "Es packte seine sieben Versalien, schob sich sein Initial in den Gürtel und " + "machte sich auf den Weg. Als es die ersten Hügel des Kursivgebirges erklommen " + "hatte, warf es einen letzten Blick zurück auf die Skyline seiner Heimatstadt " + "Buchstabhausen, die Headline von Alphabetdorf und die Subline seiner eigenen " + "Straße, der Zeilengasse. Wehmütig lief ihm eine rhetorische Frage über die " + "Wange, dann setzte es seinen Weg fort.\n" + "\n" + "Unterwegs traf es eine Copy. Die Copy warnte das Blindtextchen, da, " + "wo sie herkäme wäre sie zigmal umgeschrieben worden und alles, " + "was von ihrem Ursprung noch übrig wäre, sei das Wort \"und\" und das " + "Blindtextchen solle umkehren und wieder in sein eigenes, " + "sicheres Land zurückkehren.\n" + "\n" + "Doch alles Gutzureden konnte es nicht überzeugen und so dauerte es nicht lange, " + "bis ihm ein paar heimtückische Werbetexter auflauerten, " + "es mit Longe und Parole betrunken machten und es dann in ihre Agentur " + "schleppten, wo sie es für ihre Projekte wieder und wieder mißbrauchten. Und wenn" + " es nicht umgeschrieben wurde, dann benutzen Sie es immernoch." + ""));
    detailList.add(item);
}
Also used : SearchResult(de.geeksfactory.opacclient.objects.SearchResult) DetailedItem(de.geeksfactory.opacclient.objects.DetailedItem) Detail(de.geeksfactory.opacclient.objects.Detail)

Example 12 with DetailedItem

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

the class Adis method parseResult.

DetailedItem parseResult(String id, Document doc) throws IOException, OpacErrorException {
    List<NameValuePair> nvpairs;
    DetailedItem res = new DetailedItem();
    if (doc.select("#R001 img").size() == 1) {
        String cover_url = doc.select("#R001 img").first().absUrl("src");
        if (!cover_url.endsWith("erne.gif")) {
            // If there is no cover, the first image usually is the "n Stars" rating badge
            res.setCover(cover_url);
        }
    }
    for (Element tr : doc.select("#R06 .aDISListe table tbody tr")) {
        if (tr.children().size() < 2) {
            continue;
        }
        String title = tr.child(0).text().trim();
        String value = tr.child(1).text().trim();
        if (value.contains("hier klicken") || value.startsWith("zur ") || title.contains("URL")) {
            res.addDetail(new Detail(title, tr.child(1).select("a").first().absUrl("href")));
        } else {
            res.addDetail(new Detail(title, value));
        }
        if (title.contains("Titel") && res.getTitle() == null) {
            res.setTitle(value.split("[:/;]")[0].trim());
        }
    }
    if (res.getTitle() == null) {
        for (Detail d : res.getDetails()) {
            if (d.getDesc().contains("Gesamtwerk") || d.getDesc().contains("Zeitschrift")) {
                res.setTitle(d.getContent());
                break;
            }
        }
    }
    if (doc.select("input[value*=Reservieren], input[value*=Vormerken], " + "input[value*=Einzelbestellung]").size() > 0 && id != null) {
        res.setReservable(true);
        res.setReservation_info(id);
    }
    DateTimeFormatter fmt = DateTimeFormat.forPattern("dd.MM.yyyy").withLocale(Locale.GERMAN);
    if (doc.select("#R08 table.rTable_table, #R09 table.rTable_table").size() > 0) {
        Element table = doc.select("#R08 table.rTable_table, #R09 table.rTable_table").first();
        Map<Integer, String> colmap = new HashMap<>();
        int i = 0;
        for (Element th : table.select("thead tr th")) {
            String head = th.text().trim();
            if (head.contains("Bibliothek") || head.contains("Library")) {
                colmap.put(i, "branch");
            } else if (head.contains("Standort") || head.contains("Location")) {
                colmap.put(i, "location");
            } else if (head.contains("Signatur") || head.contains("Call number")) {
                colmap.put(i, "signature");
            } else if (head.contains("URL")) {
                colmap.put(i, "url");
            } else if (head.contains("Status") || head.contains("Hinweis") || head.contains("Leihfrist") || head.matches(".*Verf.+gbarkeit.*")) {
                colmap.put(i, "status");
            }
            i++;
        }
        for (Element tr : table.select("tbody tr")) {
            Copy copy = new Copy();
            for (Entry<Integer, String> entry : colmap.entrySet()) {
                if (entry.getValue().equals("status")) {
                    String status = tr.child(entry.getKey()).text().trim();
                    String currentStatus = copy.getStatus() != null ? copy.getStatus() + " - " : "";
                    if (status.contains(" am: ")) {
                        copy.setStatus(currentStatus + status.split("-")[0]);
                        try {
                            copy.setReturnDate(fmt.parseLocalDate(status.split(": ")[1]));
                        } catch (IllegalArgumentException e) {
                            e.printStackTrace();
                        }
                    } else {
                        copy.setStatus(currentStatus + status);
                    }
                } else {
                    copy.set(entry.getValue(), tr.child(entry.getKey()).text().trim());
                }
            }
            res.addCopy(copy);
        }
    }
    if (doc.select("a:contains(Zitierlink)").size() > 0) {
        res.setId(doc.select("a:contains(Zitierlink)").attr("href"));
    } else {
        // null would be overridden by the UI, because there _is_
        res.setId("");
    // an id,< we just can not use it.
    }
    return res;
}
Also used : NameValuePair(org.apache.http.NameValuePair) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) HashMap(java.util.HashMap) Element(org.jsoup.nodes.Element) 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 13 with DetailedItem

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

the class IOpac method parse_result.

protected DetailedItem parse_result(String html) throws IOException {
    Document doc = Jsoup.parse(html);
    DetailedItem result = new DetailedItem();
    String id = null;
    if (doc.select("input[name=mednr]").size() > 0) {
        id = doc.select("input[name=mednr]").first().val().trim();
    } else if (doc.select("a[href*=mednr]").size() > 0) {
        String href = doc.select("a[href*=mednr]").first().attr("href");
        id = getQueryParamsFirst(href).get("mednr").trim();
    }
    result.setId(id);
    // check if new share button is available (allows to share a link to the standard
    // frameset of the OPAC instead of only the detail frame)
    newShareLinks = doc.select("#sharebutton").size() > 0;
    Elements table = doc.select("table").get(1).select("tr");
    // GET COVER IMAGE
    String imgUrl = table.get(0).select("img[src~=^https?://(:?images(?:-[^\\.]*)?\\.|[^\\.]*\\" + ".images-)amazon\\.com]").attr("src");
    result.setCover(imgUrl);
    // GET INFORMATION
    Copy copy = new Copy();
    for (Element row : table) {
        Element titleElem;
        Element detailElem;
        if (row.select("> th").size() > 0) {
            // iOpac < 2.87
            titleElem = row.select("th").first();
            detailElem = row.select("td").first();
        } else if (row.select("> td").size() >= 2) {
            // iOpac >= 2.87
            titleElem = row.select("> td").first();
            detailElem = row.select("> td").get(1);
        } else {
            // we don't know what to do
            continue;
        }
        String detail = detailElem.text().trim().replace("\u00a0", "");
        String title = titleElem.text().trim().replace("\u00a0", "");
        if (!title.equals("")) {
            if (title.contains("verliehen bis")) {
                if (detail.equals("")) {
                    copy.setStatus("verfügbar");
                } else {
                    copy.setStatus("verliehen bis " + detail);
                }
            } else if (title.contains("Abteilung")) {
                copy.setDepartment(detail);
            } else if (title.contains("Signatur")) {
                copy.setShelfmark(detail);
            } else if (title.contains("Titel")) {
                result.setTitle(detail);
            } else if (!title.contains("Cover")) {
                result.addDetail(new Detail(title, detail));
            }
        }
    }
    // GET RESERVATION INFO
    if ("verfügbar".equals(copy.getStatus()) || doc.select("a[href^=/cgi-bin/di.exe?mode=10], input.resbutton").size() == 0) {
        result.setReservable(false);
    } else {
        result.setReservable(true);
        if (doc.select("a[href^=/cgi-bin/di.exe?mode=10]").size() > 0) {
            // Reservation via link
            result.setReservation_info(doc.select("a[href^=/cgi-bin/di.exe?mode=10]").first().attr("href").substring(1).replace(" ", ""));
        } else {
            // Reservation via form (method="get")
            Element form = doc.select("input.resbutton").first().parent();
            result.setReservation_info(generateQuery(form));
        }
    }
    if (copy.notEmpty())
        result.addCopy(copy);
    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) Elements(org.jsoup.select.Elements) Detail(de.geeksfactory.opacclient.objects.Detail)

Example 14 with DetailedItem

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

the class SearchResultDetailFragment method bookingDo.

public void bookingDo() {
    MultiStepResultHelper<DetailedItem> msrhBooking = new MultiStepResultHelper<>(getActivity(), item, R.string.doing_booking);
    msrhBooking.setCallback(new Callback<DetailedItem>() {

        @Override
        public void onSuccess(MultiStepResult result) {
            if (getActivity() == null) {
                return;
            }
            AccountDataSource adata = new AccountDataSource(getActivity());
            adata.invalidateCachedAccountData(app.getAccount());
            Intent intent = new Intent(getActivity(), app.getMainActivity());
            intent.putExtra(MainActivity.EXTRA_FRAGMENT, "account");
            getActivity().startActivity(intent);
            getActivity().finish();
        }

        @Override
        public void onError(MultiStepResult result) {
            if (getActivity() == null) {
                return;
            }
            dialog_wrong_credentials(result.getMessage(), false);
        }

        @Override
        public void onUnhandledResult(MultiStepResult result) {
        }

        @Override
        public void onUserCancel() {
        }

        @Override
        public StepTask<?> newTask(MultiStepResultHelper helper, int useraction, String selection, DetailedItem item) {
            return new BookingTask(helper, useraction, selection, item);
        }
    });
    msrhBooking.start();
}
Also used : AccountDataSource(de.geeksfactory.opacclient.storage.AccountDataSource) MultiStepResult(de.geeksfactory.opacclient.apis.OpacApi.MultiStepResult) DetailedItem(de.geeksfactory.opacclient.objects.DetailedItem) Intent(android.content.Intent) SuppressLint(android.annotation.SuppressLint) StepTask(de.geeksfactory.opacclient.frontend.MultiStepResultHelper.StepTask)

Example 15 with DetailedItem

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

the class LibraryApiTestCases method scrollTestHelper.

public void scrollTestHelper(String q) throws OpacErrorException, IOException, JSONException {
    List<SearchQuery> query = new ArrayList<>();
    SearchField field = findFreeSearchOrTitle(fields);
    if (field == null) {
        throw new // TODO: prevent this
        OpacErrorException("There is no free or title search field");
    }
    query.add(new SearchQuery(field, q));
    SearchRequestResult res = api.search(query);
    assertTrue(res.getTotal_result_count() == -1 || res.getResults().size() <= res.getTotal_result_count());
    assertTrue(res.getResults().size() > 0);
    SearchResult third;
    if (res.getResults().size() >= 3) {
        third = res.getResults().get(2);
    } else {
        third = res.getResults().get(res.getResults().size() - 1);
    }
    DetailedItem detail;
    if (third.getId() != null) {
        detail = api.getResultById(third.getId(), "");
    } else {
        detail = api.getResult(third.getNr());
    }
    assertNotNull(detail);
    confirmDetail(third, detail);
    if (res.getResults().size() < res.getTotal_result_count()) {
        api.searchGetPage(2);
        SearchResult second = res.getResults().get(1);
        DetailedItem detail2;
        if (second.getId() != null) {
            detail2 = api.getResultById(second.getId(), "");
        } else {
            detail2 = api.getResult(second.getNr());
        }
        confirmDetail(second, detail2);
    }
}
Also used : SearchQuery(de.geeksfactory.opacclient.searchfields.SearchQuery) TextSearchField(de.geeksfactory.opacclient.searchfields.TextSearchField) SearchField(de.geeksfactory.opacclient.searchfields.SearchField) SearchRequestResult(de.geeksfactory.opacclient.objects.SearchRequestResult) ArrayList(java.util.ArrayList) OpacErrorException(de.geeksfactory.opacclient.apis.OpacApi.OpacErrorException) SearchResult(de.geeksfactory.opacclient.objects.SearchResult) DetailedItem(de.geeksfactory.opacclient.objects.DetailedItem)

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