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
Added FOXML JAXRS resource and ModeShape sequencer
- Loading branch information
Showing
2 changed files
with
147 additions
and
0 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
src/main/java/org/fcrepo/ffmodeshapeprototype/foxml/FOXMLSequencer.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,50 @@ | ||
package org.fcrepo.ffmodeshapeprototype.foxml; | ||
|
||
import java.io.IOException; | ||
|
||
import javax.jcr.NamespaceRegistry; | ||
import javax.jcr.Node; | ||
import javax.jcr.Property; | ||
import javax.jcr.RepositoryException; | ||
|
||
import org.modeshape.common.i18n.TextI18n; | ||
import org.modeshape.common.logging.Logger; | ||
import org.modeshape.jcr.api.nodetype.NodeTypeManager; | ||
import org.modeshape.jcr.api.sequencer.Sequencer; | ||
|
||
public class FOXMLSequencer extends Sequencer { | ||
|
||
private final Logger log = Logger.getLogger(FOXMLSequencer.class); | ||
|
||
private FOXMLParser parser; | ||
|
||
public String description; | ||
|
||
@Override | ||
public boolean execute(Property inputProperty, Node outputNode, | ||
Context context) { | ||
|
||
log.debug("Now sequencing FOXML with: "); | ||
try { | ||
log.debug(parser.report()); | ||
parser.parse(inputProperty.getBinary().getStream(), outputNode); | ||
return true; | ||
} catch (Exception e) { | ||
log.error(e, new TextI18n("Failed to sequence FOXML")); | ||
return false; | ||
} | ||
|
||
} | ||
|
||
@Override | ||
public void initialize(NamespaceRegistry registry, | ||
NodeTypeManager nodeTypeManager) throws RepositoryException, | ||
IOException { | ||
// registerDefaultMimeTypes("text/xml"); | ||
getLogger().debug( | ||
"Initializing " + getClass().getCanonicalName() + "[" | ||
+ getName() + "]"); | ||
parser = new FOXMLParser(); | ||
} | ||
|
||
} |
97 changes: 97 additions & 0 deletions
97
src/main/java/org/fcrepo/ffmodeshapeprototype/foxml/FedoraOXML.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,97 @@ | ||
package org.fcrepo.ffmodeshapeprototype.foxml; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.net.URI; | ||
|
||
import javax.jcr.Node; | ||
import javax.jcr.NodeIterator; | ||
import javax.jcr.RepositoryException; | ||
import javax.jcr.Session; | ||
import javax.ws.rs.Consumes; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.PUT; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.PathParam; | ||
import javax.ws.rs.core.Response; | ||
|
||
import org.fcrepo.ffmodeshapeprototype.AbstractResource; | ||
import org.modeshape.common.logging.Logger; | ||
import org.modeshape.jcr.ConfigurationException; | ||
import org.modeshape.jcr.api.JcrTools; | ||
|
||
@Path("/foxml") | ||
public class FedoraOXML extends AbstractResource { | ||
|
||
private final JcrTools jcrtools = new JcrTools(); | ||
|
||
private final Logger logger = Logger.getLogger(FedoraOXML.class); | ||
|
||
static private final FOXMLSequencer fseq = new FOXMLSequencer(); | ||
|
||
public FedoraOXML() throws ConfigurationException, RepositoryException, | ||
IOException { | ||
super(); | ||
} | ||
|
||
@PUT | ||
@Path("/{filename}") | ||
// @Consumes("text/xml") | ||
public Response addFOXML(@PathParam("filename") final String filename, | ||
InputStream foxml) throws RepositoryException, IOException { | ||
|
||
final Session session = ws.getSession(); | ||
if (session.hasPermission("/foxml", "add_node")) { | ||
final String foxmlpath = "/foxml/" + filename; | ||
logger.debug("Adding or updating FOXML file at " + ws.getName() | ||
+ ":" + foxmlpath); | ||
final Node foxmlnode = jcrtools.uploadFile(session, foxmlpath, | ||
foxml); | ||
session.save(); | ||
/* | ||
* fseq.execute( foxmlnode.getNode("jcr:content") | ||
* .getProperty("jcr:data"), session.getRootNode() | ||
* .addNode(filename,"nt:folder"), null); | ||
*/ | ||
return Response.created(URI.create(foxmlnode.getPath())).build(); | ||
} else | ||
return four01; | ||
} | ||
|
||
@GET | ||
@Path("/{filename}") | ||
public Response getFOXML(@PathParam("filename") final String filename) | ||
throws RepositoryException { | ||
|
||
final Node foxmlfolder = ws.getSession().getNode("/foxml"); | ||
|
||
if (foxmlfolder.hasNode(filename)) { | ||
final Node foxmlfile = foxmlfolder.getNode(filename); | ||
return Response.ok( | ||
foxmlfile.getNode("jcr:content").getProperty("jcr:data") | ||
.getBinary().getStream(), "text/xml").build(); | ||
} else | ||
return four04; | ||
} | ||
|
||
@GET | ||
@Path("/") | ||
public Response getFOXMLs() throws RepositoryException { | ||
Session session = ws.getSession(); | ||
Node foxml = session.getNode("/foxml"); | ||
StringBuffer nodes = new StringBuffer(); | ||
|
||
for (NodeIterator i = foxml.getNodes(); i.hasNext();) { | ||
Node n = i.nextNode(); | ||
nodes.append("Name: " + n.getName() + ", Path:" + n.getPath() | ||
+ "\n"); | ||
for (NodeIterator j = n.getNodes(); j.hasNext();) { | ||
Node n2 = j.nextNode(); | ||
nodes.append("\t Path:" + n2.getPath() + "\n"); | ||
} | ||
} | ||
|
||
return Response.ok().entity(nodes.toString()).build(); | ||
|
||
} | ||
} |