Hi all,
I am facing a problem on locking a node or resource. I am using Jackrabbit
from Apache Sling and I have the following code (esp file) to lock a node:
<!DOCTYPE html>
<%
var session =
request.getResourceResolver().adaptTo(Packages.javax.jcr.Session);;
var wasLockableNode = currentNode.isNodeType("mix:lockable");
if (!wasLockableNode) {
currentNode.addMixin("mix:lockable");
session.save();
}
var lockOwner = null;
var workspace = session.workspace;
var lockManager = workspace.lockManager;
var wasLocked = lockManager.isLocked(currentNode.path);
var locked = false;
if (!wasLocked) {
var lock = lockManager.lock(currentNode.path, true, false, 120,
lockOwner);
lockManager.addLockToken(lock.lockToken);
locked = true;
} else {
var lock = lockManager.getLock(currentNode.path);
}
session.save();
%>
<html>
<head>
<title><%= currentNode.title %> is locked: <%= locked %></title>
</head>
<body>
<p>
Is Locking Supported by Repository <%=
session.repository.getDescriptorValue(session.repository.OPTION_LOCKING_SUPPORTED).string
%><br />
Is Locked <%= locked %><br />
Lock Owner: <span id="owner"><%= lock.lockOwner %></span><br/>
Lock Token: <span id="token"><%= lock.lockToken %></span><br />
Is Deep: <span id="deep"><%= lock.deep %></span><br />
Is Session Scoped: <span><%= lock.sessionScoped %></span><br />
Is Current Session Owning Lock: <span
id="isLockOwningSession"><%= lock.lockOwningSession %></span><br/>
Was lockable node: <%= wasLockableNode %><br />
Was Locked: <%= wasLocked %><br />
Remaining Seconds for the Lock <%= lock.secondsRemaining %><br
/>
Current Lock Tokens: <%=
Packages.java.util.Arrays.toString(lockManager.lockTokens) %><br />
</p>
</body>
</html>
After executing the above script, I find that the node was locked. But if I
execute the following script just after executing the previous one, I find
that node ia not locked!:
<code>
<!DOCTYPE html>
<html>
<head>
<title><%= currentNode.title %></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<body>
<h1><%= currentNode.title %></h1>
<p>
Title: <span id="title"><%= currentNode.title %></span><br />
Is Locked: <span id="locked"><%= currentNode.locked %></span><br />
</p>
</body>
</html>
</code>
Can anyone help me to find out the problem in my code or give me suggestion
on how to implement locking on nodes using Sling?
Thanks & Regards.