Search in sources :

Example 1 with NanopubIndex

use of org.nanopub.extra.index.NanopubIndex 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);
    }
}
Also used : NanopubIndex(org.nanopub.extra.index.NanopubIndex) MalformedNanopubException(org.nanopub.MalformedNanopubException) URI(org.openrdf.model.URI)

Aggregations

MalformedNanopubException (org.nanopub.MalformedNanopubException)1 NanopubIndex (org.nanopub.extra.index.NanopubIndex)1 URI (org.openrdf.model.URI)1