19 Commits

Author SHA1 Message Date
James
b4e277fcc0 [maven-release-plugin] prepare release enjoy-4.1 2019-05-29 21:56:19 +08:00
James
bbc1e24b87 [maven-release-plugin] prepare for next development iteration 2019-05-21 22:57:57 +08:00
James
34c1a9e53a [maven-release-plugin] prepare release enjoy-4.0 2019-05-21 22:57:51 +08:00
James
f6a855b6bf enjoy 4.0 release ^_^ 2019-05-21 22:52:26 +08:00
James
4377d19e2f [maven-release-plugin] prepare for next development iteration 2019-04-07 22:30:17 +08:00
James
820f2806ec [maven-release-plugin] prepare release enjoy-3.8 2019-04-07 22:30:15 +08:00
James
808bdf6079 enjoy 3.8 2019-04-07 22:23:49 +08:00
James
eac1d8d055 enjoy 3.8 2019-04-07 21:45:28 +08:00
James
d5a88b8be4 enjoy 3.8 2019-04-07 21:36:00 +08:00
James
fd5d554171 enjoy 3.8 2019-04-07 21:34:21 +08:00
James
6d18be3df8 [maven-release-plugin] prepare for next development iteration 2019-03-19 16:31:01 +08:00
James
869824e2bb [maven-release-plugin] prepare release enjoy-3.7 2019-03-19 16:30:57 +08:00
James
84573be584 enjoy 3.7 release ^_^ 2019-03-19 16:25:33 +08:00
James
3cc94a5b32 enjoy 3.7 release 2019-03-19 16:23:21 +08:00
James
3a4f4f4495 enjoy 3.7 2019-02-25 18:44:34 +08:00
James
d250b431a4 jfinal enjoy 3.6 release ^_^ 2019-01-31 16:45:57 +08:00
James
5e133e7de5 jfinal enjoy 3.6 release ^_^ 2019-01-31 16:45:09 +08:00
James
ef39843a25 jfinal enjoy 3.6 release ^_^ 2019-01-31 16:43:49 +08:00
James
0e5f3b7249 [maven-release-plugin] prepare for next development iteration 2019-01-31 00:15:29 +08:00
13 changed files with 84 additions and 116 deletions

View File

