Centralise configure script
[lgpl/argeo-commons.git] / jcr / org.argeo.cms.jcr / src / org / argeo / cms / jcr / acr / JcrContentProvider.java
index 7f471c9b0d656a694482076df38872fb95de098d..eaa27b7fc631d806fde1f1590c0eca142f786cd7 100644 (file)
@@ -16,6 +16,7 @@ import org.argeo.api.acr.Content;
 import org.argeo.api.acr.spi.ContentProvider;
 import org.argeo.api.acr.spi.ProvidedContent;
 import org.argeo.api.acr.spi.ProvidedSession;
+import org.argeo.api.cms.CmsConstants;
 import org.argeo.cms.acr.ContentUtils;
 import org.argeo.cms.jcr.CmsJcrUtils;
 import org.argeo.jcr.JcrException;
@@ -23,21 +24,24 @@ import org.argeo.jcr.JcrUtils;
 
 /** A JCR workspace accessed as an {@link ContentProvider}. */
 public class JcrContentProvider implements ContentProvider, NamespaceContext {
-       public final static String ACR_MOUNT_PATH_PROPERTY = "acr.mount.path";
 
        private Repository jcrRepository;
        private Session adminSession;
 
        private String mountPath;
 
+       // cache
+       private String jcrWorkspace;
+
        private Map<ProvidedSession, JcrSessionAdapter> sessionAdapters = Collections.synchronizedMap(new HashMap<>());
 
        public void start(Map<String, String> properties) {
-               mountPath = properties.get(ACR_MOUNT_PATH_PROPERTY);
+               mountPath = properties.get(CmsConstants.ACR_MOUNT_PATH);
                if ("/".equals(mountPath))
                        throw new IllegalArgumentException("JCR content provider cannot be root /");
                Objects.requireNonNull(mountPath);
-               adminSession = CmsJcrUtils.openDataAdminSession(jcrRepository, null);
+               jcrWorkspace = ContentUtils.getParentPath(mountPath)[1];
+               adminSession = CmsJcrUtils.openDataAdminSession(jcrRepository, jcrWorkspace);
        }
 
        public void stop() {
@@ -51,7 +55,6 @@ public class JcrContentProvider implements ContentProvider, NamespaceContext {
 
        @Override
        public ProvidedContent get(ProvidedSession contentSession, String relativePath) {
-               String jcrWorkspace = ContentUtils.getParentPath(mountPath)[1];
                String jcrPath = "/" + relativePath;
                return new JcrContent(contentSession, this, jcrWorkspace, jcrPath);
        }