Search in sources :

Example 6 with DropdownSearchField

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

the class Pica method parseSearchFields.

@Override
public List<SearchField> parseSearchFields() throws IOException, JSONException {
    if (!initialised) {
        start();
    }
    String html = httpGet(opac_url + "/LNG=" + getLang() + "/DB=" + db + "/ADVANCED_SEARCHFILTER", getDefaultEncoding());
    Document doc = Jsoup.parse(html);
    List<SearchField> fields = new ArrayList<>();
    Elements options = doc.select("select[name=IKT0] option");
    for (Element option : options) {
        TextSearchField field = new TextSearchField();
        field.setDisplayName(option.text());
        field.setId(option.attr("value"));
        field.setHint("");
        field.setData(new JSONObject("{\"ADI\": false}"));
        Pattern pattern = Pattern.compile("(?: --- )?(\\[X?[A-Za-z]{2,3}:?\\]|\\(X?[A-Za-z]{2,3}:?\\))");
        Matcher matcher = pattern.matcher(field.getDisplayName());
        if (matcher.find()) {
            field.getData().put("meaning", matcher.group(1).replace(":", "").toUpperCase());
            field.setDisplayName(matcher.replaceFirst("").trim());
        }
        fields.add(field);
    }
    Elements sort = doc.select("select[name=SRT]");
    if (sort.size() > 0) {
        DropdownSearchField field = new DropdownSearchField();
        field.setDisplayName(sort.first().parent().parent().select(".longval").first().text());
        field.setId("SRT");
        for (Element option : sort.select("option")) {
            field.addDropdownValue(option.attr("value"), option.text());
        }
        fields.add(field);
    }
    for (Element input : doc.select("input[type=text][name^=ADI]")) {
        TextSearchField field = new TextSearchField();
        field.setDisplayName(input.parent().parent().select(".longkey").text());
        field.setId(input.attr("name"));
        field.setHint(input.parent().select("span").text());
        field.setData(new JSONObject("{\"ADI\": true}"));
        fields.add(field);
    }
    for (Element dropdown : doc.select("select[name^=ADI]")) {
        DropdownSearchField field = new DropdownSearchField();
        field.setDisplayName(dropdown.parent().parent().select(".longkey").text());
        field.setId(dropdown.attr("name"));
        for (Element option : dropdown.select("option")) {
            field.addDropdownValue(option.attr("value"), option.text());
        }
        fields.add(field);
    }
    Elements fuzzy = doc.select("input[name=FUZZY]");
    if (fuzzy.size() > 0) {
        CheckboxSearchField field = new CheckboxSearchField();
        field.setDisplayName(fuzzy.first().parent().parent().select(".longkey").first().text());
        field.setId("FUZZY");
        fields.add(field);
    }
    Elements mediatypes = doc.select("input[name=ADI_MAT]");
    if (mediatypes.size() > 0) {
        DropdownSearchField field = new DropdownSearchField();
        field.setDisplayName("Materialart");
        field.setId("ADI_MAT");
        field.addDropdownValue("", "Alle");
        for (Element mt : mediatypes) {
            field.addDropdownValue(mt.attr("value"), mt.parent().nextElementSibling().text().replace("\u00a0", ""));
        }
        fields.add(field);
    }
    return fields;
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) 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) 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) JSONObject(org.json.JSONObject) CheckboxSearchField(de.geeksfactory.opacclient.searchfields.CheckboxSearchField)

Example 7 with DropdownSearchField

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

the class SISIS method search.

@Override
public SearchRequestResult search(List<SearchQuery> query) throws IOException, OpacErrorException, JSONException {
    List<NameValuePair> params = new ArrayList<>();
    int index = 0;
    int restrictionIndex = 0;
    start();
    params.add(new BasicNameValuePair("methodToCall", "submit"));
    params.add(new BasicNameValuePair("CSId", CSId));
    params.add(new BasicNameValuePair("methodToCallParameter", "submitSearch"));
    for (SearchQuery entry : query) {
        if (entry.getValue().equals("")) {
            continue;
        }
        if (entry.getSearchField() instanceof DropdownSearchField) {
            JSONObject data = entry.getSearchField().getData();
            if (data.optBoolean("restriction", false)) {
                params.add(new BasicNameValuePair("searchRestrictionID[" + restrictionIndex + "]", entry.getSearchField().getId()));
                params.add(new BasicNameValuePair("searchRestrictionValue1[" + restrictionIndex + "]", entry.getValue()));
                restrictionIndex++;
            } else {
                params.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
            }
        } else {
            if (index != 0) {
                params.add(new BasicNameValuePair("combinationOperator[" + index + "]", "AND"));
            }
            params.add(new BasicNameValuePair("searchCategories[" + index + "]", entry.getKey()));
            params.add(new BasicNameValuePair("searchString[" + index + "]", entry.getValue()));
            index++;
        }
    }
    if (index == 0) {
        throw new OpacErrorException(stringProvider.getString(StringProvider.NO_CRITERIA_INPUT));
    }
    if (index > 4) {
        throw new OpacErrorException(stringProvider.getQuantityString(StringProvider.LIMITED_NUM_OF_CRITERIA, 4, 4));
    }
    params.add(new BasicNameValuePair("submitSearch", "Suchen"));
    params.add(new BasicNameValuePair("callingPage", "searchParameters"));
    params.add(new BasicNameValuePair("numberOfHits", "10"));
    String html = httpGet(opac_url + "/search.do?" + URLEncodedUtils.format(params, "UTF-8"), ENCODING);
    return parse_search_wrapped(html, 1);
}
Also used : SearchQuery(de.geeksfactory.opacclient.searchfields.SearchQuery) NameValuePair(org.apache.http.NameValuePair) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) JSONObject(org.json.JSONObject) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) ArrayList(java.util.ArrayList) DropdownSearchField(de.geeksfactory.opacclient.searchfields.DropdownSearchField)

