Commit 911d8d7d authored by Ubbo Veentjer's avatar Ubbo Veentjer
Browse files

a bit more structure for browse code. fix iiif image. mets/mods needs no voyant or switchboard.

parent f7cd7acb
Pipeline #136147 passed with stages
in 9 minutes and 5 seconds
......@@ -90,118 +90,162 @@ public class BrowseController {
String format = metadata.getObject().getGeneric().getProvided().getFormat();
model.addAttribute("format", format);
/*
* Deliver different browse pages based on content type of textgridobject:
* aggregation, xml or image
*/
if (format.contains("tg.aggregation") || format.contains("text/tg.work+xml")) {
handleAggregations(model, i18n, id, format, mode);
} else if (format.equals("text/xml")) {
handleXml(model, i18n, id, metadata, fragment);
} else if (format.contains("image")) {
handleImages(model, id);
}
List<ViewMode> viewmodes = new ArrayList<ViewMode>();
viewmodes
.add(new ViewMode(i18n.get("list"), Utils.browseUrl(id) + "?mode=list", mode.equals("list")));
viewmodes.add(new ViewMode(i18n.get("gallery"), Utils.browseUrl(id) + "?mode=gallery",
mode.equals("gallery")));
return "browse";
}
if (format.equals("text/tg.edition+tg.aggregation+xml")) {
viewmodes.add(new ViewMode("TEI-Corpus", Utils.browseUrl(id) + "?mode=xml", mode.equals("xml")));
/**
* setup browse page to show tools metadata and the like for xml type files, which are now METS/XML or TEI
*
* @param model
* @param i18n
* @param id
* @param metadata
* @param fragment
*/
private void handleXml(Model model, I18N i18n, String id, ResultType metadata, String fragment) {
List<ViewMode> tools = new ArrayList<ViewMode>();
// identifier@type of trier dfg-viewer mets is METSXMLID
// TODO: look into relation/tg:rootElementNamespace
if (!metadata.getObject().getGeneric().getProvided().getIdentifier().isEmpty()
&& metadata.getObject().getGeneric().getProvided().getIdentifier().get(0) != null
&& metadata.getObject().getGeneric().getProvided().getIdentifier().get(0)
.getType() != null
&& metadata.getObject().getGeneric().getProvided().getIdentifier().get(0).getType()
.equals("METSXMLID")) {
try {
String tgcrudUrl4DFGViewer = URLEncoder.encode(
tgrepConfig.getTextgridHost() + "/1.0/tgcrud-public/rest/" + id + "/data", "UTF-8");
tools.add(new ViewMode("DFG-Viewer",
"http://dfg-viewer.de/v3/?set[zoom]=min&set[mets]=" + tgcrudUrl4DFGViewer, false));
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else { // assume tei-xml
model.addAttribute("viewmodes", viewmodes);
if (mode != null && mode.equals("xml")) {
String teiHtml = this.aggregatorClient.renderTEI(id);
String teiHtml = "";
if (fragment != "") {
teiHtml = this.aggregatorClient.renderTEIFragment(id, fragment);
} else {
teiHtml = this.aggregatorClient.renderTEI(id);
String tocHtml = this.aggregatorClient.renderToc(id);
model.addAttribute("teiHtml", teiHtml);
model.addAttribute("tocHtml", tocHtml);
} else {
log.info("listing agg: " + id);
List<ResultType> results;
if (format.contains("text/tg.work+xml")) {
List<String> editionFilter =
Arrays.asList(new String[] {"format:text/tg.edition+tg.aggregation+xml"});
results = this.tgsearchClientService
.search("isEditionOf:\"" + id + "\"", "relevance", 0, 20, editionFilter, true)
.getResult();
} else {
results = this.tgsearchClientService.listAggregation(id).getResult();
}
model.addAttribute("results", results);
}
} else if (format.equals("text/xml")) {
model.addAttribute("teiHtml", teiHtml);
model.addAttribute("isTEI", true);
// TEI specific tools here
tools.addAll(addTeiTools(id));
}
List<ViewMode> tools = new ArrayList<ViewMode>();
// identifier@type of trier dfg-viewer mets is METSXMLID
// TODO: look into relation/tg:rootElementNamespace
if (!metadata.getObject().getGeneric().getProvided().getIdentifier().isEmpty()
&& metadata.getObject().getGeneric().getProvided().getIdentifier().get(0) != null
&& metadata.getObject().getGeneric().getProvided().getIdentifier().get(0)
.getType() != null
&& metadata.getObject().getGeneric().getProvided().getIdentifier().get(0).getType()
.equals("METSXMLID")) {
try {
String tgcrudUrl4DFGViewer = URLEncoder.encode(
tgrepConfig.getTextgridHost() + "/1.0/tgcrud-public/rest/" + id + "/data", "UTF-8");
tools.add(new ViewMode("DFG-Viewer",
"http://dfg-viewer.de/v3/?set[zoom]=min&set[mets]=" + tgcrudUrl4DFGViewer, false));
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else { // assume tei-xml
String teiHtml = "";
if (fragment != "") {
teiHtml = this.aggregatorClient.renderTEIFragment(id, fragment);
} else {
teiHtml = this.aggregatorClient.renderTEI(id);
String tocHtml = this.aggregatorClient.renderToc(id);
model.addAttribute("tocHtml", tocHtml);
}
model.addAttribute("teiHtml", teiHtml);
model.addAttribute("isTEI", true);
}
// Mirador link may be shown for METS/MODS or TEI files (if manifest available for this file)
if (hasIiifManifest(metadata.getObject().getGeneric().getGenerated().getProject().getId())) {
tools.add(new ViewMode("Mirador", tgrepConfig.getToolMiradorHost() + "/?uri=" + id, false));
tools.add(new ViewMode(
"<img style='margin-top:2px; height: 21px;' title='Drop icon on Mirador to open manifest' src='" + tgrepConfig.getTextgridHost() + "/1.0/iiif/manifests/img/iiif-logo.svg'>",
tgrepConfig.getTextgridHost() + "/1.0/iiif/manifests/" + id + "/manifest.json", false
));
}
// CLARIN Language Resource Switchboard (LRS)
try {
// XML
String xml4switchboard = URLEncoder.encode(tgrepConfig.getTextgridHost() + "/1.0/tgcrud-public/rest/" + id + "/data", "UTF-8");
tools.add(new ViewMode("Switchboard (TEI)", tgrepConfig.getToolSwitchboardHost() + "/" + xml4switchboard + "/application%2Ftei+xml", false));
// txt
String text4switchboard = URLEncoder.encode(tgrepConfig.getTextgridHost() + "/1.0/aggregator/text/" + id , "UTF-8");
tools.add(new ViewMode("Switchboard (txt)", tgrepConfig.getToolSwitchboardHost() + "/" + text4switchboard + "/text%2Fplain", false));
} catch (UnsupportedEncodingException e) {
log.error("error encoding url for switchboard", e);
}
model.addAttribute("tools", tools);
}
// Voyant
tools.add(new ViewMode("Voyant", tgrepConfig.getToolVoyantHost() + "/?input=" + tgrepConfig.getTextgridHost() + "/1.0/tgcrud-public/rest/" + id + "/data", false));
/**
* Some tools only useful for browsing TEI (voyant, switchboard)
* @param tools
* @param id
*/
private List<ViewMode> addTeiTools(String id) {
// CLARIN Language Resource Switchboard (LRS)
List<ViewMode> tools = new ArrayList<ViewMode>();
try {
// XML
String xml4switchboard = URLEncoder.encode(tgrepConfig.getTextgridHost() + "/1.0/tgcrud-public/rest/" + id + "/data", "UTF-8");
tools.add(new ViewMode("Switchboard (TEI)", tgrepConfig.getToolSwitchboardHost() + "/" + xml4switchboard + "/application%2Ftei+xml", false));
// txt
String text4switchboard = URLEncoder.encode(tgrepConfig.getTextgridHost() + "/1.0/aggregator/text/" + id , "UTF-8");
tools.add(new ViewMode("Switchboard (txt)", tgrepConfig.getToolSwitchboardHost() + "/" + text4switchboard + "/text%2Fplain", false));
} catch (UnsupportedEncodingException e) {
log.error("error encoding url for switchboard", e);
}
// Mirador
if (hasIiifManifest(metadata.getObject().getGeneric().getGenerated().getProject().getId())) {
tools.add(new ViewMode("Mirador", tgrepConfig.getToolMiradorHost() + "/?uri=" + id, false));
tools.add(new ViewMode(
"<img style='margin-top:2px; height: 21px;' title='Drop icon on Mirador to open manifest' src='" + tgrepConfig.getTextgridHost() + "'/iiif/manifests/img/iiif-logo.svg'>",
tgrepConfig.getTextgridHost() + "/1.0/iiif/manifests/" + id + "/manifest.json", false
));
}
// Voyant
tools.add(new ViewMode("Voyant", tgrepConfig.getToolVoyantHost() + "/?input=" + tgrepConfig.getTextgridHost() + "/1.0/tgcrud-public/rest/" + id + "/data", false));
// Annotate
tools.add(new ViewMode("Annotate", tgrepConfig.getToolAnnotateHost() + "/data.html?uri=" + id, false, "annotation-button"));
// Annotate
tools.add(new ViewMode("Annotate", tgrepConfig.getToolAnnotateHost() + "/data.html?uri=" + id, false, "annotation-button"));
return tools;
}
model.addAttribute("tools", tools);
/**
* setup browsing of aggreagtions
*
* @param model
* @param i18n
* @param id
* @param format
* @param mode
*/
private void handleAggregations(Model model, I18N i18n, String id, String format, String mode) {
List<ViewMode> viewmodes = new ArrayList<ViewMode>();
viewmodes
.add(new ViewMode(i18n.get("list"), Utils.browseUrl(id) + "?mode=list", mode.equals("list")));
viewmodes.add(new ViewMode(i18n.get("gallery"), Utils.browseUrl(id) + "?mode=gallery",
mode.equals("gallery")));
if (format.equals("text/tg.edition+tg.aggregation+xml")) {
viewmodes.add(new ViewMode("TEI-Corpus", Utils.browseUrl(id) + "?mode=xml", mode.equals("xml")));
}
// Digilib
else if (format.contains("image")) {
model.addAttribute("image", true);
List<ViewMode> tools = new ArrayList<ViewMode>();
tools.add(new ViewMode("Digilib", tgrepConfig.getToolDigilibHost() + "/digilib.html?fn=" + id, false));
model.addAttribute("tools", tools);
model.addAttribute("viewmodes", viewmodes);
if (mode != null && mode.equals("xml")) {
String teiHtml = this.aggregatorClient.renderTEI(id);
String tocHtml = this.aggregatorClient.renderToc(id);
model.addAttribute("teiHtml", teiHtml);
model.addAttribute("tocHtml", tocHtml);
} else {
log.info("listing agg: " + id);
List<ResultType> results;
if (format.contains("text/tg.work+xml")) {
List<String> editionFilter =
Arrays.asList(new String[] {"format:text/tg.edition+tg.aggregation+xml"});
results = this.tgsearchClientService
.search("isEditionOf:\"" + id + "\"", "relevance", 0, 20, editionFilter, true)
.getResult();
} else {
results = this.tgsearchClientService.listAggregation(id).getResult();
}
model.addAttribute("results", results);
}
}
return "browse";
/**
* browsing images, digilib link in tools
* @param model
* @param id
*/
private void handleImages(Model model, String id) {
model.addAttribute("image", true);
List<ViewMode> tools = new ArrayList<ViewMode>();
tools.add(new ViewMode("Digilib", tgrepConfig.getToolDigilibHost() + "/digilib.html?fn=" + id, false));
model.addAttribute("tools", tools);
}
private boolean hasIiifManifest(String id) {
......
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