Skip to content

Commit

Permalink
First working FOXML parser
Browse files Browse the repository at this point in the history
  • Loading branch information
ajs6f committed Jan 21, 2013
1 parent 2e189f0 commit 18bb92d
Show file tree
Hide file tree
Showing 10 changed files with 247 additions and 64 deletions.
106 changes: 85 additions & 21 deletions pom.xml
Expand Up @@ -20,7 +20,7 @@
<repository>
<id>jboss-public-repository-group</id>
<name>JBoss Public Maven Repository Group</name>
<url> http://repository.jboss.org/nexus/content/groups/public/ </url>
<url>http://repository.jboss.org/nexus/content/groups/public/</url>
<layout>default</layout>
<releases>
<enabled>true</enabled>
Expand All @@ -41,36 +41,36 @@
<dependency>
<groupId>org.modeshape.bom</groupId>
<artifactId>modeshape-bom-embedded</artifactId>
<version>3.0.1.Final</version>
<version>3.1.0.Final</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>tjws</artifactId>
<version>2.3.5.Final</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>tjws</artifactId>
<version>2.3.5.Final</version>
<scope>test</scope>
</dependency>


<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.4</version><!--$NO-MVN-MAN-VER$ -->
<scope>test</scope>
</dependency>


<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version><!--$NO-MVN-MAN-VER$ -->
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.jboss.resteasy</groupId>
Expand All @@ -97,6 +97,18 @@
<groupId>org.modeshape</groupId>
<artifactId>modeshape-jcr-api</artifactId>
</dependency>
<dependency>
<groupId>org.modeshape</groupId>
<artifactId>modeshape-jcr-api</artifactId>
</dependency>
<dependency>
<groupId>org.modeshape</groupId>
<artifactId>modeshape-sequencer-images</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.jbossts</groupId>
<artifactId>jbossjta</artifactId>
</dependency>

<!-- Logging: we'll use LogBack (which implements the SLF4J API); ModeShape
knows what to do. -->
Expand All @@ -115,9 +127,16 @@
<artifactId>guava-collections</artifactId>
<version>r03</version>
</dependency>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>2.10.0</version>
</dependency>
</dependencies>

<build>
<sourceDirectory>src/main/java</sourceDirectory>
<testSourceDirectory>src/test/java</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand All @@ -131,6 +150,50 @@
</compilerArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.scala-tools</groupId>
<artifactId>maven-scala-plugin</artifactId>
<version>2.15.2</version>
<configuration>
<args>
<arg>-feature</arg>
</args>
</configuration>
<executions>
<execution>
<id>scala-compile-first</id>
<phase>process-resources</phase>
<goals>
<goal>add-source</goal>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>scala-test-compile</id>
<phase>process-test-resources</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>src/main/scala</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
Expand Down Expand Up @@ -170,10 +233,11 @@
<configuration>
<scanIntervalSeconds>2</scanIntervalSeconds>
<webApp>
<contextPath>/ff</contextPath>
<contextPath>/</contextPath>
</webApp>
</configuration>
</plugin>

</plugins>
</build>

Expand Down
Expand Up @@ -49,7 +49,8 @@ public Response ingest(@PathParam("pid") final String pid)
final Node root = session.getRootNode();

if (session.hasPermission("/" + pid, "add_node")) {
final Node obj = root.addNode(pid, "fedora:object");
final Node obj = root.addNode(pid, "nt:folder");
obj.addMixin("fedora:object");
obj.addMixin("fedora:owned");
obj.addMixin("fedora:created");
obj.setProperty("fedora:ownerId", "Fedo Radmin");
Expand Down
Expand Up @@ -7,27 +7,30 @@
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) throws Exception {
Context context) {

getLogger().debug(
"Now sequencing FOXML from: " + inputProperty.getPath());
log.debug("Now sequencing FOXML with: ");
try {
log.debug(parser.report());
parser.parse(inputProperty.getBinary().getStream(), outputNode);
return true;
} catch (Exception e) {
getLogger().error(e, "Failed to sequence {}",
inputProperty.getPath());
log.error(e, new TextI18n("Failed to sequence FOXML"));
return false;
}

Expand Down
Expand Up @@ -27,22 +27,32 @@ public class FedoraOXML extends AbstractResource {

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")
// @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);
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;
Expand All @@ -63,7 +73,7 @@ public Response getFOXML(@PathParam("filename") final String filename)
} else
return four04;
}

@GET
@Path("/")
public Response getFOXMLs() throws RepositoryException {
Expand Down
19 changes: 4 additions & 15 deletions src/main/resources/fedora-node-types.cnd
Expand Up @@ -20,25 +20,20 @@
/*
* Any Fedora resource.
*/
[fedora:resource] > mix:lastModified, mix:versionable, nt:hierarchyNode abstract
[fedora:resource] > mix:created, mix:lastModified, mix:versionable, nt:hierarchyNode abstract


/*
* A Fedora object.
*/
[fedora:object] > fedora:resource
+ * (fedora:datastream) = fedora:datastream COPY
[fedora:object] > fedora:resource, nt:folder mixin
+ * COPY


/*
* A Fedora datastream.
*/
[fedora:datastream] > fedora:resource primaryitem fedora:content

/*
* The stuff in a datastream. Is left untyped in order to allow for the use of the JCR value type system.
*/
- fedora:content (UNDEFINED) mandatory COPY
[fedora:datastream] > fedora:resource, nt:file mixin

/*
* The MIMEtype of this datastream.
Expand All @@ -62,12 +57,6 @@
- fedora:ownerId (STRING) COPY


/*
* Indicates that this resource is owned.
*/
[fedora:created] > mix:created, mix:lastModified mixin


/*
* Some entity that owns a Fedora resource.
*/
Expand Down
62 changes: 62 additions & 0 deletions src/main/resources/infinispan_configuration.xml
@@ -0,0 +1,62 @@
<infinispan
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:infinispan:config:5.1 http://www.infinispan.org/schemas/infinispan-config-5.1.xsd"
xmlns="urn:infinispan:config:5.1">

<global>
<!-- Defines the global settings shared by all caches -->
</global>

<default>
<!--
Defines the default behavior for all caches, including those created dynamically (e.g., when a
repository uses a cache that doesn't exist in this configuration).
-->
</default>

<namedCache name="DataRepository">
<!--
Our Infinispan cache needs to be transactional. However, we'll also configure it to
use pessimistic locking, which is required whenever applications will be concurrently
updating nodes within the same process. If you're not sure, use pessimistic locking.
-->
<transaction transactionManagerLookupClass="org.infinispan.transaction.lookup.GenericTransactionManagerLookup"
transactionMode="TRANSACTIONAL"
lockingMode="PESSIMISTIC"/>
<!--
Define the cache loaders (i.e., cache stores). Passivation is false because we want *all*
data to be persisted, not just what doesn't fit into memory. Shared is false because there
are no other caches sharing this file store. We set preload to false for lazy loading;
may be improved by preloading and configuring eviction.
We can have multiple cache loaders, which get chained. But we'll define just one.
-->
<loaders passivation="false" shared="false" preload="false">

<!--
The 'fetchPersistentState' attribute applies when this cache joins the cluster; the value doesn't
really matter to us in this case. See the documentation for more options.
-->
<loader class="org.infinispan.loaders.file.FileCacheStore"
fetchPersistentState="false"
purgeOnStartup="true">
<!-- See the documentation for more configuration examples and flags. -->
<properties>
<!-- We have to set the location where we want to store the data. -->
<property name="location" value="DataRepository/storage"/>
</properties>
<!-- This repository isn't clustered, so we could set up the SingletonStore.
singletonStore enabled="true" pushStateWhenCoordinator="true" pushStateTimeout="20000"/>
-->
<!--
We could use "write-behind", which actually writes to the file system asynchronously,
which can improve performance as seen by the JCR client.
Plus changes are coalesced, meaning that if multiple changes are enqueued for the
same node, only the last one is written. (This is good much of the time, but not
always.)
<async enabled="true" flushLockTimeout="15000" threadPoolSize="5"/>
-->
</loader>
</loaders>
</namedCache>
</infinispan>

0 comments on commit 18bb92d

Please sign in to comment.