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
|
Modifier and Type | Field and Description |
---|---|
RythmEngine.RenderSettings |
renderSettings
The RenderSettings instance keep the environment settings for one render operation
|
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(org.rythmengine.internal.compiler.TemplateClass parent,
org.rythmengine.internal.compiler.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
|
org.rythmengine.internal.compiler.TemplateClassCache |
classCache()
Get
class cache of the engine
|
org.rythmengine.internal.compiler.TemplateClassManager |
classes()
Get
template class manager of the engine
|
org.rythmengine.internal.compiler.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
|
org.rythmengine.internal.dialect.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
|
org.rythmengine.internal.compiler.TemplateClass |
getRegisteredTemplateClass(String name)
Return
TemplateClass from a tag name
|
static org.rythmengine.ShutdownService |
getShutdownService(boolean isGaeAvailable) |
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. |
org.rythmengine.internal.compiler.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(org.rythmengine.internal.compiler.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(org.rythmengine.internal.compiler.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 |
renderString(String template,
Object... args)
Alias of
renderString(String, Object...)
|
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 |
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
|
String |
testTemplate(String name,
org.rythmengine.internal.compiler.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 RythmEngine.RenderSettings renderSettings
public RythmEngine()
RythmConfigurationKey
public RythmEngine(File file)
file
- if is directory then the template root, otherwise then the configuration fileRythmConfigurationKey
public RythmEngine(Properties userConfiguration)
public RythmEngine(Map<String,?> userConfiguration)
userConfiguration
- RythmConfigurationKey
public static boolean set(RythmEngine engine)
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()
public static RythmEngine get()
ThreadLocal
variable which is
set
previously.
Note, this method is NOT an API to be called by user application
public static boolean insideSandbox()
Sandbox
Note, this method is NOT an API to be called by user application
public RythmConfiguration conf()
configuration
of the engine
Usually user application should not call this method
public String version()
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()
mode
public boolean isSingleton()
Rythm.engine
instance?
Note, not to be used by user application
public boolean isProdMode()
product
mode?public boolean isDevMode()
development
mode?public TemplateResourceManager resourceManager()
resource manager
of the engine
Note, this method should not be used by user application
public org.rythmengine.internal.compiler.TemplateClassManager classes()
template class manager
of the engine
Note, this method should not be used by user application
public org.rythmengine.internal.compiler.TemplateClassLoader classLoader()
class loader
of the engine
Note, this method should not be used by user application
public org.rythmengine.internal.compiler.TemplateClassCache classCache()
class cache
of the engine
Note, this method should not be used by user application
public ExtensionManager extensionManager()
ExtensionManager
of this enginepublic org.rythmengine.internal.dialect.DialectManager dialectManager()
DialectManager
instancepublic final RythmEngine prepare(ICodeType codeType, Locale locale, Map<String,Object> usrCtx)
codeType
- locale
- usrCtx
- public final RythmEngine prepare(ICodeType codeType)
codeType
- public final RythmEngine prepare(Locale locale)
locale
- public final RythmEngine prepare(Map<String,Object> userContext)
userContext
- public void setProperty(String key, Object val)
key
- val
- public <T> T getProperty(String key)
T
- key
- public static org.rythmengine.ShutdownService getShutdownService(boolean isGaeAvailable)
public void registerFormatter(Class<IFormatter>... formatterClasses)
formatters
formatterClasses
- public void registerFormatter(IFormatter... formatters)
public void registerTransformer(Class<?>... transformerClasses)
transformers
using namespace specified in
the namespace value
defined in
the annotation.transformerClasses
- public void registerTransformer(String namespace, String waivePattern, Class<?>... transformerClasses)
transformers
using namespace specified to
replace the namespace value
defined in
the annotation.transformerClasses
- public void registerPropertyAccessor(IPropertyAccessor... accessors)
IPropertyAccessor
accessors
- public void registerResourceLoader(ITemplateResourceLoader... loaders)
public ITemplate getTemplate(String template, Object... args)
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 org.rythmengine.internal.compiler.TemplateClass getTemplateClass(ITemplateResource resource)
template resource
resource
- the template resourcepublic ITemplate getTemplate(File file, Object... args)
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)
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)
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)
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)
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)
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)
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 template, Object... args)
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)
renderString(String, Object...)
See getTemplate(java.io.File, Object...)
for note on
render args
template
- the inline template contentargs
- the render args arraypublic String substitute(String template, Object... args)
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)
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)
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)
obj
- the object instance which state is to be output as a stringpublic String toString(Object obj, ToStringOption option, ToStringStyle style)
option
and stype
.
Return render result as Stringobj
- 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)
option
and
apache commons to string stype
.
Return render result as Stringobj
- 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)
template
- the template source pathargs
- render args. See getTemplate(String, Object...)
public Object eval(String script)
script
- public boolean templateRegistered(String tmplName)
template
is registered to the engine by name specified
Not an API for user application
tmplName
- public ITemplate getRegisteredTemplate(String tmplName)
template
registered to the engine by name
Not an API for user application
tmplName
- public org.rythmengine.internal.compiler.TemplateClass getRegisteredTemplateClass(String name)
TemplateClass
from a tag name
Not an API for user application
name
- public RythmEngine registerTemplateClass(org.rythmengine.internal.compiler.TemplateClass tc)
tc
- public String testTemplate(String name, org.rythmengine.internal.compiler.TemplateClass callerClass, ICodeType codeType)
Not an API for user application
name
- callerClass
- public void registerFastTag(JavaTagBase tag)
public void registerTemplate(ITemplate template)
Not an API for user application
public void registerTemplate(String name, ITemplate template)
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)
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)
Not an API for user application
line
- name
- caller
- params
- body
- context
- ignoreNonExistsTag
- public void cache(String key, Object o, int ttl, Object... args)
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)
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)
key
- identify the object should be removed from cache servicepublic Serializable cached(String key, Object... args)
Not an API for user application
key
- args
- public void addExtendRelationship(org.rythmengine.internal.compiler.TemplateClass parent, org.rythmengine.internal.compiler.TemplateClass child)
parent
- child
- public void invalidate(org.rythmengine.internal.compiler.TemplateClass parent)
parent
- public Sandbox sandbox()
Sandbox
instance to render the templatepublic Sandbox sandbox(Map<String,Object> context)
Sandbox
instance with user supplied contextcontext
- public IEventDispatcher eventDispatcher()
public Object accept(IEvent event, Object param)
accept
in interface IEventDispatcher
event
- param
- public static RythmEngine.OutputMode outputMode()
public static void renderCleanUp()
public void restart(RuntimeException cause)
Note, this is not supposed to be called by user application
cause
- public void shutdown()
Copyright © 2015. All Rights Reserved.