X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;ds=sidebyside;f=org.argeo.cms.jcr%2Fsrc%2Forg%2Fargeo%2Fcms%2Fjcr%2Facr%2FJcrContentProvider.java;h=5fc7d7c241d2496b040a13d2f2a0b68fa1fc7ed8;hb=c907acfe36acb8247bcdb8418b0e9bf81606957f;hp=258facc6c1b6c3658fc786ef4a45339eaaab8eab;hpb=311d6e47ad278fd00d1ad15fe9d59be47e23e385;p=gpl%2Fargeo-jcr.git diff --git a/org.argeo.cms.jcr/src/org/argeo/cms/jcr/acr/JcrContentProvider.java b/org.argeo.cms.jcr/src/org/argeo/cms/jcr/acr/JcrContentProvider.java index 258facc..5fc7d7c 100644 --- a/org.argeo.cms.jcr/src/org/argeo/cms/jcr/acr/JcrContentProvider.java +++ b/org.argeo.cms.jcr/src/org/argeo/cms/jcr/acr/JcrContentProvider.java @@ -61,10 +61,18 @@ public class JcrContentProvider implements ContentProvider, NamespaceContext { this.jcrRepository = jcrRepository; } + @Override + public String getMountPath() { + return mountPath; + } + + /* + * READ + */ + @Override public ProvidedContent get(ProvidedSession contentSession, String relativePath) { - String jcrPath = "/" + relativePath; - return new JcrContent(contentSession, this, jcrWorkspace, jcrPath); + return new JcrContent(contentSession, this, jcrWorkspace, toJcrPath(relativePath)); } @Override @@ -98,7 +106,7 @@ public class JcrContentProvider implements ContentProvider, NamespaceContext { /* * WRITE */ - public Node openForEdit(ProvidedSession contentSession, String jcrWorkspace, String jcrPath) { + Node openForEdit(ProvidedSession contentSession, String jcrWorkspace, String jcrPath) { try { if (contentSession.isEditing()) { JcrSessionAdapter sessionAdapter = getJcrSessionAdapter(contentSession); @@ -121,21 +129,37 @@ public class JcrContentProvider implements ContentProvider, NamespaceContext { } } + /* + * EDITING + */ + @Override - public String getMountPath() { - return mountPath; + public void openForEdit(ProvidedSession session, String relativePath) { + openForEdit(session, relativePath, toJcrPath(relativePath)); } - public synchronized T doInAdminSession(Function toDo) { + @Override + public void freeze(ProvidedSession session, String relativePath) { try { - return toDo.apply(adminSession); - } finally { - try { - if (adminSession.hasPendingChanges()) - adminSession.save(); - } catch (RepositoryException e) { - throw new JcrException("Cannot save admin session", e); + String jcrPath = toJcrPath(relativePath); + if (session.isEditing()) { + JcrSessionAdapter sessionAdapter = getJcrSessionAdapter(session); + sessionAdapter.freeze(jcrWorkspace, jcrPath); } + } catch (RepositoryException e) { + throw new JcrException("Cannot freeze " + relativePath + " in workspace " + jcrWorkspace, e); + } + } + + @Override + public boolean isOpenForEdit(ProvidedSession session, String relativePath) { + try { + String jcrPath = toJcrPath(relativePath); + JcrSessionAdapter sessionAdapter = getJcrSessionAdapter(session); + return sessionAdapter.isOpenForEdit(jcrWorkspace, jcrPath); + } catch (RepositoryException e) { + throw new JcrException( + "Cannot check whether " + relativePath + " is open for edit in workspace " + jcrWorkspace, e); } } @@ -228,4 +252,33 @@ public class JcrContentProvider implements ContentProvider, NamespaceContext { } } + + /* + * UTILITIES + */ + /** + * Just adds a '/' so that it becomes an absolute JCR path within the JCR + * workspace of this provider. + */ + private String toJcrPath(String relativePath) { + return ContentUtils.SLASH + relativePath; + } + + /* + * TRANSITIONAL, WHILE MIGRATING FROM JCR TO ACR + */ + @Deprecated + public synchronized T doInAdminSession(Function toDo) { + try { + return toDo.apply(adminSession); + } finally { + try { + if (adminSession.hasPendingChanges()) + adminSession.save(); + } catch (RepositoryException e) { + throw new JcrException("Cannot save admin session", e); + } + } + } + }