Compare commits
16 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
1aef12eb94 | ||
|
6f615bc1a8 | ||
|
0c3e7790b7 | ||
|
a1e88a4a4c | ||
|
d12d3d8abb | ||
|
ef7b0da917 | ||
|
2ed806c296 | ||
|
998df7b907 | ||
|
3e93fc970e | ||
|
010a7f3d8a | ||
|
99f024f546 | ||
|
ca3361703e | ||
|
1840d49e0a | ||
|
70d1e5a9eb | ||
|
e0abc218b1 | ||
|
bd1949fc56 |
1
LICENSE
1
LICENSE
@@ -189,3 +189,4 @@ third-party archives.
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
|
10
pom.xml
10
pom.xml
@@ -4,7 +4,7 @@
|
||||
<artifactId>enjoy</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>enjoy</name>
|
||||
<version>3.3</version>
|
||||
<version>3.4</version>
|
||||
<url>http://www.jfinal.com</url>
|
||||
<description>Enjoy is a simple, light, rapid, independent, extensible Java Template Engine.</description>
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
|
||||
<issueManagement>
|
||||
<system>Git Issue</system>
|
||||
<url>http://git.oschina.net/jfinal/enjoy/issues</url>
|
||||
<url>https://gitee.com/jfinal/enjoy/issues</url>
|
||||
</issueManagement>
|
||||
<licenses>
|
||||
<license>
|
||||
@@ -32,9 +32,9 @@
|
||||
</developer>
|
||||
</developers>
|
||||
<scm>
|
||||
<connection>scm:git:git@git.oschina.net:jfinal/enjoy.git</connection>
|
||||
<developerConnection>scm:git:git@git.oschina.net:jfinal/enjoy.git</developerConnection>
|
||||
<url>git@git.oschina.net:jfinal/enjoy.git</url>
|
||||
<connection>scm:git:git@gitee.com:jfinal/enjoy.git</connection>
|
||||
<developerConnection>scm:git:git@gitee.com:jfinal/enjoy.git</developerConnection>
|
||||
<url>git@gitee.com:jfinal/enjoy.git</url>
|
||||
</scm>
|
||||
|
||||
<parent>
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -45,7 +45,7 @@ public class ElKit {
|
||||
engine.addDirective("eval", InnerEvalDirective.class);
|
||||
}
|
||||
|
||||
public Engine getEngine() {
|
||||
public static Engine getEngine() {
|
||||
return engine;
|
||||
}
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -22,6 +22,7 @@ import java.util.Map;
|
||||
import com.jfinal.kit.HashKit;
|
||||
import com.jfinal.kit.StrKit;
|
||||
import com.jfinal.template.expr.ast.MethodKit;
|
||||
import com.jfinal.template.source.ClassPathSourceFactory;
|
||||
import com.jfinal.template.source.ISource;
|
||||
import com.jfinal.template.source.ISourceFactory;
|
||||
import com.jfinal.template.source.StringSource;
|
||||
@@ -161,6 +162,13 @@ public class Engine {
|
||||
|
||||
/**
|
||||
* Get template by string content and do not cache the template
|
||||
*/
|
||||
public Template getTemplateByString(String content) {
|
||||
return getTemplateByString(content, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get template by string content
|
||||
*
|
||||
* 重要:StringSource 中的 key = HashKit.md5(content),也即 key
|
||||
* 与 content 有紧密的对应关系,当 content 发生变化时 key 值也相应变化
|
||||
@@ -169,13 +177,7 @@ public class Engine {
|
||||
*
|
||||
* 当 getTemplateByString(String, boolean) 中的 String 参数的
|
||||
* 数量可控并且确定时,才可对其使用缓存
|
||||
*/
|
||||
public Template getTemplateByString(String content) {
|
||||
return getTemplateByString(content, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get template by string content
|
||||
*
|
||||
* @param content 模板内容
|
||||
* @param cache true 则缓存 Template,否则不缓存
|
||||
*/
|
||||
@@ -426,6 +428,13 @@ public class Engine {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置为 ClassPathSourceFactory 的快捷方法
|
||||
*/
|
||||
public Engine setToClassPathSourceFactory() {
|
||||
return setSourceFactory(new ClassPathSourceFactory());
|
||||
}
|
||||
|
||||
public ISourceFactory getSourceFactory() {
|
||||
return sourceFactory;
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,6 +16,10 @@
|
||||
|
||||
package com.jfinal.template;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.Writer;
|
||||
import java.util.Map;
|
||||
@@ -108,6 +112,32 @@ public class Template {
|
||||
return fsw.getBuffer();
|
||||
}
|
||||
|
||||
/**
|
||||
* 渲染到 File 中去
|
||||
* 适用于代码生成器类似应用场景
|
||||
*/
|
||||
public void render(Map<?, ?> data, File file) {
|
||||
FileOutputStream fos = null;
|
||||
try {
|
||||
fos = new FileOutputStream(file);
|
||||
render(data, fos);
|
||||
} catch (FileNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
if (fos != null) {
|
||||
try {fos.close();} catch (IOException e) {e.printStackTrace(System.err);}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 渲染到 String fileName 参数所指定的文件中去
|
||||
* 适用于代码生成器类似应用场景
|
||||
*/
|
||||
public void render(Map<?, ?> data, String fileName) {
|
||||
render(data, new File(fileName));
|
||||
}
|
||||
|
||||
public boolean isModified() {
|
||||
return env.isSourceListModified();
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -292,7 +292,7 @@ public class ExprParser {
|
||||
case ADD:
|
||||
case SUB:
|
||||
move();
|
||||
return new Unary(tok.sym, unary(), location);
|
||||
return new Unary(tok.sym, unary(), location).toConstIfPossible();
|
||||
case INC:
|
||||
case DEC:
|
||||
move();
|
||||
@@ -468,21 +468,26 @@ public class ExprParser {
|
||||
}
|
||||
|
||||
/**
|
||||
* mapEntry : (ID | STR) ':' expr
|
||||
* mapEntry : (ID | STR | INT | LONG | FLOAT | DOUBLE | TRUE | FALSE | NULL) ':' expr
|
||||
* 设计目标为 map 定义与初始化,所以 ID 仅当成 STR 不进行求值
|
||||
*/
|
||||
void buildMapEntry(LinkedHashMap<Object, Expr> map) {
|
||||
Tok tok = peek();
|
||||
if (tok.sym == Sym.ID || tok.sym == Sym.STR) {
|
||||
move();
|
||||
match(Sym.COLON);
|
||||
Expr value = expr();
|
||||
if (value == null) {
|
||||
throw new ParseException("Expression error: the value on the right side of map entry can not be blank", location);
|
||||
}
|
||||
map.put(tok.value(), value);
|
||||
return ;
|
||||
Expr keyExpr = expr();
|
||||
Object key;
|
||||
if (keyExpr instanceof Id) {
|
||||
key = ((Id)keyExpr).getId();
|
||||
} else if (keyExpr instanceof Const) {
|
||||
key = ((Const)keyExpr).getValue();
|
||||
} else {
|
||||
throw new ParseException("Expression error: the value of map key must be identifier, String, Boolean, null or Number", location);
|
||||
}
|
||||
throw new ParseException("Expression error: the value of map key must be identifier or String", location);
|
||||
|
||||
match(Sym.COLON);
|
||||
Expr value = expr();
|
||||
if (value == null) {
|
||||
throw new ParseException("Expression error: the value on the right side of map entry can not be blank", location);
|
||||
}
|
||||
map.put(key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -528,12 +533,14 @@ public class ExprParser {
|
||||
move();
|
||||
return new Id(tok.value());
|
||||
case STR:
|
||||
move();
|
||||
return new Const(tok.sym, tok.value());
|
||||
case INT:
|
||||
case LONG:
|
||||
case FLOAT:
|
||||
case DOUBLE:
|
||||
move();
|
||||
return new Const(tok.sym, tok.value());
|
||||
return new Const(tok.sym, ((NumTok)tok).getNumberValue());
|
||||
case TRUE:
|
||||
move();
|
||||
return Const.TRUE;
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -43,7 +43,7 @@ import com.jfinal.template.stat.ParseException;
|
||||
*/
|
||||
public class NumTok extends Tok {
|
||||
|
||||
private Object value;
|
||||
private Number value;
|
||||
|
||||
NumTok(Sym sym, String s, int radix, boolean isScientificNotation, Location location) {
|
||||
super(sym, location.getRow());
|
||||
@@ -101,3 +101,8 @@ public class NumTok extends Tok {
|
||||
return sym.value() + " : " + value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -20,54 +20,25 @@ import com.jfinal.template.expr.Sym;
|
||||
import com.jfinal.template.stat.Scope;
|
||||
|
||||
/**
|
||||
* STR INT LONG FLOAT DOUBLE true false null
|
||||
* STR INT LONG FLOAT DOUBLE TRUE FALSE NULL
|
||||
*/
|
||||
public class Const extends Expr {
|
||||
|
||||
public static final Const TRUE = new Const(Boolean.TRUE, Sym.TRUE);
|
||||
public static final Const FALSE = new Const(Boolean.FALSE, Sym.FALSE);
|
||||
public static final Const NULL = new Const(null, Sym.NULL);
|
||||
public static final Const TRUE = new Const(Sym.TRUE, Boolean.TRUE);
|
||||
public static final Const FALSE = new Const(Sym.FALSE, Boolean.FALSE);
|
||||
public static final Const NULL = new Const(Sym.NULL, null);
|
||||
|
||||
private Sym type;
|
||||
private Object value;
|
||||
private final Sym type;
|
||||
private final Object value;
|
||||
|
||||
/**
|
||||
* 构造 TRUE FALSE NULL 常量,无需对 value 进行转换
|
||||
* INT LONG FLOAT DOUBLE 常量已在 NumTok 中转换成了确切的类型,无需再次转换
|
||||
*/
|
||||
private Const(Object value, Sym type) {
|
||||
public Const(Sym type, Object value) {
|
||||
this.type = type;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public Const(Sym type, String value) {
|
||||
this.type = type;
|
||||
this.value = typeConvert(type, value);
|
||||
}
|
||||
|
||||
private Object typeConvert(Sym type, String value) {
|
||||
switch (type) {
|
||||
case STR:
|
||||
return value;
|
||||
case INT:
|
||||
return Integer.parseInt(value);
|
||||
case LONG:
|
||||
return Long.parseLong(value);
|
||||
case FLOAT:
|
||||
return Float.parseFloat(value);
|
||||
case DOUBLE:
|
||||
return Double.parseDouble(value);
|
||||
/*
|
||||
case TRUE:
|
||||
case FALSE:
|
||||
return Boolean.parseBoolean(value);
|
||||
case NULL:
|
||||
return null;
|
||||
*/
|
||||
default:
|
||||
throw new RuntimeException("never happend");
|
||||
}
|
||||
}
|
||||
|
||||
public Object eval(Scope scope) {
|
||||
return value;
|
||||
}
|
||||
@@ -108,6 +79,10 @@ public class Const extends Expr {
|
||||
return type == Sym.DOUBLE;
|
||||
}
|
||||
|
||||
public boolean isNumber() {
|
||||
return value instanceof Number;
|
||||
}
|
||||
|
||||
public Object getValue() {
|
||||
return value;
|
||||
}
|
||||
@@ -136,6 +111,10 @@ public class Const extends Expr {
|
||||
return (Double)value;
|
||||
}
|
||||
|
||||
public Number getNumber() {
|
||||
return (Number)value;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return value != null ? value.toString() : "null";
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -113,9 +113,9 @@ public class Field extends Expr {
|
||||
|
||||
if (expr instanceof Id) {
|
||||
String id = ((Id)expr).getId();
|
||||
throw new TemplateException("Field not found: \"" + id + "." + fieldName + "\" and getter method not found: \"" + id + "." + getterName + "()\"", location);
|
||||
throw new TemplateException("public field not found: \"" + id + "." + fieldName + "\" and public getter method not found: \"" + id + "." + getterName + "()\"", location);
|
||||
}
|
||||
throw new TemplateException("Field not found: \"" + fieldName + "\" and getter method not found: \"" + getterName + "()\"", location);
|
||||
throw new TemplateException("public field not found: \"" + fieldName + "\" and public getter method not found: \"" + getterName + "()\"", location);
|
||||
}
|
||||
|
||||
private Long buildFieldKey(Class<?> targetClass) {
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -23,7 +23,7 @@ import com.jfinal.template.stat.Scope;
|
||||
*/
|
||||
public class Id extends Expr {
|
||||
|
||||
private String id;
|
||||
private final String id;
|
||||
|
||||
public Id(String id) {
|
||||
this.id = id;
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -43,8 +43,8 @@ public class Index extends Expr {
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public Object eval(Scope scope) {
|
||||
Object array = expr.eval(scope);
|
||||
if (array == null) {
|
||||
Object target = expr.eval(scope);
|
||||
if (target == null) {
|
||||
if (scope.getCtrl().isNullSafe()) {
|
||||
return null;
|
||||
}
|
||||
@@ -56,25 +56,30 @@ public class Index extends Expr {
|
||||
if (scope.getCtrl().isNullSafe()) {
|
||||
return null;
|
||||
}
|
||||
throw new TemplateException("The index of list/array and the key of map can not be null", location);
|
||||
}
|
||||
|
||||
if (array instanceof List) {
|
||||
if (idx instanceof Integer) {
|
||||
return ((List<?>)array).get((Integer)idx);
|
||||
if (target instanceof java.util.Map) {
|
||||
// Map 的 key 可以是 null,不能抛异常
|
||||
} else {
|
||||
throw new TemplateException("The index of list and array can not be null", location);
|
||||
}
|
||||
throw new TemplateException("The index of list can only be integer", location);
|
||||
}
|
||||
|
||||
if (array instanceof java.util.Map) {
|
||||
return ((java.util.Map)array).get(idx);
|
||||
}
|
||||
|
||||
if (array.getClass().isArray()) {
|
||||
if (target instanceof List) {
|
||||
if (idx instanceof Integer) {
|
||||
return java.lang.reflect.Array.get(array, (Integer)idx);
|
||||
return ((List<?>)target).get((Integer)idx);
|
||||
}
|
||||
throw new TemplateException("The index of array can only be integer", location);
|
||||
throw new TemplateException("The index of list must be integer", location);
|
||||
}
|
||||
|
||||
if (target instanceof java.util.Map) {
|
||||
return ((java.util.Map)target).get(idx);
|
||||
}
|
||||
|
||||
if (target.getClass().isArray()) {
|
||||
if (idx instanceof Integer) {
|
||||
return java.lang.reflect.Array.get(target, (Integer)idx);
|
||||
}
|
||||
throw new TemplateException("The index of array must be integer", location);
|
||||
}
|
||||
|
||||
throw new TemplateException("Only the list array and map is supported by index access", location);
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -24,8 +24,10 @@ import com.jfinal.template.stat.Scope;
|
||||
* Map
|
||||
*
|
||||
* 1:定义 map 常量
|
||||
* {k1:123, k2:"abc", 'k3':true, "k4":[1,2,3], k5:1+2}
|
||||
* 如上所示,map定义的 key 可以为 String 或者 id 标识符,而右侧的 value 可以是任意的常量与表达式
|
||||
* {k1:123, k2:"abc", 'k3':true, "k4":[1,2,3], k5:1+2, 1:12, true:"Y", null:"abc"}
|
||||
* 如上所示,map定义的 key 可以为 id 标识符或者 String、Integer、Long、Boolean、null
|
||||
* 等常量值 (详见 ExprParser.buildMapEntry(...) 方法),
|
||||
* 右侧的 value 可以是任意的常量与表达式
|
||||
*
|
||||
* 2:取值
|
||||
* 先将 Map 常量赋值给某个变量: #set(map = {...})
|
||||
@@ -35,6 +37,10 @@ import com.jfinal.template.stat.Scope;
|
||||
* map.get("k1")
|
||||
* map.k1
|
||||
*
|
||||
* 3:不通过中间变量取值
|
||||
* {1:'自买', 2:'跟买'}.get(1)
|
||||
* {1:'自买', 2:'跟买'}[2]
|
||||
*
|
||||
* 如上所示,当以下标方式取值时,下标参数可以是 string 与 expr,而 expr 求值以后的值必须也为 string类型
|
||||
* 当用 map.k1 这类 field 字段取值形式时,则是使用 id 标识符,而不是 string 形参数
|
||||
*
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -75,7 +75,7 @@ public class Method extends Expr {
|
||||
if (scope.getCtrl().isNullSafe()) {
|
||||
return null;
|
||||
}
|
||||
throw new TemplateException(buildMethodNotFoundSignature("Method not found: " + target.getClass().getName() + ".", methodName, argValues), location);
|
||||
throw new TemplateException(buildMethodNotFoundSignature("public method not found: " + target.getClass().getName() + ".", methodName, argValues), location);
|
||||
}
|
||||
|
||||
try {
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -87,6 +87,9 @@ public abstract class MethodKeyBuilder {
|
||||
if (type != null) {
|
||||
hash ^= type.getName().hashCode();
|
||||
hash *= HashKit.FNV_PRIME_64;
|
||||
} else {
|
||||
hash ^= "null".hashCode();
|
||||
hash *= HashKit.FNV_PRIME_64;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -110,6 +113,8 @@ public abstract class MethodKeyBuilder {
|
||||
Class<?> type = argTypes[i];
|
||||
if (type != null) {
|
||||
hash = fnv1a64(hash, type.getName());
|
||||
} else {
|
||||
hash = fnv1a64(hash, "null");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -156,6 +156,9 @@ public class SharedMethodKit {
|
||||
if (type != null) {
|
||||
hash ^= type.getName().hashCode();
|
||||
hash *= HashKit.FNV_PRIME_64;
|
||||
} else {
|
||||
hash ^= "null".hashCode();
|
||||
hash *= HashKit.FNV_PRIME_64;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -83,6 +83,51 @@ public class Unary extends Expr {
|
||||
throw new TemplateException("Unsupported operator: " + op.value(), location);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 如果可能的话,将 Unary 表达式转化成 Const 表达式,类似于 ExprParser.buildMapEntry() 需要这种转化来简化实现
|
||||
* 除了可简化程序外,还起到一定的性能优化作用
|
||||
*
|
||||
* Number : +123 -456 +3.14 -0.12
|
||||
* Boolean : !true !false
|
||||
*
|
||||
* 特别注意:
|
||||
* Boolean 的支持并不需要,!true、!false 已在 ExprParser 中被 Logic 表达式接管,在此仅为逻辑上的完备性而添加
|
||||
*/
|
||||
public Expr toConstIfPossible() {
|
||||
if (expr instanceof Const && (op == Sym.SUB || op == Sym.ADD || op == Sym.NOT)) {
|
||||
} else {
|
||||
return this;
|
||||
}
|
||||
|
||||
Expr ret = this;
|
||||
Const c = (Const)expr;
|
||||
if (op == Sym.SUB) {
|
||||
if (c.isInt()) {
|
||||
ret = new Const(Sym.INT, -c.getInt());
|
||||
} else if (c.isLong()) {
|
||||
ret = new Const(Sym.LONG, -c.getLong());
|
||||
} else if (c.isFloat()) {
|
||||
ret = new Const(Sym.FLOAT, -c.getFloat());
|
||||
} else if (c.isDouble()) {
|
||||
ret = new Const(Sym.DOUBLE, -c.getDouble());
|
||||
}
|
||||
} else if (op == Sym.ADD) {
|
||||
if (c.isNumber()) {
|
||||
ret = c;
|
||||
}
|
||||
} else if (op == Sym.NOT) {
|
||||
if (c.isBoolean()) {
|
||||
ret = c.isTrue() ? Const.FALSE : Const.TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return op.toString() + expr.toString();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -32,7 +32,7 @@ import com.jfinal.template.stat.Scope;
|
||||
*/
|
||||
public class NowDirective extends Directive {
|
||||
|
||||
public void setExrpList(ExprList exprList) {
|
||||
public void setExprList(ExprList exprList) {
|
||||
if (exprList.length() > 1) {
|
||||
throw new ParseException("#now directive support one parameter only", location);
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,22 +16,29 @@
|
||||
|
||||
package com.jfinal.template.ext.directive;
|
||||
|
||||
import java.io.IOException;
|
||||
import com.jfinal.template.Directive;
|
||||
import com.jfinal.template.Env;
|
||||
import com.jfinal.template.TemplateException;
|
||||
import com.jfinal.template.io.Writer;
|
||||
import com.jfinal.template.stat.Scope;
|
||||
|
||||
/**
|
||||
* 输出随机数
|
||||
* 输出 int 型随机数
|
||||
*/
|
||||
public class RandomDirective extends Directive {
|
||||
|
||||
private java.util.Random random = new java.util.Random();
|
||||
|
||||
public void exec(Env env, Scope scope, Writer writer) {
|
||||
write(writer, String.valueOf(random.nextInt()));
|
||||
try {
|
||||
writer.write(random.nextInt());
|
||||
} catch (IOException e) {
|
||||
throw new TemplateException(e.getMessage(), location, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -70,7 +70,7 @@ public class RenderDirective extends Directive {
|
||||
if (len > 1) {
|
||||
for (int i = 1; i < len; i++) {
|
||||
if (!(exprList.getExpr(i) instanceof Assign)) {
|
||||
throw new ParseException("The " + i + "th parameter of #render directive must be an assignment expression", location);
|
||||
throw new ParseException("The " + (i + 1) + "th parameter of #render directive must be an assignment expression", location);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -43,6 +43,14 @@ public class ByteExt {
|
||||
public Double toDouble(Byte self) {
|
||||
return self.doubleValue();
|
||||
}
|
||||
|
||||
public Short toShort(Byte self) {
|
||||
return self.shortValue();
|
||||
}
|
||||
|
||||
public Byte toByte(Byte self) {
|
||||
return self;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -43,6 +43,14 @@ public class DoubleExt {
|
||||
public Double toDouble(Double self) {
|
||||
return self;
|
||||
}
|
||||
|
||||
public Short toShort(Double self) {
|
||||
return self.shortValue();
|
||||
}
|
||||
|
||||
public Byte toByte(Double self) {
|
||||
return self.byteValue();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -43,6 +43,14 @@ public class FloatExt {
|
||||
public Double toDouble(Float self) {
|
||||
return self.doubleValue();
|
||||
}
|
||||
|
||||
public Short toShort(Float self) {
|
||||
return self.shortValue();
|
||||
}
|
||||
|
||||
public Byte toByte(Float self) {
|
||||
return self.byteValue();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -63,6 +63,14 @@ public class IntegerExt {
|
||||
public Double toDouble(Integer self) {
|
||||
return self.doubleValue();
|
||||
}
|
||||
|
||||
public Short toShort(Integer self) {
|
||||
return self.shortValue();
|
||||
}
|
||||
|
||||
public Byte toByte(Integer self) {
|
||||
return self.byteValue();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -43,6 +43,14 @@ public class LongExt {
|
||||
public Double toDouble(Long self) {
|
||||
return self.doubleValue();
|
||||
}
|
||||
|
||||
public Short toShort(Long self) {
|
||||
return self.shortValue();
|
||||
}
|
||||
|
||||
public Byte toByte(Long self) {
|
||||
return self.byteValue();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -43,6 +43,14 @@ public class ShortExt {
|
||||
public Double toDouble(Short self) {
|
||||
return self.doubleValue();
|
||||
}
|
||||
|
||||
public Short toShort(Short self) {
|
||||
return self;
|
||||
}
|
||||
|
||||
public Byte toByte(Short self) {
|
||||
return self.byteValue();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -79,6 +79,14 @@ public class StringExt {
|
||||
public Double toDouble(String self) {
|
||||
return StrKit.isBlank(self) ? null : Double.parseDouble(self);
|
||||
}
|
||||
|
||||
public Short toShort(String self) {
|
||||
return StrKit.isBlank(self) ? null : Short.parseShort(self);
|
||||
}
|
||||
|
||||
public Byte toByte(String self) {
|
||||
return StrKit.isBlank(self) ? null : Byte.parseByte(self);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -59,101 +59,105 @@ public class JFinalView extends AbstractTemplateView {
|
||||
OutputStream os = response.getOutputStream();
|
||||
JFinalViewResolver.engine.getTemplate(getUrl()).render(model, os);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings({"unchecked", "rawtypes", "deprecation"})
|
||||
class InnerSession extends HashMap<Object, Object> implements HttpSession {
|
||||
@SuppressWarnings({"unchecked", "rawtypes", "deprecation"})
|
||||
public static class InnerSession extends HashMap<Object, Object> implements HttpSession {
|
||||
|
||||
private static final long serialVersionUID = -8679493647540628009L;
|
||||
private HttpSession session;
|
||||
private static final long serialVersionUID = -8679493647540628009L;
|
||||
private HttpSession session;
|
||||
|
||||
public InnerSession(HttpSession session) {
|
||||
this.session = session;
|
||||
}
|
||||
public InnerSession(HttpSession session) {
|
||||
this.session = session;
|
||||
}
|
||||
|
||||
// HashMap 相关方法处理 ----------------------------------------------------
|
||||
/**
|
||||
* 覆盖 HashMap 的 put
|
||||
*/
|
||||
public Object put(Object name, Object value) {
|
||||
session.setAttribute((String)name, value);
|
||||
return null;
|
||||
}
|
||||
// HashMap 相关方法处理 ----------------------------------------------------
|
||||
/**
|
||||
* 覆盖 HashMap 的 put
|
||||
*/
|
||||
public Object put(Object name, Object value) {
|
||||
session.setAttribute((String)name, value);
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 覆盖 HashMap 的 get
|
||||
*/
|
||||
public Object get(Object name) {
|
||||
return session.getAttribute((String)name);
|
||||
}
|
||||
/**
|
||||
* 覆盖 HashMap 的 get
|
||||
*/
|
||||
public Object get(Object name) {
|
||||
return session.getAttribute((String)name);
|
||||
}
|
||||
|
||||
// Session 相关方法处理 ----------------------------------------------------
|
||||
public Object getAttribute(String key) {
|
||||
return session.getAttribute(key);
|
||||
}
|
||||
// Session 相关方法处理 ----------------------------------------------------
|
||||
public Object getAttribute(String key) {
|
||||
return session.getAttribute(key);
|
||||
}
|
||||
|
||||
public Enumeration getAttributeNames() {
|
||||
return session.getAttributeNames();
|
||||
}
|
||||
public Enumeration getAttributeNames() {
|
||||
return session.getAttributeNames();
|
||||
}
|
||||
|
||||
public long getCreationTime() {
|
||||
return session.getCreationTime();
|
||||
}
|
||||
public long getCreationTime() {
|
||||
return session.getCreationTime();
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return session.getId();
|
||||
}
|
||||
public String getId() {
|
||||
return session.getId();
|
||||
}
|
||||
|
||||
public long getLastAccessedTime() {
|
||||
return session.getLastAccessedTime();
|
||||
}
|
||||
public long getLastAccessedTime() {
|
||||
return session.getLastAccessedTime();
|
||||
}
|
||||
|
||||
public int getMaxInactiveInterval() {
|
||||
return session.getMaxInactiveInterval();
|
||||
}
|
||||
public int getMaxInactiveInterval() {
|
||||
return session.getMaxInactiveInterval();
|
||||
}
|
||||
|
||||
public ServletContext getServletContext() {
|
||||
return session.getServletContext();
|
||||
}
|
||||
public ServletContext getServletContext() {
|
||||
return session.getServletContext();
|
||||
}
|
||||
|
||||
public javax.servlet.http.HttpSessionContext getSessionContext() {
|
||||
return session.getSessionContext();
|
||||
}
|
||||
public javax.servlet.http.HttpSessionContext getSessionContext() {
|
||||
return session.getSessionContext();
|
||||
}
|
||||
|
||||
public Object getValue(String key) {
|
||||
return session.getValue(key);
|
||||
}
|
||||
public Object getValue(String key) {
|
||||
return session.getValue(key);
|
||||
}
|
||||
|
||||
public String[] getValueNames() {
|
||||
return session.getValueNames();
|
||||
}
|
||||
public String[] getValueNames() {
|
||||
return session.getValueNames();
|
||||
}
|
||||
|
||||
public void invalidate() {
|
||||
session.invalidate();
|
||||
}
|
||||
public void invalidate() {
|
||||
session.invalidate();
|
||||
}
|
||||
|
||||
public boolean isNew() {
|
||||
return session.isNew();
|
||||
}
|
||||
public boolean isNew() {
|
||||
return session.isNew();
|
||||
}
|
||||
|
||||
public void putValue(String key, Object value) {
|
||||
session.putValue(key, value);
|
||||
}
|
||||
public void putValue(String key, Object value) {
|
||||
session.putValue(key, value);
|
||||
}
|
||||
|
||||
public void removeAttribute(String key) {
|
||||
session.removeAttribute(key);
|
||||
}
|
||||
public void removeAttribute(String key) {
|
||||
session.removeAttribute(key);
|
||||
}
|
||||
|
||||
public void removeValue(String key) {
|
||||
session.removeValue(key);
|
||||
}
|
||||
public void removeValue(String key) {
|
||||
session.removeValue(key);
|
||||
}
|
||||
|
||||
public void setAttribute(String key, Object value) {
|
||||
session.setAttribute(key, value);
|
||||
}
|
||||
public void setAttribute(String key, Object value) {
|
||||
session.setAttribute(key, value);
|
||||
}
|
||||
|
||||
public void setMaxInactiveInterval(int maxInactiveInterval) {
|
||||
session.setMaxInactiveInterval(maxInactiveInterval);
|
||||
public void setMaxInactiveInterval(int maxInactiveInterval) {
|
||||
session.setMaxInactiveInterval(maxInactiveInterval);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return session != null ? session.toString() : "null";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -162,4 +166,3 @@ class InnerSession extends HashMap<Object, Object> implements HttpSession {
|
||||
|
||||
|
||||
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -77,6 +77,9 @@ public class FileSource implements ISource {
|
||||
}
|
||||
|
||||
private String buildFinalFileName(String baseTemplatePath, String fileName) {
|
||||
if (baseTemplatePath == null) {
|
||||
return fileName;
|
||||
}
|
||||
char firstChar = fileName.charAt(0);
|
||||
String finalFileName;
|
||||
if (firstChar == '/' || firstChar == '\\') {
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2017, James Zhan 詹波 (jfinal@126.com).
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user