Skip to content

Commit

Permalink
add some more structured data to the HTML output
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeer committed May 20, 2013
1 parent 1e0008c commit 59e443d
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 40 deletions.
Expand Up @@ -135,6 +135,18 @@ public void testGetRepositoryGraph() throws Exception {

}

@Test
public void testGetObjectGraphHtml() throws Exception {
client.execute(postObjMethod("FedoraDescribeTestGraph"));
final HttpGet getObjMethod =
new HttpGet(serverAddress + "objects/FedoraDescribeTestGraph");
getObjMethod.addHeader("Accept", "text/html");
final HttpResponse response = client.execute(getObjMethod);
assertEquals(200, response.getStatusLine().getStatusCode());
final String content = EntityUtils.toString(response.getEntity());
logger.info(content);
}

@Test
public void testGetObjectGraph() throws Exception {
client.execute(postObjMethod("FedoraDescribeTestGraph"));
Expand Down
Expand Up @@ -32,6 +32,7 @@
import javax.ws.rs.ext.MessageBodyWriter;
import javax.ws.rs.ext.Provider;

import com.hp.hpl.jena.graph.Node;
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.VelocityEngine;
Expand Down Expand Up @@ -160,13 +161,8 @@ public void writeTo(final Dataset rdf, final Class<?> type,

final Context context = new VelocityContext();
context.put("rdf", rdf.asDatasetGraph());

if (logger.isTraceEnabled()) {
try (final Writer loggingWriter = new StringWriter()) {
nodeTypeTemplate.merge(context, loggingWriter);
logger.trace("Created HTML response: \n{}", loggingWriter);
}
}
context.put("subjects", rdf.getDefaultModel().listSubjects());
context.put("nodeany", Node.ANY);

// the contract of MessageBodyWriter<T> is _not_ to close the stream
// after writing to it
Expand Down
38 changes: 29 additions & 9 deletions fcrepo-http-commons/src/main/resources/views/nt:file.vsl
@@ -1,15 +1,35 @@
#* @vtlvariable name="rdf" type="com.hp.hpl.jena.sparql.core.DatasetGraph" *#
#* @vtlvariable name="subjects" type="com.hp.hpl.jena.rdf.model.ResIterator" *#
#* @vtlvariable name="nodeany" type="com.hp.hpl.jena.graph.Node" *#
<html>
#set($quads = $rdf.find())
<head>
<title>nt:file profile</title>
</head>

<body>
#foreach($quad in $quads)
<div>
<span>$quad.asTriple()</span>
</div>
#end
</body>

<body>
#foreach($subject in $subjects)
<div>
#if($subject.isURIResource())
<h2><a href="$subject.getURI()">$subject</a></h2>
#else
<h2>$subject</h2>
#end

<dl>
#foreach($quad in $rdf.find($nodeany, $subject.asNode(), $nodeany, $nodeany))
<dt>$quad.getPredicate()</dt>

<dd>
#if($quad.getObject().isURIResource())
<a href="$quad.getObject().getURI()">$quad.getObject()</a>
#else
$quad.getObject()
#end
</dd>
#end
</dl>
</div>
#end
</body>

</html>
44 changes: 32 additions & 12 deletions fcrepo-http-commons/src/main/resources/views/nt:folder.vsl
@@ -1,15 +1,35 @@
#* @vtlvariable name="rdf" type="com.hp.hpl.jena.sparql.core.DatasetGraph" *#
#* @vtlvariable name="subjects" type="com.hp.hpl.jena.rdf.model.ResIterator" *#
#* @vtlvariable name="nodeany" type="com.hp.hpl.jena.graph.Node" *#
<html>
#set($quads = $rdf.find())
<head>
<title>nt:folder profile</title>
</head>

<body>
#foreach($quad in $quads)
<div>
<span>$quad.asTriple()</span>
</div>
#end
</body>
<head>
<title>nt:folder profile</title>
</head>

<body>
#foreach($subject in $subjects)
<div>
#if($subject.isURIResource())
<h2><a href="$subject.getURI()">$subject</a></h2>
#else
<h2>$subject</h2>
#end

<dl>
#foreach($quad in $rdf.find($nodeany, $subject.asNode(), $nodeany, $nodeany))
<dt>$quad.getPredicate()</dt>

<dd>
#if($quad.getObject().isURIResource())
<a href="$quad.getObject().getURI()">$quad.getObject()</a>
#else
$quad.getObject()
#end
</dd>
#end
</dl>
</div>
#end
</body>

</html>
44 changes: 32 additions & 12 deletions fcrepo-http-commons/src/main/resources/views/nt:resource.vsl
@@ -1,15 +1,35 @@
#* @vtlvariable name="rdf" type="com.hp.hpl.jena.sparql.core.DatasetGraph" *#
#* @vtlvariable name="subjects" type="com.hp.hpl.jena.rdf.model.ResIterator" *#
#* @vtlvariable name="nodeany" type="com.hp.hpl.jena.graph.Node" *#
<html>
#set($quads = $rdf.find())
<head>
<title>nt:resource profile</title>
</head>

<body>
#foreach($quad in $quads)
<div>
<span>$quad.asTriple()</span>
</div>
#end
</body>
<head>
<title>nt:resource profile</title>
</head>

<body>
#foreach($subject in $subjects)
<div>
#if($subject.isURIResource())
<h2><a href="$subject.getURI()">$subject</a></h2>
#else
<h2>$subject</h2>
#end

<dl>
#foreach($quad in $rdf.find($nodeany, $subject.asNode(), $nodeany, $nodeany))
<dt>$quad.getPredicate()</dt>

<dd>
#if($quad.getObject().isURIResource())
<a href="$quad.getObject().getURI()">$quad.getObject()</a>
#else
$quad.getObject()
#end
</dd>
#end
</dl>
</div>
#end
</body>

</html>

0 comments on commit 59e443d

Please sign in to comment.