import java.util.HashMap;
import java.util.Map;
+import javax.jcr.Credentials;
+import javax.jcr.Repository;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.SimpleCredentials;
private RepositoryImpl repository;
private JcrFileSystem fileSystem;
+ private Credentials credentials;
+
+ public JackrabbitMemoryFsProvider() {
+ String username = System.getProperty("user.name");
+ credentials = new SimpleCredentials(username, username.toCharArray());
+ }
+
@Override
public String getScheme() {
return "jcr+memory";
public FileSystem newFileSystem(URI uri, Map<String, ?> env) throws IOException {
try {
Path tempDir = Files.createTempDirectory("fs-memory");
- URL confUrl = getClass().getResource("fs-memory.xml");
+ URL confUrl = JackrabbitMemoryFsProvider.class.getResource("fs-memory.xml");
RepositoryConfig repositoryConfig = RepositoryConfig.create(confUrl.toURI(), tempDir.toString());
repository = RepositoryImpl.create(repositoryConfig);
- String username = System.getProperty("user.name");
- Session session = repository.login(new SimpleCredentials(username, username.toCharArray()));
- fileSystem = new JcrFileSystem(this, session);
+ postRepositoryCreation(repository);
+ fileSystem = new JcrFileSystem(this, repository, credentials);
return fileSystem;
} catch (RepositoryException | URISyntaxException e) {
throw new IOException("Cannot login to repository", e);
return fileSystem.getPath(path);
}
+ public Repository getRepository() {
+ return repository;
+ }
+
+ public Session login() throws RepositoryException {
+ return getRepository().login(credentials);
+ }
+
+ /**
+ * Called after the repository has been created and before the file system is
+ * created.
+ */
+ protected void postRepositoryCreation(RepositoryImpl repositoryImpl) throws RepositoryException {
+
+ }
}