Search in sources :

Example 26 with SearchField

use of de.geeksfactory.opacclient.searchfields.SearchField in project opacclient by opacapp.

the class WinBiap method parseSearchFields.

@Override
public List<SearchField> parseSearchFields() throws IOException {
    // extract branches and categories
    String html = httpGet(opac_url + "/search.aspx", getDefaultEncoding());
    Document doc = Jsoup.parse(html);
    Elements mediaGroupOptions = doc.select("[id$=ListBoxMediagroups_ListBoxMultiselection] option");
    Elements branchOptions = doc.select("[id$=MultiSelectionBranch_ListBoxMultiselection] option");
    final DropdownSearchField mediaGroups = new DropdownSearchField(KEY_SEARCH_QUERY_CATEGORY, "Mediengruppe", false, null);
    mediaGroups.setMeaning(Meaning.CATEGORY);
    final DropdownSearchField branches = new DropdownSearchField(KEY_SEARCH_QUERY_BRANCH, "Zweigstelle", false, null);
    branches.setMeaning(Meaning.BRANCH);
    mediaGroups.addDropdownValue("", "Alle");
    branches.addDropdownValue("", "Alle");
    for (Element option : mediaGroupOptions) {
        mediaGroups.addDropdownValue(option.attr("value"), option.text());
    }
    for (Element option : branchOptions) {
        branches.addDropdownValue(option.attr("value"), option.text());
    }
    List<SearchField> searchFields = new ArrayList<>();
    SearchField field = new TextSearchField(KEY_SEARCH_QUERY_FREE, "", false, false, "Beliebig", true, false);
    field.setMeaning(Meaning.FREE);
    searchFields.add(field);
    field = new TextSearchField(KEY_SEARCH_QUERY_AUTHOR, "Autor", false, false, "Nachname, Vorname", false, false);
    field.setMeaning(Meaning.AUTHOR);
    searchFields.add(field);
    field = new TextSearchField(KEY_SEARCH_QUERY_TITLE, "Titel", false, false, "Stichwort", false, false);
    field.setMeaning(Meaning.TITLE);
    searchFields.add(field);
    field = new TextSearchField(KEY_SEARCH_QUERY_KEYWORDA, "Schlagwort", true, false, "", false, false);
    field.setMeaning(Meaning.KEYWORD);
    searchFields.add(field);
    field = new TextSearchField(KEY_SEARCH_QUERY_AUDIENCE, "Interessenkreis", true, false, "", false, false);
    field.setMeaning(Meaning.AUDIENCE);
    searchFields.add(field);
    field = new TextSearchField(KEY_SEARCH_QUERY_SYSTEM, "Systematik", true, false, "", false, false);
    field.setMeaning(Meaning.SYSTEM);
    searchFields.add(field);
    field = new BarcodeSearchField(KEY_SEARCH_QUERY_ISBN, "Strichcode", false, false, "ISBN");
    field.setMeaning(Meaning.ISBN);
    searchFields.add(field);
    field = new TextSearchField(KEY_SEARCH_QUERY_PUBLISHER, "Verlag", false, false, "", false, false);
    field.setMeaning(Meaning.PUBLISHER);
    searchFields.add(field);
    field = new BarcodeSearchField(KEY_SEARCH_QUERY_BARCODE, "Strichcode", false, true, "Mediennummer");
    field.setMeaning(Meaning.BARCODE);
    searchFields.add(field);
    field = new TextSearchField(KEY_SEARCH_QUERY_YEAR_RANGE_START, "Jahr", false, false, "von", false, true);
    field.setMeaning(Meaning.YEAR);
    searchFields.add(field);
    field = new TextSearchField(KEY_SEARCH_QUERY_YEAR_RANGE_END, "Jahr", false, true, "bis", false, true);
    field.setMeaning(Meaning.YEAR);
    searchFields.add(field);
    searchFields.add(branches);
    searchFields.add(mediaGroups);
    return searchFields;
}
Also used : TextSearchField(de.geeksfactory.opacclient.searchfields.TextSearchField) BarcodeSearchField(de.geeksfactory.opacclient.searchfields.BarcodeSearchField) DropdownSearchField(de.geeksfactory.opacclient.searchfields.DropdownSearchField) SearchField(de.geeksfactory.opacclient.searchfields.SearchField) BarcodeSearchField(de.geeksfactory.opacclient.searchfields.BarcodeSearchField) Element(org.jsoup.nodes.Element) FormElement(org.jsoup.nodes.FormElement) ArrayList(java.util.ArrayList) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements) TextSearchField(de.geeksfactory.opacclient.searchfields.TextSearchField) DropdownSearchField(de.geeksfactory.opacclient.searchfields.DropdownSearchField)

