Merged V1.4 to HEAD

svn merge svn://svn.alfresco.com:3691/alfresco/BRANCHES/V1.4@4227 svn://svn.alfresco.com:3691/alfresco/BRANCHES/V1.4@4228 .
   svn merge svn://svn.alfresco.com:3691/alfresco/BRANCHES/V1.4@4242 svn://svn.alfresco.com:3691/alfresco/BRANCHES/V1.4@4243 .
   Records management changes


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@4250 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley
2006-10-30 11:43:37 +00:00
parent 4645415989
commit 71d2442632
10 changed files with 146 additions and 16 deletions

View File

@@ -2,9 +2,38 @@
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'> <!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>
<beans> <beans>
<bean id="scriptService" class="org.alfresco.repo.jscript.RhinoScriptService"> <bean id="scriptService" class="org.alfresco.repo.jscript.RhinoScriptService">
<property name="serviceRegistry"> <property name="serviceRegistry">
<ref bean="ServiceRegistry"/> <ref bean="ServiceRegistry"/>
</property> </property>
</bean> </bean>
<bean id="baseScriptImplementation" abstract="true" init-method="register">
<property name="scriptService">
<ref bean="scriptService"/>
</property>
</bean>
<bean id="loggerScript" parent="baseScriptImplementation" class="org.alfresco.repo.jscript.ScriptLogger">
<property name="scriptName">
<value>logger</value>
</property>
</bean>
<bean id="utilsScript" parent="baseScriptImplementation" class="org.alfresco.repo.jscript.ScriptUtils">
<property name="scriptName">
<value>utils</value>
</property>
</bean>
<bean id="actionsScript" parent="baseScriptImplementation" class="org.alfresco.repo.jscript.Actions">
<property name="scriptName">
<value>actions</value>
</property>
<property name="serviceRegistry">
<ref bean="ServiceRegistry"/>
</property>
</bean>
</beans> </beans>

View File

