use of de.geeksfactory.opacclient.objects.Detail in project opacclient by opacapp.
the class SearchResultDetailFragment method onOptionsItemSelected.
@Override
public boolean onOptionsItemSelected(MenuItem item) {
final String bib = app.getLibrary().getIdent();
if (item.getItemId() == R.id.action_reservation) {
reservationStart();
return true;
} else if (item.getItemId() == R.id.action_lendebook) {
bookingStart();
return true;
} else if (item.getItemId() == R.id.action_tocollection) {
if (getActivity().getIntent().getBooleanExtra("from_collection", false)) {
getActivity().finish();
} else {
Intent intent = new Intent(getActivity(), SearchResultDetailActivity.class);
intent.putExtra(SearchResultDetailFragment.ARG_ITEM_ID, getItem().getCollectionId());
startActivity(intent);
getActivity().finish();
}
return true;
} else if (item.getItemId() == R.id.action_share) {
if (getItem() == null) {
Toast toast = Toast.makeText(getActivity(), getString(R.string.share_wait), Toast.LENGTH_SHORT);
toast.show();
} else {
final String title = getItem().getTitle();
final String id = getItem().getId();
final CharSequence[] items = { getString(R.string.share_link), getString(R.string.share_details) };
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle(R.string.share_dialog_select);
builder.setItems(items, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int di) {
OpacApi api = null;
try {
api = app.getApi();
} catch (OpacClient.LibraryRemovedException e) {
return;
}
if (di == 0) {
// Share link
Intent intent = new Intent(android.content.Intent.ACTION_SEND);
intent.setType("text/plain");
intent.addFlags(CompatibilityUtils.getNewDocumentIntentFlag());
// Add data to the intent, the receiving app will
// decide
// what to do with it.
intent.putExtra(Intent.EXTRA_SUBJECT, title);
String t = title;
try {
t = java.net.URLEncoder.encode(t, "UTF-8");
} catch (UnsupportedEncodingException e) {
}
String shareUrl = api.getShareUrl(id, t);
if (shareUrl != null) {
intent.putExtra(Intent.EXTRA_TEXT, shareUrl);
startActivity(Intent.createChooser(intent, getResources().getString(R.string.share)));
} else {
Toast toast = Toast.makeText(getActivity(), getString(R.string.share_notsupported), Toast.LENGTH_SHORT);
toast.show();
}
} else {
// Share details
Intent intent = new Intent(android.content.Intent.ACTION_SEND);
intent.setType("text/plain");
intent.addFlags(CompatibilityUtils.getNewDocumentIntentFlag());
// Add data to the intent, the receiving app will
// decide
// what to do with it.
intent.putExtra(Intent.EXTRA_SUBJECT, title);
String t = title;
try {
t = t != null ? java.net.URLEncoder.encode(t, "UTF-8") : "";
} catch (UnsupportedEncodingException e) {
}
String text = title + "\n\n";
for (Detail detail : getItem().getDetails()) {
String colon = "";
if (!detail.getDesc().endsWith(":")) {
colon = ":";
}
text += detail.getDesc() + colon + "\n" + detail.getContent() + "\n\n";
}
List<Copy> copies = getItem().getCopies();
if (copies.size() > 0) {
text += getString(R.string.copies_head) + ":\n\n";
}
for (Copy copy : copies) {
String labelSeparator = ": ";
String infoTypeSeparator = "\n";
String branch = copy.getBranch();
String branchTxt = "";
if (branch != null && !branch.isEmpty()) {
branchTxt += getString(R.string.branch) + labelSeparator + branch + infoTypeSeparator;
}
String dept = copy.getDepartment();
String deptTxt = "";
if (dept != null && !dept.isEmpty()) {
deptTxt += getString(R.string.department) + labelSeparator + dept + infoTypeSeparator;
}
String loc = copy.getLocation();
String locTxt = "";
if (loc != null && !loc.isEmpty()) {
locTxt += getString(R.string.location) + labelSeparator + loc + infoTypeSeparator;
}
String shelfMark = copy.getShelfmark();
String shelfMarkTxt = "";
if (shelfMark != null && !shelfMark.isEmpty()) {
shelfMarkTxt += getString(R.string.shelfmark) + labelSeparator + shelfMark + infoTypeSeparator;
}
String status = copy.getStatus();
String statusTxt = "";
if (status != null && !status.isEmpty()) {
statusTxt += getString(R.string.status) + labelSeparator + status + infoTypeSeparator;
}
String res = copy.getReservations();
String resTxt = "";
if (res != null && !res.isEmpty()) {
resTxt += getString(R.string.reservations) + labelSeparator + res + infoTypeSeparator;
}
String url = copy.getUrl();
String urlTxt = "";
if (url != null && !url.isEmpty()) {
urlTxt += getString(R.string.url) + labelSeparator + url + infoTypeSeparator;
}
LocalDate retDate = copy.getReturnDate();
String retDateTxt = "";
if (retDate != null) {
retDateTxt += getString(R.string.return_date) + labelSeparator + DateTimeFormat.shortDate().print(copy.getReturnDate()) + infoTypeSeparator;
}
text += branchTxt + deptTxt + locTxt + shelfMarkTxt + statusTxt + resTxt + urlTxt + retDateTxt + "\n";
}
String shareUrl = api.getShareUrl(id, t);
if (shareUrl != null) {
text += shareUrl;
}
intent.putExtra(Intent.EXTRA_TEXT, text);
startActivity(Intent.createChooser(intent, getResources().getString(R.string.share)));
}
}
});
AlertDialog alert = builder.create();
alert.show();
}
return true;
} else if (item.getItemId() == R.id.action_star) {
StarDataSource star = new StarDataSource(getActivity());
if (getItem() == null) {
Toast toast = Toast.makeText(getActivity(), getString(R.string.star_wait), Toast.LENGTH_SHORT);
toast.show();
} else if (getItem().getId() == null || getItem().getId().equals("")) {
final String title = getItem().getTitle();
if (title == null || title.equals("")) {
Toast toast = Toast.makeText(getActivity(), getString(R.string.star_unsupported), Toast.LENGTH_LONG);
toast.show();
} else {
if (star.isStarredTitle(bib, title)) {
star.remove(star.getItemByTitle(bib, title));
item.setIcon(R.drawable.ic_star_0_white_24dp);
} else {
star.star(null, title, bib, getItem().getMediaType());
Toast toast = Toast.makeText(getActivity(), getString(R.string.starred), Toast.LENGTH_SHORT);
toast.show();
item.setIcon(R.drawable.ic_star_1_white_24dp);
}
}
} else {
final String title = getItem().getTitle();
final String id = getItem().getId();
if (star.isStarred(bib, id)) {
star.remove(star.getItem(bib, id));
item.setIcon(R.drawable.ic_star_0_white_24dp);
} else {
star.star(id, title, bib, getItem().getMediaType());
Toast toast = Toast.makeText(getActivity(), getString(R.string.starred), Toast.LENGTH_SHORT);
toast.show();
item.setIcon(R.drawable.ic_star_1_white_24dp);
}
}
return true;
} else if (item.getItemId() == R.id.action_print) {
if (getItem() == null) {
Toast toast = Toast.makeText(getActivity(), getString(R.string.print_wait), Toast.LENGTH_SHORT);
toast.show();
} else {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
print();
}
}
return true;
} else {
return super.onOptionsItemSelected(item);
}
}
use of de.geeksfactory.opacclient.objects.Detail in project opacclient by opacapp.
the class Bibliotheca method parseResult.
static DetailedItem parseResult(String html, JSONObject data) {
Document doc = Jsoup.parse(html);
doc.setBaseUri(data.optString("baseurl"));
DetailedItem result = new DetailedItem();
if (doc.select(".detail_cover img").size() == 1) {
result.setCover(doc.select(".detail_cover img").get(0).attr("src"));
}
result.setTitle(doc.select(".detail_titel").text());
Elements detailtrs = doc.select(".detailzeile table tr");
for (int i = 0; i < detailtrs.size(); i++) {
Element tr = detailtrs.get(i);
if (tr.child(0).hasClass("detail_feld")) {
String title = tr.child(0).text();
String content = tr.child(1).text();
if (title.equals("Gesamtwerk:") || title.equals("Erschienen in:")) {
try {
if (tr.child(1).select("a").size() > 0) {
Element link = tr.child(1).select("a").first();
List<NameValuePair> query = URLEncodedUtils.parse(new URI(link.absUrl("href")), "UTF-8");
for (NameValuePair q : query) {
if (q.getName().equals("MedienNr")) {
result.setCollectionId(q.getValue());
}
}
}
} catch (URISyntaxException e) {
}
} else {
if (content.contains("hier klicken") && tr.child(1).select("a").size() > 0) {
content += " " + tr.child(1).select("a").first().attr("href");
}
result.addDetail(new Detail(title, content));
}
}
}
Elements detailcenterlinks = doc.select(".detailzeile_center a.detail_link");
for (int i = 0; i < detailcenterlinks.size(); i++) {
Element a = detailcenterlinks.get(i);
result.addDetail(new Detail(a.text().trim(), a.absUrl("href")));
}
try {
JSONObject copymap = new JSONObject();
if (data.has("copiestable")) {
copymap = data.getJSONObject("copiestable");
} else {
Elements ths = doc.select(".exemplartab .exemplarmenubar th");
for (int i = 0; i < ths.size(); i++) {
Element th = ths.get(i);
String head = th.text().trim();
if (head.equals("Zweigstelle")) {
copymap.put("branch", i);
} else if (head.equals("Abteilung")) {
copymap.put("department", i);
} else if (head.equals("Bereich") || head.equals("Standort")) {
copymap.put("location", i);
} else if (head.equals("Signatur")) {
copymap.put("signature", i);
} else if (head.equals("Barcode") || head.equals("Medien-Nummer")) {
copymap.put("barcode", i);
} else if (head.equals("Status")) {
copymap.put("status", i);
} else if (head.equals("Frist") || head.matches("Verf.+gbar")) {
copymap.put("returndate", i);
} else if (head.equals("Vorbestellungen") || head.equals("Reservierungen")) {
copymap.put("reservations", i);
}
}
}
Elements exemplartrs = doc.select(".exemplartab .tabExemplar, .exemplartab .tabExemplar_");
DateTimeFormatter fmt = DateTimeFormat.forPattern("dd.MM.yyyy").withLocale(Locale.GERMAN);
for (int i = 0; i < exemplartrs.size(); i++) {
Element tr = exemplartrs.get(i);
Copy copy = new Copy();
Iterator<?> keys = copymap.keys();
while (keys.hasNext()) {
String key = (String) keys.next();
int index;
try {
index = copymap.has(key) ? copymap.getInt(key) : -1;
} catch (JSONException e1) {
index = -1;
}
if (index >= 0) {
try {
copy.set(key, tr.child(index).text(), fmt);
} catch (IllegalArgumentException e) {
e.printStackTrace();
}
}
}
result.addCopy(copy);
}
} catch (Exception e) {
e.printStackTrace();
}
try {
Elements bandtrs = doc.select("table .tabBand a");
for (int i = 0; i < bandtrs.size(); i++) {
Element tr = bandtrs.get(i);
Volume volume = new Volume();
volume.setId(tr.attr("href").split("=")[1]);
volume.setTitle(tr.text());
result.addVolume(volume);
}
} catch (Exception e) {
e.printStackTrace();
}
if (doc.select(".detail_vorbest a").size() == 1) {
result.setReservable(true);
result.setReservation_info(doc.select(".detail_vorbest a").attr("href"));
}
return result;
}
use of de.geeksfactory.opacclient.objects.Detail in project opacclient by opacapp.
the class WebOpacNet method parse_detail.
private DetailedItem parse_detail(String text) throws OpacErrorException {
try {
DetailedItem result = new DetailedItem();
JSONObject json = new JSONObject(text);
result.setTitle(json.getString("titel"));
result.setCover(json.getString("imageurl"));
result.setId(json.getString("medid"));
// Details
JSONArray info = json.getJSONArray("medium");
for (int i = 0; i < info.length(); i++) {
JSONObject detailJson = info.getJSONObject(i);
String name = detailJson.getString("bez");
String value = "";
JSONArray values = detailJson.getJSONArray("values");
for (int j = 0; j < values.length(); j++) {
JSONObject valJson = values.getJSONObject(j);
if (j != 0) {
value += ", ";
}
String content = valJson.getString("dval");
content = content.replaceAll("<span[^>]*>", "");
content = content.replaceAll("</span>", "");
value += content;
}
Detail detail = new Detail(name, value);
result.addDetail(detail);
}
// Copies
JSONArray copies = json.getJSONArray("exemplare");
for (int i = 0; i < copies.length(); i++) {
JSONObject copyJson = copies.getJSONObject(i);
Copy copy = new Copy();
JSONArray values = copyJson.getJSONArray("rows");
for (int j = 0; j < values.length(); j++) {
JSONObject valJson = values.getJSONObject(j);
String name = valJson.getString("bez");
String value = valJson.getJSONArray("values").getJSONObject(0).getString("dval");
if (!value.equals("")) {
switch(name) {
case "Exemplarstatus":
copy.setStatus(value);
break;
case "Signatur":
copy.setShelfmark(value);
break;
case "Standort":
copy.setLocation(value);
break;
case "Themenabteilung":
if (copy.getDepartment() != null) {
value = copy.getDepartment() + value;
}
copy.setDepartment(value);
break;
case "Themenbereich":
if (copy.getDepartment() != null) {
value = copy.getDepartment() + value;
}
copy.setDepartment(value);
break;
}
}
}
result.addCopy(copy);
}
return result;
} catch (JSONException e) {
e.printStackTrace();
throw new OpacErrorException(stringProvider.getFormattedString(StringProvider.INTERNAL_ERROR_WITH_DESCRIPTION, e.getMessage()));
}
}
use of de.geeksfactory.opacclient.objects.Detail in project opacclient by opacapp.
the class Littera method getResultById.
@Override
public DetailedItem getResultById(String id, String homebranch) throws IOException, OpacErrorException {
if (!initialised) {
start();
}
final String html = httpGet(getApiUrl() + "&view=detail&id=" + id, getDefaultEncoding());
final Document doc = Jsoup.parse(html);
final Element detailData = doc.select(".detailData").first();
final Element detailTable = detailData.select("table.titel").first();
final Element availabilityTable = doc.select(".bibliothek table").first();
final DetailedItem result = new DetailedItem();
final Copy copy = new Copy();
result.addCopy(copy);
result.setId(id);
result.setCover(getCover(doc));
result.setTitle(detailData.select("h3").first().text());
result.setMediaType(MEDIA_TYPES.get(getCellContent(detailTable, "Medienart|Type of media")));
copy.setStatus(getCellContent(availabilityTable, "Verfügbar|Available"));
copy.setReturnDate(parseCopyReturn(getCellContent(availabilityTable, "Exemplare verliehen|Copies lent")));
copy.setReservations(getCellContent(availabilityTable, "Reservierungen|Reservations"));
for (final Element tr : detailTable.select("tr")) {
final String desc = tr.child(0).text();
final String content = tr.child(1).text();
if (desc != null && !desc.trim().equals("")) {
result.addDetail(new Detail(desc, content));
} else if (!result.getDetails().isEmpty()) {
final Detail lastDetail = result.getDetails().get(result.getDetails().size() - 1);
lastDetail.setHtml(true);
lastDetail.setContent(lastDetail.getContent() + "\n" + content);
}
}
return result;
}
use of de.geeksfactory.opacclient.objects.Detail in project opacclient by opacapp.
the class Pica method parse_result.
protected DetailedItem parse_result(String html) {
Document doc = Jsoup.parse(html);
doc.setBaseUri(opac_url);
DetailedItem result = new DetailedItem();
for (Element a : doc.select("a[href*=PPN")) {
Map<String, String> hrefq = getQueryParamsFirst(a.absUrl("href"));
String ppn = hrefq.get("PPN");
result.setId(ppn);
break;
}
// GET COVER
if (doc.select("img[title=Titelbild]").size() > 0) {
result.setCover(doc.select("img[title=Titelbild]").first().absUrl("src"));
} else if (doc.select("td.preslabel:contains(ISBN) + td.presvalue").size() > 0) {
Element isbnElement = doc.select("td.preslabel:contains(ISBN) + td.presvalue").first();
String isbn = isbnElement.text().trim();
if (!isbn.equals("")) {
result.setCover(ISBNTools.getAmazonCoverURL(isbn, true));
}
}
// GET TITLE AND SUBTITLE
String titleAndSubtitle;
Element titleAndSubtitleElem = null;
String titleRegex = ".*(Titel|Aufsatz|Zeitschrift|Gesamttitel" + "|Title|Article|Periodical|Collective\\stitle" + "|Titre|Article|P.riodique|Titre\\sg.n.ral).*";
String selector = "td.preslabel:matches(" + titleRegex + ") + td.presvalue";
if (doc.select(selector).size() > 0) {
titleAndSubtitleElem = doc.select(selector).first();
titleAndSubtitle = titleAndSubtitleElem.text().trim();
int slashPosition = Math.min(titleAndSubtitle.indexOf("/"), titleAndSubtitle.indexOf(":"));
String title;
if (slashPosition > 0) {
title = titleAndSubtitle.substring(0, slashPosition).trim();
String subtitle = titleAndSubtitle.substring(slashPosition + 1).trim();
result.addDetail(new Detail(stringProvider.getString(StringProvider.SUBTITLE), subtitle));
} else {
title = titleAndSubtitle;
}
result.setTitle(title);
} else {
result.setTitle("");
}
// Details
int line = 0;
Elements lines = doc.select("td.preslabel + td.presvalue");
if (titleAndSubtitleElem != null) {
lines.remove(titleAndSubtitleElem);
}
for (Element element : lines) {
Element titleElem = element.firstElementSibling();
String detail = "";
if (element.select("div").size() > 1 && element.select("div").text().equals(element.text())) {
boolean first = true;
for (Element div : element.select("div")) {
if (!div.text().replace("\u00a0", " ").trim().equals("")) {
if (!first) {
detail += "\n" + div.text().replace("\u00a0", " ").trim();
} else {
detail += div.text().replace("\u00a0", " ").trim();
first = false;
}
}
}
} else {
detail = element.text().replace("\u00a0", " ").trim();
}
String title = titleElem.text().replace("\u00a0", " ").trim();
if (element.select("hr").size() > 0 || element.text().trim().equals("")) // after the separator we get the copies
{
break;
}
if (detail.length() == 0 && title.length() == 0) {
line++;
continue;
}
if (title.contains(":")) {
// remove colon
title = title.substring(0, title.indexOf(":"));
}
result.addDetail(new Detail(title, detail));
if (element.select("a").size() == 1 && !element.select("a").get(0).text().trim().equals("")) {
String url = element.select("a").first().absUrl("href");
if (!url.startsWith(opac_url)) {
result.addDetail(new Detail(stringProvider.getString(StringProvider.LINK), url));
}
}
line++;
}
// next line after separator
line++;
// Copies
Copy copy = new Copy();
String location = "";
// reservation info will be stored as JSON
JSONArray reservationInfo = new JSONArray();
while (line < lines.size()) {
Element element = lines.get(line);
if (element.select("hr").size() == 0 && !element.text().trim().equals("")) {
Element titleElem = element.firstElementSibling();
String detail = element.text().trim();
String title = titleElem.text().replace("\u00a0", " ").trim();
if (detail.length() == 0 && title.length() == 0) {
line++;
continue;
}
if (title.contains("Standort") || title.contains("Vorhanden in") || title.contains("Location")) {
location += detail;
} else if (title.contains("Sonderstandort")) {
location += " - " + detail;
} else if (title.contains("Systemstelle") || title.contains("Sachgebiete") || title.contains("Subject")) {
copy.setDepartment(detail);
} else if (title.contains("Fachnummer") || title.contains("locationnumber") || title.contains("Schlagwörter")) {
copy.setLocation(detail);
} else if (title.contains("Signatur") || title.contains("Shelf mark")) {
copy.setShelfmark(detail);
} else if (title.contains("Anmerkung")) {
location += " (" + detail + ")";
} else if (title.contains("Link")) {
result.addDetail(new Detail(title.replace(":", "").trim(), detail));
} else if (title.contains("Status") || title.contains("Ausleihinfo") || title.contains("Ausleihstatus") || title.contains("Request info")) {
// Find return date
Pattern pattern = Pattern.compile("(till|bis) (\\d{2}-\\d{2}-\\d{4})");
Matcher matcher = pattern.matcher(detail);
if (matcher.find()) {
DateTimeFormatter fmt = DateTimeFormat.forPattern("dd-MM-yyyy").withLocale(Locale.GERMAN);
try {
copy.setStatus(detail.substring(0, matcher.start() - 1).trim());
copy.setReturnDate(fmt.parseLocalDate(matcher.group(2)));
} catch (IllegalArgumentException e) {
e.printStackTrace();
copy.setStatus(detail);
}
} else {
copy.setStatus(detail);
}
// Get reservation info
if (element.select("a:has(img[src*=inline_arrow])").size() > 0) {
Element a = element.select("a:has(img[src*=inline_arrow])").first();
boolean multipleCopies = a.text().matches(".*(Exemplare|Volume list).*");
JSONObject reservation = new JSONObject();
try {
reservation.put("multi", multipleCopies);
reservation.put("link", _extract_url(a));
reservation.put("desc", location);
reservationInfo.put(reservation);
} catch (JSONException e1) {
e1.printStackTrace();
}
result.setReservable(true);
}
}
} else {
copy.setBranch(location);
if (copy.notEmpty()) {
result.addCopy(copy);
}
location = "";
copy = new Copy();
}
line++;
}
if (copy.notEmpty()) {
copy.setBranch(location);
result.addCopy(copy);
}
if (reservationInfo.length() == 0) {
// as details, we still want to use it.
if (doc.select("td a:has(img[src*=inline_arrow])").size() > 0) {
Element a = doc.select("td a:has(img[src*=inline_arrow])").first();
boolean multipleCopies = a.text().matches(".*(Exemplare|Volume list).*");
JSONObject reservation = new JSONObject();
try {
reservation.put("multi", multipleCopies);
reservation.put("link", _extract_url(a));
reservation.put("desc", location);
reservationInfo.put(reservation);
} catch (JSONException e1) {
e1.printStackTrace();
}
result.setReservable(true);
}
}
result.setReservation_info(reservationInfo.toString());
// Volumes
if (doc.select("a[href^=FAM?PPN=]").size() > 0) {
String href = doc.select("a[href^=FAM?PPN=]").attr("href");
String ppn = getQueryParamsFirst(href).get("PPN");
Map<String, String> data = new HashMap<>();
data.put("ppn", ppn);
result.setVolumesearch(data);
}
return result;
}
Aggregations