Skip to content

Commit

Permalink
JAXB-ification complete.
Browse files Browse the repository at this point in the history
  • Loading branch information
ajs6f committed Feb 5, 2013
1 parent 0a0b029 commit dc05287
Show file tree
Hide file tree
Showing 11 changed files with 82 additions and 88 deletions.
43 changes: 31 additions & 12 deletions pom.xml
Expand Up @@ -17,6 +17,7 @@
<modeshape.version>3.1.1.Final</modeshape.version>
<cxf.version>2.7.2</cxf.version>
<activemq.version>5.7.0</activemq.version>
<enunciate.version>1.26.2</enunciate.version>
</properties>


Expand Down Expand Up @@ -82,11 +83,6 @@
<artifactId>logback-classic</artifactId>
</dependency>

<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.19</version>
</dependency>

<dependency>
<groupId>org.scala-lang</groupId>
Expand Down Expand Up @@ -149,6 +145,11 @@
<artifactId>abdera-parser</artifactId>
<version>1.1.3</version>
</dependency>
<dependency>
<groupId>org.codehaus.enunciate</groupId>
<artifactId>enunciate-cxf-rt</artifactId>
<version>${enunciate.version}</version>
</dependency>
</dependencies>

<build>
Expand All @@ -173,7 +174,7 @@
</goals>
</pluginExecutionFilter>
<action>
<ignore />
<execute />
</action>
</pluginExecution>
<pluginExecution>
Expand All @@ -188,7 +189,26 @@
</goals>
</pluginExecutionFilter>
<action>
<ignore />
<execute />
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>
org.codehaus.enunciate
</groupId>
<artifactId>
maven-enunciate-cxf-plugin
</artifactId>
<versionRange>
[1.26.2,)
</versionRange>
<goals>
<goal>docs</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute />
</action>
</pluginExecution>
</pluginExecutions>
Expand Down Expand Up @@ -300,23 +320,22 @@
</webApp>
</configuration>
</plugin>
<!--
<plugin>
<groupId>org.codehaus.enunciate</groupId>
<artifactId>maven-enunciate-plugin</artifactId>
<version>1.26</version>
<artifactId>maven-enunciate-cxf-plugin</artifactId>
<version>${enunciate.version}</version>
<executions>
<execution>
<goals>
<goal>docs</goal>
</goals>
<configuration>
<configFile>${basedir}/src/main/enunciate/enunciate.xml</configFile>
<docsDir>${project.build.directory}/docs</docsDir>
</configuration>
</execution>
</executions>
</plugin>-->
</plugin>
</plugins>
</build>

Expand Down
10 changes: 10 additions & 0 deletions src/main/enunciate/enunciate.xml
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<enunciate xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://enunciate.codehaus.org/schemas/enunciate-1.26.xsd">
<modules>
<c disabled="true"/>
<csharp disabled="true"/>
<cxf disabled="true"/>
<jaxws-ri disabled="true"/>
</modules>
</enunciate>
36 changes: 1 addition & 35 deletions src/main/java/org/fcrepo/modeshape/AbstractResource.java
@@ -1,12 +1,5 @@
package org.fcrepo.modeshape;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.util.Map;

import javax.annotation.PostConstruct;
import javax.inject.Inject;
import javax.jcr.LoginException;
Expand All @@ -25,11 +18,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import freemarker.ext.beans.BeansWrapper;
import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;

