1 package org
.argeo
.jackrabbit
.fs
;
3 import java
.io
.IOException
;
5 import java
.net
.URISyntaxException
;
7 import java
.nio
.file
.FileSystem
;
8 import java
.nio
.file
.Files
;
9 import java
.nio
.file
.Path
;
10 import java
.util
.HashMap
;
13 import javax
.jcr
.RepositoryException
;
14 import javax
.jcr
.Session
;
15 import javax
.jcr
.SimpleCredentials
;
17 import org
.apache
.jackrabbit
.core
.RepositoryImpl
;
18 import org
.apache
.jackrabbit
.core
.config
.RepositoryConfig
;
19 import org
.argeo
.jcr
.fs
.JcrFileSystem
;
20 import org
.argeo
.jcr
.fs
.JcrFsException
;
22 public class JackrabbitMemoryFsProvider
extends AbstractJackrabbitFsProvider
{
23 private RepositoryImpl repository
;
24 private JcrFileSystem fileSystem
;
27 public String
getScheme() {
32 public FileSystem
newFileSystem(URI uri
, Map
<String
, ?
> env
) throws IOException
{
34 Path tempDir
= Files
.createTempDirectory("fs-memory");
35 URL confUrl
= getClass().getResource("fs-memory.xml");
36 RepositoryConfig repositoryConfig
= RepositoryConfig
.create(confUrl
.toURI(), tempDir
.toString());
37 repository
= RepositoryImpl
.create(repositoryConfig
);
38 String username
= System
.getProperty("user.name");
39 Session session
= repository
.login(new SimpleCredentials(username
, username
.toCharArray()));
40 fileSystem
= new JcrFileSystem(this, session
);
42 } catch (RepositoryException
| URISyntaxException e
) {
43 throw new IOException("Cannot login to repository", e
);
48 public FileSystem
getFileSystem(URI uri
) {
53 public Path
getPath(URI uri
) {
54 String path
= uri
.getPath();
55 if (fileSystem
== null)
57 newFileSystem(uri
, new HashMap
<String
, Object
>());
58 } catch (IOException e
) {
59 throw new JcrFsException("Could not autocreate file system", e
);
61 return fileSystem
.getPath(path
);