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=f7bfd0949f422b5ce359111347c6e8723de1ca11;hb=e3db2eba9a7f8380a6f76d7b0e6cd4825e91893e;hp=fc4a61bf9e61a72c316f5b5f5f8bf50a291932fb;hpb=c615307d7b87bcb260d8a9f402c6e0a880862f38;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 fc4a61bf9..f7bfd0949 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 @@ -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 sessionAdapters = Collections.synchronizedMap(new HashMap<>()); - public void start() { + public void start(Map 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; } /*