]> git.argeo.org Git - lgpl/argeo-commons.git/blobdiff - jcr/org.argeo.cms.jcr/src/org/argeo/cms/jcr/acr/JcrContentProvider.java
Improve ACR.
[lgpl/argeo-commons.git] / jcr / org.argeo.cms.jcr / src / org / argeo / cms / jcr / acr / JcrContentProvider.java
index 9e0a0089ab5c4ffb6ac4e4118526a20db459c97d..235e27d1a922139558d8e8c42da322199340dda5 100644 (file)
@@ -13,10 +13,11 @@ import javax.jcr.Session;
 import javax.xml.namespace.NamespaceContext;
 
 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.ProvidedContent;
 import org.argeo.api.acr.spi.ProvidedSession;
 import org.argeo.cms.acr.CmsContentRepository;
+import org.argeo.cms.acr.ContentUtils;
 import org.argeo.cms.jcr.CmsJcrUtils;
 import org.argeo.jcr.JcrException;
 import org.argeo.jcr.JcrUtils;
@@ -32,6 +33,8 @@ public class JcrContentProvider implements ContentProvider, NamespaceContext {
 
        public void start(Map<String, String> properties) {
                mountPath = properties.get(CmsContentRepository.ACR_MOUNT_PATH_PROPERTY);
+               if ("/".equals(mountPath))
+                       throw new IllegalArgumentException("JCR content provider cannot be root /");
                Objects.requireNonNull(mountPath);
                adminSession = CmsJcrUtils.openDataAdminSession(jcrRepository, null);
        }
@@ -45,12 +48,19 @@ public class JcrContentProvider implements ContentProvider, NamespaceContext {
        }
 
        @Override
-       public Content get(ProvidedSession contentSession, String mountPath, String relativePath) {
+       public ProvidedContent get(ProvidedSession contentSession, String relativePath) {
                String jcrWorkspace = ContentUtils.getParentPath(mountPath)[1];
                String jcrPath = "/" + relativePath;
                return new JcrContent(contentSession, this, jcrWorkspace, jcrPath);
        }
 
+       @Override
+       public boolean exists(ProvidedSession contentSession, String relativePath) {
+               String jcrWorkspace = ContentUtils.getParentPath(mountPath)[1];
+               String jcrPath = "/" + relativePath;
+               return new JcrContent(contentSession, this, jcrWorkspace, jcrPath).exists();
+       }
+
        public Session getJcrSession(ProvidedSession contentSession, String jcrWorkspace) {
                JcrSessionAdapter sessionAdapter = sessionAdapters.get(contentSession);
                if (sessionAdapter == null) {
@@ -65,6 +75,10 @@ public class JcrContentProvider implements ContentProvider, NamespaceContext {
                return jcrSession;
        }
 
+       public Session getJcrSession(Content content, String jcrWorkspace) {
+               return getJcrSession(((ProvidedContent) content).getSession(), jcrWorkspace);
+       }
+
        @Override
        public String getMountPath() {
                return mountPath;