Class TemplateProcessor
- java.lang.Object
-
- org.craftercms.core.processors.impl.template.TemplateProcessor
-
- All Implemented Interfaces:
ItemProcessor
public class TemplateProcessor extends Object implements ItemProcessor
ItemProcessorthat processes the content of certain XML nodes in item descriptors as templates. Template engines that can be used are adapted through theTemplateCompilerinterface. Current implementations of this interface include an adapter for FreeMarker templates and another one for SpEL (Spring Expression Language) templates.- Author:
- Sumer Jabri, Alfonso Vásquez
- See Also:
TemplateCompiler,FreeMarkerStringTemplateCompiler,SpELStringTemplateCompiler, FreeMarker,-
-
Field Summary
Fields Modifier and Type Field Description protected NodeTemplateModelFactorymodelFactoryFactory that provides the models for the templates.protected TemplateCompiler<IdentifiableStringTemplateSource>templateCompilerTemplate compiler.protected NodeScannertemplateNodeScannerNodeScannerfor template nodes.
-
Constructor Summary
Constructors Constructor Description TemplateProcessor()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object o)Returns true if the specifiedTemplateProcessor's and this instance's fields are equal.inthashCode()Returns the hash code for this instance, which is basically the combination of the hash code of each field.Itemprocess(Context context, CachingOptions cachingOptions, Item item)Processes the content of certain nodes (found by theNodeScannerin the item's descriptor as templates, by compiling the node text templates through thetemplateCompilerand then processing the compiled template with a model returned bymodelFactory.voidsetModelFactory(NodeTemplateModelFactory modelFactory)Sets the factory that provides the models for the templates.voidsetTemplateCompiler(TemplateCompiler<IdentifiableStringTemplateSource> templateCompiler)Sets the template compiler.voidsetTemplateNodeScanner(NodeScanner templateNodeScanner)Sets theNodeScannerfor template nodes.StringtoString()
-
-
-
-
Field Detail
-
templateNodeScanner
protected NodeScanner templateNodeScanner
NodeScannerfor template nodes.
-
templateCompiler
protected TemplateCompiler<IdentifiableStringTemplateSource> templateCompiler
Template compiler. It basically compiles the template provided in an element and then processes it by using a model obtained through themodelFactory.
-
modelFactory
protected NodeTemplateModelFactory modelFactory
Factory that provides the models for the templates.
-
-
Method Detail
-
setTemplateNodeScanner
public void setTemplateNodeScanner(NodeScanner templateNodeScanner)
Sets theNodeScannerfor template nodes.
-
setTemplateCompiler
public void setTemplateCompiler(TemplateCompiler<IdentifiableStringTemplateSource> templateCompiler)
Sets the template compiler. It basically compiles the template provided in an element and then processes it by using a model obtained through themodelFactory.
-
setModelFactory
public void setModelFactory(NodeTemplateModelFactory modelFactory)
Sets the factory that provides the models for the templates.
-
process
public Item process(Context context, CachingOptions cachingOptions, Item item) throws ItemProcessingException
Processes the content of certain nodes (found by theNodeScannerin the item's descriptor as templates, by compiling the node text templates through thetemplateCompilerand then processing the compiled template with a model returned bymodelFactory.- Specified by:
processin interfaceItemProcessor- Parameters:
context- the current contextcachingOptions- caching options in case you need access to itemsitem- the item to process- Returns:
- the modified item or a new item.
- Throws:
ItemProcessingException- if an error occurred while processing a template
-
equals
public boolean equals(Object o)
Returns true if the specifiedTemplateProcessor's and this instance's fields are equal.
-
hashCode
public int hashCode()
Returns the hash code for this instance, which is basically the combination of the hash code of each field. As with any otherItemProcessor, this method is defined because any processor which is passed in the method call of aContentStoreServicecan be used as part of a key for caching.
-
-