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:
Roy Wetherall
2007-04-20 17:13:34 +00:00
parent 03c56f4c90
commit 5401499003
44 changed files with 1392 additions and 713 deletions

View File

@@ -0,0 +1,158 @@
/*
* 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.repo.processor;
import java.util.HashMap;
import java.util.Map;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.repository.Processor;
import org.alfresco.service.cmr.repository.ProcessorExtension;
import org.alfresco.service.cmr.repository.ScriptProcessor;
import org.alfresco.service.cmr.repository.ScriptService;
import org.alfresco.service.cmr.repository.TemplateProcessor;
import org.alfresco.service.cmr.repository.TemplateService;
/**
* Base class of a processor, encapsulates the implementation reguarding the registration of the processor
* with the relevant services and the handling of processor extensions.
*
* @author Roy Wetherall
*/
public abstract class BaseProcessor implements Processor
{
/** The name of the processor */
protected String name;
/** The file extension that this processor understands */
protected String extension;
/** The script service */
protected ScriptService scriptService;
/** The template service */
protected TemplateService templateService;
/** The service registry */
protected ServiceRegistry services;
/** A map containing all the processor extenstions */
protected Map<String, ProcessorExtension> processExtensions = new HashMap<String, ProcessorExtension>(10);
/**
* Registers this processor with the relevant services
*/
public void register()
{
if (this instanceof ScriptProcessor)
{
scriptService.registerScriptProcessor((ScriptProcessor)this);
}
if (this instanceof TemplateProcessor)
{
templateService.registerTemplateProcessor((TemplateProcessor)this);
}
}
/**
* Sets the script service
*
* @param scriptService the script service
*/
public void setScriptService(ScriptService scriptService)
{
this.scriptService = scriptService;
}
/**
* Sets the template service
*
* @param templateService the template service
*/
public void setTemplateService(TemplateService templateService)
{
this.templateService = templateService;
}
/**
* Sets the service registry
*
* @param serviceRegistry the service registry
*/
public void setServiceRegistry(ServiceRegistry serviceRegistry)
{
this.services = serviceRegistry;
}
/**
* Get the name of the processor
*
* @return String the name of the processor
*/
public String getName()
{
return name;
}
/**
* Sets the name of the processor
*
* @param name the name of the processor
*/
public void setName(String name)
{
this.name = name;
}
/**
* Gets the extension that the processor understands
*
* @return String the extension
*/
public String getExtension()
{
return extension;
}
/**
* Sets the extenstion that the processor understands
*
* @param extension the extension
*/
public void setExtension(String extension)
{
this.extension = extension;
}
/**
* Registers a processor extension with the processor
*
* @param processorExtension the processor extension
*/
public void registerProcessorExtension(ProcessorExtension processorExtension)
{
this.processExtensions.put(processorExtension.getExtensionName(), processorExtension);
}
}

View File

@@ -0,0 +1,78 @@
/*
* 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.repo.processor;
import org.alfresco.service.cmr.repository.Processor;
import org.alfresco.service.cmr.repository.ProcessorExtension;
/**
* Abstract base class for a processor extension
*
* @author Roy Wetherall
*/
public abstract class BaseProcessorExtension implements ProcessorExtension
{
/** The processor */
private Processor processor;
/** The name of the extension */
private String extensionName;
/**
* Sets the processor
*
* @param scriptProcessor the processor
*/
public void setProcessor(Processor processor)
{
this.processor = processor;
}
/**
* Registers this script with the script service
*/
public void register()
{
this.processor.registerProcessorExtension(this);
}
/**
* Sets the extension name
*
* @param extensionName the extension name
*/
public void setExtensionName(String extension)
{
this.extensionName = extension;
}
/**
* @see org.alfresco.service.cmr.repository.ProcessorExtension#getExtensionName()
*/
public String getExtensionName()
{
return this.extensionName;
}
}

View File