/**
* Abstract superclass for Fedora JAX-RS Resources, providing convenience fields
* and methods.
Expand All @@ -41,7 +29,7 @@ public abstract class AbstractResource extends Constants {

final private Logger logger = LoggerFactory
.getLogger(AbstractResource.class);

/**
* Useful for constructing URLs
*/
Expand Down Expand Up @@ -69,12 +57,6 @@ public abstract class AbstractResource extends Constants {

static protected Workspace ws;

/**
* A Freemarker Configuration for use in generating XML responses. Should
* eventually be replaced by the use of proper JAX-RS Providers.
*/
final static protected Configuration freemarker = new Configuration();

/**
* A convenience object provided by ModeShape for acting against the JCR
* repository.
Expand All @@ -87,10 +69,6 @@ public void initialize() throws LoginException, NoSuchWorkspaceException,

ws = repo.login("fedora").getWorkspace();
ws.getNamespaceRegistry().registerNamespace("test", "info:fedora/test");

freemarker.setObjectWrapper(new BeansWrapper());
// Specify the data source where the template files come from.
freemarker.setClassForTemplateLoading(this.getClass(), "/freemarker");
}

protected synchronized Response deleteResource(final String path)
Expand All @@ -117,16 +95,4 @@ protected synchronized Response deleteResource(final String path)
}
}

protected InputStream renderTemplate(final String templatename,
final Map<String, ?> map) throws RepositoryException, IOException,
TemplateException {

final Template template = freemarker.getTemplate(templatename);
final ByteArrayOutputStream out = new ByteArrayOutputStream();
template.process(map, new OutputStreamWriter(out));
InputStream in = new ByteArrayInputStream(out.toByteArray());
out.close();
return in;
}

}
23 changes: 12 additions & 11 deletions src/main/java/org/fcrepo/modeshape/FedoraDatastreams.java
Expand Up @@ -11,6 +11,7 @@
import java.io.InputStream;
import java.net.URI;
import java.util.Calendar;
import java.util.Collections;

import javax.jcr.Node;
import javax.jcr.NodeIterator;
Expand All @@ -30,6 +31,7 @@
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import org.fcrepo.modeshape.jaxb.responses.DatastreamHistory;
import org.fcrepo.modeshape.jaxb.responses.DatastreamProfile;
import org.fcrepo.modeshape.jaxb.responses.ObjectDatastreams;
import org.fcrepo.modeshape.jaxb.responses.ObjectDatastreams.Datastream;
Expand All @@ -38,11 +40,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet.Builder;

import freemarker.template.TemplateException;

@Path("/objects/{pid}/datastreams")
public class FedoraDatastreams extends AbstractResource {

Expand All @@ -64,7 +63,7 @@ public class FedoraDatastreams extends AbstractResource {
@Path("/")
@Produces({ TEXT_XML, APPLICATION_JSON })
public Response getDatastreams(@PathParam("pid") final String pid)
throws RepositoryException, IOException, TemplateException {
throws RepositoryException, IOException {

final Session session = repo.login();

Expand Down Expand Up @@ -253,7 +252,7 @@ private URI addDatastreamNode(final String dsPath,
@Produces("text/xml")
public Response getDatastream(@PathParam("pid") final String pid,
@PathParam("dsid") final String dsid) throws RepositoryException,
IOException, TemplateException {
IOException {

Session session = repo.login();

Expand Down Expand Up @@ -329,19 +328,21 @@ public Response getDatastreamContent(@PathParam("pid") final String pid,
@GET
@Path("/{dsid}/versions")
@Produces("text/xml")
// TODO implement this after deciding on a versioning model
public Response getDatastreamHistory(@PathParam("pid") final String pid,
@PathParam("dsid") final String dsid) throws RepositoryException,
IOException, TemplateException {
IOException {

final Session session = repo.login();
final String dsPath = pid + "/" + dsid;
final String dsPath = "/" + pid + "/" + dsid;

if (session.nodeExists(dsPath)) {
final Node ds = session.getNode(dsPath);
final InputStream content = renderTemplate("datastreamHistory.ftl",
ImmutableMap.of("ds", ds, "obj", ds.getParent()));
session.logout();
return Response.ok().entity(content).build();
return Response
.ok()
.entity(new DatastreamHistory(Collections
.singletonList(new DatastreamProfile()))).build();
} else {
session.logout();
return four04;
Expand Down Expand Up @@ -369,7 +370,7 @@ public Response getDatastreamHistory(@PathParam("pid") final String pid,
@Deprecated
public Response getDatastreamHistoryOld(@PathParam("pid") final String pid,
@PathParam("dsid") final String dsid) throws RepositoryException,
IOException, TemplateException {
IOException {
return getDatastreamHistory(pid, dsid);
}

Expand Down
4 changes: 1 addition & 3 deletions src/main/java/org/fcrepo/modeshape/FedoraIdentifiers.java
Expand Up @@ -18,8 +18,6 @@

import com.google.common.base.Function;

import freemarker.template.TemplateException;

/**
* JAX-RS Resource offering PID creation.
*
Expand All @@ -40,7 +38,7 @@ public class FedoraIdentifiers extends AbstractResource {
@Produces("text/xml")
public NextPid getNextPid(
@QueryParam("numPids") @DefaultValue("1") Integer numPids)
throws RepositoryException, IOException, TemplateException {
throws RepositoryException, IOException {

return new NextPid(copyOf(transform(closed(1, numPids)
.asSet(integers()), makePid)));
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/org/fcrepo/modeshape/FedoraNamespaces.java
Expand Up @@ -25,7 +25,6 @@

import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSet.Builder;
import freemarker.template.TemplateException;

/**
* The purpose of this class is to allow clients to manipulate the JCR
Expand Down Expand Up @@ -118,7 +117,7 @@ public Response getObjectNamespaces() throws RepositoryException {
@Path("")
@Produces("text/xml")
public Response getObjectNamespacesInXML() throws RepositoryException,
IOException, TemplateException {
IOException {

final Session session = repo.login();
final NamespaceRegistry r = session.getWorkspace()
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/org/fcrepo/modeshape/FedoraObjects.java
Expand Up @@ -21,8 +21,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import freemarker.template.TemplateException;

@Path("/objects")
public class FedoraObjects extends AbstractResource {

Expand Down Expand Up @@ -81,7 +79,7 @@ public Response ingest(@PathParam("pid") final String pid)
@Path("/{pid}")
@Produces("text/xml")
public Response getObjectInXML(@PathParam("pid") final String pid)
throws RepositoryException, IOException, TemplateException {
throws RepositoryException, IOException {

final Session session = repo.login();

Expand Down
@@ -0,0 +1,20 @@
package org.fcrepo.modeshape.jaxb.responses;

import java.util.List;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name = "datastreamHistory", namespace = "http://www.fedora.info/definitions/1/0/management/")
public class DatastreamHistory {

@XmlElement
List<DatastreamProfile> datastreamProfiles;

public DatastreamHistory() {
}

public DatastreamHistory(List<DatastreamProfile> datastreamProfiles) {
this.datastreamProfiles = datastreamProfiles;
}
}
@@ -1,6 +1,7 @@
@XmlSchema(elementFormDefault = XmlNsForm.UNQUALIFIED, xmlns = {
@XmlNs(prefix = "fedora-access", namespaceURI = "http://www.fedora.info/definitions/1/0/access/"),
@XmlNs(prefix = "fedora-management", namespaceURI = "http://www.fedora.info/definitions/1/0/management/") })
@XmlNs(prefix = "fedora-management", namespaceURI = "http://www.fedora.info/definitions/1/0/management/"),
@XmlNs(prefix = "none", namespaceURI = "") })
package org.fcrepo.modeshape.jaxb.responses;

import javax.xml.bind.annotation.XmlSchema;
Expand Down
18 changes: 0 additions & 18 deletions src/main/resources/freemarker/datastreamHistory.ftl

This file was deleted.

6 changes: 3 additions & 3 deletions src/main/resources/spring/rest.xml
Expand Up @@ -12,14 +12,14 @@
<import resource="classpath:META-INF/cxf/osgi/cxf-extension-osgi.xml"/>

<!-- Context that houses JAX-RS Resources that compose the API
as well as som utility gear. -->
as well as som utility gear. -->

<context:annotation-config/>

<!-- Supports JSON output for API methods. Should be replaced with a properly-
configured JAX-RS Provider-->
<bean class="org.codehaus.jackson.map.ObjectMapper"/>

<!-- Mints PIDs-->
<bean class="org.fcrepo.modeshape.identifiers.UUIDPidMinter"/>

Expand Down

0 comments on commit dc05287

Please sign in to comment.