@Versioned public class RythmEngine extends Object implements IEventDispatcher
Not Thread Safe
A Rythm Template Engine is the entry to the Rythm templating system. It provides a set of
APIs to render template. Each JVM allows multiple RythmEngine instance, with each
one represent a set of configurations.
The Rythm facade contains a default RythmEngine instance to make it
easy to use for most cases
| Modifier and Type | Class and Description |
|---|---|
static class |
RythmEngine.OutputMode
Defines the output method for render result.
|
class |
RythmEngine.RenderSettings
Define the render time settings, which is intialized each time a renderXX method get called
|
static class |
RythmEngine.TemplateTestResult
Transport Template Test Result especially if there was an error thrown
|
| Modifier and Type | Field and Description |
|---|---|
RythmEngine.RenderSettings |
renderSettings
The RenderSettings instance keep the environment settings for one render operation
|
static String[] |
VALID_SUFFIXES
Valid Suffixes
|
static osgl.version.Version |
VERSION |
| Constructor and Description |
|---|
RythmEngine()
Create a rythm engine instance with default configuration
|
RythmEngine(File file)
Create a rythm engine instance with either template root or configuration file specified
|
RythmEngine(Map<String,?> userConfiguration)
Create a rythm engine instance with user supplied configuration data
|
RythmEngine(Properties userConfiguration) |
| Modifier and Type | Method and Description |
|---|---|
Object |
accept(IEvent event,
Object param)
Not an API for user application
|
void |
addExtendRelationship(TemplateClass parent,
TemplateClass child)
Not an API for user application
|
void |
cache(String key,
Object o,
int ttl,
Object... args)
Cache object using key and args for ttl seconds
|
void |
cache(String key,
Object o,
String duration,
Object... args)
Store object o into cache service with ttl equals to duration specified.
|
Serializable |
cached(String key,
Object... args)
Get cached value using key and a list of argument values
|
TemplateClassCache |
classCache()
Get
class cache of the engine |
TemplateClassManager |
classes()
Get
template class manager of the engine |
TemplateClassLoader |
classLoader()
Get
class loader of the engine |
static void |
clear()
Clear the engine threadlocal variable
|
String |
commonsToString(Object obj,
ToStringOption option,
org.apache.commons.lang3.builder.ToStringStyle style)
Render template in AutoToString mode by one object instance which state is to be output and
option and apache commons to string stype. |
RythmConfiguration |
conf()
Return
configuration of the engine |
IDateFormatFactory |
dateFormatFactory() |
DialectManager |
dialectManager()
Not an API
|
Object |
eval(String script)
Evaluate a script and return executing result.
|
Object |
eval(String script,
Map<String,Object> params) |
Object |
eval(String script,
Object context,
Map<String,Object> params) |
IEventDispatcher |
eventDispatcher() |
void |
evict(String key)
Evict an object from cache service by key
|
ExtensionManager |
extensionManager()
Return
ExtensionManager of this engine |
static RythmEngine |
get()
Get the current engine instance from a
ThreadLocal variable which is set previously. |
String |
getId()
Alias of
id() |
<T> T |
getProperty(String key)
Get user property by key
|
ITemplate |
getRegisteredTemplate(String tmplName)
Get a
template registered to the engine by name |
TemplateClass |
getRegisteredTemplateClass(String name)
Return
TemplateClass from a tag name |
ITemplate |
getTemplate(File file,
Object... args)
Get an new template instance by template source
file and an array of arguments. |
ITemplate |
getTemplate(String template,
Object... args)
Get an new
template instance from a String and an array of render args. |
TemplateClass |
getTemplateClass(ITemplateResource resource)
(3rd party API, not for user application) Get an new template class by
template resource |
String |
id()
Return the instance
ID |
static boolean |
insideSandbox()
Check if the current rendering is dominated by a
Sandbox |
void |
invalidate(TemplateClass parent)
Not an API for user application
|
void |
invokeTemplate(int line,
String name,
ITemplate caller,
ITag.__ParameterList params,
ITag.__Body body,
ITag.__Body context)
Invoke a template
|
void |
invokeTemplate(int line,
String name,
ITemplate caller,
ITag.__ParameterList params,
ITag.__Body body,
ITag.__Body context,
boolean ignoreNonExistsTag)
Invoke a tag
|
boolean |
isDevMode()
Is the engine running in
development mode? |
boolean |
isProdMode()
Is the engine running in
product mode? |
boolean |
isSingleton()
Is this engine the default
Rythm.engine instance? |
Rythm.Mode |
mode()
Return the engine
mode |
static RythmEngine.OutputMode |
outputMode()
Not an API.
|
RythmEngine |
prepare(ICodeType codeType)
Prepare the render operation environment settings
|
RythmEngine |
prepare(ICodeType codeType,
Locale locale,
Map<String,Object> usrCtx)
Prepare the render operation environment settings
|
RythmEngine |
prepare(Locale locale)
Prepare the render operation environment settings
|
RythmEngine |
prepare(Map<String,Object> userContext)
Prepare the render operation environment settings
|
void |
registerFastTag(JavaTagBase tag) |
void |
registerFormatter(Class<IFormatter>... formatterClasses)
Register
formatters |
void |
registerFormatter(IFormatter... formatters) |
void |
registerPropertyAccessor(IPropertyAccessor... accessors)
Register user implemented
IPropertyAccessor |
void |
registerResourceLoader(ITemplateResourceLoader... loaders) |
void |
registerTemplate(ITemplate template)
Register a template.
|
void |
registerTemplate(String name,
ITemplate template)
Register a tag using the given name
|
RythmEngine |
registerTemplateClass(TemplateClass tc)
Register a template class and return self
|
void |
registerTransformer(Class<?>... transformerClasses)
Register
transformers using namespace specified in the namespace value defined in the annotation. |
void |
registerTransformer(String namespace,
String waivePattern,
Class<?>... transformerClasses)
Register
transformers using namespace specified to replace the namespace value defined in the annotation. |
String |
render(File file,
Object... args)
Render template with source specified by
file instance and an array of render args. |
void |
render(OutputStream os,
File file,
Object... args)
Render template with source specified by
file instance and an array of render args. |
void |
render(OutputStream os,
String template,
Object... args)
Render template by string parameter and an array of template args.
|
String |
render(String template,
Object... args)
Render template by string parameter and an array of template args.
|
void |
render(Writer w,
File file,
Object... args)
Render template with source specified by
file instance and an array of render args. |
void |
render(Writer w,
String template,
Object... args)
Render template by string parameter and an array of template args.
|
static void |
renderCleanUp() |
String |
renderIfTemplateExists(String template,
Object... args)
Render template if specified template exists, otherwise return empty string
|
String |
renderStr(String template,
Object... args)
Render template by string typed inline template content and an array of template args.
|
String |
renderStr(String key,
String template,
Object... args)
Render template by string typed inline template content and an array of template args.
|
String |
renderString(String template,
Object... args)
Render result from a direct template content.
|
String |
renderString(String key,
String template,
Object... args)
Render result from a direct template content.
|
TemplateResourceManager |
resourceManager()
Get
resource manager of the engine |
void |
restart(RuntimeException cause)
Restart the engine with an exception as the cause.
|
Sandbox |
sandbox()
Create a
Sandbox instance to render the template |
Sandbox |
sandbox(Map<String,Object> context)
Create a
Sandbox instance with user supplied context |
static boolean |
set(RythmEngine engine)
Set the engine instance to a
ThreadLocal variable, thus it is easy to get the current RythmEngine dominating the rendering process. |
void |
setDateFormatFactory(IDateFormatFactory factory) |
void |
setProperty(String key,
Object val)
Set user property to the engine.
|
void |
shutdown()
Shutdown this rythm engine
|
String |
substitute(File file,
Object... args)
Render template in substitute mode by File typed template source and an array of render args.
|
String |
substitute(String template,
Object... args)
Render template in substitute mode by string typed template source and an array of render args.
|
boolean |
templateRegistered(String tmplName)
Whether a
template is registered to the engine by name specified |
RythmEngine.TemplateTestResult |
testTemplate(String name,
TemplateClass callerClass,
ICodeType codeType)
Check if a template exists and return it’s name
|
String |
toString() |
String |
toString(Object obj)
Render template in AutoToString mode by one object instance which state is to be output.
|
String |
toString(Object obj,
ToStringOption option,
ToStringStyle style)
|
String |
toString(String template,
Object obj)
Render template in ToString mode by string typed template source and one object instance which state is to be output.
|
String |
version()
Return Version string of the engine instance.
|
public static final osgl.version.Version VERSION
public RythmEngine.RenderSettings renderSettings
The RenderSettings instance keep the environment settings for one render operation
public static final String[] VALID_SUFFIXES
Valid Suffixes
public RythmEngine()
Create a rythm engine instance with default configuration
RythmConfigurationKeypublic RythmEngine(File file)
Create a rythm engine instance with either template root or configuration file specified
file - if is directory then the template root, otherwise then the configuration fileRythmConfigurationKeypublic RythmEngine(Properties userConfiguration)
public RythmEngine(Map<String,?> userConfiguration)
Create a rythm engine instance with user supplied configuration data
userConfiguration - RythmConfigurationKeypublic static boolean set(RythmEngine engine)
Set the engine instance to a ThreadLocal variable, thus it is easy to get the current RythmEngine dominating the rendering process.
Note, this method is NOT an API to be called by user application
engine - true if engine instance set to the threadlocal, false if the threadlocal has set an instance alreadypublic static void clear()
Clear the engine threadlocal variable
public static RythmEngine get()
Get the current engine instance from a ThreadLocal variable which is set previously.
Note, this method is NOT an API to be called by user application
public static boolean insideSandbox()
Check if the current rendering is dominated by a Sandbox
Note, this method is NOT an API to be called by user application
public RythmConfiguration conf()
Return configuration of the engine
Usually user application should not call this method
public String version()
Return Version string of the engine instance. The version string is composed by Rythm version and the configured plugin version. The version string will be used by Rythm to see if compiled bytecodes cached on disk should be refreshed in an new version or not.
Note, this method is not generally used by user application
public Rythm.Mode mode()
Return the engine mode
public boolean isSingleton()
Is this engine the default Rythm.engine instance?
Note, not to be used by user application
public boolean isProdMode()
Is the engine running in product mode?
public boolean isDevMode()
Is the engine running in development mode?
public TemplateResourceManager resourceManager()
Get resource manager of the engine
Note, this method should not be used by user application
public TemplateClassManager classes()
Get template class manager of the engine
Note, this method should not be used by user application
public TemplateClassLoader classLoader()
Get class loader of the engine
Note, this method should not be used by user application
public TemplateClassCache classCache()
Get class cache of the engine
Note, this method should not be used by user application
public ExtensionManager extensionManager()
Return ExtensionManager of this engine
public DialectManager dialectManager()
Not an API
DialectManager instancepublic void setDateFormatFactory(IDateFormatFactory factory)
public IDateFormatFactory dateFormatFactory()
public final RythmEngine prepare(ICodeType codeType, Locale locale, Map<String,Object> usrCtx)
Prepare the render operation environment settings
codeType - locale - usrCtx - public final RythmEngine prepare(ICodeType codeType)
Prepare the render operation environment settings
codeType - public final RythmEngine prepare(Locale locale)
Prepare the render operation environment settings
locale - public final RythmEngine prepare(Map<String,Object> userContext)
Prepare the render operation environment settings
userContext - public void setProperty(String key, Object val)
Set user property to the engine. Note The property is not used by the engine program it’s purely a place for user to add any tags or properties to the engine and later get fetched out and use in the user application
key - val - public <T> T getProperty(String key)
Get user property by key
T - key - public void registerFormatter(Class<IFormatter>... formatterClasses)
Register formatters
formatterClasses - public void registerFormatter(IFormatter... formatters)
public void registerTransformer(Class<?>... transformerClasses)
Register transformers using namespace specified in the namespace value defined in the annotation.
transformerClasses - public void registerTransformer(String namespace, String waivePattern, Class<?>... transformerClasses)
Register transformers using namespace specified to replace the namespace value defined in the annotation.
transformerClasses - public void registerPropertyAccessor(IPropertyAccessor... accessors)
Register user implemented IPropertyAccessor
accessors - public void registerResourceLoader(ITemplateResourceLoader... loaders)
public ITemplate getTemplate(String template, Object... args)
Get an new template instance from a String and an array of render args. The string parameter could be either a template file path or the inline template source content.
When the args array contains only one element and is of Map type the the render args are passed to template by name, otherwise they passes to template instance by position
template - args - public TemplateClass getTemplateClass(ITemplateResource resource)
(3rd party API, not for user application) Get an new template class by template resource
resource - the template resourcepublic ITemplate getTemplate(File file, Object... args)
Get an new template instance by template source file and an array of arguments.
When the args array contains only one element and is of Map type the the render args are passed to template by name, otherwise they passes to template instance by position
file - the template source fileargs - the render args. See getTemplate(String, Object...)public String render(String template, Object... args)
Render template by string parameter and an array of template args. The string parameter could be either a path point to the template source file, or the inline template source content. The render result is returned as a String
See getTemplate(java.io.File, Object...) for note on render args
template - either the path of template source file or inline template contentargs - render args arraypublic void render(OutputStream os, String template, Object... args)
Render template by string parameter and an array of template args. The string parameter could be either a path point to the template source file, or the inline template source content. The render result is output to the specified binary output stream
See getTemplate(java.io.File, Object...) for note on render args
os - the output streamtemplate - either the path of template source file or inline template contentargs - render args arraypublic void render(Writer w, String template, Object... args)
Render template by string parameter and an array of template args. The string parameter could be either a path point to the template source file, or the inline template source content. The render result is output to the specified character based writer
See getTemplate(java.io.File, Object...) for note on render args
w - the writertemplate - either the path of template source file or inline template contentargs - render args arraypublic String render(File file, Object... args)
Render template with source specified by file instance and an array of render args. Render result return as a String
See getTemplate(java.io.File, Object...) for note on render args
file - the template source fileargs - render args arraypublic void render(OutputStream os, File file, Object... args)
Render template with source specified by file instance and an array of render args. Render result output into the specified binary OutputStream
See getTemplate(java.io.File, Object...) for note on render args
os - the output streamfile - the template source fileargs - render args arraypublic void render(Writer w, File file, Object... args)
Render template with source specified by file instance and an array of render args. Render result output into the specified binary Writer
See getTemplate(java.io.File, Object...) for note on render args
w - the writerfile - the template source fileargs - render args arraypublic String renderStr(String key, String template, Object... args)
Render template by string typed inline template content and an array of template args. The render result is returned as a String
See getTemplate(java.io.File, Object...) for note on render args
template - the inline template contentargs - the render args arraypublic String renderStr(String template, Object... args)
Render template by string typed inline template content and an array of template args. The render result is returned as a String
See getTemplate(java.io.File, Object...) for note on render args
template - the inline template contentargs - the render args arraypublic String renderString(String template, Object... args)
Render result from a direct template content. The content will also be used as the template key to generate the recommended class name
template - the template contentargs - the render argspublic String renderString(String key, String template, Object... args)
Render result from a direct template content. The template key has been provided as well
See getTemplate(java.io.File, Object...) for note on
render args
key - the template key which will be used to generatetemplate - the inline template contentargs - the render args arraypublic String substitute(String template, Object... args)
Render template in substitute mode by string typed template source and an array of render args. The string parameter could be either a path point to the template source file, or the inline template source content. Return render result as String
See getTemplate(java.io.File, Object...) for note on render args
template - either the template source file path or the inline template contentargs - the render args arraypublic String substitute(File file, Object... args)
Render template in substitute mode by File typed template source and an array of render args. Return render result as String
See getTemplate(java.io.File, Object...) for note on render args
file - the template source fileargs - the render args arraypublic String toString(String template, Object obj)
Render template in ToString mode by string typed template source and one object instance which state is to be output. The string parameter could be either a path point to the template source file, or the inline template source content. Return render result as String
template - either the template source file path or the inline template contentobj - the object instance which state is to be output as a stringpublic String toString(Object obj)
Render template in AutoToString mode by one object instance which state is to be output. Return render result as String
obj - the object instance which state is to be output as a stringpublic String toString(Object obj, ToStringOption option, ToStringStyle style)
Render template in AutoToString mode by one object instance which state is to be output and option and stype. Return render result as String
obj - the object instance which state is to be output as a stringoption - the output optionstyle - the output stylepublic String commonsToString(Object obj, ToStringOption option, org.apache.commons.lang3.builder.ToStringStyle style)
Render template in AutoToString mode by one object instance which state is to be output and option and apache commons to string stype. Return render result as String
obj - the object instance which state is to be output as a stringoption - the output optionstyle - the output style specified as apache commons ToStringStylepublic String renderIfTemplateExists(String template, Object... args)
Render template if specified template exists, otherwise return empty string
template - the template source pathargs - render args. See getTemplate(String, Object...)public Object eval(String script)
Evaluate a script and return executing result. Note the API is not mature yet don’t use it in your application
script - public boolean templateRegistered(String tmplName)
Whether a template is registered to the engine by name specified
Not an API for user application
tmplName - public ITemplate getRegisteredTemplate(String tmplName)
Get a template registered to the engine by name
Not an API for user application
tmplName - public TemplateClass getRegisteredTemplateClass(String name)
Return TemplateClass from a tag name
Not an API for user application
name - public RythmEngine registerTemplateClass(TemplateClass tc)
Register a template class and return self
tc - public RythmEngine.TemplateTestResult testTemplate(String name, TemplateClass callerClass, ICodeType codeType)
Check if a template exists and return it’s name
Not an API for user application
name - callerClass - public void registerFastTag(JavaTagBase tag)
public void registerTemplate(ITemplate template)
Register a template.
Not an API for user application
public void registerTemplate(String name, ITemplate template)
Register a tag using the given name
Not an API for user application
name - template - public void invokeTemplate(int line,
String name,
ITemplate caller,
ITag.__ParameterList params,
ITag.__Body body,
ITag.__Body context)
Invoke a template
Not an API for user application
line - name - caller - params - body - context - public void invokeTemplate(int line,
String name,
ITemplate caller,
ITag.__ParameterList params,
ITag.__Body body,
ITag.__Body context,
boolean ignoreNonExistsTag)
Invoke a tag
Not an API for user application
line - name - caller - params - body - context - ignoreNonExistsTag - public void cache(String key, Object o, int ttl, Object... args)
Cache object using key and args for ttl seconds
Not an API for user application
key - o - ttl - if zero then defaultTTL used, if negative then never expireargs - public void cache(String key, Object o, String duration, Object... args)
Store object o into cache service with ttl equals to duration specified.
The duration is a string to be parsed by @{link #durationParser}
The object o is associated with given key and a list of argument values
Not an API for user application
key - o - duration - args - public void evict(String key)
Evict an object from cache service by key
key - identify the object should be removed from cache servicepublic Serializable cached(String key, Object... args)
Get cached value using key and a list of argument values
Not an API for user application
key - args - public void addExtendRelationship(TemplateClass parent, TemplateClass child)
Not an API for user application
parent - child - public void invalidate(TemplateClass parent)
Not an API for user application
parent - public Sandbox sandbox()
Create a Sandbox instance to render the template
public Sandbox sandbox(Map<String,Object> context)
Create a Sandbox instance with user supplied context
context - public IEventDispatcher eventDispatcher()
public Object accept(IEvent event, Object param)
Not an API for user application
accept in interface IEventDispatcherevent - param - public static RythmEngine.OutputMode outputMode()
Not an API.
public static void renderCleanUp()
public void restart(RuntimeException cause)
Restart the engine with an exception as the cause.
Note, this is not supposed to be called by user application
cause - public void shutdown()
Shutdown this rythm engine
Copyright © 2017–2021 OSGL (Open Source General Library). All rights reserved.