@@ -35,7 +35,7 @@ import org.mozilla.javascript.Wrapper;
* *
* @author davidc * @author davidc
*/ */
public final class Actions implements Scopeable public final class Actions extends BaseScriptImplementation implements Scopeable
{ {
/** Repository Service Registry */ /** Repository Service Registry */
private ServiceRegistry services; private ServiceRegistry services;
@@ -44,14 +44,13 @@ public final class Actions implements Scopeable
private Scriptable scope; private Scriptable scope;
/** /**
* Constructor * Set the service registry
* *
* @param services * @param serviceRegistry the service registry
* repository service registry
*/ */
public Actions(ServiceRegistry services) public void setServiceRegistry(ServiceRegistry serviceRegistry)
{ {
this.services = services; this.services = serviceRegistry;
} }
/** /**
@@ -216,6 +215,9 @@ public final class Actions implements Scopeable
} }
} }
services.getActionService().executeAction(action, node.getNodeRef()); services.getActionService().executeAction(action, node.getNodeRef());
// Reset the actioned upon node
node.reset();
} }
/** /**

View File

@@ -0,0 +1,57 @@
/**
*
*/
package org.alfresco.repo.jscript;
import org.alfresco.service.cmr.repository.ScriptImplementation;
import org.alfresco.service.cmr.repository.ScriptService;
/**
* Abstract base class for a script implementation
*
* @author Roy Wetherall
*/
public abstract class BaseScriptImplementation implements ScriptImplementation
{
/** The script service */
private ScriptService scriptService;
/** The name of the script */
private String scriptName;
/**
* Sets the script service
*
* @param scriptService the script service
*/
public void setScriptService(ScriptService scriptService)
{
this.scriptService = scriptService;
}
/**
* Registers this script with the script service
*/
public void register()
{
this.scriptService.registerScript(this);
}
/**
* Sets the script name
*
* @param scriptName the script name
*/
public void setScriptName(String scriptName)
{
this.scriptName = scriptName;
}
/**
* @see org.alfresco.service.cmr.repository.ScriptImplementation#getScriptName()
*/
public String getScriptName()
{
return this.scriptName;
}
}

View File

@@ -1738,7 +1738,7 @@ public class Node implements Serializable, Scopeable
/** /**
* Reset the Node cached state * Reset the Node cached state
*/ */
private void reset() public void reset()
{ {
this.name = null; this.name = null;
this.type = null; this.type = null;

View File

@@ -21,7 +21,9 @@ import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.Reader; import java.io.Reader;
import java.io.StringReader; import java.io.StringReader;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import org.alfresco.error.AlfrescoRuntimeException; import org.alfresco.error.AlfrescoRuntimeException;
@@ -30,6 +32,7 @@ import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.repository.ContentReader; import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.ScriptException; import org.alfresco.service.cmr.repository.ScriptException;
import org.alfresco.service.cmr.repository.ScriptImplementation;
import org.alfresco.service.cmr.repository.ScriptService; import org.alfresco.service.cmr.repository.ScriptService;
import org.alfresco.service.cmr.repository.TemplateImageResolver; import org.alfresco.service.cmr.repository.TemplateImageResolver;
import org.alfresco.service.namespace.QName; import org.alfresco.service.namespace.QName;
@@ -51,6 +54,8 @@ public class RhinoScriptService implements ScriptService
/** Repository Service Registry */ /** Repository Service Registry */
private ServiceRegistry services; private ServiceRegistry services;
/** List of global scripts */
private List<ScriptImplementation> globalScripts = new ArrayList<ScriptImplementation>(5);
/** /**
* Set the Service Registry * Set the Service Registry
@@ -62,6 +67,14 @@ public class RhinoScriptService implements ScriptService
this.services = services; this.services = services;
} }
/**
* @see org.alfresco.service.cmr.repository.ScriptService#registerScript(java.lang.Object)
*/
public void registerScript(ScriptImplementation script)
{
this.globalScripts.add(script);
}
/** /**
* @see org.alfresco.service.cmr.repository.ScriptService#executeScript(java.lang.String, java.util.Map) * @see org.alfresco.service.cmr.repository.ScriptService#executeScript(java.lang.String, java.util.Map)
*/ */
@@ -217,10 +230,11 @@ public class RhinoScriptService implements ScriptService
model = new HashMap<String, Object>(); model = new HashMap<String, Object>();
} }
// add useful util objects // add the global scripts
model.put("actions", new Actions(services)); for (ScriptImplementation script : this.globalScripts)
model.put("logger", new ScriptLogger()); {
model.put("utils", new ScriptUtils()); model.put(script.getScriptName(), script);
}
// insert supplied object model into root of the default scope // insert supplied object model into root of the default scope
for (String key : model.keySet()) for (String key : model.keySet())

View File

@@ -21,7 +21,7 @@ import org.apache.log4j.Logger;
/** /**
* @author Kevin Roast * @author Kevin Roast
*/ */
public final class ScriptLogger public final class ScriptLogger extends BaseScriptImplementation
{ {
private static final Logger logger = Logger.getLogger(ScriptLogger.class); private static final Logger logger = Logger.getLogger(ScriptLogger.class);

View File

@@ -23,7 +23,7 @@ import org.mozilla.javascript.Scriptable;
* *
* @author Kevin Roast * @author Kevin Roast
*/ */
public final class ScriptUtils implements Scopeable public final class ScriptUtils extends BaseScriptImplementation implements Scopeable
{ {
/** Root scope for this object */ /** Root scope for this object */
private Scriptable scope; private Scriptable scope;

View File

@@ -202,7 +202,7 @@ public interface ActionService
* @param nodeRef the node reference * @param nodeRef the node reference
* @param action the action * @param action the action
*/ */
@Auditable(key = Auditable.Key.ARG_1, parameters = {"nodeRef", "action" }) @Auditable(key = Auditable.Key.ARG_0, parameters = {"nodeRef", "action" })
void saveAction(NodeRef nodeRef, Action action); void saveAction(NodeRef nodeRef, Action action);
/** /**
@@ -211,7 +211,7 @@ public interface ActionService
* @param nodeRef the node reference * @param nodeRef the node reference
* @return the list of actions * @return the list of actions
*/ */
@Auditable(key = Auditable.Key.ARG_1, parameters = {"nodeRef"}) @Auditable(key = Auditable.Key.ARG_0, parameters = {"nodeRef"})
List<Action> getActions(NodeRef nodeRef); List<Action> getActions(NodeRef nodeRef);
/** /**

View File

@@ -0,0 +1,20 @@
/**
*
*/
package org.alfresco.service.cmr.repository;
/**
* Interface to represent a server side script implementation
*
* @author Roy Wetherall
*
*/
public interface ScriptImplementation
{
/**
* Returns the name of the script
*
* @return the name of the script
*/
String getScriptName();
}

View File

@@ -83,4 +83,12 @@ public interface ScriptService
@Auditable(parameters = {"script", "model"}) @Auditable(parameters = {"script", "model"})
public Object executeScriptString(String script, Map<String, Object> model) public Object executeScriptString(String script, Map<String, Object> model)
throws ScriptException; throws ScriptException;
/**
* Registers a script implementation with the script service
*
* @param script the script implementation
*/
@Auditable(parameters = {"script"})
public void registerScript(ScriptImplementation script);
} }