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
/*
* 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);
}
}
+ /*
+ * EDITING
+ */
+
@Override
- public String getMountPath() {
- return mountPath;
+ public void openForEdit(ProvidedSession session, String relativePath) {
+ openForEdit(session, relativePath, toJcrPath(relativePath));
}
- public synchronized <T> T doInAdminSession(Function<Session, T> 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);
}
}
}
}
+
+ /*
+ * 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> T doInAdminSession(Function<Session, T> toDo) {
+ try {
+ return toDo.apply(adminSession);
+ } finally {
+ try {
+ if (adminSession.hasPendingChanges())
+ adminSession.save();
+ } catch (RepositoryException e) {
+ throw new JcrException("Cannot save admin session", e);
+ }
+ }
+ }
+
}
return node;
}
+ public synchronized Node freeze(String workspace, String jcrPath) throws RepositoryException {
+ Session session = getWriteSession(workspace);
+ Node node = session.getNode(jcrPath);
+ if (node.isNodeType(NodeType.MIX_SIMPLE_VERSIONABLE)) {
+ VersionManager versionManager = session.getWorkspace().getVersionManager();
+ if (versionManager.isCheckedOut(jcrPath)) {
+ versionManager.checkin(jcrPath);
+ }
+ }
+ return node;
+ }
+
+ public synchronized boolean isOpenForEdit(String workspace, String jcrPath) throws RepositoryException {
+ Session session = getWriteSession(workspace);
+ VersionManager versionManager = session.getWorkspace().getVersionManager();
+ return versionManager.isCheckedOut(jcrPath);
+ }
+
public synchronized void persist() throws RepositoryException {
for (String workspace : writeSessions.keySet()) {
Session session = writeSessions.get(workspace);