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;
}
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);
}
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;
}
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);
}
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);
}
Aggregations