@@ -34,9 +34,10 @@ Enjoy 是基于 Java 语言的极轻量极魔板引擎。极轻量级仅 171K
``` ```
**2.详细使用方法见 jfinal 手册** **2.详细使用方法见 jfinal 手册**
read me 正在补充,详细使用文档请下载 jfinal.com 官网的 jfinal 手册[http://www.jfinal.com](http://www.jfinal.com)
**JFinal 官方网站[http://www.jfinal.com](http://www.jfinal.com)** read me 正在补充,详细使用文档见官网[https://www.jfinal.com/doc/6-1](https://www.jfinal.com/doc/6-1)
**JFinal Enjoy 官方文档:[https://www.jfinal.com/doc/6-1](https://www.jfinal.com/doc/6-1)**

View File

@@ -4,7 +4,7 @@
<artifactId>enjoy</artifactId> <artifactId>enjoy</artifactId>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>enjoy</name> <name>enjoy</name>
<version>3.6</version> <version>4.1</version>
<url>http://www.jfinal.com</url> <url>http://www.jfinal.com</url>
<description>Enjoy is a simple, light, rapid, independent, extensible Java Template Engine.</description> <description>Enjoy is a simple, light, rapid, independent, extensible Java Template Engine.</description>

View File

@@ -30,11 +30,6 @@ import java.util.Map;
@SuppressWarnings({"serial", "rawtypes", "unchecked"}) @SuppressWarnings({"serial", "rawtypes", "unchecked"})
public class Kv extends HashMap { public class Kv extends HashMap {
@Deprecated
private static final String STATE_OK = "isOk";
@Deprecated
private static final String STATE_FAIL = "isFail";
public Kv() { public Kv() {
} }
@@ -46,68 +41,6 @@ public class Kv extends HashMap {
return new Kv(); return new Kv();
} }
@Deprecated
public static Kv ok() {
return new Kv().setOk();
}
@Deprecated
public static Kv ok(Object key, Object value) {
return ok().set(key, value);
}
@Deprecated
public static Kv fail() {
return new Kv().setFail();
}
@Deprecated
public static Kv fail(Object key, Object value) {
return fail().set(key, value);
}
@Deprecated
public Kv setOk() {
super.put(STATE_OK, Boolean.TRUE);
super.put(STATE_FAIL, Boolean.FALSE);
return this;
}
@Deprecated
public Kv setFail() {
super.put(STATE_FAIL, Boolean.TRUE);
super.put(STATE_OK, Boolean.FALSE);
return this;
}
@Deprecated
public boolean isOk() {
Boolean isOk = (Boolean)get(STATE_OK);
if (isOk != null) {
return isOk;
}
Boolean isFail = (Boolean)get(STATE_FAIL);
if (isFail != null) {
return !isFail;
}
throw new IllegalStateException("调用 isOk() 之前,必须先调用 ok()、fail() 或者 setOk()、setFail() 方法");
}
@Deprecated
public boolean isFail() {
Boolean isFail = (Boolean)get(STATE_FAIL);
if (isFail != null) {
return isFail;
}
Boolean isOk = (Boolean)get(STATE_OK);
if (isOk != null) {
return !isOk;
}
throw new IllegalStateException("调用 isFail() 之前,必须先调用 ok()、fail() 或者 setOk()、setFail() 方法");
}
public Kv set(Object key, Object value) { public Kv set(Object key, Object value) {
super.put(key, value); super.put(key, value);
return this; return this;

View File

@@ -16,6 +16,9 @@
package com.jfinal.kit; package com.jfinal.kit;
import java.lang.reflect.Method;
import java.lang.reflect.Parameter;
/** /**
* 反射工具类 * 反射工具类
*/ */
@@ -29,6 +32,45 @@ public class ReflectKit {
} }
} }
public static String getMethodSignature(Method method) {
StringBuilder ret = new StringBuilder()
.append(method.getDeclaringClass().getName())
.append(".")
.append(method.getName())
.append("(");
int index = 0;
Parameter[] paras = method.getParameters();
for (Parameter p : paras) {
if (index++ > 0) {
ret.append(", ");
}
ret.append(p.getParameterizedType().getTypeName());
}
return ret.append(")").toString();
}
/*
public static String getMethodSignature(Method method) {
StringBuilder ret = new StringBuilder()
.append(method.getDeclaringClass().getName())
.append(".")
.append(method.getName())
.append("(");
int index = 0;
java.lang.reflect.Type[] paraTypes = method.getGenericParameterTypes();
for (java.lang.reflect.Type type : paraTypes) {
if (index++ > 0) {
ret.append(", ");
}
ret.append(type.getTypeName());
}
return ret.append(")").toString();
}*/
} }

View File

@@ -26,6 +26,7 @@ import com.jfinal.template.expr.ast.FieldGetter;
import com.jfinal.template.expr.ast.FieldKeyBuilder; import com.jfinal.template.expr.ast.FieldKeyBuilder;
import com.jfinal.template.expr.ast.FieldKit; import com.jfinal.template.expr.ast.FieldKit;
import com.jfinal.template.expr.ast.MethodKit; import com.jfinal.template.expr.ast.MethodKit;
import com.jfinal.template.io.EncoderFactory;
import com.jfinal.template.source.ClassPathSourceFactory; import com.jfinal.template.source.ClassPathSourceFactory;
import com.jfinal.template.source.ISource; import com.jfinal.template.source.ISource;
import com.jfinal.template.source.ISourceFactory; import com.jfinal.template.source.ISourceFactory;
@@ -471,6 +472,17 @@ public class Engine {
return config.getEncoding(); return config.getEncoding();
} }
/**
* Enjoy 模板引擎对 UTF-8 的 encoding 做过性能优化,某些偏门字符在
* 被编码为 UTF-8 时会出现异常,此时可以通过继承扩展 EncoderFactory
* 来解决编码异常,具体用法参考:
* http://www.jfinal.com/feedback/5340
*/
public Engine setEncoderFactory(EncoderFactory encoderFactory) {
config.setEncoderFactory(encoderFactory);
return this;
}
public Engine setWriterBufferSize(int bufferSize) { public Engine setWriterBufferSize(int bufferSize) {
config.setWriterBufferSize(bufferSize); config.setWriterBufferSize(bufferSize);
return this; return this;

View File

@@ -17,7 +17,6 @@
package com.jfinal.template; package com.jfinal.template;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
@@ -117,16 +116,10 @@ public class Template {
* 适用于代码生成器类似应用场景 * 适用于代码生成器类似应用场景
*/ */
public void render(Map<?, ?> data, File file) { public void render(Map<?, ?> data, File file) {
FileOutputStream fos = null; try (FileOutputStream fos = new FileOutputStream(file)) {
try {
fos = new FileOutputStream(file);
render(data, fos); render(data, fos);
} catch (FileNotFoundException e) { } catch (IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} finally {
if (fos != null) {
try {fos.close();} catch (IOException e) {e.printStackTrace(System.err);}
}
} }
} }

View File

@@ -28,8 +28,8 @@ public class TemplateException extends RuntimeException {
super(loc != null ? msg + loc : msg); super(loc != null ? msg + loc : msg);
} }
public TemplateException(String msg, Location loc, Throwable t) { public TemplateException(String msg, Location loc, Throwable cause) {
super(loc != null ? msg + loc : msg, t); super(loc != null ? msg + loc : msg, cause);
} }
} }

