mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Template extension spring configuration support
- similar pattern to existing script bean extension support - new root model helper objects and custom methods can be added via spring configuration Cleanup of script extension spring support Fix to thread safety of configured script extension beans that use the Scopable interface git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@5369 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -26,23 +26,19 @@ package org.alfresco.repo.jscript;
|
||||
|
||||
import org.alfresco.config.JNDIConstants;
|
||||
import org.alfresco.repo.avm.AVMNodeConverter;
|
||||
import org.alfresco.service.cmr.avm.AVMNodeDescriptor;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.mozilla.javascript.Scriptable;
|
||||
import org.alfresco.service.cmr.avm.AVMNodeDescriptor;
|
||||
|
||||
/**
|
||||
* Helper to access AVM nodes from a script context.
|
||||
*
|
||||
* @author Kevin Roast
|
||||
*/
|
||||
public final class AVM extends BaseScriptImplementation implements Scopeable
|
||||
public final class AVM extends BaseScopableScriptImplementation
|
||||
{
|
||||
/** Repository Service Registry */
|
||||
private ServiceRegistry services;
|
||||
|
||||
/** Root scope for this object */
|
||||
private Scriptable scope;
|
||||
|
||||
/**
|
||||
* Set the service registry
|
||||
*
|
||||
@@ -53,14 +49,6 @@ public final class AVM extends BaseScriptImplementation implements Scopeable
|
||||
this.services = serviceRegistry;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.jscript.Scopeable#setScope(org.mozilla.javascript.Scriptable)
|
||||
*/
|
||||
public void setScope(Scriptable scope)
|
||||
{
|
||||
this.scope = scope;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an AVM Node representing the public store root folder.
|
||||
*
|
||||
@@ -77,7 +65,7 @@ public final class AVM extends BaseScriptImplementation implements Scopeable
|
||||
AVMNodeDescriptor nodeDesc = this.services.getAVMService().lookup(-1, rootPath);
|
||||
if (nodeDesc != null)
|
||||
{
|
||||
rootNode = new AVMNode(AVMNodeConverter.ToNodeRef(-1, rootPath), this.services, this.scope);
|
||||
rootNode = new AVMNode(AVMNodeConverter.ToNodeRef(-1, rootPath), this.services, getScope());
|
||||
}
|
||||
}
|
||||
return rootNode;
|
||||
@@ -98,7 +86,7 @@ public final class AVM extends BaseScriptImplementation implements Scopeable
|
||||
AVMNodeDescriptor nodeDesc = this.services.getAVMService().lookup(-1, path);
|
||||
if (nodeDesc != null)
|
||||
{
|
||||
node = new AVMNode(AVMNodeConverter.ToNodeRef(-1, path), this.services, this.scope);
|
||||
node = new AVMNode(AVMNodeConverter.ToNodeRef(-1, path), this.services, getScope());
|
||||
}
|
||||
}
|
||||
return node;
|
||||
|
@@ -30,21 +30,17 @@ import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.action.Action;
|
||||
import org.alfresco.service.cmr.action.ActionDefinition;
|
||||
import org.alfresco.service.cmr.action.ActionService;
|
||||
import org.mozilla.javascript.Scriptable;
|
||||
|
||||
/**
|
||||
* Scripted Action service for describing and executing actions against Nodes.
|
||||
*
|
||||
* @author davidc
|
||||
*/
|
||||
public final class Actions extends BaseScriptImplementation implements Scopeable
|
||||
public final class Actions extends BaseScopableScriptImplementation
|
||||
{
|
||||
/** Repository Service Registry */
|
||||
private ServiceRegistry services;
|
||||
|
||||
/** Root scope for this object */
|
||||
private Scriptable scope;
|
||||
|
||||
/**
|
||||
* Set the service registry
|
||||
*
|
||||
@@ -54,14 +50,6 @@ public final class Actions extends BaseScriptImplementation implements Scopeable
|
||||
{
|
||||
this.services = serviceRegistry;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.jscript.Scopeable#setScope(org.mozilla.javascript.Scriptable)
|
||||
*/
|
||||
public void setScope(Scriptable scope)
|
||||
{
|
||||
this.scope = scope;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the list of registered action names
|
||||
@@ -102,7 +90,7 @@ public final class Actions extends BaseScriptImplementation implements Scopeable
|
||||
{
|
||||
Action action = actionService.createAction(actionName);
|
||||
scriptAction = new ScriptAction(this.services, action, actionDef);
|
||||
scriptAction.setScope(scope);
|
||||
scriptAction.setScope(getScope());
|
||||
}
|
||||
return scriptAction;
|
||||
}
|
||||
|
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
package org.alfresco.repo.jscript;
|
||||
|
||||
import org.mozilla.javascript.Scriptable;
|
||||
|
||||
/**
|
||||
* Abstract base class for a script implementation that requires a script execution scope.
|
||||
*
|
||||
* The scope is local to the currently executing script and therefore a ThreadLocal is required.
|
||||
*
|
||||
* @author Kevin Roast
|
||||
*/
|
||||
public class BaseScopableScriptImplementation extends BaseScriptImplementation implements Scopeable
|
||||
{
|
||||
private static ThreadLocal<Scriptable> scope = new ThreadLocal<Scriptable>();
|
||||
|
||||
/**
|
||||
* Set the Scriptable global scope
|
||||
*
|
||||
* @param script relative global scope
|
||||
*/
|
||||
public void setScope(Scriptable scope)
|
||||
{
|
||||
this.scope.set(scope);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return script global scope
|
||||
*/
|
||||
public Scriptable getScope()
|
||||
{
|
||||
return this.scope.get();
|
||||
}
|
||||
}
|
@@ -31,18 +31,14 @@ import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.StoreRef;
|
||||
import org.alfresco.service.cmr.search.CategoryService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.mozilla.javascript.Scriptable;
|
||||
|
||||
/**
|
||||
* Support class for finding categories, finding root nodes for categories and creating root categories.
|
||||
*
|
||||
* @author Andy Hind
|
||||
*/
|
||||
public final class Classification extends BaseScriptImplementation implements Scopeable
|
||||
public final class Classification extends BaseScopableScriptImplementation
|
||||
{
|
||||
@SuppressWarnings("unused")
|
||||
private Scriptable scope;
|
||||
|
||||
private ServiceRegistry services;
|
||||
|
||||
private StoreRef storeRef;
|
||||
@@ -67,14 +63,6 @@ public final class Classification extends BaseScriptImplementation implements S
|
||||
this.services = services;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.jscript.Scopeable#setScope(org.mozilla.javascript.Scriptable)
|
||||
*/
|
||||
public void setScope(Scriptable scope)
|
||||
{
|
||||
this.scope = scope;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find all the category nodes in a given classification.
|
||||
*
|
||||
@@ -137,7 +125,7 @@ public final class Classification extends BaseScriptImplementation implements S
|
||||
int i = 0;
|
||||
for (ChildAssociationRef car : cars)
|
||||
{
|
||||
categoryNodes[i++] = new CategoryNode(car.getChildRef(), this.services, this.scope);
|
||||
categoryNodes[i++] = new CategoryNode(car.getChildRef(), this.services, getScope());
|
||||
}
|
||||
return categoryNodes;
|
||||
}
|
||||
|
@@ -37,24 +37,13 @@ import org.mozilla.javascript.Scriptable;
|
||||
*
|
||||
* @author Kevin Roast
|
||||
*/
|
||||
public final class CrossRepositoryCopy extends BaseScriptImplementation implements Scopeable
|
||||
public final class CrossRepositoryCopy extends BaseScopableScriptImplementation
|
||||
{
|
||||
public final static String BEAN_NAME = "crossCopyScript";
|
||||
|
||||
/** Service registry */
|
||||
private ServiceRegistry services;
|
||||
|
||||
/** Root scope for this object */
|
||||
private Scriptable scope;
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.jscript.Scopeable#setScope(org.mozilla.javascript.Scriptable)
|
||||
*/
|
||||
public void setScope(Scriptable scope)
|
||||
{
|
||||
this.scope = scope;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the service registry
|
||||
*
|
||||
@@ -98,7 +87,7 @@ public final class CrossRepositoryCopy extends BaseScriptImplementation implemen
|
||||
AVMNodeDescriptor node = this.services.getAVMService().lookup(-1, destPath);
|
||||
if (node != null)
|
||||
{
|
||||
result = ((AVMNode)dest).newInstance(destPath, -1, this.services, this.scope);
|
||||
result = ((AVMNode)dest).newInstance(destPath, -1, this.services, getScope());
|
||||
}
|
||||
}
|
||||
else if (dest.getNodeRef().getStoreRef().getProtocol().equals(StoreRef.PROTOCOL_WORKSPACE))
|
||||
|
@@ -1550,9 +1550,13 @@ public class Node implements Serializable, Scopeable
|
||||
private String processTemplate(String template, NodeRef templateRef, ScriptableObject args)
|
||||
{
|
||||
// build default model for the template processing
|
||||
Map<String, Object> model = FreeMarkerProcessor.buildDefaultModel(services, ((Node) ((Wrapper) scope.get(
|
||||
"person", scope)).unwrap()).getNodeRef(), ((Node) ((Wrapper) scope.get("companyhome", scope)).unwrap())
|
||||
.getNodeRef(), ((Node) ((Wrapper) scope.get("userhome", scope)).unwrap()).getNodeRef(), templateRef, null);
|
||||
Map<String, Object> model = FreeMarkerProcessor.buildDefaultModel(
|
||||
services,
|
||||
((Node)((Wrapper)scope.get("person", scope)).unwrap()).getNodeRef(),
|
||||
((Node)((Wrapper)scope.get("companyhome", scope)).unwrap()).getNodeRef(),
|
||||
((Node)((Wrapper)scope.get("userhome", scope)).unwrap()).getNodeRef(),
|
||||
templateRef,
|
||||
null);
|
||||
|
||||
// add the current node as either the document/space as appropriate
|
||||
if (this.getIsDocument())
|
||||
|
@@ -33,22 +33,18 @@ import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.security.AuthorityService;
|
||||
import org.alfresco.service.cmr.security.AuthorityType;
|
||||
import org.alfresco.service.cmr.security.PersonService;
|
||||
import org.mozilla.javascript.Scriptable;
|
||||
|
||||
/**
|
||||
* Scripted People service for describing and executing actions against People & Groups.
|
||||
*
|
||||
* @author davidc
|
||||
*/
|
||||
public final class People extends BaseScriptImplementation implements Scopeable
|
||||
public final class People extends BaseScopableScriptImplementation
|
||||
{
|
||||
/** Repository Service Registry */
|
||||
private ServiceRegistry services;
|
||||
private AuthorityDAO authorityDAO;
|
||||
|
||||
/** Root scope for this object */
|
||||
private Scriptable scope;
|
||||
|
||||
/**
|
||||
* Set the service registry
|
||||
*
|
||||
@@ -69,14 +65,6 @@ public final class People extends BaseScriptImplementation implements Scopeable
|
||||
this.authorityDAO = authorityDAO;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.jscript.Scopeable#setScope(org.mozilla.javascript.Scriptable)
|
||||
*/
|
||||
public void setScope(Scriptable scope)
|
||||
{
|
||||
this.scope = scope;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Person given the username
|
||||
*
|
||||
@@ -90,7 +78,7 @@ public final class People extends BaseScriptImplementation implements Scopeable
|
||||
if (personService.personExists(username))
|
||||
{
|
||||
NodeRef personRef = personService.getPerson(username);
|
||||
person = new Node(personRef, services, scope);
|
||||
person = new Node(personRef, services, getScope());
|
||||
}
|
||||
return person;
|
||||
}
|
||||
@@ -107,7 +95,7 @@ public final class People extends BaseScriptImplementation implements Scopeable
|
||||
NodeRef groupRef = authorityDAO.getAuthorityNodeRefOrNull(groupName);
|
||||
if (groupRef != null)
|
||||
{
|
||||
group = new Node(groupRef, services, scope);
|
||||
group = new Node(groupRef, services, getScope());
|
||||
}
|
||||
return group;
|
||||
}
|
||||
|
@@ -69,7 +69,7 @@ public class RhinoScriptService implements ScriptService
|
||||
private ServiceRegistry services;
|
||||
|
||||
/** List of global scripts */
|
||||
private List<ScriptImplementation> globalScripts = new ArrayList<ScriptImplementation>(5);
|
||||
private List<ScriptImplementation> globalScripts = new ArrayList<ScriptImplementation>();
|
||||
|
||||
/**
|
||||
* Set the Service Registry
|
||||
|
@@ -39,7 +39,7 @@ public interface Scopeable
|
||||
/**
|
||||
* Set the Scriptable global scope
|
||||
*
|
||||
* @param scope global scope
|
||||
* @param script relative global scope
|
||||
*/
|
||||
void setScope(Scriptable scope);
|
||||
}
|
||||
|
@@ -26,29 +26,17 @@ package org.alfresco.repo.jscript;
|
||||
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.mozilla.javascript.Scriptable;
|
||||
|
||||
/**
|
||||
* Place for general and miscellenous utility functions not already found in generic JavaScript.
|
||||
*
|
||||
* @author Kevin Roast
|
||||
*/
|
||||
public final class ScriptUtils extends BaseScriptImplementation implements Scopeable
|
||||
public final class ScriptUtils extends BaseScopableScriptImplementation
|
||||
{
|
||||
/** Root scope for this object */
|
||||
private Scriptable scope;
|
||||
|
||||
/** Services */
|
||||
private ServiceRegistry services;
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.jscript.Scopeable#setScope(org.mozilla.javascript.Scriptable)
|
||||
*/
|
||||
public void setScope(Scriptable scope)
|
||||
{
|
||||
this.scope = scope;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the service registry
|
||||
*
|
||||
@@ -86,6 +74,6 @@ public final class ScriptUtils extends BaseScriptImplementation implements Scope
|
||||
public Node getNodeFromString(String nodeRefString)
|
||||
{
|
||||
NodeRef nodeRef = new NodeRef(nodeRefString);
|
||||
return (Node)new ValueConverter().convertValueForScript(this.services, this.scope, null, nodeRef);
|
||||
return (Node)new ValueConverter().convertValueForScript(this.services, getScope(), null, nodeRef);
|
||||
}
|
||||
}
|
||||
|
@@ -40,7 +40,6 @@ import org.alfresco.service.cmr.search.SearchService;
|
||||
import org.dom4j.Document;
|
||||
import org.dom4j.Element;
|
||||
import org.dom4j.io.SAXReader;
|
||||
import org.mozilla.javascript.Scriptable;
|
||||
|
||||
/**
|
||||
* Search component for use by the ScriptService.
|
||||
@@ -55,7 +54,7 @@ import org.mozilla.javascript.Scriptable;
|
||||
*
|
||||
* @author Kevin Roast
|
||||
*/
|
||||
public final class Search extends BaseScriptImplementation implements Scopeable
|
||||
public final class Search extends BaseScopableScriptImplementation
|
||||
{
|
||||
/** Service registry */
|
||||
private ServiceRegistry services;
|
||||
@@ -63,9 +62,6 @@ public final class Search extends BaseScriptImplementation implements Scopeable
|
||||
/** Default store reference */
|
||||
private StoreRef storeRef;
|
||||
|
||||
/** Root scope for this object */
|
||||
private Scriptable scope;
|
||||
|
||||
/**
|
||||
* Set the default store reference
|
||||
*
|
||||
@@ -86,14 +82,6 @@ public final class Search extends BaseScriptImplementation implements Scopeable
|
||||
this.services = services;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.jscript.Scopeable#setScope(org.mozilla.javascript.Scriptable)
|
||||
*/
|
||||
public void setScope(Scriptable scope)
|
||||
{
|
||||
this.scope = scope;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a single Node by the Node reference
|
||||
*
|
||||
@@ -251,7 +239,7 @@ public final class Search extends BaseScriptImplementation implements Scopeable
|
||||
for (ResultSetRow row: results)
|
||||
{
|
||||
NodeRef nodeRef = row.getNodeRef();
|
||||
set.add(new Node(nodeRef, services, this.scope));
|
||||
set.add(new Node(nodeRef, services, getScope()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user