REPO-2724 Apply default maven folder structure

This commit is contained in:
Alex Mukha
2017-07-28 14:51:21 +01:00
parent 6b91eba4f1
commit 5e247e50b4
6085 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,170 @@
/*
* #%L
* Alfresco Repository
* %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
package org.alfresco.repo.processor;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import org.alfresco.processor.Processor;
import org.alfresco.processor.ProcessorExtension;
import org.alfresco.service.ServiceRegistry;
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> processorExtensions = new HashMap<String, ProcessorExtension>(16);
/**
* 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.processorExtensions.put(processorExtension.getExtensionName(), processorExtension);
}
/**
* Get the collection of processor extensions
*
* @return collection of processor extensions
*/
public Collection<ProcessorExtension> getProcessorExtensions()
{
return this.processorExtensions.values();
}
}

View File

@@ -0,0 +1,81 @@
/*
* #%L
* Alfresco Repository
* %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
package org.alfresco.repo.processor;
import org.alfresco.api.AlfrescoPublicApi;
import org.alfresco.processor.Processor;
import org.alfresco.processor.ProcessorExtension;
/**
* Abstract base class for a processor extension
*
* @author Roy Wetherall
*/
@AlfrescoPublicApi
public abstract class BaseProcessorExtension implements ProcessorExtension
{
/** The processor */
private Processor processor;
/** The name of the extension */
private String extensionName;
/**
* Sets the processor
*
* @param processor 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 extension the extension name
*/
public void setExtensionName(String extension)
{
this.extensionName = extension;
}
/**
* @see org.alfresco.processor.ProcessorExtension#getExtensionName()
*/
public String getExtensionName()
{
return this.extensionName;
}
}

View File

