Search in sources :

Example 26 with DropdownSearchField

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

the class Zones method addParameters.

private int addParameters(SearchQuery query, List<NameValuePair> params, int index) {
    if (query.getValue().equals("")) {
        return index;
    }
    if (query.getSearchField() instanceof TextSearchField) {
        if (index != 1) {
            params.add(new BasicNameValuePair(".form.t" + index + ".logic", "and"));
        }
        params.add(new BasicNameValuePair("q.form.t" + index + ".term", query.getKey()));
        params.add(new BasicNameValuePair("q.form.t" + index + ".expr", query.getValue()));
        return index + 1;
    } else if (query.getSearchField() instanceof DropdownSearchField) {
        params.add(new BasicNameValuePair("q.limits.limit", query.getValue()));
    }
    return index;
}
Also used : BasicNameValuePair(org.apache.http.message.BasicNameValuePair) TextSearchField(de.geeksfactory.opacclient.searchfields.TextSearchField) DropdownSearchField(de.geeksfactory.opacclient.searchfields.DropdownSearchField)

Example 27 with DropdownSearchField

use of de.geeksfactory.opacclient.searchfields.DropdownSearchField 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 28 with DropdownSearchField

use of de.geeksfactory.opacclient.searchfields.DropdownSearchField 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)

Example 29 with DropdownSearchField

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

the class Adis method search.

@Override
public SearchRequestResult search(List<SearchQuery> queries) throws IOException, OpacErrorException {
    start();
    // TODO: There are also libraries with a different search form,
    // s_exts=SS2 instead of s_exts=SS6
    // e.g. munich. Treat them differently!
    Document doc = htmlGet(opac_url + ";jsessionid=" + s_sid + "?service=" + s_service + getSpParams());
    int dropdownTextCount = 0;
    int totalCount = 0;
    List<NameValuePair> nvpairs = new ArrayList<>();
    for (SearchQuery query : queries) {
        if (!query.getValue().equals("")) {
            totalCount++;
            if (query.getSearchField() instanceof DropdownSearchField) {
                doc.select("select#" + query.getKey()).val(query.getValue());
                continue;
            }
            if (query.getSearchField() instanceof TextSearchField && query.getSearchField().getData() != null && !query.getSearchField().getData().optBoolean("selectable", true) && doc.select("#" + query.getKey()).size() > 0) {
                doc.select("#" + query.getKey()).val(query.getValue());
                continue;
            }
            dropdownTextCount++;
            if (s_exts.get(0).equals("SS2") || (query.getSearchField().getData() != null && !query.getSearchField().getData().optBoolean("selectable", true))) {
                doc.select("input#" + query.getKey()).val(query.getValue());
            } else {
                if (doc.select("select#SUCH01_1").size() == 0 && doc.select("input[fld=FELD01_" + dropdownTextCount + "]").size() > 0) {
                    // Hack needed for Nürnberg
                    doc.select("input[fld=FELD01_" + dropdownTextCount + "]").first().previousElementSibling().val(query.getKey());
                    doc.select("input[fld=FELD01_" + dropdownTextCount + "]").val(query.getValue());
                } else {
                    doc.select("select#SUCH01_" + dropdownTextCount).val(query.getKey());
                    doc.select("input#FELD01_" + dropdownTextCount).val(query.getValue());
                }
            }
            if (dropdownTextCount > 4) {
                throw new OpacErrorException(stringProvider.getQuantityString(StringProvider.LIMITED_NUM_OF_CRITERIA, 4, 4));
            }
        }
    }
    for (Element input : doc.select("input, select")) {
        if (!"image".equals(input.attr("type")) && !"submit".equals(input.attr("type")) && !"".equals(input.attr("name"))) {
            nvpairs.add(new BasicNameValuePair(input.attr("name"), input.attr("value")));
        }
    }
    nvpairs.add(new BasicNameValuePair("$Toolbar_0.x", "1"));
    nvpairs.add(new BasicNameValuePair("$Toolbar_0.y", "1"));
    if (totalCount == 0) {
        throw new OpacErrorException(stringProvider.getString(StringProvider.NO_CRITERIA_INPUT));
    }
    Document docresults = htmlPost(opac_url + ";jsessionid=" + s_sid, nvpairs);
    return parse_search_wrapped(docresults, 1);
}
Also used : SearchQuery(de.geeksfactory.opacclient.searchfields.SearchQuery) NameValuePair(org.apache.http.NameValuePair) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) Element(org.jsoup.nodes.Element) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) ArrayList(java.util.ArrayList) Document(org.jsoup.nodes.Document) TextSearchField(de.geeksfactory.opacclient.searchfields.TextSearchField) DropdownSearchField(de.geeksfactory.opacclient.searchfields.DropdownSearchField)

Example 30 with DropdownSearchField

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

the class Adis method parseSearchFields.