View File

@@ -28,10 +28,10 @@ import com.jfinal.template.stat.Scope;
* *
* field 表达式取值优先次序,以 user.name 为例 * field 表达式取值优先次序,以 user.name 为例
* 1假如 user.getName() 存在,则优先调用 * 1假如 user.getName() 存在,则优先调用
* 2假如 user 为 Model 子类,则调用 user.get("name") * 2假如 user 具有 public name 属性,则取 user.name 属性值
* 3假如 user 为 Record,则调用 user.get("name") * 3假如 user 为 Model 子类,则调用 user.get("name")
* 4假如 user 为 Map,则调用 user.get("name") * 4假如 user 为 Record,则调用 user.get("name")
* 5假如 user 具有 public name 属性,则取 user.name 属性值 * 5假如 user 为 Map则调用 user.get("name")
*/ */
public class Field extends Expr { public class Field extends Expr {

View File

@@ -44,10 +44,13 @@ public class FieldKit {
LinkedList<FieldGetter> ret = new LinkedList<FieldGetter>(); LinkedList<FieldGetter> ret = new LinkedList<FieldGetter>();
ret.addLast(new GetterMethodFieldGetter(null)); ret.addLast(new GetterMethodFieldGetter(null));
ret.addLast(new RealFieldGetter(null));
// ret.addLast(new ModelFieldGetter()); // ret.addLast(new ModelFieldGetter());
// ret.addLast(new RecordFieldGetter()); // ret.addLast(new RecordFieldGetter());
ret.addLast(new MapFieldGetter()); ret.addLast(new MapFieldGetter());
ret.addLast(new RealFieldGetter(null));
// 挪到第二的位置addSharedObject(..., modelObj) 用法可以获取到 model 中的 public 属性
// ret.addLast(new RealFieldGetter(null));
ret.addLast(new ArrayLengthGetter()); ret.addLast(new ArrayLengthGetter());
// ret.addLast(new IsMethodFieldGetter()); // ret.addLast(new IsMethodFieldGetter());
@@ -133,6 +136,10 @@ public class FieldKit {
getters = ret.toArray(new FieldGetter[ret.size()]); getters = ret.toArray(new FieldGetter[ret.size()]);
} }
public static void clearCache() {
fieldGetterCache.clear();
}
} }