Example 27 with SearchField

use of de.geeksfactory.opacclient.searchfields.SearchField in project opacclient by opacapp.

the class Zones method parseSearchFields.

@Override
public List<SearchField> parseSearchFields() throws IOException {
    if (!initialised)
        start();
    List<SearchField> fields = new ArrayList<>();
    String html = httpGet(opac_url + "/APS_ZONES?fn=AdvancedSearch&Style=Portal3&SubStyle=&Lang=GER" + "&ResponseEncoding=utf-8", getDefaultEncoding());
    Document doc = Jsoup.parse(html);
    // find text fields
    Elements txt_opts = doc.select("#formSelectTerm_1 option");
    for (Element opt : txt_opts) {
        TextSearchField field = new TextSearchField();
        field.setId(opt.attr("value"));
        field.setHint("");
        field.setDisplayName(opt.text());
        fields.add(field);
    }
    // find filters
    String filtersQuery = version18 ? ".inSearchLimits .floatingBox" : ".TabRechAv .limitBlock";
    Elements filters = doc.select(filtersQuery);
    int i = 0;
    for (Element filter : filters) {
        DropdownSearchField dropdown = new DropdownSearchField();
        dropdown.addDropdownValue("", "Alle");
        // All dropdowns use "q.limits.limit" as URL param, but they must not have the same ID
        dropdown.setId("dropdown_" + i);
        if (version18) {
            dropdown.setDisplayName(filter.select("tr").get(0).text().trim());
            Elements opts = filter.select("tr").get(1).select("table td:has(input)");
            for (Element opt : opts) {
                dropdown.addDropdownValue(opt.select("input").attr("value"), opt.text().trim());
            }
        } else {
            dropdown.setDisplayName(filter.parent().previousElementSibling().text().trim());
            Elements opts = filter.select(".limitChoice label");
            for (Element opt : opts) {
                dropdown.addDropdownValue(opt.attr("for"), opt.text().trim());
            }
        }
        fields.add(dropdown);
        i++;
    }
    return fields;
}
Also used : TextSearchField(de.geeksfactory.opacclient.searchfields.TextSearchField) DropdownSearchField(de.geeksfactory.opacclient.searchfields.DropdownSearchField) SearchField(de.geeksfactory.opacclient.searchfields.SearchField) Element(org.jsoup.nodes.Element) ArrayList(java.util.ArrayList) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements) TextSearchField(de.geeksfactory.opacclient.searchfields.TextSearchField) DropdownSearchField(de.geeksfactory.opacclient.searchfields.DropdownSearchField)

Example 28 with SearchField

use of de.geeksfactory.opacclient.searchfields.SearchField in project opacclient by opacapp.

the class Open method search.

@Override
public SearchRequestResult search(List<SearchQuery> queries) throws IOException, OpacErrorException, JSONException {
    String url = opac_url + "/" + data.getJSONObject("urls").getString("advanced_search") + NO_MOBILE;
    Document doc = Jsoup.parse(httpGet(url, getDefaultEncoding()));
    doc.setBaseUri(url);
    int selectableCount = 0;
    for (SearchQuery query : queries) {
        if (query.getValue().equals("") || query.getValue().equals("false"))
            continue;
        if (query.getSearchField() instanceof TextSearchField | query.getSearchField() instanceof BarcodeSearchField) {
            SearchField field = query.getSearchField();
            if (field.getData().getBoolean("selectable")) {
                selectableCount++;
                if (selectableCount > 3) {
                    throw new OpacErrorException(stringProvider.getQuantityString(StringProvider.LIMITED_NUM_OF_CRITERIA, 3, 3));
                }
                String number = numberToText(selectableCount);
                Element searchField = doc.select("select[name$=" + number + "SearchField]").first();
                Element searchValue = doc.select("input[name$=" + number + "SearchValue]").first();
                setSelectValue(searchField, field.getId());
                searchValue.val(query.getValue());
            } else {
                Element input = doc.select("input[name=" + field.getId() + "]").first();
                input.val(query.getValue());
            }
        } else if (query.getSearchField() instanceof DropdownSearchField) {
            DropdownSearchField field = (DropdownSearchField) query.getSearchField();
            Element select = doc.select("select[name=" + field.getId() + "]").first();
            setSelectValue(select, query.getValue());
        } else if (query.getSearchField() instanceof CheckboxSearchField) {
            CheckboxSearchField field = (CheckboxSearchField) query.getSearchField();
            Element input = doc.select("input[name=" + field.getId() + "]").first();
            input.attr("checked", query.getValue());
        }
    }
    // Submit form
    FormElement form = (FormElement) doc.select("form").first();
    MultipartBody data = formData(form, "BtnSearch").build();
    String postUrl = form.attr("abs:action");
    String html = httpPost(postUrl, data, "UTF-8");
    Document doc2 = Jsoup.parse(html);
    doc2.setBaseUri(postUrl);
    return parse_search(doc2, 0);
}
Also used : SearchQuery(de.geeksfactory.opacclient.searchfields.SearchQuery) BarcodeSearchField(de.geeksfactory.opacclient.searchfields.BarcodeSearchField) Element(org.jsoup.nodes.Element) FormElement(org.jsoup.nodes.FormElement) Document(org.jsoup.nodes.Document) TextSearchField(de.geeksfactory.opacclient.searchfields.TextSearchField) FormElement(org.jsoup.nodes.FormElement) DropdownSearchField(de.geeksfactory.opacclient.searchfields.DropdownSearchField) TextSearchField(de.geeksfactory.opacclient.searchfields.TextSearchField) CheckboxSearchField(de.geeksfactory.opacclient.searchfields.CheckboxSearchField) BarcodeSearchField(de.geeksfactory.opacclient.searchfields.BarcodeSearchField) DropdownSearchField(de.geeksfactory.opacclient.searchfields.DropdownSearchField) SearchField(de.geeksfactory.opacclient.searchfields.SearchField) CheckboxSearchField(de.geeksfactory.opacclient.searchfields.CheckboxSearchField) MultipartBody(okhttp3.MultipartBody)

Example 29 with SearchField

use of de.geeksfactory.opacclient.searchfields.SearchField in project opacclient by opacapp.

the class BaseApi method getSearchFields.

@Override
public List<SearchField> getSearchFields() throws JSONException, OpacErrorException, IOException {
    List<SearchField> fields = parseSearchFields();
    if (shouldUseMeaningDetector()) {
        MeaningDetector md = new MeaningDetectorImpl(library);
        for (int i = 0; i < fields.size(); i++) {
            fields.set(i, md.detectMeaning(fields.get(i)));
        }
        Collections.sort(fields, new SearchField.OrderComparator());
    }
    return fields;
}
Also used : SearchField(de.geeksfactory.opacclient.searchfields.SearchField) MeaningDetectorImpl(de.geeksfactory.opacclient.searchfields.MeaningDetectorImpl) MeaningDetector(de.geeksfactory.opacclient.searchfields.MeaningDetector)

Example 30 with SearchField

use of de.geeksfactory.opacclient.searchfields.SearchField in project opacclient by opacapp.

the class Heidi method parseSearchFields.

