1 package org
.argeo
.jackrabbit
.fs
;
3 import java
.io
.IOException
;
6 import java
.nio
.file
.FileSystem
;
7 import java
.nio
.file
.Files
;
8 import java
.nio
.file
.Path
;
9 import java
.util
.HashMap
;
12 import javax
.jcr
.Session
;
13 import javax
.jcr
.SimpleCredentials
;
15 import org
.apache
.jackrabbit
.core
.RepositoryImpl
;
16 import org
.apache
.jackrabbit
.core
.config
.RepositoryConfig
;
17 import org
.argeo
.jcr
.fs
.JcrFileSystem
;
18 import org
.argeo
.jcr
.fs
.JcrFsException
;
20 public class JackrabbitMemoryFsProvider
extends AbstractJackrabbitFsProvider
{
21 private RepositoryImpl repository
;
22 private JcrFileSystem fileSystem
;
25 public String
getScheme() {
30 public FileSystem
newFileSystem(URI uri
, Map
<String
, ?
> env
) throws IOException
{
32 Path tempDir
= Files
.createTempDirectory("fs-memory");
33 URL confUrl
= getClass().getResource("fs-memory.xml");
34 RepositoryConfig repositoryConfig
= RepositoryConfig
.create(confUrl
.toURI(), tempDir
.toString());
35 repository
= RepositoryImpl
.create(repositoryConfig
);
36 String username
= System
.getProperty("user.name");
37 Session session
= repository
.login(new SimpleCredentials(username
, username
.toCharArray()));
38 fileSystem
= new JcrFileSystem(this, session
);
40 } catch (Exception e
) {
41 throw new JcrFsException("Cannot login to repository", e
);
46 public FileSystem
getFileSystem(URI uri
) {
51 public Path
getPath(URI uri
) {
52 String path
= uri
.getPath();
55 newFileSystem(uri
, new HashMap
<String
, Object
>());
56 } catch (IOException e
) {
57 throw new JcrFsException("Could not autocreate file system",e
);
59 return fileSystem
.getPath(path
);