public class Engine extends Object
Modifier and Type | Field and Description |
---|---|
static String |
MAIN_ENGINE_NAME |
Constructor and Description |
---|
Engine()
Create engine without management of JFinal
|
Engine(String engineName)
Create engine by engineName without management of JFinal
|
Modifier and Type | Method and Description |
---|---|
Engine |
addDirective(String directiveName,
Class<? extends Directive> directiveClass)
Add directive
|
Engine |
addDirective(String directiveName,
Directive directive)
Deprecated.
|
static void |
addExtensionMethod(Class<?> targetClass,
Class<?> extensionClass) |
static void |
addExtensionMethod(Class<?> targetClass,
Object objectOfExtensionClass) |
Engine |
addSharedFunction(ISource source)
Add shared function by ISource
|
Engine |
addSharedFunction(String... fileNames)
Add shared function with files
|
Engine |
addSharedFunction(String fileName)
Add shared function with file
|
Engine |
addSharedFunctionByString(String content)
Add shared function by string content
|
Engine |
addSharedMethod(Class<?> sharedMethodFromClass)
Add shared method from class
|
Engine |
addSharedMethod(Object sharedMethodFromObject)
Add shared method from object
|
Engine |
addSharedObject(String name,
Object object)
Add shared object
|
Engine |
addSharedStaticMethod(Class<?> sharedStaticMethodFromClass)
Add shared static method of Class
|
static Engine |
create(String engineName)
Create engine with engine name managed by JFinal
|
String |
getBaseTemplatePath() |
String |
getDatePattern() |
boolean |
getDevMode() |
String |
getEncoding() |
EngineConfig |
getEngineConfig() |
String |
getName() |
ISourceFactory |
getSourceFactory() |
Template |
getTemplate(ISource source)
Get template with implementation of ISource
|
Template |
getTemplate(String fileName)
Get template with file name
|
Template |
getTemplateByString(String content)
Get template by string content and do not cache the template
|
Template |
getTemplateByString(String content,
boolean cache)
Get template by string content
重要:StringSource 中的 key = HashKit.md5(content),也即 key
与 content 有紧密的对应关系,当 content 发生变化时 key 值也相应变化
因此,原先 key 所对应的 Template 缓存对象已无法被获取,当 getTemplateByString(String)
的 String 参数的数量不确定时会引发内存泄漏
当 getTemplateByString(String, boolean) 中的 String 参数的
数量可控并且确定时,才可对其使用缓存
|
int |
getTemplateCacheSize() |
static Engine |
remove(String engineName)
Remove engine with engine name managed by JFinal
|
void |
removeAllTemplateCache()
Remove all template cache
|
Engine |
removeDirective(String directiveName)
Remove directive
|
static void |
removeExtensionMethod(Class<?> targetClass,
Class<?> extensionClass) |
static void |
removeExtensionMethod(Class<?> targetClass,
Object objectOfExtensionClass) |
Engine |
removeSharedMethod(Class<?> clazz)
Remove shared Method of the Class
|
Engine |
removeSharedMethod(Method method)
Remove shared Method
|
Engine |
removeSharedMethod(String methodName)
Remove shared Method with method name
|
void |
removeTemplateCache(String templateKey)
Remove template cache with template key
|
Engine |
setBaseTemplatePath(String baseTemplatePath) |
Engine |
setDatePattern(String datePattern) |
Engine |
setDevMode(boolean devMode)
设置 true 为开发模式,支持模板文件热加载
设置 false 为生产模式,不支持模板文件热加载,以达到更高的性能
|
Engine |
setEncoding(String encoding) |
static void |
setMainEngine(Engine engine)
Set main engine
|
Engine |
setOutputDirectiveFactory(IOutputDirectiveFactory outputDirectiveFactory)
Set output directive factory
|
Engine |
setReloadModifiedSharedFunctionInDevMode(boolean reloadModifiedSharedFunctionInDevMode)
Engine 独立设置为 devMode 可以方便模板文件在修改后立即生效,
但如果在 devMode 之下并不希望对 addSharedFunction(...),
添加的模板进行是否被修改的检测可以通过此方法设置 false 参进去
注意:Engine 在生产环境下(devMode 为 false),该参数无效
|
Engine |
setSourceFactory(ISourceFactory sourceFactory)
设置 ISourceFactory 用于为 engine 切换不同的 ISource 实现类
ISource 用于从不同的来源加载模板内容
|
Engine |
setToClassPathSourceFactory()
设置为 ClassPathSourceFactory 的快捷方法
|
Engine |
setWriterBufferSize(int bufferSize) |
String |
toString() |
static Engine |
use()
Using the main Engine
|
static Engine |
use(String engineName)
Using the engine with engine name
|
public static final String MAIN_ENGINE_NAME
public Engine()
public Engine(String engineName)
public static Engine use()
public static Engine create(String engineName)
public static Engine remove(String engineName)
public static void setMainEngine(Engine engine)
public Template getTemplateByString(String content)
public Template getTemplateByString(String content, boolean cache)
content
- 模板内容cache
- true 则缓存 Template,否则不缓存public Engine addSharedFunction(String... fileNames)
public Engine addSharedFunctionByString(String content)
public Engine setOutputDirectiveFactory(IOutputDirectiveFactory outputDirectiveFactory)
public Engine addDirective(String directiveName, Class<? extends Directive> directiveClass)
示例: addDirective("now", NowDirective.class)
@Deprecated public Engine addDirective(String directiveName, Directive directive)
public Engine addSharedMethod(Object sharedMethodFromObject)
public Engine addSharedMethod(Class<?> sharedMethodFromClass)
public Engine addSharedStaticMethod(Class<?> sharedStaticMethodFromClass)
public Engine removeSharedMethod(String methodName)
public Engine removeSharedMethod(Class<?> clazz)
public void removeTemplateCache(String templateKey)
public void removeAllTemplateCache()
public int getTemplateCacheSize()
public String getName()
public EngineConfig getEngineConfig()
public Engine setDevMode(boolean devMode)
public boolean getDevMode()
public Engine setSourceFactory(ISourceFactory sourceFactory)
配置为 ClassPathSourceFactory 时特别注意: 由于 JFinal 会在 configEngine(Engine me) 方法调用 “之前”,会默认调用一次如下方法: me.setBaseTemplatePath(PathKit.getWebRootPath()) 而 ClassPathSourceFactory 在以上默认值下不能工作,所以需要通过如下方式清掉该值: me.setBaseTemplatePath(null) 或者配置具体要用的 baseTemplatePath 值,例如: me.setBaseTemplatePath("view");
public Engine setToClassPathSourceFactory()
public ISourceFactory getSourceFactory()
public String getBaseTemplatePath()
public String getDatePattern()
public String getEncoding()
public Engine setWriterBufferSize(int bufferSize)
public Engine setReloadModifiedSharedFunctionInDevMode(boolean reloadModifiedSharedFunctionInDevMode)
public static void addExtensionMethod(Class<?> targetClass, Object objectOfExtensionClass)
public static void addExtensionMethod(Class<?> targetClass, Class<?> extensionClass)
public static void removeExtensionMethod(Class<?> targetClass, Object objectOfExtensionClass)
Copyright © 2018. All rights reserved.