use of de.geeksfactory.opacclient.searchfields.DropdownSearchField in project opacclient by opacapp.
the class Open method parseSearchFields.
@Override
public List<SearchField> parseSearchFields() throws IOException, OpacErrorException, JSONException {
String url = opac_url + "/" + data.getJSONObject("urls").getString("advanced_search") + NO_MOBILE;
Document doc = Jsoup.parse(httpGet(url, getDefaultEncoding()));
if (doc.select("[id$=LblErrorMsg]").size() > 0 && doc.select("[id$=ContentPane] input").size() == 0) {
throw new OpacErrorException(doc.select("[id$=LblErrorMsg]").text());
}
Element module = doc.select(".ModOPENExtendedSearchModuleC").first();
List<SearchField> fields = new ArrayList<>();
JSONObject selectable = new JSONObject();
selectable.put("selectable", true);
JSONObject notSelectable = new JSONObject();
notSelectable.put("selectable", false);
// Selectable search criteria
Elements options = module.select("select[id$=FirstSearchField] option");
for (Element option : options) {
TextSearchField field = new TextSearchField();
field.setId(option.val());
field.setDisplayName(option.text());
field.setData(selectable);
fields.add(field);
}
// More criteria
Element moreHeader = null;
if (module.select("table").size() == 1) {
moreHeader = module.select("span[id$=LblMoreCriterias]").parents().select("tr").first();
} else {
// Newer OPEN, e.g. Erlangen
moreHeader = module.select("span[id$=LblMoreCriterias]").first();
}
if (moreHeader != null) {
Elements siblings = moreHeader.siblingElements();
int startIndex = moreHeader.elementSiblingIndex();
for (int i = startIndex; i < siblings.size(); i++) {
Element tr = siblings.get(i);
if (tr.select("input, select").size() == 0)
continue;
if (tr.select("input[type=text]").size() == 1) {
Element input = tr.select("input[type=text]").first();
TextSearchField field = new TextSearchField();
field.setId(input.attr("name"));
field.setDisplayName(tr.select("span[id*=Lbl]").first().text());
field.setData(notSelectable);
if (tr.text().contains("nur Ziffern"))
field.setNumber(true);
fields.add(field);
} else if (tr.select("input[type=text]").size() == 2) {
Element input1 = tr.select("input[type=text]").get(0);
Element input2 = tr.select("input[type=text]").get(1);
TextSearchField field1 = new TextSearchField();
field1.setId(input1.attr("name"));
field1.setDisplayName(tr.select("span[id*=Lbl]").first().text());
field1.setData(notSelectable);
if (tr.text().contains("nur Ziffern"))
field1.setNumber(true);
fields.add(field1);
TextSearchField field2 = new TextSearchField();
field2.setId(input2.attr("name"));
field2.setDisplayName(tr.select("span[id*=Lbl]").first().text());
field2.setData(notSelectable);
field2.setHalfWidth(true);
if (tr.text().contains("nur Ziffern"))
field2.setNumber(true);
fields.add(field2);
} else if (tr.select("select").size() == 1) {
Element select = tr.select("select").first();
DropdownSearchField dropdown = new DropdownSearchField();
dropdown.setId(select.attr("name"));
dropdown.setDisplayName(tr.select("span[id*=Lbl]").first().text());
List<DropdownSearchField.Option> values = new ArrayList<>();
for (Element option : select.select("option")) {
DropdownSearchField.Option opt = new DropdownSearchField.Option(option.val(), option.text());
values.add(opt);
}
dropdown.setDropdownValues(values);
fields.add(dropdown);
} else if (tr.select("input[type=checkbox]").size() == 1) {
Element checkbox = tr.select("input[type=checkbox]").first();
CheckboxSearchField field = new CheckboxSearchField();
field.setId(checkbox.attr("name"));
field.setDisplayName(tr.select("span[id*=Lbl]").first().text());
fields.add(field);
}
}
}
return fields;
}
use of de.geeksfactory.opacclient.searchfields.DropdownSearchField in project opacclient by opacapp.
the class Primo method parseSearchFields.
@Override
public List<SearchField> parseSearchFields() throws IOException, OpacErrorException, JSONException {
start();
String html = httpGet(opac_url + "/action/search.do?mode=Advanced&ct=AdvancedSearch&vid=" + vid, getDefaultEncoding());
Document doc = Jsoup.parse(html);
List<SearchField> fields = new ArrayList<>();
if (doc.select("select#exlidInput_scope_1").size() < 1) {
throw new NotReachableException();
}
Elements options = doc.select("select#exlidInput_scope_1").first().select("option");
for (Element option : options) {
TextSearchField field = new TextSearchField();
field.setDisplayName(option.text());
field.setId(option.val());
field.setHint("");
field.setData(new JSONObject());
field.getData().put("meaning", option.val());
fields.add(field);
}
if (fields.size() == 0) {
// Weird JavaScript, e.g. view-source:http://vopac.nlg.gr/Search/Advanced
Pattern pattern_key = Pattern.compile("searchFields\\[\"([^\"]+)\"\\] = \"([^\"]+)\";");
for (Element script : doc.select("script")) {
if (!script.html().contains("searchFields"))
continue;
for (String line : script.html().split("\n")) {
Matcher matcher = pattern_key.matcher(line);
if (matcher.find()) {
TextSearchField field = new TextSearchField();
field.setDisplayName(matcher.group(2));
field.setId(matcher.group(1));
field.setHint("");
field.setData(new JSONObject());
field.getData().put("meaning", field.getId());
fields.add(field);
}
}
}
}
Elements selects = doc.select("#exlidInput_mediaType_, #exlidInput_publicationDate_, " + "#exlidInput_language_, #exlidSearchIn");
for (Element select : selects) {
DropdownSearchField field = new DropdownSearchField();
if (select.parent().select("label").size() > 0) {
field.setDisplayName(select.parent().select("label").first().text());
} else {
continue;
}
field.setId("#" + select.attr("id"));
for (Element option : select.select("option")) {
if (option.val().equals("all_items")) {
field.addDropdownValue(0, option.val(), option.text());
} else {
field.addDropdownValue(option.val(), option.text());
}
}
field.setData(new JSONObject());
field.getData().put("meaning", field.getId());
fields.add(field);
}
return fields;
}
use of de.geeksfactory.opacclient.searchfields.DropdownSearchField in project opacclient by opacapp.
the class Bibliotheca method parseSearchFields.
@Override
public List<SearchField> parseSearchFields() throws IOException, JSONException {
if (!initialised) {
start();
}
List<SearchField> fields = new ArrayList<>();
// Read branches and media types
FormBody.Builder formData = new FormBody.Builder(Charset.forName(getDefaultEncoding()));
formData.add("link_profis.x", "0");
formData.add("link_profis.y", "1");
String html = httpPost(opac_url + "/index.asp", formData.build(), getDefaultEncoding());
Document doc = Jsoup.parse(html);
Elements fieldElems = doc.select(".suchfeldinhalt");
for (Element fieldElem : fieldElems) {
String name = fieldElem.select(".suchfeld_inhalt_titel label").text();
String hint = "";
if (fieldElem.select(".suchfeld_inhalt_input").size() > 0) {
List<TextNode> textNodes = fieldElem.select(".suchfeld_inhalt_input").first().textNodes();
if (textNodes.size() > 0) {
for (TextNode node : textNodes) {
String text = node.getWholeText().replace("\n", "");
if (!text.equals("")) {
hint = node.getWholeText().replace("\n", "");
break;
}
}
}
}
Elements inputs = fieldElem.select(".suchfeld_inhalt_input input[type=text], " + ".suchfeld_inhalt_input select");
if (inputs.size() == 1) {
SearchField field = createSearchField(name, hint, inputs.get(0));
Elements radios = fieldElem.select("input[type=radio]");
if (field instanceof TextSearchField && radios.size() > 0) {
TextSearchField tf = (TextSearchField) field;
if (radios.get(0).attr("value").equals("stich")) {
tf.setFreeSearch(true);
if (fieldElem.select("label[for=stichtit_sich]").size() > 0) {
tf.setHint(fieldElem.select("label[for=stichtit_sich]").text().trim());
}
JSONObject addData = new JSONObject();
JSONObject params = new JSONObject();
params.put("stichtit", "stich");
addData.put("additional_params", params);
tf.setData(addData);
}
if (radios.size() == 2 && radios.get(1).attr("value").equals("titel")) {
TextSearchField tf2 = new TextSearchField();
tf2.setId(tf.getId());
if (fieldElem.select("label[for=stichtit_titel]").size() > 0) {
tf2.setDisplayName(fieldElem.select("label[for=stichtit_titel]").text().trim());
}
JSONObject addData = new JSONObject();
JSONObject params = new JSONObject();
params.put("stichtit", "titel");
addData.put("additional_params", params);
tf2.setData(addData);
fields.add(tf2);
}
}
fields.add(field);
} else if (inputs.size() == 2 && inputs.select("input[type=text]").size() == 2) {
// Two text fields, e.g. year from/to or two keywords
fields.add(createSearchField(name, hint, inputs.get(0)));
TextSearchField secondField = (TextSearchField) createSearchField(name, hint, inputs.get(1));
secondField.setHalfWidth(true);
fields.add(secondField);
} else if (inputs.size() == 2 && inputs.get(0).tagName().equals("select") && inputs.get(1).tagName().equals("input") && inputs.get(0).attr("name").equals("feld1")) {
// Break it down into single text fields.
for (Element option : inputs.get(0).select("option")) {
TextSearchField field = new TextSearchField();
field.setHint(hint);
field.setDisplayName(option.text());
field.setId(inputs.get(1).attr("name") + "$" + option.attr("value"));
JSONObject data = new JSONObject();
JSONObject params = new JSONObject();
params.put(inputs.get(0).attr("name"), option.attr("value"));
data.put("additional_params", params);
field.setData(data);
fields.add(field);
}
}
}
if (fields.size() > 0) {
DropdownSearchField orderField = new DropdownSearchField("orderselect", stringProvider.getString(StringProvider.ORDER), false, null);
orderField.addDropdownValue("1", stringProvider.getString(StringProvider.ORDER_DEFAULT));
orderField.addDropdownValue("2:desc", stringProvider.getString(StringProvider.ORDER_YEAR_DESC));
orderField.addDropdownValue("2:asc", stringProvider.getString(StringProvider.ORDER_YEAR_ASC));
orderField.addDropdownValue("3:desc", stringProvider.getString(StringProvider.ORDER_CATEGORY_DESC));
orderField.addDropdownValue("3:asc", stringProvider.getString(StringProvider.ORDER_CATEGORY_ASC));
orderField.setMeaning(Meaning.ORDER);
fields.add(orderField);
}
return fields;
}
use of de.geeksfactory.opacclient.searchfields.DropdownSearchField in project opacclient by opacapp.
the class Bibliotheca method createSearchField.
private SearchField createSearchField(String name, String hint, Element input) {
if (input.tagName().equals("input") && input.attr("type").equals("text")) {
TextSearchField field = new TextSearchField();
field.setDisplayName(name);
field.setHint(hint);
field.setId(input.attr("name"));
return field;
} else if (input.tagName().equals("select")) {
DropdownSearchField field = new DropdownSearchField();
field.setDisplayName(name);
field.setId(input.attr("name"));
for (Element option : input.select("option")) {
field.addDropdownValue(option.attr("value"), option.text());
}
return field;
} else {
return null;
}
}
use of de.geeksfactory.opacclient.searchfields.DropdownSearchField in project opacclient by opacapp.
the class VuFind method parseSearchFields.
@Override
public List<SearchField> parseSearchFields() throws IOException, OpacErrorException, JSONException {
start();
String html = httpGet(opac_url + "/Search/Advanced?mylang = " + languageCode, getDefaultEncoding());
Document doc = Jsoup.parse(html);
List<SearchField> fields = new ArrayList<>();
Elements options = doc.select("select#search_type0_0 option");
for (Element option : options) {
TextSearchField field = new TextSearchField();
field.setDisplayName(option.text());
field.setId(option.val());
field.setHint("");
field.setData(new JSONObject());
field.getData().put("meaning", option.val());
fields.add(field);
}
if (fields.size() == 0) {
// Weird JavaScript, e.g. view-source:http://vopac.nlg.gr/Search/Advanced
Pattern pattern_key = Pattern.compile("searchFields\\[\"([^\"]+)\"\\] = \"([^\"]+)\";");
for (Element script : doc.select("script")) {
if (!script.html().contains("searchFields"))
continue;
for (String line : script.html().split("\n")) {
Matcher matcher = pattern_key.matcher(line);
if (matcher.find()) {
TextSearchField field = new TextSearchField();
field.setDisplayName(matcher.group(2));
field.setId(matcher.group(1));
field.setHint("");
field.setData(new JSONObject());
field.getData().put("meaning", field.getId());
fields.add(field);
}
}
}
}
Elements selects = doc.select("select");
for (Element select : selects) {
if (!select.attr("name").equals("filter[]"))
continue;
DropdownSearchField field = new DropdownSearchField();
if (select.parent().select("label").size() > 0) {
field.setDisplayName(select.parent().select("label").first().text());
} else if (select.parent().parent().select("label").size() == 1) {
field.setDisplayName(select.parent().parent().select("label").first().text());
}
field.setId(select.attr("name") + select.attr("id"));
String meaning = select.attr("id");
field.addDropdownValue("", "");
for (Element option : select.select("option")) {
if (option.val().contains(":")) {
meaning = option.val().split(":")[0];
}
field.addDropdownValue(option.val(), option.text());
}
field.setData(new JSONObject());
field.getData().put("meaning", meaning);
fields.add(field);
}
return fields;
}
Aggregations