mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
Merged BRANCHES/DEV/V4.1-BUG-FIX/root to HEAD/root:
39191: ALF-14863: no scope is available when ScriptNode is used from within Activiti expression, causes issue when scope is needed (eg. creating javascript-arrays) + fixed typo in activiti-source jars git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@39196 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -22,10 +22,10 @@ import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
import org.alfresco.repo.jscript.ScriptNode;
|
||||
import org.alfresco.repo.workflow.jbpm.JBPMNode;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.mozilla.javascript.Context;
|
||||
import org.mozilla.javascript.Scriptable;
|
||||
|
||||
/**
|
||||
@@ -80,9 +80,14 @@ public class ActivitiScriptNode extends ScriptNode
|
||||
@Override
|
||||
public Serializable convertValueForScript(ServiceRegistry serviceRegistry, Scriptable theScope, QName qname, Serializable value)
|
||||
{
|
||||
// ALF-14863: If script-node is used outside of Script-call (eg. Activiti evaluating an expression that contains variables of type ScriptNode)
|
||||
// a scope should be created solely for this conversion. The scope will ALWAYS be set when value-conversion is called from the
|
||||
// ScriptProcessor
|
||||
ensureScopePresent();
|
||||
|
||||
if (value instanceof NodeRef)
|
||||
{
|
||||
return new JBPMNode(((NodeRef)value), serviceRegistry);
|
||||
return new ActivitiScriptNode(((NodeRef)value), serviceRegistry);
|
||||
}
|
||||
else if (value instanceof Date)
|
||||
{
|
||||
@@ -93,5 +98,27 @@ public class ActivitiScriptNode extends ScriptNode
|
||||
return super.convertValueForScript(serviceRegistry, theScope, qname, value);
|
||||
}
|
||||
}
|
||||
|
||||
private void ensureScopePresent() {
|
||||
if(scope == null) {
|
||||
// Create a scope for the value conversion. This scope will be an empty scope exposing basic Object and Function, sufficient for value-conversion.
|
||||
// In case no context is active for the current thread, we can safely enter end exit one to get hold of a scope
|
||||
Context ctx = Context.getCurrentContext();
|
||||
boolean closeContext = false;
|
||||
if(ctx == null)
|
||||
{
|
||||
ctx = Context.enter();
|
||||
closeContext = true;
|
||||
}
|
||||
|
||||
scope = ctx.initStandardObjects();
|
||||
scope.setParentScope(null);
|
||||
|
||||
if(closeContext) {
|
||||
// Only an exit call should be done when context didn't exist before
|
||||
Context.exit();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user