|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.rythmengine.RythmEngine
public class RythmEngine
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
Nested Class Summary | |
---|---|
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 |
Field Summary | |
---|---|
RythmEngine.RenderSettings |
renderSettings
The RenderSettings instance keep the environment settings for one render operation |
Constructor Summary | |
---|---|
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)
|
Method Summary | ||
---|---|---|
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
|
|
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> context)
|
|
IEventDispatcher |
eventDispatcher()
|
|
ExtensionManager |
extensionManager()
Return ExtensionManager of this engine |
|
static RythmEngine |
get()
Get the current engine instance from a ThreadLocal variable which is
set previously. |
|
|
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
|
|
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 RythmConfigurationKey.ENGINE_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 |
registerPropertyAccessor(IPropertyAccessor... accessors)
Register user implemented IPropertyAccessor |
|
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. |
|
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 void |
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)
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)
Render template in AutoToString mode by one object instance which state is to be output and option and stype . |
|
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. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public RythmEngine.RenderSettings renderSettings
Constructor Detail |
---|
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
Method Detail |
---|
public static void 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
- 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 String toString()
toString
in class Object
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 String id()
RythmConfigurationKey.ENGINE_ID
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 engine
public 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 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 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 resource
public 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 array
public 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 array
public 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 array
public 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 array
public 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 array
public 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 array
public 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 string
public String toString(Object obj)
obj
- the object instance which state is to be output as a string
public String toString(Object obj, ToStringOption option, ToStringStyle style)
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 style
public String commonsToString(Object obj, ToStringOption option, org.apache.commons.lang3.builder.ToStringStyle style)
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 ToStringStyle
public String renderIfTemplateExists(String template, Object... args)
template
- the template source pathargs
- render args. See getTemplate(String, Object...)
public Object eval(String script)
script
-
public Object eval(String script, Map<String,Object> context)
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)
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 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 template
public Sandbox sandbox(Map<String,Object> context)
Sandbox
instance with user supplied context
context
-
public IEventDispatcher eventDispatcher()
public Object accept(IEvent event, Object param)
accept
in interface IEventDispatcher
event
- param
-
public static RythmEngine.OutputMode outputMode()
public void restart(RuntimeException cause)
Note, this is not supposed to be called by user application
cause
- public void shutdown()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |