Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Merge branch 'rdf-generator'
* rdf-generator: explicit dependency on xerces in generator-rdf wire in rdf generator wire in rdf generator to the webapp by default. Rename fcrepo-dc module to fcrepo-generator-dc update the webapp with the new names for some of the classes rename dublin core stuff for consistency with the rdf generator add RDF generator stub, that pulls data from the jcr properties
- Loading branch information
Showing
29 changed files
with
499 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>fcrepo</artifactId> | ||
<groupId>org.fcrepo</groupId> | ||
<version>4.0-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>fcrepo-generator-rdf</artifactId> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.fcrepo</groupId> | ||
<artifactId>fcrepo-kernel</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.fcrepo</groupId> | ||
<artifactId>fcrepo-http-commons</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
|
||
<!-- test gear --> | ||
<dependency> | ||
<groupId>org.fcrepo</groupId> | ||
<artifactId>fcrepo-http-api</artifactId> | ||
<version>${project.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.cxf</groupId> | ||
<artifactId>cxf-rt-frontend-jaxrs</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.cxf</groupId> | ||
<artifactId>cxf-rt-transports-http-jetty</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.cxf</groupId> | ||
<artifactId>cxf-rt-rs-extension-providers</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-test</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.httpcomponents</groupId> | ||
<artifactId>httpclient</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.jena</groupId> | ||
<artifactId>jena-core</artifactId> | ||
<version>2.10.0</version> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-log4j12</artifactId> | ||
</exclusion> | ||
|
||
<exclusion> | ||
<groupId>log4j</groupId> | ||
<artifactId>log4j</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>xerces</groupId> | ||
<artifactId>xercesImpl</artifactId> | ||
<version>2.7.1</version> | ||
</dependency> | ||
<!-- This dependency is for compile-time: it keeps this module independent | ||
of any given choice of JAX-RS implementation. It must be _after_ the test | ||
gear. Otherwise it will get loaded during test phase, but because this is | ||
just an API, the tests will not be able to execute. --> | ||
<dependency> | ||
<groupId>javax</groupId> | ||
<artifactId>javaee-api</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
60 changes: 60 additions & 0 deletions
60
fcrepo-generator-rdf/src/main/java/org/fcrepo/generator/RdfGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package org.fcrepo.generator; | ||
|
||
|
||
import com.hp.hpl.jena.rdf.model.Model; | ||
import com.hp.hpl.jena.rdf.model.ModelFactory; | ||
import com.hp.hpl.jena.rdf.model.RDFWriter; | ||
import org.fcrepo.generator.rdf.TripleGenerator; | ||
|
||
import javax.annotation.Resource; | ||
import javax.jcr.Node; | ||
import javax.jcr.RepositoryException; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.PathParam; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.core.Response; | ||
import java.io.ByteArrayOutputStream; | ||
import java.util.List; | ||
|
||
import static javax.ws.rs.core.MediaType.TEXT_XML; | ||
import static javax.ws.rs.core.Response.ok; | ||
import static org.fcrepo.services.ObjectService.getObjectNode; | ||
|
||
@Path("/objects/{pid}/rdf") | ||
public class RdfGenerator { | ||
|
||
@Resource | ||
List<TripleGenerator> indexers; | ||
|
||
@GET | ||
@Produces(TEXT_XML) | ||
public Response getObjectAsRdfXml(@PathParam("pid") | ||
final String pid) throws RepositoryException { | ||
|
||
final Node obj = getObjectNode(pid); | ||
|
||
|
||
final Model model = getObjectAsRdf(obj); | ||
|
||
RDFWriter w = model.getWriter("RDF/XML"); | ||
|
||
ByteArrayOutputStream os = new ByteArrayOutputStream(); | ||
w.write(model, os, "RDF/XML"); | ||
|
||
return ok(os.toString()).build(); | ||
} | ||
|
||
private Model getObjectAsRdf(final Node obj) throws RepositoryException { | ||
|
||
final Model model = ModelFactory.createDefaultModel(); | ||
|
||
final com.hp.hpl.jena.rdf.model.Resource resource = model.createResource(obj.getIdentifier()); | ||
for (TripleGenerator indexer : indexers) { | ||
indexer.updateResourceFromNode(resource, obj); | ||
} | ||
|
||
return model; | ||
} | ||
|
||
} |
43 changes: 43 additions & 0 deletions
43
fcrepo-generator-rdf/src/main/java/org/fcrepo/generator/rdf/JcrPropertiesGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package org.fcrepo.generator.rdf; | ||
|
||
import com.hp.hpl.jena.rdf.model.Resource; | ||
|
||
import javax.jcr.Node; | ||
import javax.jcr.Property; | ||
import javax.jcr.PropertyIterator; | ||
import javax.jcr.RepositoryException; | ||
import javax.jcr.Value; | ||
|
||
public class JcrPropertiesGenerator implements TripleGenerator { | ||
|
||
@Override | ||
public void updateResourceFromNode(final Resource resource, final Node node) throws RepositoryException { | ||
final PropertyIterator properties = node.getProperties(); | ||
|
||
while(properties.hasNext()) { | ||
|
||
final Property property = (Property) properties.next(); | ||
|
||
if(property.isMultiple()) { | ||
for(final Value v : property.getValues()) { | ||
addPropertyToResource(resource, property, v); | ||
} | ||
} | ||
else { | ||
addPropertyToResource(resource, property, property.getValue()); | ||
} | ||
} | ||
} | ||
|
||
private void addPropertyToResource(final Resource resource, final Property property, final Value v) throws RepositoryException { | ||
String n = property.getName(); | ||
|
||
final String[] parts = n.split(":", 2); | ||
|
||
String namespace = property.getParent().getSession().getWorkspace().getNamespaceRegistry().getURI(parts[0]); | ||
|
||
String local_part = parts[1]; | ||
|
||
resource.addProperty(resource.getModel().createProperty(namespace, local_part), v.getString()); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
fcrepo-generator-rdf/src/main/java/org/fcrepo/generator/rdf/TripleGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package org.fcrepo.generator.rdf; | ||
|
||
import com.hp.hpl.jena.rdf.model.Resource; | ||
|
||
import javax.jcr.Node; | ||
import javax.jcr.RepositoryException; | ||
|
||
public interface TripleGenerator { | ||
|
||
public void updateResourceFromNode(Resource resource, Node node) throws RepositoryException; | ||
|
||
} |
Oops, something went wrong.