mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Refactor of template and script services to allow easy addition of further template and script processors.
Hightlights of check-in include: - Introduction of script processor - Neutralisation of script and template models - The notion of a processor extension introduced - Extensions applied to processor implementation rather than the services - Auto selection of processor based on file extension of template or script git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@5519 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2007 Alfresco Software Limited.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
* As a special exception to the terms and conditions of version 2.0 of
|
||||
* the GPL, you may redistribute this Program in connection with Free/Libre
|
||||
* and Open Source Software ("FLOSS") applications as described in Alfresco's
|
||||
* FLOSS exception. You should have recieved a copy of the text describing
|
||||
* the FLOSS exception, and it is also available here:
|
||||
* http://www.alfresco.com/legal/licensing"
|
||||
*/
|
||||
package org.alfresco.service.cmr.repository;
|
||||
|
||||
|
||||
/**
|
||||
* Processor interface.
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
*/
|
||||
public interface Processor
|
||||
{
|
||||
/**
|
||||
* Get the name of the processor
|
||||
*
|
||||
* @return the name of the processor
|
||||
*/
|
||||
public String getName();
|
||||
|
||||
/**
|
||||
* The file extension that the processor is associated with, null if none.
|
||||
*
|
||||
* @return the extension
|
||||
*/
|
||||
public String getExtension();
|
||||
|
||||
/**
|
||||
* Registers a processor extension with the processor
|
||||
*
|
||||
* @param processorExtension the process extension
|
||||
*/
|
||||
public void registerProcessorExtension(ProcessorExtension processorExtension);
|
||||
}
|
@@ -29,12 +29,12 @@ package org.alfresco.service.cmr.repository;
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
*/
|
||||
public interface ScriptImplementation
|
||||
public interface ProcessorExtension
|
||||
{
|
||||
/**
|
||||
* Returns the name of the script
|
||||
* Returns the name of the extension
|
||||
*
|
||||
* @return the name of the script
|
||||
* @return the name of the extension
|
||||
*/
|
||||
String getScriptName();
|
||||
String getExtensionName();
|
||||
}
|
@@ -31,6 +31,8 @@ import org.alfresco.error.AlfrescoRuntimeException;
|
||||
*/
|
||||
public class ScriptException extends AlfrescoRuntimeException
|
||||
{
|
||||
private static final long serialVersionUID = 1739480648583299623L;
|
||||
|
||||
/**
|
||||
* @param msgId
|
||||
*/
|
||||
|
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2007 Alfresco Software Limited.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
* As a special exception to the terms and conditions of version 2.0 of
|
||||
* the GPL, you may redistribute this Program in connection with Free/Libre
|
||||
* and Open Source Software ("FLOSS") applications as described in Alfresco's
|
||||
* FLOSS exception. You should have recieved a copy of the text describing
|
||||
* the FLOSS exception, and it is also available here:
|
||||
* http://www.alfresco.com/legal/licensing"
|
||||
*/
|
||||
package org.alfresco.service.cmr.repository;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
/**
|
||||
* Script processor interface
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
*/
|
||||
public interface ScriptProcessor extends Processor
|
||||
{
|
||||
/**
|
||||
* Execute script
|
||||
*
|
||||
* @param location the location of the script
|
||||
* @param model context model
|
||||
* @return Object the result of the script
|
||||
*/
|
||||
public Object execute(ScriptLocation location, Map<String, Object> model);
|
||||
|
||||
/**
|
||||
* Execute script
|
||||
*
|
||||
* @param nodeRef the script node reference
|
||||
* @param contentProp the content property of the script
|
||||
* @param model the context model
|
||||
* @return Object the result of the script
|
||||
*/
|
||||
public Object execute(NodeRef nodeRef, QName contentProp, Map<String, Object> model);
|
||||
|
||||
/**
|
||||
* Execute script
|
||||
*
|
||||
* @param location the classpath string locating the script
|
||||
* @param model the context model
|
||||
* @return Object the result of the script
|
||||
*/
|
||||
public Object execute(String location, Map<String, Object> model);
|
||||
|
||||
/**
|
||||
* Execute script string
|
||||
*
|
||||
* @param script the script string
|
||||
* @param model the context model
|
||||
* @return Obejct the result of the script
|
||||
*/
|
||||
public Object executeString(String script, Map<String, Object> model);
|
||||
|
||||
}
|
@@ -49,7 +49,9 @@ import org.alfresco.service.namespace.QName;
|
||||
public interface ScriptService
|
||||
{
|
||||
/**
|
||||
* Process a script against the supplied data model.
|
||||
* Process a script against the supplied data model.
|
||||
*
|
||||
* Uses the most approparite script engine or the default if none found.
|
||||
*
|
||||
* @param scriptClasspath Script location as qualified classpath name
|
||||
* @param model Object model to process script against
|
||||
@@ -61,10 +63,28 @@ public interface ScriptService
|
||||
@Auditable(parameters = {"scriptClasspath", "model"})
|
||||
public Object executeScript(String scriptClasspath, Map<String, Object> model)
|
||||
throws ScriptException;
|
||||
/**
|
||||
* Process a script against the supplied data model.
|
||||
*
|
||||
* Use the
|
||||
*
|
||||
* @param engine the script engine to use
|
||||
* @param scriptClasspath Script location as qualified classpath name
|
||||
* @param model Object model to process script against
|
||||
*
|
||||
* @return output of the script (may be null or any valid wrapped JavaScript object)
|
||||
*
|
||||
* @throws ScriptException
|
||||
*/
|
||||
@Auditable(parameters = {"engine", "scriptClasspath", "model"})
|
||||
public Object executeScript(String engine, String scriptClasspath, Map<String, Object> model)
|
||||
throws ScriptException;
|
||||
|
||||
/**
|
||||
* Process a script against the supplied data model.
|
||||
*
|
||||
* Uses the most approparite script engine or the default if none found.
|
||||
*
|
||||
* @param scriptRef Script NodeRef location
|
||||
* @param contentProp QName of the property on the node that contains the content, null can
|
||||
* be passed to indicate the default property of 'cm:content'
|
||||
@@ -81,6 +101,25 @@ public interface ScriptService
|
||||
/**
|
||||
* Process a script against the supplied data model.
|
||||
*
|
||||
* @param engine the script engine to use
|
||||
* @param scriptRef Script NodeRef location
|
||||
* @param contentProp QName of the property on the node that contains the content, null can
|
||||
* be passed to indicate the default property of 'cm:content'
|
||||
* @param model Object model to process script against
|
||||
*
|
||||
* @return output of the script (may be null or any valid wrapped JavaScript object)
|
||||
*
|
||||
* @throws ScriptException
|
||||
*/
|
||||
@Auditable(key = Auditable.Key.ARG_1, parameters = {"engine", "scriptRef", "contentProp", "model"})
|
||||
public Object executeScript(String engine, NodeRef scriptRef, QName contentProp, Map<String, Object> model)
|
||||
throws ScriptException;
|
||||
|
||||
/**
|
||||
* Process a script against the supplied data model
|
||||
*
|
||||
* Uses the most approparite script engine or the default if none found.
|
||||
*
|
||||
* @param scriptLocation object representing the script location
|
||||
* @param model Object model to process script against
|
||||
*
|
||||
@@ -95,6 +134,21 @@ public interface ScriptService
|
||||
/**
|
||||
* Process a script against the supplied data model.
|
||||
*
|
||||
* @param engine the script engine to use
|
||||
* @param scriptLocation object representing the script location
|
||||
* @param model Object model to process script against
|
||||
*
|
||||
* @return output of the script (may be null or any other valid wrapped JavaScript object)
|
||||
*
|
||||
* @throws ScriptException
|
||||
*/
|
||||
@Auditable(parameters = {"engine", "scriptLocation", "model"})
|
||||
public Object executeScript(String engine, ScriptLocation scriptLocation, Map<String, Object> model)
|
||||
throws ScriptException;
|
||||
|
||||
/**
|
||||
* Process a script against the supplied data model. Uses the default script engine.
|
||||
*
|
||||
* @param script Script content as a String.
|
||||
* @param model Object model to process script against
|
||||
*
|
||||
@@ -107,10 +161,53 @@ public interface ScriptService
|
||||
throws ScriptException;
|
||||
|
||||
/**
|
||||
* Registers a script implementation with the script service
|
||||
* Process a script against the supplied data model.
|
||||
*
|
||||
* @param script the script implementation
|
||||
* @param engine the script engine to use
|
||||
* @param script Script content as a String.
|
||||
* @param model Object model to process script against
|
||||
*
|
||||
* @return output of the script (may be null or any valid wrapped JavaScript object)
|
||||
*
|
||||
* @throws ScriptException
|
||||
*/
|
||||
@Auditable(parameters = {"script"})
|
||||
public void registerScript(ScriptImplementation script);
|
||||
@Auditable(parameters = {"engine", "script", "model"})
|
||||
public Object executeScriptString(String engine, String script, Map<String, Object> model)
|
||||
throws ScriptException;
|
||||
|
||||
/**
|
||||
* Registers a script processor with the script service
|
||||
*
|
||||
* @param scriptProcessor
|
||||
*/
|
||||
@Auditable(parameters = {"scriptProcessot"})
|
||||
public void registerScriptProcessor(ScriptProcessor scriptProcessor);
|
||||
|
||||
/**
|
||||
* Create the default data-model available to scripts as global scope level objects:
|
||||
* <p>
|
||||
* 'companyhome' - the Company Home node<br>
|
||||
* 'userhome' - the current user home space node<br>
|
||||
* 'person' - the node representing the current user Person<br>
|
||||
* 'script' - the node representing the script itself (may not be available)<br>
|
||||
* 'document' - document context node (may not be available)<br>
|
||||
* 'space' - space context node (may not be available)
|
||||
*
|
||||
* @param person The current user Person Node
|
||||
* @param companyHome The CompanyHome ref
|
||||
* @param userHome The User home space ref
|
||||
* @param script Optional ref to the script itself
|
||||
* @param document Optional ref to a document Node
|
||||
* @param space Optional ref to a space Node
|
||||
* @param resolver Image resolver to resolve icon images etc.
|
||||
*
|
||||
* @return A Map of global scope scriptable Node objects
|
||||
*/
|
||||
public Map<String, Object> buildDefaultModel(
|
||||
NodeRef person,
|
||||
NodeRef companyHome,
|
||||
NodeRef userHome,
|
||||
NodeRef script,
|
||||
NodeRef document,
|
||||
NodeRef space);
|
||||
}
|
||||
|
@@ -31,6 +31,8 @@ import org.alfresco.error.AlfrescoRuntimeException;
|
||||
*/
|
||||
public class TemplateException extends AlfrescoRuntimeException
|
||||
{
|
||||
private static final long serialVersionUID = 2863142603098852564L;
|
||||
|
||||
/**
|
||||
* @param msgId
|
||||
*/
|
||||
|
@@ -33,8 +33,8 @@ import java.io.Writer;
|
||||
*
|
||||
* @author Kevin Roast
|
||||
*/
|
||||
public interface TemplateProcessor
|
||||
{
|
||||
public interface TemplateProcessor extends Processor
|
||||
{
|
||||
/**
|
||||
* Process a template against the supplied data model and write to the out.
|
||||
*
|
||||
|
@@ -29,15 +29,8 @@ package org.alfresco.service.cmr.repository;
|
||||
*
|
||||
* @author Kevin Roast
|
||||
*/
|
||||
public interface TemplateExtensionImplementation
|
||||
{
|
||||
/**
|
||||
* Returns the name of the template extension
|
||||
*
|
||||
* @return the name of the template extension
|
||||
*/
|
||||
String getExtensionName();
|
||||
|
||||
public interface TemplateProcessorExtension extends ProcessorExtension
|
||||
{
|
||||
/**
|
||||
* Set the template image resolver for this extension
|
||||
*
|
@@ -25,7 +25,7 @@
|
||||
package org.alfresco.service.cmr.repository;
|
||||
|
||||
import java.io.Writer;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.service.Auditable;
|
||||
import org.alfresco.service.PublicService;
|
||||
@@ -47,6 +47,44 @@ import org.alfresco.service.PublicService;
|
||||
@PublicService
|
||||
public interface TemplateService
|
||||
{
|
||||
/** Keys for default model values */
|
||||
public static final String KEY_IMAGE_RESOLVER = "imageresolver";
|
||||
public static final String KEY_COMPANY_HOME = "companyhome";
|
||||
public static final String KEY_USER_HOME = "userhome";
|
||||
public static final String KEY_PERSON = "person";
|
||||
public static final String KEY_TEMPLATE = "template";
|
||||
public static final String KEY_DATE = "date";
|
||||
|
||||
/**
|
||||
* Process a template against the upplied data model and return the result as
|
||||
* a string.
|
||||
*
|
||||
* The template engine used will be determined by the extension of the template.
|
||||
*
|
||||
* @param template Template (qualified classpath name or noderef)
|
||||
* @param model Object model to process template against
|
||||
*
|
||||
* @return output of the template process as a String
|
||||
* @throws TemplateException
|
||||
*/
|
||||
@Auditable(parameters = {"template", "model"})
|
||||
public String processTemplate(String template, Object model)
|
||||
throws TemplateException;
|
||||
|
||||
/**
|
||||
* Process a template against the supplied data model and write to the out.
|
||||
*
|
||||
* The template engine used will be determined by the extension of the template.
|
||||
*
|
||||
* @param engine Name of the template engine to use
|
||||
* @param template Template (qualified classpath name or noderef)
|
||||
* @param model Object model to process template against
|
||||
* @param out Writer object to send output too
|
||||
*/
|
||||
@Auditable(parameters = {"template", "model", "out"})
|
||||
public void processTemplate(String template, Object model, Writer out)
|
||||
throws TemplateException;
|
||||
|
||||
/**
|
||||
* Process a template against the supplied data model and write to the out.
|
||||
*
|
||||
@@ -101,7 +139,7 @@ public interface TemplateService
|
||||
@Auditable(parameters = {"engine", "template", "model", "out"})
|
||||
public void processTemplateString(String engine, String template, Object model, Writer out)
|
||||
throws TemplateException;
|
||||
|
||||
|
||||
/**
|
||||
* Return a TemplateProcessor instance for the specified engine name.
|
||||
* Note that the processor instance is NOT thread safe!
|
||||
@@ -114,18 +152,28 @@ public interface TemplateService
|
||||
public TemplateProcessor getTemplateProcessor(String engine);
|
||||
|
||||
/**
|
||||
* Registers a template extension implementation with the Template service
|
||||
* Registers a new template processor with the template service
|
||||
*
|
||||
* @param extension the template extension implementation
|
||||
* @param templateProcessor the template processor to register
|
||||
*/
|
||||
@Auditable(parameters = {"extension"})
|
||||
public void registerExtension(TemplateExtensionImplementation extension);
|
||||
@Auditable(parameters = {"templateProcessor"})
|
||||
public void registerTemplateProcessor(TemplateProcessor templateProcessor);
|
||||
|
||||
/**
|
||||
* Returns a list of the Template Extension objects configured for this service
|
||||
* Helper method to build a default model
|
||||
*
|
||||
* @return list of the Template Extension objects configured for this service
|
||||
* @param person the person node reference
|
||||
* @param companyHome the company home node refereence
|
||||
* @param userHome the user home node reference
|
||||
* @param template the node ref for the template (optional)
|
||||
* @param imageResolver the image resolver (optional)
|
||||
* @return
|
||||
*/
|
||||
@Auditable(warn = true, recordReturnedObject = false)
|
||||
public List<TemplateExtensionImplementation> getExtensions();
|
||||
@Auditable(parameters = {"person", "compantHome", "userHome", "template", "imageResolver"})
|
||||
public Map<String, Object> buildDefaultModel(
|
||||
NodeRef person,
|
||||
NodeRef companyHome,
|
||||
NodeRef userHome,
|
||||
NodeRef template,
|
||||
TemplateImageResolver imageResolver);
|
||||
}
|
||||
|
Reference in New Issue
Block a user