Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
add HTML rendering for fcr:nodetypes
  • Loading branch information
cbeer committed Nov 6, 2013
1 parent e76f7a9 commit f4e7e62
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 1 deletion.
Expand Up @@ -20,6 +20,7 @@
import com.hp.hpl.jena.query.Dataset;
import com.hp.hpl.jena.query.DatasetFactory;
import org.fcrepo.http.commons.AbstractResource;
import org.fcrepo.http.commons.responses.HtmlTemplate;
import org.fcrepo.http.commons.session.InjectedSession;
import org.slf4j.Logger;
import org.springframework.context.annotation.Scope;
Expand Down Expand Up @@ -72,6 +73,7 @@ public class FedoraRepositoryNodeTypes extends AbstractResource {
@Produces({TURTLE, N3, N3_ALT1, N3_ALT2, RDF_XML, RDF_JSON, NTRIPLES,
TEXT_HTML})
@Timed
@HtmlTemplate("jcr:nodetypes")
public Dataset getNodeTypes() throws RepositoryException {
try {
return DatasetFactory.create(nodeService.getNodeTypes(session).asModel());
Expand Down
1 change: 1 addition & 0 deletions fcrepo-http-api/src/main/resources/views/common-header.vsl
Expand Up @@ -17,6 +17,7 @@
<li><a href="$uriInfo.baseUriBuilder.build()">Home</a></li>
<li><a href="$uriInfo.baseUriBuilder.build()fcr:namespaces">Namespaces</a></li>
<li><a href="$uriInfo.baseUriBuilder.build()fcr:workspaces">Workspaces</a></li>
<li><a href="$uriInfo.baseUriBuilder.build()fcr:nodetypes">Types</a></li>
</ul>
<form class="navbar-form navbar-left" role="search" method="GET" action="$uriInfo.baseUriBuilder.build()fcr:search">
<div class="form-group">
Expand Down
69 changes: 69 additions & 0 deletions fcrepo-http-api/src/main/resources/views/jcr-nodetypes.vsl
@@ -0,0 +1,69 @@
#* @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" *#
#* @vtlvariable name="topic" type="com.hp.hpl.jena.graph.Node" *#
#* @vtlvariable name="model" type="com.hp.hpl.jena.rdf.model.Model" *#
<!DOCTYPE html>
#parse("views/common.vsl")
<html>
<head>
<title>registered types</title>
#parse("views/common-head.vsl")
<script type="text/javascript">
$(function() {

var uriToId = {};

$('h3').each(function() {
if ( !this.id && this.innerText ) {
this.id = this.innerText.toLowerCase().replace(/[^a-z0-9\-_]+/g, "_");
}

uriToId[this.innerText] = this.id;
});

$('dd a').each(function() {
if (uriToId[this.href]) {
this.href = "#" + uriToId[this.href];
}
});
});
</script>
</head>
<body>
<div id="main" class="container" resource="$uriInfo.baseUriBuilder.build()fcr:nodetypes">
#parse("views/common-header.vsl")

<div class="row">
<div class="col-md-9">
<h1>Node Types</h1>

#foreach($subject in $model.listSubjectsWithProperty($helpers.rdfType(), $helpers.rdfsClass()))
<div class="panel panel-default">

<div class="panel-heading">
<h3 class="panel-title">$subject.getURI()</h3>
</div>


<div class="panel-body">
#triples($subject.asNode())


<h4>Properties</h4>
#foreach($propertySubject in $model.listSubjectsWithProperty($helpers.rdfsDomain(), $subject))
<div resource="$propertySubject.getURI()">
<h5>$propertySubject.getURI()</h5>
<div>
#triples($propertySubject.asNode())
</div>
</div>
#end
</div>
</div>
#end
</div>

</div>
</body>
</html>
Expand Up @@ -17,6 +17,7 @@

import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.NicelyResynchronizingAjaxController;
import com.gargoylesoftware.htmlunit.Page;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.DomElement;
import com.gargoylesoftware.htmlunit.html.HtmlButton;
Expand Down Expand Up @@ -137,6 +138,12 @@ public void testCreateNewObjectAndDeleteIt() throws IOException {
webClient.getOptions().setThrowExceptionOnFailingStatusCode(throwExceptionOnFailingStatusCode);
}

@Test
public void testNodeTypes() throws IOException {
final HtmlPage page = webClient.getPage(serverAddress + "fcr:nodetypes");
assertTrue(page.asText().contains("fedora:object"));
}

@Test
@Ignore
public void testCreateNewObjectAndSetProperties() throws IOException {
Expand Down
Expand Up @@ -153,7 +153,7 @@ void init() throws IOException, RepositoryException {

final List<String> otherTemplates =
ImmutableList.of("search:results", "jcr:namespaces",
"jcr:workspaces", "node");
"jcr:workspaces", "jcr:nodetypes", "node");

for (final String key : otherTemplates) {
final Template template =
Expand Down
Expand Up @@ -27,6 +27,8 @@

import javax.ws.rs.core.UriInfo;

import com.hp.hpl.jena.vocabulary.RDF;
import com.hp.hpl.jena.vocabulary.RDFS;
import org.fcrepo.http.commons.api.rdf.QuadOrdering;
import org.slf4j.Logger;

Expand Down Expand Up @@ -268,4 +270,28 @@ public Node asNode(final Resource r) {
public int addOne(final int i) {
return i + 1;
}

/**
* Proxying access to the RDF type static property
* @return
*/
public Property rdfType() {
return RDF.type;
}

/**
* Proxying access to the RDFS domain static property
* @return
*/
public Property rdfsDomain() {
return RDFS.domain;
}

/**
* Proxying access to the RDFS class static property
* @return
*/
public Resource rdfsClass() {
return RDFS.Class;
}
}

0 comments on commit f4e7e62

Please sign in to comment.