Search in sources :

Example 16 with SearchQuery

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

the class Zones method search.

@Override
public SearchRequestResult search(List<SearchQuery> queries) throws IOException, OpacErrorException {
    start();
    List<NameValuePair> params = new ArrayList<>();
    params.add(new BasicNameValuePair("Style", version18 ? "Portal2" : "Portal3"));
    params.add(new BasicNameValuePair("SubStyle", ""));
    params.add(new BasicNameValuePair("Lang", "GER"));
    params.add(new BasicNameValuePair("ResponseEncoding", "utf-8"));
    params.add(new BasicNameValuePair("Method", "QueryWithLimits"));
    params.add(new BasicNameValuePair("SearchType", "AdvancedSearch"));
    params.add(new BasicNameValuePair("TargetSearchType", "AdvancedSearch"));
    params.add(new BasicNameValuePair("DB", "SearchServer"));
    params.add(new BasicNameValuePair("q.PageSize", "10"));
    int index = 1;
    for (SearchQuery query : queries) {
        index = addParameters(query, params, index);
    }
    if (index > 3) {
        throw new OpacErrorException(stringProvider.getQuantityString(StringProvider.LIMITED_NUM_OF_CRITERIA, 3, 3));
    } else if (index == 1) {
        throw new OpacErrorException(stringProvider.getString(StringProvider.NO_CRITERIA_INPUT));
    }
    String html = httpGet(opac_url + "/" + searchobj + "?" + URLEncodedUtils.format(params, "UTF-8"), getDefaultEncoding());
    page = 1;
    return parse_search(html, page);
}
Also used : SearchQuery(de.geeksfactory.opacclient.searchfields.SearchQuery) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) NameValuePair(org.apache.http.NameValuePair) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) ArrayList(java.util.ArrayList)

Example 17 with SearchQuery

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

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

the class Bibliotheca method search.

@Override
public SearchRequestResult search(List<SearchQuery> queries) throws IOException, JSONException, OpacErrorException {
    if (!initialised) {
        start();
    }
    FormBody.Builder formData = new FormBody.Builder(Charset.forName(getDefaultEncoding()));
    boolean stichtitSet = false;
    int ifeldCount = 0;
    String order = "asc";
    for (SearchQuery query : queries) {
        if (query.getValue().equals("")) {
            continue;
        }
        String key = query.getKey();
        if (key.contains("$")) {
            key = key.substring(0, key.indexOf("$"));
        }
        if (key.contains("ifeld")) {
            ifeldCount++;
            if (ifeldCount > 1) {
                throw new OpacErrorException(stringProvider.getString(StringProvider.COMBINATION_NOT_SUPPORTED));
            }
        }
        if (key.equals("orderselect") && query.getValue().contains(":")) {
            formData.add("orderselect", query.getValue().split(":")[0]);
            order = query.getValue().split(":")[1];
        } else {
            formData.add(key, query.getValue());
        }
        if (query.getSearchField().getData() != null) {
            JSONObject data = query.getSearchField().getData();
            if (data.has("additional_params")) {
                JSONObject params = data.getJSONObject("additional_params");
                Iterator<String> keys = new JsonKeyIterator(params);
                while (keys.hasNext()) {
                    String additionalKey = keys.next();
                    if (additionalKey.equals("stichtit")) {
                        if (stichtitSet) {
                            throw new OpacErrorException(stringProvider.getString(StringProvider.COMBINATION_NOT_SUPPORTED));
                        }
                        stichtitSet = true;
                    }
                    formData.add(additionalKey, params.getString(additionalKey));
                }
            }
        }
    }
    if (!stichtitSet) {
        formData.add("stichtit", "stich");
    }
    formData.add("suche_starten.x", "1");
    formData.add("suche_starten.y", "1");
    if (data.has("db")) {
        try {
            formData.add("dbase", data.getString("db"));
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
    String html = httpPost(opac_url + "/index.asp", formData.build(), getDefaultEncoding());
    if (html.contains("<a href=\"index.asp?order=" + order + "\">")) {
        html = httpGet(opac_url + "/index.asp?order=" + order, getDefaultEncoding());
    }
    return parseSearch(html, 1, data);
}
Also used : SearchQuery(de.geeksfactory.opacclient.searchfields.SearchQuery) JSONObject(org.json.JSONObject) FormBody(okhttp3.FormBody) JsonKeyIterator(de.geeksfactory.opacclient.utils.JsonKeyIterator) JSONException(org.json.JSONException)

Example 19 with SearchQuery

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

the class Heidi method searchGetPage.

@Override
public SearchRequestResult searchGetPage(int page) throws IOException, OpacErrorException {
    TextSearchField pagefield = new TextSearchField();
    pagefield.setId("_heidi_page");
    pagefield.setVisible(false);
    pagefield.setDisplayName("Seite");
    pagefield.setHint("");
    for (SearchQuery q : last_query) {
        if (q.getKey().equals("_heidi_page")) {
            last_query.remove(q);
        }
    }
    last_query.add(new SearchQuery(pagefield, String.valueOf(page)));
    return search(last_query);
}
Also used : SearchQuery(de.geeksfactory.opacclient.searchfields.SearchQuery) TextSearchField(de.geeksfactory.opacclient.searchfields.TextSearchField)

Example 20 with SearchQuery

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

Aggregations

SearchQuery (de.geeksfactory.opacclient.searchfields.SearchQuery)21 ArrayList (java.util.ArrayList)16 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)11 NameValuePair (org.apache.http.NameValuePair)9 TextSearchField (de.geeksfactory.opacclient.searchfields.TextSearchField)8 DropdownSearchField (de.geeksfactory.opacclient.searchfields.DropdownSearchField)6 SearchField (de.geeksfactory.opacclient.searchfields.SearchField)6 Element (org.jsoup.nodes.Element)4 SearchRequestResult (de.geeksfactory.opacclient.objects.SearchRequestResult)3 BarcodeSearchField (de.geeksfactory.opacclient.searchfields.BarcodeSearchField)3 Document (org.jsoup.nodes.Document)3 OpacErrorException (de.geeksfactory.opacclient.apis.OpacApi.OpacErrorException)2 SearchResult (de.geeksfactory.opacclient.objects.SearchResult)2 CheckboxSearchField (de.geeksfactory.opacclient.searchfields.CheckboxSearchField)2 JsonSearchFieldDataSource (de.geeksfactory.opacclient.storage.JsonSearchFieldDataSource)2 JSONObject (org.json.JSONObject)2 SuppressLint (android.annotation.SuppressLint)1 PendingIntent (android.app.PendingIntent)1 Intent (android.content.Intent)1 SharedPreferences (android.content.SharedPreferences)1