public class TemplateProcessor extends Object implements ItemProcessor
ItemProcessor
that processes the content of certain XML nodes in item descriptors as templates. Template
engines that can be used are adapted through the TemplateCompiler
interface. Current implementations of this
interface include an adapter for FreeMarker templates and another one for SpEL (Spring Expression Language)
templates.TemplateCompiler
,
FreeMarkerStringTemplateCompiler
,
SpELStringTemplateCompiler
,
FreeMarker,
Modifier and Type | Field and Description |
---|---|
protected NodeTemplateModelFactory |
modelFactory
Factory that provides the models for the templates.
|
protected TemplateCompiler<IdentifiableStringTemplateSource> |
templateCompiler
Template compiler.
|
protected NodeScanner |
templateNodeScanner
NodeScanner for template nodes. |
Constructor and Description |
---|
TemplateProcessor() |
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object o)
Returns true if the specified
TemplateProcessor 's and this instance's fields are equal. |
int |
hashCode()
Returns the hash code for this instance, which is basically the combination of the hash code of each field.
|
Item |
process(Context context,
CachingOptions cachingOptions,
Item item)
Processes the content of certain nodes (found by the
NodeScanner in the item's descriptor as templates,
by compiling the node text templates through the templateCompiler and then processing the compiled
template with a model returned by modelFactory . |
void |
setModelFactory(NodeTemplateModelFactory modelFactory)
Sets the factory that provides the models for the templates.
|
void |
setTemplateCompiler(TemplateCompiler<IdentifiableStringTemplateSource> templateCompiler)
Sets the template compiler.
|
void |
setTemplateNodeScanner(NodeScanner templateNodeScanner)
Sets the
NodeScanner for template nodes. |
String |
toString() |
protected NodeScanner templateNodeScanner
NodeScanner
for template nodes.protected TemplateCompiler<IdentifiableStringTemplateSource> templateCompiler
modelFactory
.protected NodeTemplateModelFactory modelFactory
public void setTemplateNodeScanner(NodeScanner templateNodeScanner)
NodeScanner
for template nodes.public void setTemplateCompiler(TemplateCompiler<IdentifiableStringTemplateSource> templateCompiler)
modelFactory
.public void setModelFactory(NodeTemplateModelFactory modelFactory)
public Item process(Context context, CachingOptions cachingOptions, Item item) throws ItemProcessingException
NodeScanner
in the item's descriptor as templates,
by compiling the node text templates through the templateCompiler
and then processing the compiled
template with a model returned by modelFactory
.process
in interface ItemProcessor
context
- the current contextcachingOptions
- caching options in case you need access to itemsitem
- the item to processItemProcessingException
- if an error occurred while processing a templatepublic boolean equals(Object o)
TemplateProcessor
's and this instance's fields are equal.public int hashCode()
ItemProcessor
, this method is defined because any processor which is passed in the
method call of a ContentStoreService
can be used as part of a
key for caching.Copyright © 2015 CrafterCMS. All Rights Reserved.