public class ClassPathSource extends Object implements ISource
注意:
1:如果被加载的文件是 class path 中的普通文件,则该文件支持热加载
2:如果被加载的文件处于 jar 包之中,则该文件不支持热加载,jar 包之中的文件在运行时通常不会被修改
在极少数情况下如果需要对 jar 包之中的模板文件进行热加载,可以通过继承 ClassPathSource
的方式进行扩展
3:JFinal Template Engine 开启热加载需要配置 engine.setDevMode(true)
| 限定符和类型 | 字段和说明 |
|---|---|
protected ClassLoader |
classLoader |
protected String |
encoding |
protected String |
fileName |
protected String |
finalFileName |
protected boolean |
isInJar |
protected long |
lastModified |
protected URL |
url |
| 构造器和说明 |
|---|
ClassPathSource(String fileName) |
ClassPathSource(String baseTemplatePath,
String fileName) |
ClassPathSource(String baseTemplatePath,
String fileName,
String encoding) |
| 限定符和类型 | 方法和说明 |
|---|---|
protected String |
buildFinalFileName(String baseTemplatePath,
String fileName) |
String |
getCacheKey()
cache key used to cache, return null if do not cache the template
注意:如果不希望缓存从该 ISource 解析出来的 Template 对象
让 getCacheKey() 返回 null 值即可
|
protected ClassLoader |
getClassLoader() |
StringBuilder |
getContent()
content of ISource
|
String |
getEncoding()
encoding of content
|
protected long |
getLastModified() |
boolean |
isModified()
模板文件在 jar 包文件之内则不支持热加载
|
static StringBuilder |
loadFile(InputStream inputStream,
String encoding) |
protected void |
processIsInJarAndlastModified() |
String |
toString() |
protected String finalFileName
protected String fileName
protected String encoding
protected boolean isInJar
protected long lastModified
protected ClassLoader classLoader
protected URL url
public ClassPathSource(String fileName)
protected void processIsInJarAndlastModified()
protected ClassLoader getClassLoader()
public String getCacheKey()
ISourcegetCacheKey 在接口中 ISourcepublic String getEncoding()
ISourcegetEncoding 在接口中 ISourceprotected long getLastModified()
public boolean isModified()
isModified 在接口中 ISourcepublic StringBuilder getContent()
ISourcegetContent 在接口中 ISourcepublic static StringBuilder loadFile(InputStream inputStream, String encoding)
Copyright © 2024. All rights reserved.