Package org.craftercms.engine.freemarker
Class RenderComponentDirective
- java.lang.Object
-
- org.craftercms.engine.freemarker.RenderComponentDirective
-
- All Implemented Interfaces:
freemarker.template.TemplateDirectiveModel
,freemarker.template.TemplateModel
public class RenderComponentDirective extends Object implements freemarker.template.TemplateDirectiveModel
Custom directive to render a component by processing the template defined in the component element's template name sub-element.- Author:
- Alfonso Vásquez
-
-
Field Summary
Fields Modifier and Type Field Description static String
ADDITIONAL_MODEL_PARAM_NAME
static String
COMPONENT_PARAM_NAME
static String
COMPONENT_PARENT_PARAM_NAME
static String
COMPONENT_PATH_PARAM_NAME
protected String
componentElementName
protected String
includeElementName
static String
KEY_CONTENT_MODEL
static String
KEY_MODEL
Deprecated.protected org.springframework.beans.factory.ObjectFactory<freemarker.template.SimpleHash>
modelFactory
protected SiteItemScriptResolver
scriptResolver
protected javax.servlet.ServletContext
servletContext
protected SiteItemService
siteItemService
protected String
templateNamePrefix
protected String
templateNameSuffix
protected String
templateXPathQuery
-
Constructor Summary
Constructors Constructor Description RenderComponentDirective()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Map<String,Object>
createScriptVariables(SiteItem component, Map<String,Object> templateModel, Map<String,Object> additionalModel)
void
execute(freemarker.core.Environment env, Map params, freemarker.template.TemplateModel[] loopVars, freemarker.template.TemplateDirectiveBody body)
protected void
executeScript(Script script, Map<String,Object> scriptVariables, freemarker.core.Environment env)
protected Map<String,Object>
executeScripts(SiteItem component, Map<String,Object> additionalModel, freemarker.core.Environment env)
protected SiteItem
getComponent(String componentPath, freemarker.core.Environment env)
protected SiteItem
getComponentFromNode(freemarker.template.TemplateModel parentParam, freemarker.template.TemplateModel componentParam, freemarker.core.Environment env)
protected SiteItem
getComponentFromPath(freemarker.template.TemplateModel componentPathParam, freemarker.core.Environment env)
protected String
getComponentTemplateName(SiteItem component, freemarker.core.Environment env)
protected freemarker.template.SimpleHash
getFullModel(SiteItem component, Map<String,Object> templateModel, Map<String,Object> additionalModel)
protected freemarker.template.Template
getTemplate(SiteItem component, freemarker.core.Environment env)
protected void
processComponentTemplate(freemarker.template.Template template, freemarker.template.SimpleHash model, Writer output, freemarker.core.Environment env)
void
setComponentElementName(String componentElementName)
void
setIncludeElementName(String includeElementName)
void
setModelFactory(org.springframework.beans.factory.ObjectFactory<freemarker.template.SimpleHash> modelFactory)
void
setScriptResolver(SiteItemScriptResolver scriptResolver)
void
setServletContext(javax.servlet.ServletContext servletContext)
void
setSiteItemService(SiteItemService siteItemService)
void
setTemplateNamePrefix(String templateNamePrefix)
void
setTemplateNameSuffix(String templateNameSuffix)
void
setTemplateXPathQuery(String templateXPathQuery)
protected <T> T
unwrap(String name, freemarker.template.TemplateModel value, Class<T> expectedClass, freemarker.core.Environment env)
-
-
-
Field Detail
-
KEY_MODEL
@Deprecated public static final String KEY_MODEL
Deprecated.- See Also:
- Constant Field Values
-
KEY_CONTENT_MODEL
public static final String KEY_CONTENT_MODEL
- See Also:
- Constant Field Values
-
COMPONENT_PARENT_PARAM_NAME
public static final String COMPONENT_PARENT_PARAM_NAME
- See Also:
- Constant Field Values
-
COMPONENT_PARAM_NAME
public static final String COMPONENT_PARAM_NAME
- See Also:
- Constant Field Values
-
COMPONENT_PATH_PARAM_NAME
public static final String COMPONENT_PATH_PARAM_NAME
- See Also:
- Constant Field Values
-
ADDITIONAL_MODEL_PARAM_NAME
public static final String ADDITIONAL_MODEL_PARAM_NAME
- See Also:
- Constant Field Values
-
servletContext
protected javax.servlet.ServletContext servletContext
-
siteItemService
protected SiteItemService siteItemService
-
modelFactory
protected org.springframework.beans.factory.ObjectFactory<freemarker.template.SimpleHash> modelFactory
-
templateXPathQuery
protected String templateXPathQuery
-
templateNamePrefix
protected String templateNamePrefix
-
templateNameSuffix
protected String templateNameSuffix
-
includeElementName
protected String includeElementName
-
componentElementName
protected String componentElementName
-
scriptResolver
protected SiteItemScriptResolver scriptResolver
-
-
Method Detail
-
setServletContext
public void setServletContext(javax.servlet.ServletContext servletContext)
-
setSiteItemService
public void setSiteItemService(SiteItemService siteItemService)
-
setModelFactory
public void setModelFactory(org.springframework.beans.factory.ObjectFactory<freemarker.template.SimpleHash> modelFactory)
-
setTemplateXPathQuery
public void setTemplateXPathQuery(String templateXPathQuery)
-
setTemplateNamePrefix
public void setTemplateNamePrefix(String templateNamePrefix)
-
setTemplateNameSuffix
public void setTemplateNameSuffix(String templateNameSuffix)
-
setIncludeElementName
public void setIncludeElementName(String includeElementName)
-
setComponentElementName
public void setComponentElementName(String componentElementName)
-
setScriptResolver
public void setScriptResolver(SiteItemScriptResolver scriptResolver)
-
execute
public void execute(freemarker.core.Environment env, Map params, freemarker.template.TemplateModel[] loopVars, freemarker.template.TemplateDirectiveBody body) throws freemarker.template.TemplateException
- Specified by:
execute
in interfacefreemarker.template.TemplateDirectiveModel
- Throws:
freemarker.template.TemplateException
-
getComponentFromNode
protected SiteItem getComponentFromNode(freemarker.template.TemplateModel parentParam, freemarker.template.TemplateModel componentParam, freemarker.core.Environment env) throws freemarker.template.TemplateException
- Throws:
freemarker.template.TemplateException
-
getComponentFromPath
protected SiteItem getComponentFromPath(freemarker.template.TemplateModel componentPathParam, freemarker.core.Environment env) throws freemarker.template.TemplateException
- Throws:
freemarker.template.TemplateException
-
getComponent
protected SiteItem getComponent(String componentPath, freemarker.core.Environment env) throws freemarker.template.TemplateException
- Throws:
freemarker.template.TemplateException
-
executeScripts
protected Map<String,Object> executeScripts(SiteItem component, Map<String,Object> additionalModel, freemarker.core.Environment env) throws freemarker.template.TemplateException
- Throws:
freemarker.template.TemplateException
-
createScriptVariables
protected Map<String,Object> createScriptVariables(SiteItem component, Map<String,Object> templateModel, Map<String,Object> additionalModel)
-
executeScript
protected void executeScript(Script script, Map<String,Object> scriptVariables, freemarker.core.Environment env) throws freemarker.template.TemplateException
- Throws:
freemarker.template.TemplateException
-
getTemplate
protected freemarker.template.Template getTemplate(SiteItem component, freemarker.core.Environment env) throws freemarker.template.TemplateException
- Throws:
freemarker.template.TemplateException
-
getComponentTemplateName
protected String getComponentTemplateName(SiteItem component, freemarker.core.Environment env) throws freemarker.template.TemplateException
- Throws:
freemarker.template.TemplateException
-
getFullModel
protected freemarker.template.SimpleHash getFullModel(SiteItem component, Map<String,Object> templateModel, Map<String,Object> additionalModel) throws freemarker.template.TemplateException
- Throws:
freemarker.template.TemplateException
-
processComponentTemplate
protected void processComponentTemplate(freemarker.template.Template template, freemarker.template.SimpleHash model, Writer output, freemarker.core.Environment env) throws freemarker.template.TemplateException
- Throws:
freemarker.template.TemplateException
-
-