Commit af3f8cae authored by Ubbo Veentjer's avatar Ubbo Veentjer
Browse files

mime icons if no image in gallery mode

parent 5284abdd
Pipeline #140169 passed with stages
in 9 minutes and 30 seconds
......@@ -16,6 +16,16 @@ public class Utils {
private final static String BROWSE_URL = "/browse/";
private final static String SEARCH_URL = "/search";
private final static String MIME_IMG_BASE = "/images/tg-icons/";
private final static String MIME_IMG_XML = MIME_IMG_BASE + "x14-document-xml.svg";
private final static String MIME_IMG_WORK = MIME_IMG_BASE + "130-ist_Werk.svg";
private final static String MIME_IMG_EDITION = MIME_IMG_BASE + "108-ist-Edition.svg";
private final static String MIME_IMG_COLLECTION = MIME_IMG_BASE + "109-ist-Collection.svg";
private final static String MIME_IMG_AGGREGATION = MIME_IMG_BASE + "072-zeige-Aggregation-Perspektive.svg";
private final static String MIME_IMG_TEXT = MIME_IMG_BASE + "x11-document-text.svg";
private static final Log log = LogFactory.getLog(Utils.class);
public static String browseUrl(String tgurl) {
......@@ -37,42 +47,86 @@ public class Utils {
}
public static String getImageUrl(String textgridHost, ResultType tgsearchresult) {
return getImageUrl(textgridHost, tgsearchresult, false);
}
public static String getGalleryImageUrl(String textgridHost, ResultType tgsearchresult) {
return getImageUrl(textgridHost, tgsearchresult, true);
}
private static String getImageUrl(String textgridHost, ResultType tgsearchresult, boolean gallery) {
String imageUri = null;
String format = tgsearchresult.getObject().getGeneric().getProvided().getFormat();
if (tgsearchresult.getObject().getGeneric().getProvided().getFormat().contains("image")) {
if (format.contains("image")) {
imageUri = tgsearchresult.getObject().getGeneric().getGenerated().getTextgridUri().getValue();
} else if (tgsearchresult.getObject().getGeneric().getProvided().getFormat()
.contains("tg.collection")) {
} else if (format.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();
}
}
}
imageUri = getImageFromCollectionRdf(tgsearchresult);
}
if (imageUri != null) {
return textgridHost + "/1.0/digilib/rest/IIIF/" + imageUri + "/full/," + THUMBSIZE
+ "/0/native.jpg";
} else if(gallery){
return getImageForMimetype(format);
} else {
return "/images/no_image.svg";
}
}
private static String getImageForMimetype(String format) {
String img = "";
switch(format) {
case "text/xml":
img = MIME_IMG_XML;
break;
case "text/tg.work+xml":
img = MIME_IMG_WORK;
break;
case "text/tg.aggregation+xml":
img = MIME_IMG_AGGREGATION;
break;
case "text/tg.collection+tg.aggregation+xml":
img = MIME_IMG_COLLECTION;
break;
case "text/tg.edition+tg.aggregation+xml":
img = MIME_IMG_EDITION;
break;
default:
if(format.startsWith("text/")) {
img = MIME_IMG_TEXT;
} else {
img = "";
};
}
return img;
}
private static String getImageFromCollectionRdf(ResultType tgsearchresult) {
String imageUri = null;
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();
}
}
}
return imageUri;
}
public static String getFilterQueryString(List<String> filters) {
if (filters == null) {
......
......@@ -35,6 +35,14 @@
img
width: 100%
img.mime-icon
width: 75%
opacity: 0.5
display: block
margin-top: 3em
margin-left: auto
margin-right: auto
.tgrep.gallery-item_title
background: rgba(#fff, .9)
padding: ($grid / 4) ($grid / 2)
......
......@@ -30,6 +30,11 @@
<function-class>info.textgrid.rep.shared.Utils</function-class>
<function-signature>java.lang.String getImageUrl(java.lang.String, info.textgrid.namespaces.middleware.tgsearch.ResultType)</function-signature>
</function>
<function>
<name>getGalleryImageUrl</name>
<function-class>info.textgrid.rep.shared.Utils</function-class>
<function-signature>java.lang.String getGalleryImageUrl(java.lang.String, info.textgrid.namespaces.middleware.tgsearch.ResultType)</function-signature>
</function>
<function>
<name>replaceAll</name>
<function-class>info.textgrid.rep.shared.Utils</function-class>
......
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ taglib uri="http://textgrid.info/rep/utils" prefix="utils"%>
<li class="tgrep gallery-item">
<div>
<div class="tgrep gallery-item_image">
<a href="${utils:browseUrl(result.object.generic.generated.textgridUri.value)}"> <img src="${utils:getImageUrl(config.textgridHost, result)}"
alt="${result.object.generic.provided.title[0]}" title="${result.object.generic.provided.title[0]}" />
<c:set var="imageUrl" value="${utils:getGalleryImageUrl(config.textgridHost, result)}"/>
<c:if test="${fn:contains(imageUrl, 'tg-icons')}">
<c:set var="mimeIconClass" value="mime-icon" />
</c:if>
<a href="${utils:browseUrl(result.object.generic.generated.textgridUri.value)}">
<img src="${imageUrl}"
class="${mimeIconClass}"
alt="${result.object.generic.provided.title[0]}"
title="${result.object.generic.provided.title[0]}" />
</a>
</div>
<div class="tgrep gallery-item_title">
......
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