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=7f471c9b0d656a694482076df38872fb95de098d;hb=7e464c3cedfa41ece64811fb55ddc9ce740a1050;hp=198a2a3ed4480054cc87e738d770c818489d2774;hpb=cc1dd97ebcc32e1bd754073ad23def182f460452;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 198a2a3ed..7f471c9b0 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 @@ -12,10 +12,10 @@ import javax.jcr.RepositoryException; import javax.jcr.Session; import javax.xml.namespace.NamespaceContext; +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.cms.acr.CmsContentRepository; import org.argeo.cms.acr.ContentUtils; import org.argeo.cms.jcr.CmsJcrUtils; import org.argeo.jcr.JcrException; @@ -23,6 +23,8 @@ 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; @@ -31,7 +33,7 @@ public class JcrContentProvider implements ContentProvider, NamespaceContext { private Map sessionAdapters = Collections.synchronizedMap(new HashMap<>()); public void start(Map properties) { - mountPath = properties.get(CmsContentRepository.ACR_MOUNT_PATH_PROPERTY); + mountPath = properties.get(ACR_MOUNT_PATH_PROPERTY); if ("/".equals(mountPath)) throw new IllegalArgumentException("JCR content provider cannot be root /"); Objects.requireNonNull(mountPath); @@ -39,7 +41,8 @@ public class JcrContentProvider implements ContentProvider, NamespaceContext { } public void stop() { - JcrUtils.logoutQuietly(adminSession); + if (adminSession.isLive()) + JcrUtils.logoutQuietly(adminSession); } public void setJcrRepository(Repository jcrRepository) { @@ -47,12 +50,19 @@ public class JcrContentProvider implements ContentProvider, NamespaceContext { } @Override - public ProvidedContent 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) { @@ -67,6 +77,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;