Skip to content
Permalink
Browse files

use the rdf ns prefix mapping to control predicate display

  • Loading branch information...
cbeer committed Jun 20, 2013
1 parent cac6c8e commit f11e5df695e3c1a2cabcbc2ec13c5042e796cfab
@@ -181,6 +181,7 @@ public void writeTo(final Dataset rdf, final Class<?> type,
context.put("rdfLexicon", fieldTool.in(RdfLexicon.class));
context.put("helpers", ViewHelpers.getInstance());
context.put("rdf", rdf.asDatasetGraph());
context.put("model", rdf.getDefaultModel());
context.put("subjects", rdf.getDefaultModel().listSubjects());
context.put("nodeany", Node.ANY);
context.put("topic", subject);
@@ -2,6 +2,7 @@

import com.google.common.collect.ImmutableMap;
import com.hp.hpl.jena.graph.Node;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.sparql.core.DatasetGraph;
import com.hp.hpl.jena.sparql.core.Quad;
@@ -109,4 +110,14 @@ public String getObjectsAsString(final DatasetGraph dataset, final Node subject,
return builder.build();

}

public String getNamespacePrefix(final Model model, final String namespace) {
final String nsURIPrefix = model.getNsURIPrefix(namespace);

if (nsURIPrefix == null) {
return namespace;
} else {
return nsURIPrefix + ":";
}
}
}
@@ -1,4 +1,6 @@
#* @vtlvariable name="quad" type="com.hp.hpl.jena.sparql.core.Quad" *#
#* @vtlvariable name="rdf" type="com.hp.hpl.jena.sparql.core.DatasetGraph" *#
#* @vtlvariable name="model" type="com.hp.hpl.jena.rdf.model.Model" *#
#macro( triples $sub )
<div resource="$sub.getURI()">
#if($sub.isURI())
@@ -11,12 +13,8 @@
#foreach($quad in $rdf.find($nodeany, $nodeany, $nodeany, $nodeany))
#if($sub.equals($quad.getSubject()))
<dt>
#if($quad.getPredicate().toString().startsWith("info:fedora/fedora-system:def/internal#") )
<span class="namespace muted">fedora</span><span class="divider muted">:</span><span class="localName">$quad.getPredicate().getLocalName()</span>
#else
<span class="namespace muted">$quad.getPredicate().getNameSpace()</span><span class="divider muted">:</span>
<span class="localName">$quad.getPredicate().getLocalName()</span>
#end
<span class="namespace muted">$helpers.getNamespacePrefix($model, $quad.getPredicate().getNameSpace())</span><span class="localName">$quad.getPredicate().getLocalName()</span>

</dt>
<dd>
#if($quad.getObject().isURI() && $quad.getObject().getURI().startsWith("http"))
@@ -44,7 +44,7 @@
<dd>
<ol>
#foreach($quad in $helpers.getObjects($rdf, $topic, $rdfLexicon.HAS_CHILD))
<li><a href="$quad.getObject().getURI()">$helpers.getObjectTitle($rdf, $topic)</a></li>
<li><a href="$quad.getObject().getURI()">$helpers.getObjectTitle($rdf, $quad.getObject())</a></li>
#end
</ol>
</dd>
@@ -44,7 +44,7 @@
<dd>
<ol>
#foreach($quad in $helpers.getObjects($rdf, $topic, $rdfLexicon.HAS_CHILD))
<li><a href="$quad.getObject().getURI()">$helpers.getObjectTitle($rdf, $topic)</a></li>
<li><a href="$quad.getObject().getURI()">$helpers.getObjectTitle($rdf, $quad.getObject())</a></li>
#end
</ol>
</dd>
@@ -44,7 +44,7 @@
<dd>
<ol>
#foreach($quad in $helpers.getObjects($rdf, $topic, $rdfLexicon.HAS_CHILD))
<li><a href="$quad.getObject().getURI()">$helpers.getObjectTitle($rdf, $topic)</a></li>
<li><a href="$quad.getObject().getURI()">$helpers.getObjectTitle($rdf, $quad.getObject())</a></li>
#end
</ol>
</dd>

0 comments on commit f11e5df

Please sign in to comment.
You can’t perform that action at this time.