Example 8 with DropdownSearchField

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

the class TouchPoint method parseSearchFields.

public List<SearchField> parseSearchFields() throws IOException, JSONException {
    if (!initialised) {
        start();
    }
    String html = httpGet(opac_url + "/search.do?methodToCall=switchSearchPage&SearchType=2", ENCODING);
    Document doc = Jsoup.parse(html);
    List<SearchField> fields = new ArrayList<>();
    Elements options = doc.select("select[name=searchCategories[0]] option");
    for (Element option : options) {
        TextSearchField field = new TextSearchField();
        field.setDisplayName(option.text());
        field.setId(option.attr("value"));
        field.setHint("");
        fields.add(field);
    }
    for (Element dropdown : doc.select(".accordion-body select")) {
        parseDropdown(dropdown, fields);
    }
    if (doc.select(".selectDatabase").size() > 0) {
        DropdownSearchField dropdown = new DropdownSearchField();
        dropdown.setId("_database");
        for (Element option : doc.select(".selectDatabase")) {
            String label = option.parent().ownText().trim();
            if (label.equals("")) {
                for (Element a : option.siblingElements()) {
                    label += a.ownText().trim();
                }
            }
            dropdown.addDropdownValue(option.attr("name") + "=" + option.attr("value"), label.trim());
        }
        dropdown.setDisplayName(doc.select(".dbselection h3").first().text().trim());
        fields.add(dropdown);
    }
    return fields;
}
Also used : SearchField(de.geeksfactory.opacclient.searchfields.SearchField) TextSearchField(de.geeksfactory.opacclient.searchfields.TextSearchField) DropdownSearchField(de.geeksfactory.opacclient.searchfields.DropdownSearchField) 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 9 with DropdownSearchField

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

the class TouchPoint method search.

@Override
public SearchRequestResult search(List<SearchQuery> query) throws IOException, OpacErrorException, JSONException {
    List<NameValuePair> params = new ArrayList<>();
    boolean selectDatabase = false;
    int index = 0;
    start();
    params.add(new BasicNameValuePair("methodToCall", "submitButtonCall"));
    params.add(new BasicNameValuePair("CSId", CSId));
    params.add(new BasicNameValuePair("refine", "false"));
    params.add(new BasicNameValuePair("numberOfHits", "10"));
    for (SearchQuery entry : query) {
        if (entry.getValue().equals("")) {
            continue;
        }
        if (entry.getSearchField() instanceof DropdownSearchField) {
            if (entry.getKey().equals("_database")) {
                String[] parts = entry.getValue().split("=", 2);
                params.add(new BasicNameValuePair(parts[0], parts[1]));
                selectDatabase = true;
            } else {
                params.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
            }
        } else {
            if (index != 0) {
                params.add(new BasicNameValuePair("combinationOperator[" + index + "]", "AND"));
            }
            params.add(new BasicNameValuePair("searchCategories[" + index + "]", entry.getKey()));
            params.add(new BasicNameValuePair("searchString[" + index + "]", entry.getValue()));
            index++;
        }
    }
    if (index == 0) {
        throw new OpacErrorException(stringProvider.getString(StringProvider.NO_CRITERIA_INPUT));
    }
    if (index > 4) {
        throw new OpacErrorException(stringProvider.getQuantityString(StringProvider.LIMITED_NUM_OF_CRITERIA, 4, 4));
    }
    if (selectDatabase) {
        List<NameValuePair> selectParams = new ArrayList<>();
        selectParams.addAll(params);
        selectParams.add(new BasicNameValuePair("methodToCallParameter", "selectDatabase"));
        httpGet(opac_url + "/search.do?" + URLEncodedUtils.format(selectParams, "UTF-8"), ENCODING);
    }
    params.add(new BasicNameValuePair("submitButtonCall_submitSearch", "Suchen"));
    params.add(new BasicNameValuePair("methodToCallParameter", "submitSearch"));
    String html = httpGet(opac_url + "/search.do?" + URLEncodedUtils.format(params, "UTF-8"), ENCODING);
    return parse_search_wrapped(html, 1);
}
Also used : SearchQuery(de.geeksfactory.opacclient.searchfields.SearchQuery) NameValuePair(org.apache.http.NameValuePair) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) ArrayList(java.util.ArrayList) DropdownSearchField(de.geeksfactory.opacclient.searchfields.DropdownSearchField)

Example 10 with DropdownSearchField

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

the class TouchPoint method parseDropdown.

private void parseDropdown(Element dropdownElement, List<SearchField> fields) {
    Elements options = dropdownElement.select("option");
    DropdownSearchField dropdown = new DropdownSearchField();
    dropdown.setId(dropdownElement.attr("name"));
    // Some fields make no sense or are not supported in the app
    if (dropdown.getId().equals("numberOfHits") || dropdown.getId().equals("timeOut") || dropdown.getId().equals("rememberList")) {
        return;
    }
    for (Element option : options) {
        dropdown.addDropdownValue(option.attr("value"), option.text());
    }
    dropdown.setDisplayName(dropdownElement.parent().select("label").text());
    fields.add(dropdown);
}
Also used : Element(org.jsoup.nodes.Element) Elements(org.jsoup.select.Elements) DropdownSearchField(de.geeksfactory.opacclient.searchfields.DropdownSearchField)

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