Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Just cant get this dang sequencer to engage
- Loading branch information
Showing
7 changed files
with
430 additions
and
12 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
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
47 changes: 47 additions & 0 deletions
47
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,47 @@ | ||
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.jcr.api.nodetype.NodeTypeManager; | ||
import org.modeshape.jcr.api.sequencer.Sequencer; | ||
|
||
public class FOXMLSequencer extends Sequencer { | ||
|
||
private FOXMLParser parser; | ||
|
||
public String description; | ||
|
||
@Override | ||
public boolean execute(Property inputProperty, Node outputNode, | ||
Context context) throws Exception { | ||
|
||
getLogger().debug( | ||
"Now sequencing FOXML from: " + inputProperty.getPath()); | ||
try { | ||
parser.parse(inputProperty.getBinary().getStream(), outputNode); | ||
return true; | ||
} catch (Exception e) { | ||
getLogger().error(e, "Failed to sequence {}", | ||
inputProperty.getPath()); | ||
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(); | ||
} | ||
|
||
} |
87 changes: 87 additions & 0 deletions
87
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,87 @@ | ||
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); | ||
|
||
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 { | ||
logger.debug("Operating in workspace: " + ws.getName()); | ||
final Session session = ws.getSession(); | ||
if (session.hasPermission("/foxml", "add_node")) { | ||
final Node foxmlnode = jcrtools.uploadFile(session, "/foxml/" | ||
+ filename, foxml); | ||
session.save(); | ||
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(); | ||
|
||
} | ||
} |
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
29 changes: 29 additions & 0 deletions
29
src/main/scala/org/fcrepo/ffmodeshapeprototype/foxml/FOXMLParser.scala
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,29 @@ | ||
package org.fcrepo.ffmodeshapeprototype.foxml | ||
|
||
import javax.jcr._ | ||
import java.io.InputStream | ||
import xml.XML | ||
|
||
class FOXMLParser { | ||
|
||
def parse(input: InputStream, objNode: Node) { | ||
|
||
val foxmlObj = XML.load(input) \ "digitalObject" | ||
|
||
objNode.setPrimaryType("fedora:object") | ||
|
||
val objProperties = foxmlObj \ "objectProperties" \ "property" | ||
val ownerProperty = objProperties filter (p => ((p.\("@NAME")) text) == "info:fedora/fedora-system:def/model#ownerId") | ||
val ownerId = (ownerProperty \ "@VALUE") text | ||
|
||
objNode.setProperty("fedora:ownerId", ownerId) | ||
|
||
for (datastream <- foxmlObj \\ "datastream") { | ||
var dsNode = objNode.addNode(datastream \ "@ID" text, "fedora:datastream") | ||
dsNode.setProperty("fedora:contentType", | ||
(datastream \ "datastreamVersion").head \ "@MIMETYPE" text) | ||
} | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.