@@ -0,0 +1,403 @@
/*
* 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.repo.processor;
import java.util.HashMap;
import java.util.Map;
import org.alfresco.model.ContentModel;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.ScriptException;
import org.alfresco.service.cmr.repository.ScriptLocation;
import org.alfresco.service.cmr.repository.ScriptProcessor;
import org.alfresco.service.cmr.repository.ScriptService;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.ParameterCheck;
import org.apache.log4j.Logger;
/**
* Script service implementation
*
* @author Kevin Roast
* @author Roy Wetherall
*/
public class ScriptServiceImpl implements ScriptService
{
/** Logger */
private static final Logger logger = Logger.getLogger(ScriptServiceImpl.class);
/** The name of the default script processor */
private String defaultScriptProcessor;
/** Maps containing the script processors */
private Map<String, ScriptProcessor> scriptProcessors = new HashMap<String, ScriptProcessor>(5);
private Map<String, String> scriptProcessorNamesByExtension = new HashMap<String, String>(5);
/** The node service */
private NodeService nodeService;
/**
* Sets the name of the default script processor
*
* @param defaultScriptProcessor the name of the default script processor
*/
public void setDefaultScriptProcessor(String defaultScriptProcessor)
{
this.defaultScriptProcessor = defaultScriptProcessor;
}
/**
* Set the node service
*
* @param nodeService the node service
*/
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
/**
* Register a script processor
*
* @param scriptProcessor the script processor to register with the script service
*/
public void registerScriptProcessor(ScriptProcessor scriptProcessor)
{
this.scriptProcessors.put(scriptProcessor.getName(), scriptProcessor);
this.scriptProcessorNamesByExtension.put(scriptProcessor.getExtension(), scriptProcessor.getName());
}
/**
* @see org.alfresco.service.cmr.repository.ScriptService#executeScript(java.lang.String, java.util.Map)
*/
public Object executeScript(String scriptClasspath, Map<String, Object> model)
throws ScriptException
{
if (scriptClasspath == null)
{
throw new IllegalArgumentException("Script ClassPath is mandatory.");
}
if (logger.isDebugEnabled())
{
logger.debug("Executing script: " + scriptClasspath);
}
try
{
ScriptProcessor scriptProcessor = getScriptProcessor(scriptClasspath);
return scriptProcessor.execute(scriptClasspath, model);
}
catch (Throwable err)
{
throw new ScriptException("Failed to execute script '" + scriptClasspath + "': " + err.getMessage(), err);
}
}
/**
* @see org.alfresco.service.cmr.repository.ScriptService#executeScript(java.lang.String, java.lang.String, java.util.Map)
*/
public Object executeScript(String engine, String scriptClasspath, Map<String, Object> model)
throws ScriptException
{
if (scriptClasspath == null)
{
throw new IllegalArgumentException("Script ClassPath is mandatory.");
}
if (logger.isDebugEnabled())
{
logger.debug("Executing script: " + scriptClasspath);
}
try
{
ScriptProcessor scriptProcessor = lookupScriptProcessor(engine);
return scriptProcessor.execute(scriptClasspath, model);
}
catch (Throwable err)
{
throw new ScriptException("Failed to execute script '" + scriptClasspath + "': " + err.getMessage(), err);
}
}
/**
* @see org.alfresco.service.cmr.repository.ScriptService#executeScript(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName, java.util.Map)
*/
public Object executeScript(NodeRef scriptRef, QName contentProp, Map<String, Object> model)
throws ScriptException
{
if (scriptRef == null)
{
throw new IllegalArgumentException("Script NodeRef is mandatory.");
}
if (logger.isDebugEnabled())
{
logger.debug("Executing script: " + scriptRef.toString());
}
try
{
ScriptProcessor scriptProcessor = getScriptProcessor(scriptRef);
return scriptProcessor.execute(scriptRef, contentProp, model);
}
catch (Throwable err)
{
throw new ScriptException("Failed to execute script '" + scriptRef.toString() + "': " + err.getMessage(), err);
}
}
/**
* @see org.alfresco.service.cmr.repository.ScriptService#executeScript(java.lang.String, org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName, java.util.Map)
*/
public Object executeScript(String engine, NodeRef scriptRef, QName contentProp, Map<String, Object> model)
throws ScriptException
{
if (scriptRef == null)
{
throw new IllegalArgumentException("Script NodeRef is mandatory.");
}
if (logger.isDebugEnabled())
{
logger.debug("Executing script: " + scriptRef.toString());
}
try
{
ScriptProcessor scriptProcessor = lookupScriptProcessor(engine);
return scriptProcessor.execute(scriptRef, contentProp, model);
}
catch (Throwable err)
{
throw new ScriptException("Failed to execute script '" + scriptRef.toString() + "': " + err.getMessage(), err);
}
}
/**
* @see org.alfresco.service.cmr.repository.ScriptService#executeScript(org.alfresco.service.cmr.repository.ScriptLocation, java.util.Map)
*/
public Object executeScript(ScriptLocation location, Map<String, Object> model)
throws ScriptException
{
ParameterCheck.mandatory("Location", location);
if (logger.isDebugEnabled())
{
logger.debug("Executing script: " + location.toString());
}
try
{
ScriptProcessor scriptProcessor = getScriptProcessor(location.toString());
return scriptProcessor.execute(location, model);
}
catch (Throwable err)
{
throw new ScriptException("Failed to execute script '" + location.toString() + "': " + err.getMessage(), err);
}
}
/**
* @see org.alfresco.service.cmr.repository.ScriptService#executeScript(java.lang.String, org.alfresco.service.cmr.repository.ScriptLocation, java.util.Map)
*/
public Object executeScript(String engine, ScriptLocation location, Map<String, Object> model)
throws ScriptException
{
ParameterCheck.mandatory("Location", location);
if (logger.isDebugEnabled())
{
logger.debug("Executing script: " + location.toString());
}
try
{
ScriptProcessor scriptProcessor = lookupScriptProcessor(engine);
return scriptProcessor.execute(location, model);
}
catch (Throwable err)
{
throw new ScriptException("Failed to execute script '" + location.toString() + "': " + err.getMessage(), err);
}
}
/**
* @see org.alfresco.service.cmr.repository.ScriptService#executeScriptString(java.lang.String, java.util.Map)
*/
public Object executeScriptString(String script, Map<String, Object> model)
throws ScriptException
{
return executeScriptString(this.defaultScriptProcessor, script, model);
}
/**
* @see org.alfresco.service.cmr.repository.ScriptService#executeScriptString(java.lang.String, java.util.Map)
*/
public Object executeScriptString(String engine, String script, Map<String, Object> model)
throws ScriptException
{
if (script == null || script.length() == 0)
{
throw new IllegalArgumentException("Script argument is mandatory.");
}
if (logger.isDebugEnabled())
{
logger.debug("Executing script:\n" + script);
}
try
{
ScriptProcessor scriptProcessor = lookupScriptProcessor(engine);
return scriptProcessor.executeString(script, model);
}
catch (Throwable err)
{
throw new ScriptException("Failed to execute supplied script: " + err.getMessage(), err);
}
}
/**
* Helper method to lookup the script proecessor based on a name
*
* @param name the name of the script processor
* @return ScriptProcessor the script processor, default processor if no match found
*/
protected ScriptProcessor lookupScriptProcessor(String name)
{
ScriptProcessor scriptProcessor = this.scriptProcessors.get(name);
if (scriptProcessor == null)
{
scriptProcessor = this.scriptProcessors.get(this.defaultScriptProcessor);
}
return scriptProcessor;
}
/**
* Gets a scipt processor based on the node reference of a script
*
* @param scriptNode the node reference of the script
* @return ScriptProcessor the script processor
*/
protected ScriptProcessor getScriptProcessor(NodeRef scriptNode)
{
String scriptName = (String)this.nodeService.getProperty(scriptNode, ContentModel.PROP_NAME);
return getScriptProcessorImpl(scriptName);
}
/**
* Gets a script processor based on the script location string
*
* @param scriptLocation the script location
* @return ScriptProcessor the script processor
*/
protected ScriptProcessor getScriptProcessor(String scriptLocation)
{
if (scriptLocation.indexOf(StoreRef.URI_FILLER) != -1)
{
// Try and create the nodeRef
NodeRef nodeRef = new NodeRef(scriptLocation);
scriptLocation = (String)this.nodeService.getProperty(nodeRef, ContentModel.PROP_NAME);
}
return getScriptProcessorImpl(scriptLocation);
}
/**
* Gets a script processor based on the scripts file name
*
* @param scriptFileName the scripts file name
* @return ScriptProcessor the matching script processor
*/
protected ScriptProcessor getScriptProcessorImpl(String scriptFileName)
{
String engine = null;
if (scriptFileName != null)
{
String extension = getFileExtension(scriptFileName);
if (extension != null)
{
engine = this.scriptProcessorNamesByExtension.get(extension);
}
}
return lookupScriptProcessor(engine);
}
/**
* Gets the file extension of a file
*
* @param fileName the file name
* @return the file extension
*/
private String getFileExtension(String fileName)
{
String extension = null;
int index = fileName.lastIndexOf('.');
if (index > -1 && (index < fileName.length() - 1))
{
extension = fileName.substring(index + 1);
}
return extension;
}
/**
* @see org.alfresco.service.cmr.repository.ScriptService#buildDefaultModel(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.cmr.repository.NodeRef)
*/
public Map<String, Object> buildDefaultModel(
NodeRef person,
NodeRef companyHome,
NodeRef userHome,
NodeRef script,
NodeRef document,
NodeRef space)
{
Map<String, Object> model = new HashMap<String, Object>();
// add the well known node wrapper objects
model.put("companyhome", companyHome);
model.put("userhome", userHome);
model.put("person", person);
if (script != null)
{
model.put("script", script);
}
if (document != null)
{
model.put("document", document);
}
if (space != null)
{
model.put("space", space);
}
return model;
}
}

