Commit 5284abdd authored by Ubbo Veentjer's avatar Ubbo Veentjer
Browse files

indention/tabs

parent 5f191b1d
......@@ -12,92 +12,96 @@ import info.textgrid.namespaces.middleware.tgsearch.ResultType;
public class Utils {
private final static int THUMBSIZE = 250;
private final static String BROWSE_URL = "/browse/";
private final static String SEARCH_URL = "/search";
private static final Log log = LogFactory.getLog(Utils.class);
public static String browseUrl(String tgurl) {
return BROWSE_URL + urlmod(tgurl);
}
public static String searchUrl(String mode, String query, List<String> filter, String order, int start, int limit) {
String querystring = query.replace("\"", "&quot;")+getFilterQueryString(filter);
return SEARCH_URL + "?query="+querystring+"&start="+start+"&limit="+limit+"&order="+order+"&mode="+mode ;
}
public static String urlmod(String tgurl) {
if(tgurl.length() > 10) {
return tgurl.substring(9);
}
return "tgurl";
}
public static String getImageUrl(String textgridHost, ResultType tgsearchresult) {
String imageUri = null;
if(tgsearchresult.getObject().getGeneric().getProvided().getFormat().contains("image")) {
imageUri = tgsearchresult.getObject().getGeneric().getGenerated().getTextgridUri().getValue();
}else if(tgsearchresult.getObject().getGeneric().getProvided().getFormat().contains("tg.collection")) {
// collections may have author images linked in the "digitale bibliothek"
RelationType rel = tgsearchresult.getObject().getRelations();
if (rel != null) {
RdfType rdf = rel.getRDF();
if (rdf != null) {
List<Object> rdfs = rdf.getAny();
for (Object o : rdfs) {
Element dom = (Element) o;
imageUri = dom
.getElementsByTagNameNS("http://textgrid.info/relation-ns#", "depiction")
.item(0)
.getAttributes()
.getNamedItemNS("http://www.w3.org/1999/02/22-rdf-syntax-ns#", "resource")
.getTextContent();
}
}
}
}
if (imageUri != null) {
return textgridHost + "/1.0/digilib/rest/IIIF/"+imageUri+"/full/,"+THUMBSIZE+"/0/native.jpg";
} else {
return "/images/no_image.svg";
}
}
public static String getFilterQueryString(List<String> filters) {
if(filters==null) {
return "";
}
StringBuffer sb = new StringBuffer();
for(String filter : filters) {
try {
filter = URLEncoder.encode(filter, "UTF-8");
} catch (UnsupportedEncodingException e) {
log.error("could not urlencode the string: " + filter);
}
sb.append("&filter=").append(filter).append("");
}
return sb.toString();
}
public static String urlencode(String string) {
try {
string = URLEncoder.encode(string, "UTF-8");
} catch (UnsupportedEncodingException e) {
log.error("could not urlencode the string: " + string);
}
return string;
}
public static String replaceAll(String string, String pattern, String replacement) {
return string.replaceAll(pattern, replacement);
private final static int THUMBSIZE = 250;
private final static String BROWSE_URL = "/browse/";
private final static String SEARCH_URL = "/search";
private static final Log log = LogFactory.getLog(Utils.class);
public static String browseUrl(String tgurl) {
return BROWSE_URL + urlmod(tgurl);
}
public static String searchUrl(String mode, String query, List<String> filter, String order,
int start, int limit) {
String querystring = query.replace("\"", "&quot;") + getFilterQueryString(filter);
return SEARCH_URL + "?query=" + querystring + "&start=" + start + "&limit=" + limit + "&order="
+ order + "&mode=" + mode;
}
public static String urlmod(String tgurl) {
if (tgurl.length() > 10) {
return tgurl.substring(9);
}
return "tgurl";
}
public static String getImageUrl(String textgridHost, ResultType tgsearchresult) {
String imageUri = null;
if (tgsearchresult.getObject().getGeneric().getProvided().getFormat().contains("image")) {
imageUri = tgsearchresult.getObject().getGeneric().getGenerated().getTextgridUri().getValue();
} else if (tgsearchresult.getObject().getGeneric().getProvided().getFormat()
.contains("tg.collection")) {
// collections may have author images linked in the "digitale bibliothek"
RelationType rel = tgsearchresult.getObject().getRelations();
if (rel != null) {
RdfType rdf = rel.getRDF();
if (rdf != null) {
List<Object> rdfs = rdf.getAny();
for (Object o : rdfs) {
Element dom = (Element) o;
imageUri = dom
.getElementsByTagNameNS("http://textgrid.info/relation-ns#", "depiction")
.item(0)
.getAttributes()
.getNamedItemNS("http://www.w3.org/1999/02/22-rdf-syntax-ns#", "resource")
.getTextContent();
}
}
}
}
if (imageUri != null) {
return textgridHost + "/1.0/digilib/rest/IIIF/" + imageUri + "/full/," + THUMBSIZE
+ "/0/native.jpg";
} else {
return "/images/no_image.svg";
}
}
public static String getFilterQueryString(List<String> filters) {
if (filters == null) {
return "";
}
StringBuffer sb = new StringBuffer();
for (String filter : filters) {
try {
filter = URLEncoder.encode(filter, "UTF-8");
} catch (UnsupportedEncodingException e) {
log.error("could not urlencode the string: " + filter);
}
sb.append("&filter=").append(filter).append("");
}
return sb.toString();
}
public static String urlencode(String string) {
try {
string = URLEncoder.encode(string, "UTF-8");
} catch (UnsupportedEncodingException e) {
log.error("could not urlencode the string: " + string);
}
return string;
}
public static String replaceAll(String string, String pattern, String replacement) {
return string.replaceAll(pattern, replacement);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment