use of org.nanopub.MalformedNanopubException in project nanopub-server by tkuhn.
the class NanopubDb method getNanopub.
public Nanopub getNanopub(String artifactCode) {
BasicDBObject query = new BasicDBObject("_id", artifactCode);
DBCursor cursor = getNanopubCollection().find(query);
if (!cursor.hasNext()) {
return null;
}
String nanopubString = cursor.next().get("nanopub").toString();
Nanopub np = null;
try {
np = new NanopubImpl(nanopubString, internalFormat);
} catch (MalformedNanopubException ex) {
throw new RuntimeException("Stored nanopub is not wellformed (this shouldn't happen)", ex);
} catch (OpenRDFException ex) {
throw new RuntimeException("Stored nanopub is corrupted (this shouldn't happen)", ex);
}
if (ServerConf.get().isCheckNanopubsOnGetEnabled() && !TrustyNanopubUtils.isValidTrustyNanopub(np)) {
throw new RuntimeException("Stored nanopub is not trusty (this shouldn't happen)");
}
return np;
}
use of org.nanopub.MalformedNanopubException in project nanopub-server by tkuhn.
the class NanopubPage method showIndex.
private void showIndex(Nanopub np) throws IOException {
try {
NanopubIndex npi = IndexUtils.castToIndex(np);
getResp().setContentType("text/html");
String title, headerTitle;
if (npi.getName() == null) {
if (npi.isIncomplete()) {
headerTitle = "Part of Unnamed Index";
title = "<em>Part of Unnamed Index</em>";
} else {
headerTitle = "Unnamed Index";
title = "<em>Unnamed Index</em>";
}
} else {
String escapedName = StringEscapeUtils.escapeHtml(npi.getName());
if (npi.isIncomplete()) {
headerTitle = "Part of Index '" + escapedName + "'";
title = "<em>Part of Index</em> '" + escapedName + "'";
} else {
headerTitle = escapedName + " (Nanopub Index)";
title = escapedName + " <em>(Nanopub Index)</em>";
}
}
printHtmlHeader(headerTitle);
println("<h1>" + title + "</h1>");
println("<p>[ <a href=\".\" rel=\"home\">home</a> ]</p>");
println("<h3>This:</h3>");
println("<table><tbody>");
printItem(npi.getUri());
println("</tbody></table>");
if (!npi.isIncomplete()) {
if (npi.getDescription() != null) {
println("<h3>Description:</h3>");
println("<p>");
println(StringEscapeUtils.escapeHtml(npi.getDescription()));
println("</p>");
}
if (npi.getCreationTime() != null) {
println("<h3>Creation Time:</h3>");
println("<p>" + SimpleDateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG).format(npi.getCreationTime().getTime()) + "</p>");
}
if (!npi.getCreators().isEmpty()) {
println("<h3>Creators:</h3>");
println("<ul>");
for (URI uri : npi.getCreators()) {
println("<li><a href=\"" + uri + "\" rel=\"nofollow\">" + uri + "</a></li>");
}
println("</ul>");
}
}
if (!npi.getSeeAlsoUris().isEmpty()) {
println("<h3>See Also:</h3>");
println("<ul>");
for (URI uri : npi.getSeeAlsoUris()) {
println("<li><a href=\"" + uri + "\" rel=\"nofollow\">" + uri + "</a></li>");
}
println("</ul>");
}
if (npi.getAppendedIndex() != null) {
println("<h3>Appends:</h3>");
println("<table><tbody>");
printItem(npi.getAppendedIndex());
println("</tbody></table>");
}
if (!npi.getSubIndexes().isEmpty()) {
println("<h3>Includes as Sub-Indexes:</h3>");
println("<table><tbody>");
for (URI uri : npi.getSubIndexes()) {
printItem(uri);
}
println("</tbody></table>");
}
if (!npi.getElements().isEmpty()) {
println("<h3>Includes as Elements:</h3>");
println("<table><tbody>");
for (URI uri : npi.getElements()) {
printItem(uri);
}
println("</tbody></table>");
}
printHtmlFooter();
} catch (MalformedNanopubException ex) {
throw new RuntimeException(ex);
}
}
Aggregations