X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=org.argeo.jcr%2Fsrc%2Forg%2Fargeo%2Fjackrabbit%2Ffs%2FDavexFsProvider.java;h=331e9acdd948062ebb6644b4b70e26424d1f1be5;hb=905c6bcd909d84c6e980994d9eeed22a0bf237af;hp=d9e106b56a4039d0a903a41bad37f668360fb569;hpb=1d5ef69cc76d286d59de4f02d90196ca52cbe0f3;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.jcr/src/org/argeo/jackrabbit/fs/DavexFsProvider.java b/org.argeo.jcr/src/org/argeo/jackrabbit/fs/DavexFsProvider.java index d9e106b56..331e9acdd 100644 --- a/org.argeo.jcr/src/org/argeo/jackrabbit/fs/DavexFsProvider.java +++ b/org.argeo.jcr/src/org/argeo/jackrabbit/fs/DavexFsProvider.java @@ -15,14 +15,19 @@ import javax.jcr.Repository; import javax.jcr.RepositoryFactory; import javax.jcr.Session; -import org.apache.jackrabbit.jcr2dav.Jcr2davRepositoryFactory; +import org.apache.jackrabbit.core.security.authentication.LocalAuthContext; +import org.argeo.jackrabbit.client.ClientDavexRepositoryFactory; import org.argeo.jcr.ArgeoJcrException; import org.argeo.jcr.fs.JcrFileSystem; import org.argeo.jcr.fs.JcrFsException; +/** + * A file system provider based on a JCR repository remotely accessed via the + * DAVEX protocol. + */ public class DavexFsProvider extends AbstractJackrabbitFsProvider { - final static String JACKRABBIT_REPOSITORY_URI = "org.apache.jackrabbit.repository.uri"; - final static String JACKRABBIT_REMOTE_DEFAULT_WORKSPACE = "org.apache.jackrabbit.spi2davex.WorkspaceNameDefault"; +// final static String JACKRABBIT_REPOSITORY_URI = "org.apache.jackrabbit.repository.uri"; +// final static String JACKRABBIT_REMOTE_DEFAULT_WORKSPACE = "org.apache.jackrabbit.spi2davex.WorkspaceNameDefault"; private Map fileSystems = new HashMap<>(); @@ -40,17 +45,18 @@ public class DavexFsProvider extends AbstractJackrabbitFsProvider { String repoKey = repoUri.toString(); if (fileSystems.containsKey(repoKey)) throw new FileSystemAlreadyExistsException("CMS file system already exists for " + repoKey); - RepositoryFactory repositoryFactory = new Jcr2davRepositoryFactory(); - return tryGetRepo(repositoryFactory, repoUri, "main"); + RepositoryFactory repositoryFactory = new ClientDavexRepositoryFactory(); + return tryGetRepo(repositoryFactory, repoUri, "home"); } catch (Exception e) { throw new ArgeoJcrException("Cannot open file system " + uri, e); } } - private JcrFileSystem tryGetRepo(RepositoryFactory repositoryFactory, URI repoUri, String workspace) { + private JcrFileSystem tryGetRepo(RepositoryFactory repositoryFactory, URI repoUri, String workspace) + throws IOException { Map params = new HashMap(); - params.put(JACKRABBIT_REPOSITORY_URI, repoUri.toString()); - params.put(JACKRABBIT_REMOTE_DEFAULT_WORKSPACE, "main"); + params.put(ClientDavexRepositoryFactory.JACKRABBIT_DAVEX_URI, repoUri.toString()); + params.put(ClientDavexRepositoryFactory.JACKRABBIT_REMOTE_DEFAULT_WORKSPACE, "main"); Repository repository = null; Session session = null; try { @@ -77,7 +83,7 @@ public class DavexFsProvider extends AbstractJackrabbitFsProvider { } return tryGetRepo(repositoryFactory, nextUri, nextWorkspace); } else { - JcrFileSystem fileSystem = new JcrFileSystem(this, session); + JcrFileSystem fileSystem = new JcrFileSystem(this, repository); fileSystems.put(repoUri.toString() + "/" + workspace, fileSystem); return fileSystem; } @@ -101,8 +107,7 @@ public class DavexFsProvider extends AbstractJackrabbitFsProvider { try { repoUri = new URI("http", uri.getUserInfo(), uri.getHost(), uri.getPort(), uri.getPath(), null, null); } catch (URISyntaxException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + throw new IllegalArgumentException(e); } String uriStr = repoUri.toString(); String localPath = null; @@ -111,6 +116,8 @@ public class DavexFsProvider extends AbstractJackrabbitFsProvider { localPath = uriStr.toString().substring(key.length()); } } + if ("".equals(localPath)) + localPath = "/"; return fileSystem.getPath(localPath); } @@ -125,7 +132,7 @@ public class DavexFsProvider extends AbstractJackrabbitFsProvider { public static void main(String args[]) { try { DavexFsProvider fsProvider = new DavexFsProvider(); - Path path = fsProvider.getPath(new URI("davex://root:demo@localhost:7070/jcr/node/main/home/")); + Path path = fsProvider.getPath(new URI("davex://root:demo@localhost:7070/jcr/ego/")); System.out.println(path); DirectoryStream ds = Files.newDirectoryStream(path); for (Path p : ds) {