Permalink
Browse files

add some more structured data to the HTML output

  • Loading branch information...
1 parent 1e0008c commit 59e443d1957571a26854b264a0fe8631b2b90ca3 @cbeer cbeer committed May 20, 2013
@@ -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"));
@@ -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;
@@ -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
@@ -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>
@@ -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>
@@ -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.