@Override
public List<SearchField> parseSearchFields() throws IOException, OpacErrorException, JSONException {
    String html = httpGet(opac_url + "/search.cgi?art=f", ENCODING, false, cookieStore);
    Document doc = Jsoup.parse(html);
    doc.setBaseUri(opac_url);
    List<SearchField> fields = new ArrayList<>();
    Elements options = doc.select("select[name=kat1] option");
    for (Element option : options) {
        TextSearchField field = new TextSearchField();
        field.setDisplayName(option.text());
        field.setId(option.attr("value"));
        field.setHint("");
        fields.add(field);
    }
    DropdownSearchField field = new DropdownSearchField();
    Elements zst_opts = doc.select("#teilk2 option");
    for (int i = 0; i < zst_opts.size(); i++) {
        Element opt = zst_opts.get(i);
        field.addDropdownValue(opt.val(), opt.text());
    }
    field.setDisplayName("Einrichtung");
    field.setId("f[teil2]");
    field.setVisible(true);
    field.setMeaning(SearchField.Meaning.BRANCH);
    fields.add(field);
    try {
        field = new DropdownSearchField();
        Document doc2 = Jsoup.parse(httpGet(opac_url + "/zweigstelle.cgi?sess=" + sessid, ENCODING, false, cookieStore));
        Elements home_opts = doc2.select("#zweig option");
        for (int i = 0; i < home_opts.size(); i++) {
            Element opt = home_opts.get(i);
            if (!opt.val().equals("")) {
                Map<String, String> option = new HashMap<>();
                option.put("key", opt.val());
                option.put("value", opt.text());
                field.addDropdownValue(opt.val(), opt.text());
            }
        }
        field.setDisplayName("Leihstelle");
        field.setId("_heidi_branch");
        field.setVisible(true);
        field.setMeaning(SearchField.Meaning.HOME_BRANCH);
        fields.add(field);
    } catch (IOException e) {
        e.printStackTrace();
    }
    TextSearchField pagefield = new TextSearchField();
    pagefield.setId("_heidi_page");
    pagefield.setVisible(false);
    pagefield.setDisplayName("Seite");
    pagefield.setHint("");
    fields.add(pagefield);
    return fields;
}
Also used : HashMap(java.util.HashMap) Element(org.jsoup.nodes.Element) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements) TextSearchField(de.geeksfactory.opacclient.searchfields.TextSearchField) DropdownSearchField(de.geeksfactory.opacclient.searchfields.DropdownSearchField) TextSearchField(de.geeksfactory.opacclient.searchfields.TextSearchField) DropdownSearchField(de.geeksfactory.opacclient.searchfields.DropdownSearchField) SearchField(de.geeksfactory.opacclient.searchfields.SearchField)

Aggregations

SearchField (de.geeksfactory.opacclient.searchfields.SearchField)32 TextSearchField (de.geeksfactory.opacclient.searchfields.TextSearchField)26 ArrayList (java.util.ArrayList)23 DropdownSearchField (de.geeksfactory.opacclient.searchfields.DropdownSearchField)22 Document (org.jsoup.nodes.Document)16 Element (org.jsoup.nodes.Element)16 Elements (org.jsoup.select.Elements)15 BarcodeSearchField (de.geeksfactory.opacclient.searchfields.BarcodeSearchField)12 JSONObject (org.json.JSONObject)11 CheckboxSearchField (de.geeksfactory.opacclient.searchfields.CheckboxSearchField)10 ViewGroup (android.view.ViewGroup)6 Spinner (android.widget.Spinner)6 SearchQuery (de.geeksfactory.opacclient.searchfields.SearchQuery)6 CheckBox (android.widget.CheckBox)5 EditText (android.widget.EditText)5 IOException (java.io.IOException)4 NotReachableException (de.geeksfactory.opacclient.networking.NotReachableException)3 JsonSearchFieldDataSource (de.geeksfactory.opacclient.storage.JsonSearchFieldDataSource)3 Matcher (java.util.regex.Matcher)3 Pattern (java.util.regex.Pattern)3