Commit 21005c6e authored by Ubbo Veentjer's avatar Ubbo Veentjer
Browse files

handle text/plain. closes #84

parent a678de82
Pipeline #163242 passed with stages
in 11 minutes and 49 seconds
......@@ -5,6 +5,7 @@ import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
......@@ -13,6 +14,7 @@ import java.util.TreeMap;
import javax.ws.rs.client.ClientBuilder;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.cxf.helpers.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
......@@ -118,6 +120,8 @@ public class BrowseController {
handleImages(model, id);
} else if (format.equals("text/markdown")) {
handleMarkdown(model, id);
} else if (format.equals("text/plain")) {
handlePlaintext(model, id);
}
// add revisions info
listRevisions(model, id, metadata);
......@@ -290,6 +294,26 @@ public class BrowseController {
model.addAttribute("htmlContent", content);
}
private void handlePlaintext(Model model, String id) {
InputStream contentStream;
String content;
try {
contentStream = this.tgcrudClient.read(id);
content = IOUtils.toString(contentStream, StandardCharsets.UTF_8.name());
} catch (CrudClientException e) {
//TODO: nicer error strings
log.error("error reading data from crud", e);
content = "error reading data from crud";
} catch (IOException e) {
//TODO: nicer error strings
log.error("error reading data", e);
content = "error reading data";
}
model.addAttribute("textContent", content);
}
private void listRevisions(Model model, String id, ResultType metadata) {
String baseUri = id.substring(0, id.indexOf("."));
Revisions revisions = tgsearchClient.listRevisions(id);
......
......@@ -7,7 +7,7 @@ tgrep.ssl = false
server.servlet.session.cookie.secure: ${tgrep.ssl}
# textgrid defaults
textgrid.host: https://test.textgridlab.org
textgrid.host: https://textgridlab.org
tgsearch.url: ${textgrid.host}/1.0/tgsearch-public
handle.host: https://hdl.handle.net
......
......@@ -255,6 +255,12 @@
${htmlContent}
</c:when>
<c:when test="${metadata.object.generic.provided.format eq 'text/plain'}">
<pre>
${textContent}
</pre>
</c:when>
<c:otherwise>
<p>${i18n['dont-know-what-todo']} ${format}</p>
<a target="_blank" href="${config.textgridHost}/1.0/tgcrud-public/rest/${metadata.object.generic.generated.textgridUri.value}/data">${i18n['open-html-in-new-window']}</a>
......
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