-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
2,277 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# ignore Maven generated target folders | ||
target | ||
|
||
# ignore eclipse files and folders | ||
.project | ||
.classpath | ||
.settings | ||
.metadata | ||
.scala_dependencies | ||
.externalToolBuilders | ||
/.metadata | ||
/RemoteSystemsTempFiles | ||
|
||
# ignore overlay folders | ||
overlays | ||
|
||
# ignore IDEA files | ||
*.iml | ||
*.ipr | ||
*.iws | ||
.idea | ||
atlassian-ide-plugin.xml | ||
|
||
# log files | ||
*.log | ||
|
||
# Object files | ||
ObjectStore | ||
|
||
# Compiled python files | ||
*.pyc | ||
|
||
# REST client module bin folder | ||
/tools/org.modeshape.eclipse.jcr.rest.client/bin | ||
|
||
# Presentation Keynote files | ||
/docs/presentations/*.key | ||
|
||
# ignore OS X (Mac) files | ||
.DS_Store |
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,49 @@ | ||
<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"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>org.polyglotter</groupId> | ||
<artifactId>modeshape</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>modeshape-files</artifactId> | ||
|
||
<dependencies> | ||
|
||
<!-- Java Content Repository API --> | ||
<dependency> | ||
<groupId>javax.jcr</groupId> | ||
<artifactId>jcr</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.modeshape</groupId> | ||
<artifactId>modeshape-jcr</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.modeshape</groupId> | ||
<artifactId>modeshape-sequencer-xml</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.modeshape</groupId> | ||
<artifactId>modeshape-sequencer-xsd</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.modeshape</groupId> | ||
<artifactId>modeshape-sequencer-sramp</artifactId> | ||
</dependency> | ||
|
||
<!-- Test --> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
</project> |
168 changes: 168 additions & 0 deletions
168
modeshape-files/src/main/java/org/modeshape/files/ModeShapeFileManager.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,168 @@ | ||
/* | ||
* Polyglotter (http://polyglotter.org) | ||
* See the COPYRIGHT.txt file distributed with this work for information | ||
* regarding copyright ownership. Some portions may be licensed | ||
* to Red Hat, Inc. under one or more contributor license agreements. | ||
* See the AUTHORS.txt file in the distribution for a full listing of | ||
* individual contributors. | ||
* | ||
* Polyglotter is free software. Unless otherwise indicated, all code in Polyglotter | ||
* is licensed to you under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation; either version 2.1 of | ||
* the License, or (at your option) any later version. | ||
* | ||
* Polyglotter is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this software; if not, write to the Free | ||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org. | ||
*/ | ||
package org.modeshape.files; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.concurrent.CountDownLatch; | ||
import java.util.concurrent.ExecutionException; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import javax.jcr.Node; | ||
import javax.jcr.Repository; | ||
import javax.jcr.RepositoryException; | ||
import javax.jcr.Session; | ||
import javax.jcr.observation.Event; | ||
import javax.jcr.observation.EventIterator; | ||
import javax.jcr.observation.EventListener; | ||
import javax.jcr.observation.ObservationManager; | ||
|
||
import org.modeshape.common.collection.Problem; | ||
import org.modeshape.common.collection.Problems; | ||
import org.modeshape.common.logging.Logger; | ||
import org.modeshape.common.util.CheckArg; | ||
import org.modeshape.jcr.ModeShapeEngine; | ||
import org.modeshape.jcr.NoSuchRepositoryException; | ||
import org.modeshape.jcr.RepositoryConfiguration; | ||
import org.modeshape.jcr.api.JcrTools; | ||
import org.modeshape.jcr.api.observation.Event.Sequencing; | ||
|
||
public final class ModeShapeFileManager { | ||
|
||
public static final String DEFAULT_MODESHAPE_CONFIGURATION_PATH = "jcr/modeShapeConfig.json"; | ||
|
||
private String modeShapeConfigurationPath = DEFAULT_MODESHAPE_CONFIGURATION_PATH; | ||
private ModeShapeEngine modeShape; | ||
private Session session; | ||
|
||
/** | ||
* @return the path to the ModeShape configuration file. Default is {@value #DEFAULT_MODESHAPE_CONFIGURATION_PATH}. | ||
*/ | ||
public String modeShapeConfigurationPath() { | ||
return modeShapeConfigurationPath; | ||
} | ||
|
||
/** | ||
* @return the JCR repository session (never <code>null</code>) | ||
* @throws ModeShapeFileManagerException | ||
*/ | ||
public Session session() throws ModeShapeFileManagerException { | ||
if ( this.session == null ) { | ||
modeShape = new ModeShapeEngine(); | ||
modeShape.start(); | ||
try { | ||
final RepositoryConfiguration config = RepositoryConfiguration.read( modeShapeConfigurationPath ); | ||
final Problems problems = config.validate(); | ||
if ( problems.hasProblems() ) { | ||
for ( final Problem problem : problems ) | ||
Logger.getLogger( getClass() ).error( problem.getMessage(), problem.getThrowable() ); | ||
throw problems.iterator().next().getThrowable(); | ||
} | ||
Repository repository; | ||
try { | ||
repository = modeShape.getRepository( config.getName() ); | ||
} catch ( final NoSuchRepositoryException err ) { | ||
repository = modeShape.deploy( config ); | ||
} | ||
session = repository.login( "default" ); | ||
Logger.getLogger( getClass() ).info( ModeShapeFileManagerI18n.modeShapeFileManagerStarted ); | ||
} catch ( final Throwable e ) { | ||
throw new ModeShapeFileManagerException( e ); | ||
} | ||
} | ||
return session; | ||
} | ||
|
||
public void setModeShapeConfigurationPath( final String modeShapeConfigurationPath ) { | ||
this.modeShapeConfigurationPath = modeShapeConfigurationPath == null ? DEFAULT_MODESHAPE_CONFIGURATION_PATH | ||
: modeShapeConfigurationPath; | ||
} | ||
|
||
/** | ||
* @throws ModeShapeFileManagerException | ||
*/ | ||
public void stop() throws ModeShapeFileManagerException { | ||
if ( session == null ) Logger.getLogger( getClass() ) | ||
.debug( "Attempt to stop ModeShape File Manager when it is already stopped" ); | ||
else { | ||
session.logout(); | ||
try { | ||
modeShape.shutdown().get(); | ||
} catch ( InterruptedException | ExecutionException e ) { | ||
throw new ModeShapeFileManagerException( e ); | ||
} | ||
session = null; | ||
Logger.getLogger( getClass() ).info( ModeShapeFileManagerI18n.modeShapeFileManagerStopped ); | ||
} | ||
} | ||
|
||
/** | ||
* @param file | ||
* @param workspaceParentPath | ||
* @return The node representing the imported file | ||
* @throws ModeShapeFileManagerException | ||
*/ | ||
public Node upload( final File file, | ||
final String workspaceParentPath ) throws ModeShapeFileManagerException { | ||
CheckArg.isNotNull( file, "file" ); | ||
final String path = workspaceParentPath == null ? file.getName() : workspaceParentPath.endsWith( "/" ) | ||
? workspaceParentPath | ||
+ '/' | ||
+ file.getName() | ||
: workspaceParentPath | ||
+ file.getName(); | ||
try { | ||
final ObservationManager observationMgr = session().getWorkspace().getObservationManager(); | ||
final CountDownLatch latch = new CountDownLatch( 1 ); | ||
final EventListener listener = new EventListener() { | ||
|
||
@Override | ||
public void onEvent( final EventIterator events ) { | ||
final Event event = events.nextEvent(); | ||
try { | ||
try { | ||
if ( event.getType() == Sequencing.NODE_SEQUENCING_FAILURE ) { | ||
Logger.getLogger( getClass() ).error( ModeShapeFileManagerI18n.unableToSequenceUploadedFile, path, | ||
event.getInfo().get( Sequencing.SEQUENCING_FAILURE_CAUSE ) ); | ||
} | ||
} catch ( final RepositoryException e ) { | ||
throw new RuntimeException( e ); | ||
} | ||
} finally { | ||
latch.countDown(); | ||
} | ||
} | ||
}; | ||
observationMgr.addEventListener( listener, Sequencing.ALL, "/", true, null, null, false ); | ||
final Node node = new JcrTools().uploadFile( session, path, file ); | ||
node.addMixin( "modefm:unstructured" ); | ||
session.save(); | ||
if ( !latch.await( 15, TimeUnit.SECONDS ) ) Logger.getLogger( getClass() ).debug( "Timed out" ); | ||
observationMgr.removeEventListener( listener ); | ||
return node; | ||
} catch ( RepositoryException | IOException | InterruptedException e ) { | ||
throw new ModeShapeFileManagerException( e ); | ||
} | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
modeshape-files/src/main/java/org/modeshape/files/ModeShapeFileManagerException.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,53 @@ | ||
/* | ||
* Polyglotter (http://polyglotter.org) | ||
* See the COPYRIGHT.txt file distributed with this work for information | ||
* regarding copyright ownership. Some portions may be licensed | ||
* to Red Hat, Inc. under one or more contributor license agreements. | ||
* See the AUTHORS.txt file in the distribution for a full listing of | ||
* individual contributors. | ||
* | ||
* Polyglotter is free software. Unless otherwise indicated, all code in Polyglotter | ||
* is licensed to you under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation; either version 2.1 of | ||
* the License, or (at your option) any later version. | ||
* | ||
* Polyglotter is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this software; if not, write to the Free | ||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org. | ||
*/ | ||
|
||
package org.modeshape.files; | ||
|
||
public class ModeShapeFileManagerException extends Exception { | ||
|
||
/** | ||
* @param message | ||
*/ | ||
public ModeShapeFileManagerException( final String message ) { | ||
super( message ); | ||
|
||
} | ||
|
||
/** | ||
* @param message | ||
* @param cause | ||
*/ | ||
public ModeShapeFileManagerException( final String message, | ||
final Throwable cause ) { | ||
super( message, cause ); | ||
|
||
} | ||
|
||
/** | ||
* @param cause | ||
*/ | ||
public ModeShapeFileManagerException( final Throwable cause ) { | ||
super( cause ); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
modeshape-files/src/main/java/org/modeshape/files/ModeShapeFileManagerI18n.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,44 @@ | ||
/* | ||
* Polyglotter (http://polyglotter.org) | ||
* See the COPYRIGHT.txt file distributed with this work for information | ||
* regarding copyright ownership. Some portions may be licensed | ||
* to Red Hat, Inc. under one or more contributor license agreements. | ||
* See the AUTHORS.txt file in the distribution for a full listing of | ||
* individual contributors. | ||
* | ||
* Polyglotter is free software. Unless otherwise indicated, all code in Polyglotter | ||
* is licensed to you under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation; either version 2.1 of | ||
* the License, or (at your option) any later version. | ||
* | ||
* Polyglotter is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this software; if not, write to the Free | ||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org. | ||
*/ | ||
package org.modeshape.files; | ||
|
||
import org.modeshape.common.i18n.I18n; | ||
|
||
/** | ||
* Internationalized string constants for the <strong>ModeShape File Manager</strong> project. | ||
*/ | ||
public class ModeShapeFileManagerI18n { | ||
|
||
public static I18n modeShapeFileManagerStarted; | ||
public static I18n modeShapeFileManagerStopped; | ||
public static I18n unableToSequenceUploadedFile; | ||
|
||
static { | ||
try { | ||
I18n.initialize( ModeShapeFileManagerI18n.class ); | ||
} catch ( final Exception err ) { | ||
System.err.println( err ); | ||
} | ||
} | ||
} |
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,30 @@ | ||
/* | ||
* Polyglotter (http://polyglotter.org) | ||
* See the COPYRIGHT.txt file distributed with this work for information | ||
* regarding copyright ownership. Some portions may be licensed | ||
* to Red Hat, Inc. under one or more contributor license agreements. | ||
* See the AUTHORS.txt file in the distribution for a full listing of | ||
* individual contributors. | ||
* | ||
* Polyglotter is free software. Unless otherwise indicated, all code in Polyglotter | ||
* is licensed to you under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation; either version 2.1 of | ||
* the License, or (at your option) any later version. | ||
* | ||
* Polyglotter is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this software; if not, write to the Free | ||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org. | ||
*/ | ||
<nt='http://www.jcp.org/jcr/nt/1.0'> | ||
<modefm='http://modeshape.org/modeshape-files/1.0'> | ||
|
||
[modefm:unstructured] mixin orderable | ||
- * (undefined) multiple | ||
- * (undefined) | ||
+ * (nt:base) = nt:unstructured sns version |
Oops, something went wrong.