@@ -0,0 +1,453 @@
/*
* #%L
* Alfresco Repository
* %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
package org.alfresco.repo.processor;
import java.util.HashMap;
import java.util.Map;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.admin.SysAdminParams;
import org.alfresco.repo.jscript.ScriptUrls;
import org.alfresco.scripts.ScriptException;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
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.springframework.extensions.surf.util.ParameterCheck;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Script service implementation
*
* @author Kevin Roast
* @author Roy Wetherall
*/
public class ScriptServiceImpl implements ScriptService
{
/** Logger */
private static final Log logger = LogFactory.getLog(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>(8);
private Map<String, String> scriptProcessorNamesByExtension = new HashMap<String, String>(8);
/** The node service */
private NodeService nodeService;
private SysAdminParams sysAdminParams;
/**
* 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;
}
/**
* Set the sysAdminParams
*
* @param sysAdminParams the sysAdminParams
*/
public void setSysAdminParams(SysAdminParams sysAdminParams)
{
this.sysAdminParams = sysAdminParams;
}
/**
* 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());
}
/**
* Reset all registered script processors
*/
public void resetScriptProcessors()
{
for (ScriptProcessor p : this.scriptProcessors.values())
{
p.reset();
}
}
/**
* @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
{
ParameterCheck.mandatory("scriptClasspath", scriptClasspath);
ScriptProcessor scriptProcessor = getScriptProcessor(scriptClasspath);
return execute(scriptProcessor, scriptClasspath, model);
}
/**
* @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
{
ScriptProcessor scriptProcessor = lookupScriptProcessor(engine);
return execute(scriptProcessor, scriptClasspath, model);
}
/**
* @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
{
ParameterCheck.mandatory("scriptRef", scriptRef);
ScriptProcessor scriptProcessor = getScriptProcessor(scriptRef);
return execute(scriptProcessor, scriptRef, contentProp, model);
}
/**
* @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
{
ScriptProcessor scriptProcessor = lookupScriptProcessor(engine);
return execute(scriptProcessor, scriptRef, contentProp, model);
}
/**
* @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);
ScriptProcessor scriptProcessor = getScriptProcessor(location.toString());
return execute(scriptProcessor, location, model);
}
/**
* @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
{
ScriptProcessor scriptProcessor = lookupScriptProcessor(engine);
return execute(scriptProcessor, location, model);
}
/**
* @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
{
ScriptProcessor scriptProcessor = lookupScriptProcessor(engine);
return executeString(scriptProcessor, script, model);
}
/**
* Execute script
*
* @param location the location of the script
* @param model context model
* @return Object the result of the script
*/
protected Object execute(ScriptProcessor processor, ScriptLocation location, Map<String, Object> model)
{
ParameterCheck.mandatory("location", location);
if (logger.isDebugEnabled())
{
logger.debug("Executing script:\n" + location);
}
try
{
return processor.execute(location, model);
}
catch (Throwable err)
{
throw translateProcessingException(location.toString(), err);
}
}
/**
* Execute script
*
* @param scriptRef the script node reference
* @param contentProp the content property of the script
* @param model the context model
* @return Object the result of the script
*/
protected Object execute(ScriptProcessor processor, NodeRef scriptRef, QName contentProp, Map<String, Object> model)
{
ParameterCheck.mandatory("scriptRef", scriptRef);
if (logger.isDebugEnabled())
{
logger.debug("Executing script:\n" + scriptRef);
}
try
{
return processor.execute(scriptRef, contentProp, model);
}
catch (Throwable err)
{
throw translateProcessingException(scriptRef.toString(), err);
}
}
/**
* Execute script
*
* @param location the classpath string locating the script
* @param model the context model
* @return Object the result of the script
*/
protected Object execute(ScriptProcessor processor, String location, Map<String, Object> model)
{
ParameterCheck.mandatoryString("location", location);
if (logger.isDebugEnabled())
{
logger.debug("Executing script:\n" + location);
}
try
{
return processor.execute(location, model);
}
catch (Throwable err)
{
throw translateProcessingException(location, err);
}
}
/**
* Execute script string
*
* @param script the script string
* @param model the context model
* @return Object the result of the script
*/
protected Object executeString(ScriptProcessor processor, String script, Map<String, Object> model)
{
ParameterCheck.mandatoryString("script", script);
if (logger.isDebugEnabled())
{
logger.debug("Executing script:\n" + script);
}
try
{
return processor.executeString(script, model);
}
catch (Throwable err)
{
throw translateProcessingException("provided by caller", err);
}
}
protected ScriptException translateProcessingException(String scriptInfo, Throwable err)
{
ScriptException result = null;
String msg = "Failed to execute script " + (scriptInfo == null ? "" : scriptInfo);
if (logger.isWarnEnabled())
{
logger.warn(msg, err);
}
if (ScriptException.class.isAssignableFrom(err.getClass()))
{
result = (ScriptException)err;
}
else
{
result = new ScriptException(msg, err);
}
return result;
}
/**
* Helper method to lookup the script processor 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 = (name == null ? null : 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#buildCoreModel(java.util.Map)
*/
public void buildCoreModel(Map<String, Object> inputMap)
{
ParameterCheck.mandatory("InputMap", inputMap);
inputMap.put("urls", new ScriptUrls(sysAdminParams));
}
/**
* @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>();
buildCoreModel(model);
// add the well known node wrapper objects
model.put("companyhome", companyHome);
if (userHome!= null)
{
model.put("userhome", userHome);
}
if (person != null)
{
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,322 @@
/*
* #%L
* Alfresco Repository
* %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
package org.alfresco.repo.processor;
import java.io.StringWriter;
import java.io.Writer;
import java.util.Date;
import java.util.HashMap;
import java.util.Locale;
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;
import org.springframework.extensions.surf.util.I18NUtil;
/**
* 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)
{
if (engine == null)
{
engine = this.defaultTemplateEngine;
}
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, Locale locale)
*/
public String processTemplate(String engine, String template, Object model, Locale locale)
throws TemplateException
{
Writer out = new StringWriter(1024);
processTemplate(engine, template, model, out, locale);
return out.toString();
}
/**
* @see org.alfresco.service.cmr.repository.TemplateService#processTemplate(java.lang.String, java.lang.String, java.lang.Object, java.util.Locale)
*/
private void processTemplate(String engine, String template, Object model, Writer out, Locale locale)
throws TemplateException
{
Locale currentLocale = I18NUtil.getLocaleOrNull();
Locale currentContentLocale = I18NUtil.getContentLocaleOrNull();
try
{
// set locale for cases where message method is used inside of template
I18NUtil.setLocale(locale);
// execute template processor
TemplateProcessor processor = getTemplateProcessor(engine);
processor.process(template, model, out, locale);
}
catch (TemplateException terr)
{
throw terr;
}
catch (Throwable err)
{
throw new TemplateException(err.getMessage(), err);
}
finally
{
I18NUtil.setLocale(currentLocale);
I18NUtil.setContentLocale(currentContentLocale);
}
}
/**
* @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
if (companyHome != null)
{
model.put(KEY_COMPANY_HOME, companyHome);
}
if (userHome != null)
{
model.put(KEY_USER_HOME, userHome);
}
if (person != null)
{
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;
}
}