@Override
public List<SearchField> parseSearchFields() throws IOException, JSONException {
    start();
    Document doc = htmlGet(opac_url + ";jsessionid=" + s_sid + "?service=" + s_service + getSpParams());
    List<SearchField> fields = new ArrayList<>();
    // dropdown to select which field you want to search in
    Elements searchoptions = doc.select("#SUCH01_1 option");
    if (searchoptions.size() == 0 && doc.select("input[fld=FELD01_1]").size() > 0) {
        // Hack is needed in Nuernberg
        searchoptions = doc.select("input[fld=FELD01_1]").first().previousElementSibling().select("option");
    }
    Set<String> fieldIds = new HashSet<>();
    for (Element opt : searchoptions) {
        // (bei Stadtbücherei Stuttgart der Fall)
        if (fieldIds.contains(opt.attr("value")))
            continue;
        TextSearchField field = new TextSearchField();
        field.setId(opt.attr("value"));
        field.setDisplayName(opt.text());
        field.setHint("");
        fields.add(field);
        fieldIds.add(field.getId());
    }
    // Save data so that the search() function knows that this
    // is not a selectable search field
    JSONObject selectableData = new JSONObject();
    selectableData.put("selectable", false);
    for (Element row : doc.select("div[id~=F\\d+], .search-adv-source")) {
        if (row.select("input[type=text]").size() == 1 && row.select("input, select").first().tagName().equals("input")) {
            // A single text search field
            Element input = row.select("input[type=text]").first();
            TextSearchField field = new TextSearchField();
            field.setId(input.attr("id"));
            field.setDisplayName(row.select("label").first().text());
            field.setHint("");
            field.setData(selectableData);
            fields.add(field);
        } else if (row.select("select").size() == 1 && row.select("input[type=text]").size() == 0) {
            // Things like language, media type, etc.
            Element select = row.select("select").first();
            DropdownSearchField field = new DropdownSearchField();
            field.setId(select.id());
            field.setDisplayName(row.select("label").first().text());
            for (Element opt : select.select("option")) {
                field.addDropdownValue(opt.attr("value"), opt.text());
            }
            fields.add(field);
        } else if (row.select("select").size() == 0 && row.select("input[type=text]").size() == 3 && row.select("label").size() == 3) {
            // Three text inputs.
            // Year single/from/to or things like Band-/Heft-/Satznummer
            String name1 = row.select("label").get(0).text();
            String name2 = row.select("label").get(1).text();
            String name3 = row.select("label").get(2).text();
            Element input1 = row.select("input[type=text]").get(0);
            Element input2 = row.select("input[type=text]").get(1);
            Element input3 = row.select("input[type=text]").get(2);
            if (name2.contains("von") && name3.contains("bis")) {
                TextSearchField field1 = new TextSearchField();
                field1.setId(input1.id());
                field1.setDisplayName(name1);
                field1.setHint("");
                field1.setData(selectableData);
                fields.add(field1);
                TextSearchField field2 = new TextSearchField();
                field2.setId(input2.id());
                field2.setDisplayName(name2.replace("von", "").trim());
                field2.setHint("von");
                field2.setData(selectableData);
                fields.add(field2);
                TextSearchField field3 = new TextSearchField();
                field3.setId(input3.id());
                field3.setDisplayName(name3.replace("bis", "").trim());
                field3.setHint("bis");
                field3.setHalfWidth(true);
                field3.setData(selectableData);
                fields.add(field3);
            } else {
                TextSearchField field1 = new TextSearchField();
                field1.setId(input1.id());
                field1.setDisplayName(name1);
                field1.setHint("");
                field1.setData(selectableData);
                fields.add(field1);
                TextSearchField field2 = new TextSearchField();
                field2.setId(input2.id());
                field2.setDisplayName(name2);
                field2.setHint("");
                field2.setData(selectableData);
                fields.add(field2);
                TextSearchField field3 = new TextSearchField();
                field3.setId(input3.id());
                field3.setDisplayName(name3);
                field3.setHint("");
                field3.setData(selectableData);
                fields.add(field3);
            }
        }
    }
    for (Iterator<SearchField> iterator = fields.iterator(); iterator.hasNext(); ) {
        SearchField field = iterator.next();
        if (ignoredFieldNames.contains(field.getDisplayName())) {
            iterator.remove();
        }
    }
    return fields;
}
Also used : 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) SearchField(de.geeksfactory.opacclient.searchfields.SearchField) TextSearchField(de.geeksfactory.opacclient.searchfields.TextSearchField) DropdownSearchField(de.geeksfactory.opacclient.searchfields.DropdownSearchField) JSONObject(org.json.JSONObject) HashSet(java.util.HashSet)

Aggregations

DropdownSearchField (de.geeksfactory.opacclient.searchfields.DropdownSearchField)32 TextSearchField (de.geeksfactory.opacclient.searchfields.TextSearchField)27 SearchField (de.geeksfactory.opacclient.searchfields.SearchField)21 Element (org.jsoup.nodes.Element)21 ArrayList (java.util.ArrayList)17 Document (org.jsoup.nodes.Document)17 Elements (org.jsoup.select.Elements)16 BarcodeSearchField (de.geeksfactory.opacclient.searchfields.BarcodeSearchField)13 CheckboxSearchField (de.geeksfactory.opacclient.searchfields.CheckboxSearchField)10 JSONObject (org.json.JSONObject)10 ViewGroup (android.view.ViewGroup)6 Spinner (android.widget.Spinner)6 SearchQuery (de.geeksfactory.opacclient.searchfields.SearchQuery)6 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)6 CheckBox (android.widget.CheckBox)5 EditText (android.widget.EditText)5 Matcher (java.util.regex.Matcher)4 Pattern (java.util.regex.Pattern)4 NotReachableException (de.geeksfactory.opacclient.networking.NotReachableException)3 NameValuePair (org.apache.http.NameValuePair)3