View File

@@ -115,6 +115,10 @@ public class MethodKit {
forbiddenMethods.remove(methodName); forbiddenMethods.remove(methodName);
} }
public static void clearCache() {
methodCache.clear();
}
public static MethodInfo getMethod(Class<?> targetClass, String methodName, Object[] argValues) { public static MethodInfo getMethod(Class<?> targetClass, String methodName, Object[] argValues) {
Class<?>[] argTypes = getArgTypes(argValues); Class<?>[] argTypes = getArgTypes(argValues);
Long key = getMethodKey(targetClass, methodName, argTypes); Long key = getMethodKey(targetClass, methodName, argTypes);

View File

@@ -18,7 +18,6 @@ package com.jfinal.template.source;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.net.URL; import java.net.URL;
@@ -64,7 +63,7 @@ public class ClassPathSource implements ISource {
this.classLoader = getClassLoader(); this.classLoader = getClassLoader();
this.url = classLoader.getResource(finalFileName); this.url = classLoader.getResource(finalFileName);
if (url == null) { if (url == null) {
throw new IllegalArgumentException("File not found : \"" + finalFileName + "\""); throw new IllegalArgumentException("File not found in CLASSPATH or JAR : \"" + finalFileName + "\"");
} }
processIsInJarAndlastModified(); processIsInJarAndlastModified();
@@ -141,9 +140,8 @@ public class ClassPathSource implements ISource {
public static StringBuilder loadFile(InputStream inputStream, String encoding) { public static StringBuilder loadFile(InputStream inputStream, String encoding) {
StringBuilder ret = new StringBuilder(); StringBuilder ret = new StringBuilder();
BufferedReader br = null;
try { try (BufferedReader br = new BufferedReader(new InputStreamReader(inputStream, encoding))) {
br = new BufferedReader(new InputStreamReader(inputStream, encoding));
// br = new BufferedReader(new FileReader(fileName)); // br = new BufferedReader(new FileReader(fileName));
String line = br.readLine(); String line = br.readLine();
if (line != null) { if (line != null) {
@@ -159,16 +157,6 @@ public class ClassPathSource implements ISource {
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
// com.jfinal.kit.LogKit.error(e.getMessage(), e);
e.printStackTrace();
}
}
}
} }
public String toString() { public String toString() {

View File

@@ -19,7 +19,6 @@ package com.jfinal.template.source;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import com.jfinal.template.EngineConfig; import com.jfinal.template.EngineConfig;
@@ -92,9 +91,8 @@ public class FileSource implements ISource {
public static StringBuilder loadFile(File file, String encoding) { public static StringBuilder loadFile(File file, String encoding) {
StringBuilder ret = new StringBuilder((int)file.length() + 3); StringBuilder ret = new StringBuilder((int)file.length() + 3);
BufferedReader br = null;
try { try (BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file), encoding))) {
br = new BufferedReader(new InputStreamReader(new FileInputStream(file), encoding));
// br = new BufferedReader(new FileReader(fileName)); // br = new BufferedReader(new FileReader(fileName));
String line = br.readLine(); String line = br.readLine();
if (line != null) { if (line != null) {
@@ -110,16 +108,6 @@ public class FileSource implements ISource {
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
// com.jfinal.kit.LogKit.error(e.getMessage(), e);
e.printStackTrace();
}
}
}
} }
public String toString() { public String toString() {

View File

@@ -69,7 +69,7 @@ public class Include extends Stat {
Expr expr = exprList.getExpr(0); Expr expr = exprList.getExpr(0);
if (expr instanceof Const && ((Const)expr).isStr()) { if (expr instanceof Const && ((Const)expr).isStr()) {
} else { } else {
throw new ParseException("The first parameter of #include directive must be String", location); throw new ParseException("The first parameter of #include directive must be String, or use the #render directive", location);
} }
// 其它参数必须为赋值表达式 // 其它参数必须为赋值表达式
if (len > 1) { if (len > 1) {