]> git.argeo.org Git - lgpl/argeo-commons.git/blobdiff - jcr/org.argeo.cms.jcr/src/org/argeo/cms/jcr/acr/JcrContentProvider.java
Start supporting mounting of XML with FS.
[lgpl/argeo-commons.git] / jcr / org.argeo.cms.jcr / src / org / argeo / cms / jcr / acr / JcrContentProvider.java
index fc4a61bf9e61a72c316f5b5f5f8bf50a291932fb..f7bfd0949f422b5ce359111347c6e8723de1ca11 100644 (file)
@@ -5,8 +5,8 @@ import java.util.Collections;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
+import java.util.Objects;
 
-import javax.jcr.Node;
 import javax.jcr.Repository;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
@@ -16,6 +16,7 @@ import org.argeo.api.acr.Content;
 import org.argeo.api.acr.ContentUtils;
 import org.argeo.api.acr.spi.ContentProvider;
 import org.argeo.api.acr.spi.ProvidedSession;
+import org.argeo.cms.acr.CmsContentRepository;
 import org.argeo.cms.jcr.CmsJcrUtils;
 import org.argeo.jcr.JcrException;
 import org.argeo.jcr.JcrUtils;
@@ -25,9 +26,13 @@ public class JcrContentProvider implements ContentProvider, NamespaceContext {
        private Repository jcrRepository;
        private Session adminSession;
 
+       private String mountPath;
+
        private Map<ProvidedSession, JcrSessionAdapter> sessionAdapters = Collections.synchronizedMap(new HashMap<>());
 
-       public void start() {
+       public void start(Map<String, String> properties) {
+               mountPath = properties.get(CmsContentRepository.ACR_MOUNT_PATH_PROPERTY);
+               Objects.requireNonNull(mountPath);
                adminSession = CmsJcrUtils.openDataAdminSession(jcrRepository, null);
        }
 
@@ -41,7 +46,12 @@ public class JcrContentProvider implements ContentProvider, NamespaceContext {
 
        @Override
        public Content get(ProvidedSession contentSession, String mountPath, String relativePath) {
-               String workspace = ContentUtils.getParentPath(mountPath)[1];
+               String jcrWorkspace = ContentUtils.getParentPath(mountPath)[1];
+               String jcrPath = "/" + relativePath;
+               return new JcrContent(contentSession, this, jcrWorkspace, jcrPath);
+       }
+
+       public Session getJcrSession(ProvidedSession contentSession, String jcrWorkspace) {
                JcrSessionAdapter sessionAdapter = sessionAdapters.get(contentSession);
                if (sessionAdapter == null) {
                        final JcrSessionAdapter newSessionAdapter = new JcrSessionAdapter(jcrRepository,
@@ -51,15 +61,13 @@ public class JcrContentProvider implements ContentProvider, NamespaceContext {
                        sessionAdapter = newSessionAdapter;
                }
 
-               Session jcrSession = sessionAdapter.getSession(workspace);
-               String jcrPath = "/" + relativePath;
-               try {
-                       Node node = jcrSession.getNode(jcrPath);
-                       return new JcrContent(contentSession, this, node);
-               } catch (RepositoryException e) {
-                       throw new JcrException("Cannot get JCR content '" + jcrPath + ", mounted from '" + mountPath
-                                       + "' with JCR session " + jcrSession, e);
-               }
+               Session jcrSession = sessionAdapter.getSession(jcrWorkspace);
+               return jcrSession;
+       }
+
+       @Override
+       public String getMountPath() {
+               return mountPath;
        }
 
        /*