View File

@@ -0,0 +1,262 @@
/*
* 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.repo.processor;
import java.io.StringWriter;
import java.io.Writer;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ContentModel;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.TemplateException;
import org.alfresco.service.cmr.repository.TemplateImageResolver;
import org.alfresco.service.cmr.repository.TemplateProcessor;
import org.alfresco.service.cmr.repository.TemplateService;
/**
* Implementation of the TemplateService using Spring configured script engines.
*
* @author Kevin Roast
*/
public class TemplateServiceImpl implements TemplateService
{
/** Default Template processor engine to use */
private String defaultTemplateEngine;
/** List of available template processors */
private Map<String, TemplateProcessor> processors = new HashMap<String, TemplateProcessor>(5);
private Map<String, String> processorNamesByExtension = new HashMap<String, String>(5);
/** The node service */
private NodeService nodeService;
/**
* @param defaultTemplateEngine The default Template Engine name to set.
*/
public void setDefaultTemplateEngine(String defaultTemplateEngine)
{
this.defaultTemplateEngine = defaultTemplateEngine;
}
/**
* Set the node service
*
* @param nodeService the node service
*/
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
/**
* @see org.alfresco.service.cmr.repository.TemplateService#getTemplateProcessor(java.lang.String)
*/
public TemplateProcessor getTemplateProcessor(String engine)
{
return this.processors.get(engine);
}
/**
* @see org.alfresco.service.cmr.repository.TemplateService#registerTemplateProcessor(org.alfresco.service.cmr.repository.TemplateProcessor)
*/
public void registerTemplateProcessor(TemplateProcessor templateProcessor)
{
this.processors.put(templateProcessor.getName(), templateProcessor);
this.processorNamesByExtension.put(templateProcessor.getExtension(), templateProcessor.getName());
}
/**
* @see org.alfresco.service.cmr.repository.TemplateService#processTemplate(java.lang.String, java.lang.Object)
*/
public String processTemplate(String template, Object model) throws TemplateException
{
return processTemplate(getTemplateProcessorName(template), template, model);
}
/**
* @see org.alfresco.service.cmr.repository.TemplateService#processTemplate(java.lang.String, java.lang.Object, java.io.Writer)
*/
public void processTemplate(String template, Object model, Writer out) throws TemplateException
{
processTemplate(getTemplateProcessorName(template), template, model, out);
}
/**
* Gets the template processor name from the template string
*
* @param template the template string location
* @return the template processor string
*/
private String getTemplateProcessorName(String template)
{
String engine = null;
try
{
// Try and create the nodeRef
NodeRef templateNodeRef = new NodeRef(template);
String templateName = (String)this.nodeService.getProperty(templateNodeRef, ContentModel.PROP_NAME);
String extension = getFileExtension(templateName);
if (extension != null)
{
engine = this.processorNamesByExtension.get(extension);
}
}
catch (AlfrescoRuntimeException exception)
{
// Presume that the provided template is a classpath
String extension = getFileExtension(template);
if (extension != null)
{
engine = this.processorNamesByExtension.get(extension);
}
}
// Set the default engine if none found
if (engine == null)
{
engine = this.defaultTemplateEngine;
}
return engine;
}
/**
* Gets the file extension of a file
*
* @param fileName the file name
* @return the file extension
*/
private String getFileExtension(String fileName)
{
String extension = null;
int index = fileName.lastIndexOf('.');
if (index > -1 && (index < fileName.length() - 1))
{
extension = fileName.substring(index + 1);
}
return extension;
}
/**
* @see org.alfresco.service.cmr.repository.TemplateService#processTemplate(java.lang.String, java.lang.String, java.lang.Object, java.io.Writer)
*/
public void processTemplate(String engine, String template, Object model, Writer out)
throws TemplateException
{
try
{
// execute template processor
TemplateProcessor processor = getTemplateProcessor(engine);
processor.process(template, model, out);
}
catch (TemplateException terr)
{
throw terr;
}
catch (Throwable err)
{
throw new TemplateException(err.getMessage(), err);
}
}
/**
* @see org.alfresco.service.cmr.repository.TemplateService#processTemplate(java.lang.String, java.lang.String, java.lang.Object)
*/
public String processTemplate(String engine, String template, Object model)
throws TemplateException
{
Writer out = new StringWriter(1024);
processTemplate(engine, template, model, out);
return out.toString();
}
/**
* @see org.alfresco.service.cmr.repository.TemplateService#processTemplateString(java.lang.String, java.lang.String, java.lang.Object, java.io.Writer)
*/
public void processTemplateString(String engine, String template, Object model, Writer out)
throws TemplateException
{
try
{
// execute template processor
TemplateProcessor processor = getTemplateProcessor(engine);
processor.processString(template, model, out);
}
catch (TemplateException terr)
{
throw terr;
}
catch (Throwable err)
{
throw new TemplateException(err.getMessage(), err);
}
}
/**
* @see org.alfresco.service.cmr.repository.TemplateService#processTemplateString(java.lang.String, java.lang.String, java.lang.Object)
*/
public String processTemplateString(String engine, String template, Object model)
throws TemplateException
{
Writer out = new StringWriter(1024);
processTemplateString(engine, template, model, out);
return out.toString();
}
/**
* @see org.alfresco.service.cmr.repository.TemplateService#buildDefaultModel(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.cmr.repository.TemplateImageResolver)
*/
public Map<String, Object> buildDefaultModel(NodeRef person, NodeRef companyHome, NodeRef userHome, NodeRef template, TemplateImageResolver imageResolver)
{
Map<String, Object> model = new HashMap<String, Object>(16, 1.0f);
// Place the image resolver into the model
if (imageResolver != null)
{
model.put(KEY_IMAGE_RESOLVER, imageResolver);
}
// Put the common node reference into the model
model.put(KEY_COMPANY_HOME, companyHome);
model.put(KEY_USER_HOME, userHome);
model.put(KEY_PERSON, person);
// add the template itself as "template" if it comes from content on a node
if (template != null)
{
model.put(KEY_TEMPLATE, template);
}
// current date/time is useful to have and isn't supplied by FreeMarker by default
model.put(KEY_DATE, new Date());
return model;
}
}