X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=jcr%2Forg.argeo.cms.jcr%2Fsrc%2Forg%2Fargeo%2Fcms%2Fjcr%2Facr%2FJcrContentProvider.java;h=eaa27b7fc631d806fde1f1590c0eca142f786cd7;hb=c424738be0c47c808f8cc64c2a51a67eb8e3d584;hp=9e0a0089ab5c4ffb6ac4e4118526a20db459c97d;hpb=279880f110272df643cee670aa976ae5ab9ec396;p=lgpl%2Fargeo-commons.git diff --git a/jcr/org.argeo.cms.jcr/src/org/argeo/cms/jcr/acr/JcrContentProvider.java b/jcr/org.argeo.cms.jcr/src/org/argeo/cms/jcr/acr/JcrContentProvider.java index 9e0a0089a..eaa27b7fc 100644 --- a/jcr/org.argeo.cms.jcr/src/org/argeo/cms/jcr/acr/JcrContentProvider.java +++ b/jcr/org.argeo.cms.jcr/src/org/argeo/cms/jcr/acr/JcrContentProvider.java @@ -13,31 +13,40 @@ 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.api.cms.CmsConstants; +import org.argeo.cms.acr.ContentUtils; import org.argeo.cms.jcr.CmsJcrUtils; import org.argeo.jcr.JcrException; import org.argeo.jcr.JcrUtils; /** A JCR workspace accessed as an {@link ContentProvider}. */ public class JcrContentProvider implements ContentProvider, NamespaceContext { + private Repository jcrRepository; private Session adminSession; private String mountPath; + // cache + private String jcrWorkspace; + private Map sessionAdapters = Collections.synchronizedMap(new HashMap<>()); public void start(Map properties) { - mountPath = properties.get(CmsContentRepository.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() { - JcrUtils.logoutQuietly(adminSession); + if (adminSession.isLive()) + JcrUtils.logoutQuietly(adminSession); } public void setJcrRepository(Repository jcrRepository) { @@ -45,12 +54,18 @@ public class JcrContentProvider implements ContentProvider, NamespaceContext { } @Override - public Content get(ProvidedSession contentSession, String mountPath, String relativePath) { - String jcrWorkspace = ContentUtils.getParentPath(mountPath)[1]; + public ProvidedContent get(ProvidedSession contentSession, String relativePath) { 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 +80,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;