@OpenApiAll public class DefaultTemplateEngine extends AbstractTemplateEngine implements IExtensionTemplateEngine
Modifier and Type | Field and Description |
---|---|
protected org.apache.velocity.VelocityContext |
velocityContext
Hold velocity context to abort engine.
|
context, isAborted, preProcessFile, processFile, properties
Modifier | Constructor and Description |
---|---|
protected |
DefaultTemplateEngine()
Create an instance of engine.
|
Modifier and Type | Method and Description |
---|---|
void |
abort()
Call to abort Velocity context.
|
protected void |
checkFileNotFoundException(java.lang.Exception e,
java.io.File file) |
protected java.lang.String |
createComment(java.lang.String message)
Return a formatted comment from given message.
|
Template |
createTemplate()
Creates a new and empty
Template for generating report by this engine. |
Template |
createTemplate(java.io.File input,
java.io.File output)
Creates a new
Template object. |
Template |
createTemplate(java.io.File input,
java.io.File output,
boolean ignoreLocation)
Creates a new
Template object. |
void |
destroy()
Called by the application or
TemplateEngineFactory to inform this engine
that it should destroy any resources that it has allocated. |
java.lang.ClassLoader |
getClassLoader()
Returns the class loader for the engine.
|
IFormatter |
getFormatter()
Returns a formatter that can be used to create the object layout, and formats of state
InsertionHandler . |
protected void |
handleForPage(Template template,
java.lang.StringBuffer inProcessBuffer)
Handle the #forpage directive.
|
protected void |
handleForRow(Template template,
java.lang.StringBuffer inProcessBuffer)
Handle the #forrow directive.
|
protected void |
handleImport(Template template,
java.lang.StringBuffer inProcessBuffer)
Handle the #include directive.
|
protected void |
handleIncludeSection(Template template,
java.lang.StringBuffer inProcessBuffer)
Handle the #includeSection directive.
|
protected void |
handleSectionBegin(Template template,
java.lang.StringBuffer inProcessBuffer)
Handle the #sectionBegin directive.
|
protected boolean |
isNoSpaceException(java.lang.Exception e) |
protected int |
lineCount(java.lang.String content)
Count number of line from given content string.
|
protected void |
postProcess(Template template)
Perform a post-processing after the template has been evaluated.
|
protected void |
preProcess(Template template)
Perform a pre-processing before evaluate template.
|
void |
process(Template template)
Process a template.
|
void |
process(Template template,
ITemplateEngine parentEngine)
Process a template.
|
protected TemplateException |
processException(Template template,
ParseErrorException e)
Call this method to process a
ParseErrorException . |
protected TemplateException |
processVelocityException(Template template,
org.apache.velocity.exception.MethodInvocationException e)
Call this method to process an Velocity exception and return in new format (
ParseErrorException ). |
protected TemplateException |
processVelocityException(Template template,
org.apache.velocity.exception.ParseErrorException e)
Call this method to process an Velocity exception and return in new format (
ParseErrorException ). |
void |
setClassLoader(java.lang.ClassLoader loader)
Sets the class loader for this engine.
|
void |
setFormatter(IFormatter formatter)
Set the formatter to be used with this template engine.
|
protected void |
setLatestLocation(java.io.File input,
java.io.File output)
Call this method to set the latest input and output location from given
input and output
file. |
protected void |
setLocation(java.io.File input,
java.io.File output)
Call this method to set the input and output location from given
input and output
file. |
void |
setProperty(java.lang.String key,
java.lang.Object value)
Set an engine Runtime property.
|
protected void |
translate(Template template,
java.lang.StringBuffer inProcessBuffer)
Process the template in
inProcessBuffer into valid format. |
int |
trimTrailSpace(int currentEndCursor,
java.lang.StringBuffer inProcessBuffer)
Calculate and return the new cursor at the end of #hash statement after trim.
|
addContext, addInvalidReferenceHandler, addObserver, addReferenceInsertionHandler, evaluate, evaluate, getConcurrentToolException, getContext, getCurrentRuntimeInstance, getInvalidReferenceHandler, getProcessSize, getProperties, getProperty, getReferenceInsertionHandler, isMemoryMode, notifyObservers, observers, setConcurrentToolException, setContext, setCurrentRuntimeInstance
protected org.apache.velocity.VelocityContext velocityContext
protected DefaultTemplateEngine()
public Template createTemplate()
Template
for generating report by this engine.createTemplate
in interface ITemplateEngine
Template
createTemplate(File, File)
public Template createTemplate(java.io.File input, java.io.File output) throws java.io.IOException
Template
object.createTemplate
in interface ITemplateEngine
input
- template file.output
- output file.Template
java.io.FileNotFoundException
- if the file does not exist, is a directory rather than a regular file,
or for some other reason cannot be opened.java.io.IOException
- If an I/O error occurspublic Template createTemplate(java.io.File input, java.io.File output, boolean ignoreLocation) throws java.io.IOException
Template
object.input
- template file.output
- output file.ignoreLocation
- true to ignore location property for child documentTemplate
java.io.FileNotFoundException
- if the file does not exist, is a directory rather than a regular file,
or for some other reason cannot be opened.java.io.IOException
- If an I/O error occursprotected void checkFileNotFoundException(java.lang.Exception e, java.io.File file) throws java.io.FileNotFoundException
java.io.FileNotFoundException
protected boolean isNoSpaceException(java.lang.Exception e)
protected void setLocation(java.io.File input, java.io.File output)
input
and output
file.input
- input template fileoutput
- output report fileTemplateConstants.TEMPLATE_INPUT_FILE
,
TemplateConstants.TEMPLATE_INPUT_LOCATION
,
TemplateConstants.TEMPLATE_OUTPUT_FILE
,
TemplateConstants.TEMPLATE_OUTPUT_LOCATION
,
setProperty(String, Object)
protected void setLatestLocation(java.io.File input, java.io.File output)
input
and output
file.input
- input template fileoutput
- output report filepublic void setProperty(java.lang.String key, java.lang.Object value)
setProperty
in interface ITemplateEngine
setProperty
in class AbstractTemplateEngine
key
- the key to be placed into this property list.value
- the value corresponding to key.ITemplateEngine.getProperty(String)
public IFormatter getFormatter()
InsertionHandler
.
By default this class returns a DefaultFormatter
. This formatter handle common text and no Bookmark,
Link and Image support. The engine should override this method and return proper formatter implementation.
getFormatter
in interface ITemplateEngine
public void setFormatter(IFormatter formatter)
formatter
- a formatterprotected void preProcess(Template template) throws TemplateException
preProcess
in class AbstractTemplateEngine
template
- template before evaluated.ParseErrorException
- if a syntax or other error which prevents it from being
parsed.InitializationEngineException
- error while initializing engineTemplateException
- other error while processing the templateAbstractTemplateEngine.preProcess(com.nomagic.magicreport.Template)
protected void translate(Template template, java.lang.StringBuffer inProcessBuffer) throws ParseErrorException, java.io.IOException
inProcessBuffer
into valid format.template
- Template source.inProcessBuffer
- in process buffer.ParseErrorException
- when error while translation, or syntax not recognized.java.io.IOException
- if IO Error occurs while reading template.protected void handleForPage(Template template, java.lang.StringBuffer inProcessBuffer) throws ParseErrorException
template
- Template source.inProcessBuffer
- in process buffer.ParseErrorException
- when error while translation, or syntax not recognized.protected void handleForRow(Template template, java.lang.StringBuffer inProcessBuffer) throws ParseErrorException
template
- Template source.inProcessBuffer
- in process buffer.ParseErrorException
- when error while translation, or syntax not recognized.protected void handleSectionBegin(Template template, java.lang.StringBuffer inProcessBuffer) throws ParseErrorException
template
- Template source.inProcessBuffer
- in process buffer.ParseErrorException
- when error while translation, or syntax not recognized.protected void handleIncludeSection(Template template, java.lang.StringBuffer inProcessBuffer) throws ParseErrorException
template
- Template source.inProcessBuffer
- in process buffer.ParseErrorException
- when error while translation, or syntax not recognized.protected void handleImport(Template template, java.lang.StringBuffer inProcessBuffer) throws ParseErrorException
template
- Template source.inProcessBuffer
- in process buffer.ParseErrorException
- when error while translation, or syntax not recognized.public int trimTrailSpace(int currentEndCursor, java.lang.StringBuffer inProcessBuffer)
currentEndCursor
- current end statement cursorinProcessBuffer
- in process bufferprotected java.lang.String createComment(java.lang.String message)
message
- message to put in document commentpublic void process(Template template) throws TemplateException
process
in class AbstractTemplateEngine
template
- template being evaluated.ParseErrorException
- if a syntax or other error which prevents it from being
parsed.InitializationEngineException
- error while initializing engineTemplateException
- other error while processing the templateAbstractTemplateEngine.process(com.nomagic.magicreport.Template)
public void process(Template template, ITemplateEngine parentEngine) throws TemplateException
process
in class AbstractTemplateEngine
template
- template being evaluated.parentEngine
- an engine to shared a runtime instance for evaluateParseErrorException
- if a syntax or other error which prevents it from being
parsed.InitializationEngineException
- error while initializing engineTemplateException
- other error while processing the templateAbstractTemplateEngine.process(com.nomagic.magicreport.Template)
protected void postProcess(Template template) throws TemplateException
postProcess
in class AbstractTemplateEngine
template
- template after evaluated.ParseErrorException
- if a syntax or other error which prevents it from being
parsed.InitializationEngineException
- error while initializing engineTemplateException
- other error while processing the templateAbstractTemplateEngine.postProcess(com.nomagic.magicreport.Template)
protected TemplateException processVelocityException(Template template, org.apache.velocity.exception.MethodInvocationException e)
ParseErrorException
). By
default, we can't get a nice error message from Velocity (Velocity error message containing in plain text
and not readable by non-programmer.) And velocity itself doesn't provide any mechanism to get an message
from ParseErrorException. This method will format the error message, remove unstructured text from velocity
message e.g. "of" (with out appending text)template
- Templatee
- MethodInvocationExceptionprotected TemplateException processVelocityException(Template template, org.apache.velocity.exception.ParseErrorException e)
ParseErrorException
). By
default, we can't get a nice error message from Velocity (Velocity error message containing in plain text
and not readable by non-programmer.) And velocity itself doesn't provide any mechanism to get an message
from ParseErrorException. This method will format the error message, remove unstructured text from velocity
message e.g. "of" (with out appending text)template
- Templatee
- Velocity exceptionprotected TemplateException processException(Template template, ParseErrorException e)
ParseErrorException
. This method call internally by
postProcess(Template)
. If code was performed by Velocity (process(Template)
), uses method
processVelocityException(Template, org.apache.velocity.exception.ParseErrorException)
. By default
this method try to calculate line number from ParseErrorException.getSource()
.template
- Templatee
- MagicReport parse error exceptionprotected int lineCount(java.lang.String content)
content
- the input stringpublic java.lang.ClassLoader getClassLoader()
getClassLoader
in interface IExtensionTemplateEngine
public void setClassLoader(java.lang.ClassLoader loader)
setClassLoader
in interface IExtensionTemplateEngine
loader
- Class loader for this enginepublic void destroy()
TemplateEngineFactory
to inform this engine
that it should destroy any resources that it has allocated.
A subclass of engine should override this method if it has any operation that it wants to perform before it is destroyed.
destroy
in interface ITemplateEngine
destroy
in class AbstractTemplateEngine
public void abort()
abort
in interface ITemplateEngine
abort
in class AbstractTemplateEngine
Copyright © 2010 - No Magic Asia