Interface TemplateService
-
- All Known Implementing Classes:
TemplateServiceImpl
@AlfrescoPublicApi public interface TemplateServiceTemplate Service.Provides an interface to services for executing template engine against a template file and data model.
The service provides a configured list of available template engines. The template file can either be in the repository (passed as NodeRef string) or on the classpath. Also a template can be passed directly as a String using the processTemplateString() methods.
The data model is specified to the template engine. The FreeMarker template engine is used by default.
- Author:
- Kevin Roast
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringKEY_COMPANY_HOMEstatic java.lang.StringKEY_DATEstatic java.lang.StringKEY_IMAGE_RESOLVERKeys for default model valuesstatic java.lang.StringKEY_PERSONstatic java.lang.StringKEY_PRODUCT_NAMEstatic java.lang.StringKEY_SHARE_URLstatic java.lang.StringKEY_TEMPLATEstatic java.lang.StringKEY_USER_HOME
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description java.util.Map<java.lang.String,java.lang.Object>buildDefaultModel(org.alfresco.service.cmr.repository.NodeRef person, org.alfresco.service.cmr.repository.NodeRef companyHome, org.alfresco.service.cmr.repository.NodeRef userHome, org.alfresco.service.cmr.repository.NodeRef template, TemplateImageResolver imageResolver)Helper method to build a default modelTemplateProcessorgetTemplateProcessor(java.lang.String engine)Return a TemplateProcessor instance for the specified engine name.java.lang.StringprocessTemplate(java.lang.String template, java.lang.Object model)Process a template against the upplied data model and return the result as a string.voidprocessTemplate(java.lang.String template, java.lang.Object model, java.io.Writer out)Process a template against the supplied data model and write to the out.java.lang.StringprocessTemplate(java.lang.String engine, java.lang.String template, java.lang.Object model)Process a template against the supplied data model and write to the out.voidprocessTemplate(java.lang.String engine, java.lang.String template, java.lang.Object model, java.io.Writer out)Process a template against the supplied data model and write to the out.java.lang.StringprocessTemplate(java.lang.String engine, java.lang.String templateRef, java.lang.Object model, java.util.Locale locale)Process a template using the supplied locale against the supplied data model and write to the out.java.lang.StringprocessTemplateString(java.lang.String engine, java.lang.String template, java.lang.Object model)Process a given template, provided as a string, against the supplied data model and return the result as a StringvoidprocessTemplateString(java.lang.String engine, java.lang.String template, java.lang.Object model, java.io.Writer out)Process a given template, provided as a string, against the supplied data model and report the result back in the provided writer.voidregisterTemplateProcessor(TemplateProcessor templateProcessor)Registers a new template processor with the template service
-
-
-
Field Detail
-
KEY_IMAGE_RESOLVER
static final java.lang.String KEY_IMAGE_RESOLVER
Keys for default model values- See Also:
- Constant Field Values
-
KEY_COMPANY_HOME
static final java.lang.String KEY_COMPANY_HOME
- See Also:
- Constant Field Values
-
KEY_USER_HOME
static final java.lang.String KEY_USER_HOME
- See Also:
- Constant Field Values
-
KEY_PERSON
static final java.lang.String KEY_PERSON
- See Also:
- Constant Field Values
-
KEY_TEMPLATE
static final java.lang.String KEY_TEMPLATE
- See Also:
- Constant Field Values
-
KEY_DATE
static final java.lang.String KEY_DATE
- See Also:
- Constant Field Values
-
KEY_SHARE_URL
static final java.lang.String KEY_SHARE_URL
- See Also:
- Constant Field Values
-
KEY_PRODUCT_NAME
static final java.lang.String KEY_PRODUCT_NAME
- See Also:
- Constant Field Values
-
-
Method Detail
-
processTemplate
@Auditable(parameters={"template","model"}) java.lang.String processTemplate(java.lang.String template, java.lang.Object model) throws TemplateExceptionProcess 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.- Parameters:
template- Template (qualified classpath name or noderef)model- Object model to process template against- Returns:
- output of the template process as a String
- Throws:
TemplateException
-
processTemplate
@Auditable(parameters={"template","model","out"}) void processTemplate(java.lang.String template, java.lang.Object model, java.io.Writer out) throws TemplateExceptionProcess 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.- Parameters:
template- Template (qualified classpath name or noderef)model- Object model to process template againstout- Writer object to send output too- Throws:
TemplateException
-
processTemplate
@Auditable(parameters={"engine","template","model"}) java.lang.String processTemplate(java.lang.String engine, java.lang.String template, java.lang.Object model) throws TemplateExceptionProcess a template against the supplied data model and write to the out.- Parameters:
engine- Name of the template engine to usetemplate- Template (qualified classpath name or noderef)model- Object model to process template against- Returns:
- output of the template process as a String
- Throws:
TemplateException
-
processTemplate
@Auditable(parameters={"engine","template","model","out"}) void processTemplate(java.lang.String engine, java.lang.String template, java.lang.Object model, java.io.Writer out) throws TemplateExceptionProcess a template against the supplied data model and write to the out.- Parameters:
engine- Name of the template engine to usetemplate- Template (qualified classpath name or noderef)model- Object model to process template againstout- Writer object to send output too- Throws:
TemplateException
-
processTemplate
@Auditable(parameters={"engine","template","model","out","locale"}) java.lang.String processTemplate(java.lang.String engine, java.lang.String templateRef, java.lang.Object model, java.util.Locale locale) throws TemplateExceptionProcess a template using the supplied locale against the supplied data model and write to the out.- Parameters:
engine- Name of the template engine to usetemplateRef- Template ref (qualified classpath name or noderef)model- Object model to process template againstlocale- Locale to process the template as- Throws:
TemplateException
-
processTemplateString
@Auditable(parameters={"engine","template","model"}) java.lang.String processTemplateString(java.lang.String engine, java.lang.String template, java.lang.Object model) throws TemplateExceptionProcess a given template, provided as a string, against the supplied data model and return the result as a String- Parameters:
engine- Name of the template engine to usetemplate- Template stringmodel- Object model to process template against- Returns:
- output of the template process as a String
- Throws:
TemplateException
-
processTemplateString
@Auditable(parameters={"engine","template","model","out"}) void processTemplateString(java.lang.String engine, java.lang.String template, java.lang.Object model, java.io.Writer out) throws TemplateExceptionProcess a given template, provided as a string, against the supplied data model and report the result back in the provided writer.- Parameters:
engine- Name of the template engine to usetemplate- Template stringmodel- Object model to process template againstout- Writer object to send output too- Throws:
TemplateException
-
getTemplateProcessor
@Auditable(parameters="engine") TemplateProcessor getTemplateProcessor(java.lang.String engine)
Return a TemplateProcessor instance for the specified engine name. Note that the processor instance is NOT thread safe!- Parameters:
engine- Name of the template engine to get or null for default- Returns:
- TemplateProcessor
-
registerTemplateProcessor
@Auditable(parameters="templateProcessor") void registerTemplateProcessor(TemplateProcessor templateProcessor)
Registers a new template processor with the template service- Parameters:
templateProcessor- the template processor to register
-
buildDefaultModel
@Auditable(parameters={"person","companyHome","userHome","template","imageResolver"}) java.util.Map<java.lang.String,java.lang.Object> buildDefaultModel(org.alfresco.service.cmr.repository.NodeRef person, org.alfresco.service.cmr.repository.NodeRef companyHome, org.alfresco.service.cmr.repository.NodeRef userHome, org.alfresco.service.cmr.repository.NodeRef template, TemplateImageResolver imageResolver)Helper method to build a default model- Parameters:
person- the person node referencecompanyHome- the company home node refereenceuserHome- the user home node referencetemplate- the node ref for the template (optional)imageResolver- the image resolver (optional)- Returns:
- Map
-
-