16 Commits

Author SHA1 Message Date
James
1aef12eb94 [maven-release-plugin] prepare release enjoy-3.4 2018-04-27 12:18:43 +08:00
James
6f615bc1a8 enjoy 3.4 release ^_^ 2018-04-25 22:10:00 +08:00
James
0c3e7790b7 enjoy 3.4 release ^_^ 2018-04-25 22:09:05 +08:00
James
a1e88a4a4c enjoy 3.4 2018-04-02 19:14:24 +08:00
James
d12d3d8abb jfinal 3.4 2018-04-02 14:15:59 +08:00
James
ef7b0da917 enjoy 3.4 2018-04-01 16:29:13 +08:00
James
2ed806c296 enjoy 3.4 2018-03-30 17:06:02 +08:00
James
998df7b907 enjoy 3.4 2018-03-30 02:51:56 +08:00
James
3e93fc970e jfinal enjoy 3.4 2018-03-02 23:41:05 +08:00
James
010a7f3d8a [maven-release-plugin] prepare for next development iteration 2017-12-25 11:47:53 +08:00
James
99f024f546 [maven-release-plugin] prepare release enjoy-3.4 2017-12-25 11:47:51 +08:00
James
ca3361703e enjoy 3.4 2017-12-24 23:37:35 +08:00
James
1840d49e0a [maven-release-plugin] prepare for next development iteration 2017-12-24 22:46:28 +08:00
James
70d1e5a9eb [maven-release-plugin] prepare release enjoy-3.4 2017-12-24 22:46:25 +08:00
James
e0abc218b1 Map 定义初始化表达式,添加支持 key 可以为 int、long、float、double、true、false、null 常量 2017-12-10 19:40:40 +08:00
James
bd1949fc56 [maven-release-plugin] prepare for next development iteration 2017-11-21 23:14:12 +08:00
119 changed files with 668 additions and 491 deletions

View File

@@ -189,3 +189,4 @@ third-party archives.
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.

View File

@@ -40,3 +40,4 @@ read me 正在补充,详细使用文档请下载 jfinal.com 官网的 jfinal

10
pom.xml
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.3</version> <version>3.4</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>
@@ -15,7 +15,7 @@
<issueManagement> <issueManagement>
<system>Git Issue</system> <system>Git Issue</system>
<url>http://git.oschina.net/jfinal/enjoy/issues</url> <url>https://gitee.com/jfinal/enjoy/issues</url>
</issueManagement> </issueManagement>
<licenses> <licenses>
<license> <license>
@@ -32,9 +32,9 @@
</developer> </developer>
</developers> </developers>
<scm> <scm>
<connection>scm:git:git@git.oschina.net:jfinal/enjoy.git</connection> <connection>scm:git:git@gitee.com:jfinal/enjoy.git</connection>
<developerConnection>scm:git:git@git.oschina.net:jfinal/enjoy.git</developerConnection> <developerConnection>scm:git:git@gitee.com:jfinal/enjoy.git</developerConnection>
<url>git@git.oschina.net:jfinal/enjoy.git</url> <url>git@gitee.com:jfinal/enjoy.git</url>
</scm> </scm>
<parent> <parent>

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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); engine.addDirective("eval", InnerEvalDirective.class);
} }
public Engine getEngine() { public static Engine getEngine() {
return engine; return engine;
} }

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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.HashKit;
import com.jfinal.kit.StrKit; import com.jfinal.kit.StrKit;
import com.jfinal.template.expr.ast.MethodKit; import com.jfinal.template.expr.ast.MethodKit;
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;
import com.jfinal.template.source.StringSource; import com.jfinal.template.source.StringSource;
@@ -161,6 +162,13 @@ public class Engine {
/** /**
* Get template by string content and do not cache the template * 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 * 重要StringSource 中的 key = HashKit.md5(content),也即 key
* 与 content 有紧密的对应关系,当 content 发生变化时 key 值也相应变化 * 与 content 有紧密的对应关系,当 content 发生变化时 key 值也相应变化
@@ -169,13 +177,7 @@ public class Engine {
* *
* 当 getTemplateByString(String, boolean) 中的 String 参数的 * 当 getTemplateByString(String, boolean) 中的 String 参数的
* 数量可控并且确定时,才可对其使用缓存 * 数量可控并且确定时,才可对其使用缓存
*/ *
public Template getTemplateByString(String content) {
return getTemplateByString(content, false);
}
/**
* Get template by string content
* @param content 模板内容 * @param content 模板内容
* @param cache true 则缓存 Template否则不缓存 * @param cache true 则缓存 Template否则不缓存
*/ */
@@ -426,6 +428,13 @@ public class Engine {
return this; return this;
} }
/**
* 设置为 ClassPathSourceFactory 的快捷方法
*/
public Engine setToClassPathSourceFactory() {
return setSourceFactory(new ClassPathSourceFactory());
}
public ISourceFactory getSourceFactory() { public ISourceFactory getSourceFactory() {
return sourceFactory; return sourceFactory;
} }

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -16,6 +16,10 @@
package com.jfinal.template; 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.OutputStream;
import java.io.Writer; import java.io.Writer;
import java.util.Map; import java.util.Map;
@@ -108,6 +112,32 @@ public class Template {
return fsw.getBuffer(); 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() { public boolean isModified() {
return env.isSourceListModified(); return env.isSourceListModified();
} }

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -292,7 +292,7 @@ public class ExprParser {
case ADD: case ADD:
case SUB: case SUB:
move(); move();
return new Unary(tok.sym, unary(), location); return new Unary(tok.sym, unary(), location).toConstIfPossible();
case INC: case INC:
case DEC: case DEC:
move(); 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) { void buildMapEntry(LinkedHashMap<Object, Expr> map) {
Tok tok = peek(); Expr keyExpr = expr();
if (tok.sym == Sym.ID || tok.sym == Sym.STR) { Object key;
move(); 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);
}
match(Sym.COLON); match(Sym.COLON);
Expr value = expr(); Expr value = expr();
if (value == null) { if (value == null) {
throw new ParseException("Expression error: the value on the right side of map entry can not be blank", location); throw new ParseException("Expression error: the value on the right side of map entry can not be blank", location);
} }
map.put(tok.value(), value); map.put(key, value);
return ;
}
throw new ParseException("Expression error: the value of map key must be identifier or String", location);
} }
/** /**
@@ -528,12 +533,14 @@ public class ExprParser {
move(); move();
return new Id(tok.value()); return new Id(tok.value());
case STR: case STR:
move();
return new Const(tok.sym, tok.value());
case INT: case INT:
case LONG: case LONG:
case FLOAT: case FLOAT:
case DOUBLE: case DOUBLE:
move(); move();
return new Const(tok.sym, tok.value()); return new Const(tok.sym, ((NumTok)tok).getNumberValue());
case TRUE: case TRUE:
move(); move();
return Const.TRUE; return Const.TRUE;

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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 { public class NumTok extends Tok {
private Object value; private Number value;
NumTok(Sym sym, String s, int radix, boolean isScientificNotation, Location location) { NumTok(Sym sym, String s, int radix, boolean isScientificNotation, Location location) {
super(sym, location.getRow()); super(sym, location.getRow());
@@ -101,3 +101,8 @@ public class NumTok extends Tok {
return sym.value() + " : " + value; return sym.value() + " : " + value;
} }
} }

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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; 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 class Const extends Expr {
public static final Const TRUE = new Const(Boolean.TRUE, Sym.TRUE); public static final Const TRUE = new Const(Sym.TRUE, Boolean.TRUE);
public static final Const FALSE = new Const(Boolean.FALSE, Sym.FALSE); public static final Const FALSE = new Const(Sym.FALSE, Boolean.FALSE);
public static final Const NULL = new Const(null, Sym.NULL); public static final Const NULL = new Const(Sym.NULL, null);
private Sym type; private final Sym type;
private Object value; 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.type = type;
this.value = value; 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) { public Object eval(Scope scope) {
return value; return value;
} }
@@ -108,6 +79,10 @@ public class Const extends Expr {
return type == Sym.DOUBLE; return type == Sym.DOUBLE;
} }
public boolean isNumber() {
return value instanceof Number;
}
public Object getValue() { public Object getValue() {
return value; return value;
} }
@@ -136,6 +111,10 @@ public class Const extends Expr {
return (Double)value; return (Double)value;
} }
public Number getNumber() {
return (Number)value;
}
public String toString() { public String toString() {
return value != null ? value.toString() : "null"; return value != null ? value.toString() : "null";
} }

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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) { if (expr instanceof Id) {
String id = ((Id)expr).getId(); 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) { private Long buildFieldKey(Class<?> targetClass) {

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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 { public class Id extends Expr {
private String id; private final String id;
public Id(String id) { public Id(String id) {
this.id = id; this.id = id;

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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") @SuppressWarnings("rawtypes")
public Object eval(Scope scope) { public Object eval(Scope scope) {
Object array = expr.eval(scope); Object target = expr.eval(scope);
if (array == null) { if (target == null) {
if (scope.getCtrl().isNullSafe()) { if (scope.getCtrl().isNullSafe()) {
return null; return null;
} }
@@ -56,25 +56,30 @@ public class Index extends Expr {
if (scope.getCtrl().isNullSafe()) { if (scope.getCtrl().isNullSafe()) {
return null; return null;
} }
throw new TemplateException("The index of list/array and the key of map can not be null", location);
if (target instanceof java.util.Map) {
// Map 的 key 可以是 null不能抛异常
} else {
throw new TemplateException("The index of list and array can not be null", location);
}
} }
if (array instanceof List) { if (target instanceof List) {
if (idx instanceof Integer) { if (idx instanceof Integer) {
return ((List<?>)array).get((Integer)idx); return ((List<?>)target).get((Integer)idx);
} }
throw new TemplateException("The index of list can only be integer", location); throw new TemplateException("The index of list must be integer", location);
} }
if (array instanceof java.util.Map) { if (target instanceof java.util.Map) {
return ((java.util.Map)array).get(idx); return ((java.util.Map)target).get(idx);
} }
if (array.getClass().isArray()) { if (target.getClass().isArray()) {
if (idx instanceof Integer) { if (idx instanceof Integer) {
return java.lang.reflect.Array.get(array, (Integer)idx); return java.lang.reflect.Array.get(target, (Integer)idx);
} }
throw new TemplateException("The index of array can only be integer", location); 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); throw new TemplateException("Only the list array and map is supported by index access", location);

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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 * Map
* *
* 1定义 map 常量 * 1定义 map 常量
* {k1:123, k2:"abc", 'k3':true, "k4":[1,2,3], k5:1+2} * {k1:123, k2:"abc", 'k3':true, "k4":[1,2,3], k5:1+2, 1:12, true:"Y", null:"abc"}
* 如上所示map定义的 key 可以为 String 或者 id 标识符,而右侧的 value 可以是任意的常量与表达式 * 如上所示map定义的 key 可以为 id 标识符或者 String、Integer、Long、Boolean、null
* 等常量值 (详见 ExprParser.buildMapEntry(...) 方法)
* 右侧的 value 可以是任意的常量与表达式
* *
* 2取值 * 2取值
* 先将 Map 常量赋值给某个变量: #set(map = {...}) * 先将 Map 常量赋值给某个变量: #set(map = {...})
@@ -35,6 +37,10 @@ import com.jfinal.template.stat.Scope;
* map.get("k1") * map.get("k1")
* map.k1 * map.k1
* *
* 3不通过中间变量取值
* {1:'自买', 2:'跟买'}.get(1)
* {1:'自买', 2:'跟买'}[2]
*
* 如上所示,当以下标方式取值时,下标参数可以是 string 与 expr而 expr 求值以后的值必须也为 string类型 * 如上所示,当以下标方式取值时,下标参数可以是 string 与 expr而 expr 求值以后的值必须也为 string类型
* 当用 map.k1 这类 field 字段取值形式时,则是使用 id 标识符,而不是 string 形参数 * 当用 map.k1 这类 field 字段取值形式时,则是使用 id 标识符,而不是 string 形参数
* *

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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()) { if (scope.getCtrl().isNullSafe()) {
return null; 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 { try {

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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) { if (type != null) {
hash ^= type.getName().hashCode(); hash ^= type.getName().hashCode();
hash *= HashKit.FNV_PRIME_64; 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]; Class<?> type = argTypes[i];
if (type != null) { if (type != null) {
hash = fnv1a64(hash, type.getName()); hash = fnv1a64(hash, type.getName());
} else {
hash = fnv1a64(hash, "null");
} }
} }
} }

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -156,6 +156,9 @@ public class SharedMethodKit {
if (type != null) { if (type != null) {
hash ^= type.getName().hashCode(); hash ^= type.getName().hashCode();
hash *= HashKit.FNV_PRIME_64; hash *= HashKit.FNV_PRIME_64;
} else {
hash ^= "null".hashCode();
hash *= HashKit.FNV_PRIME_64;
} }
} }
} }

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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); 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();
}
} }

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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 class NowDirective extends Directive {
public void setExrpList(ExprList exprList) { public void setExprList(ExprList exprList) {
if (exprList.length() > 1) { if (exprList.length() > 1) {
throw new ParseException("#now directive support one parameter only", location); throw new ParseException("#now directive support one parameter only", location);
} }

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -16,22 +16,29 @@
package com.jfinal.template.ext.directive; package com.jfinal.template.ext.directive;
import java.io.IOException;
import com.jfinal.template.Directive; import com.jfinal.template.Directive;
import com.jfinal.template.Env; import com.jfinal.template.Env;
import com.jfinal.template.TemplateException;
import com.jfinal.template.io.Writer; import com.jfinal.template.io.Writer;
import com.jfinal.template.stat.Scope; import com.jfinal.template.stat.Scope;
/** /**
* 输出随机数 * 输出 int 型随机数
*/ */
public class RandomDirective extends Directive { public class RandomDirective extends Directive {
private java.util.Random random = new java.util.Random(); private java.util.Random random = new java.util.Random();
public void exec(Env env, Scope scope, Writer writer) { 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);
}
} }
} }

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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) { if (len > 1) {
for (int i = 1; i < len; i++) { for (int i = 1; i < len; i++) {
if (!(exprList.getExpr(i) instanceof Assign)) { 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);
} }
} }
} }

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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) { public Double toDouble(Byte self) {
return self.doubleValue(); return self.doubleValue();
} }
public Short toShort(Byte self) {
return self.shortValue();
}
public Byte toByte(Byte self) {
return self;
}
} }

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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) { public Double toDouble(Double self) {
return self; return self;
} }
public Short toShort(Double self) {
return self.shortValue();
}
public Byte toByte(Double self) {
return self.byteValue();
}
} }

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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) { public Double toDouble(Float self) {
return self.doubleValue(); return self.doubleValue();
} }
public Short toShort(Float self) {
return self.shortValue();
}
public Byte toByte(Float self) {
return self.byteValue();
}
} }

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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) { public Double toDouble(Integer self) {
return self.doubleValue(); return self.doubleValue();
} }
public Short toShort(Integer self) {
return self.shortValue();
}
public Byte toByte(Integer self) {
return self.byteValue();
}
} }

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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) { public Double toDouble(Long self) {
return self.doubleValue(); return self.doubleValue();
} }
public Short toShort(Long self) {
return self.shortValue();
}
public Byte toByte(Long self) {
return self.byteValue();
}
} }

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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) { public Double toDouble(Short self) {
return self.doubleValue(); return self.doubleValue();
} }
public Short toShort(Short self) {
return self;
}
public Byte toByte(Short self) {
return self.byteValue();
}
} }

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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) { public Double toDouble(String self) {
return StrKit.isBlank(self) ? null : Double.parseDouble(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);
}
} }

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -59,10 +59,9 @@ public class JFinalView extends AbstractTemplateView {
OutputStream os = response.getOutputStream(); OutputStream os = response.getOutputStream();
JFinalViewResolver.engine.getTemplate(getUrl()).render(model, os); JFinalViewResolver.engine.getTemplate(getUrl()).render(model, os);
} }
}
@SuppressWarnings({"unchecked", "rawtypes", "deprecation"}) @SuppressWarnings({"unchecked", "rawtypes", "deprecation"})
class InnerSession extends HashMap<Object, Object> implements HttpSession { public static class InnerSession extends HashMap<Object, Object> implements HttpSession {
private static final long serialVersionUID = -8679493647540628009L; private static final long serialVersionUID = -8679493647540628009L;
private HttpSession session; private HttpSession session;
@@ -155,6 +154,11 @@ class InnerSession extends HashMap<Object, Object> implements HttpSession {
public void setMaxInactiveInterval(int maxInactiveInterval) { public void setMaxInactiveInterval(int maxInactiveInterval) {
session.setMaxInactiveInterval(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 {

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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) { private String buildFinalFileName(String baseTemplatePath, String fileName) {
if (baseTemplatePath == null) {
return fileName;
}
char firstChar = fileName.charAt(0); char firstChar = fileName.charAt(0);
String finalFileName; String finalFileName;
if (firstChar == '/' || firstChar == '\\') { if (firstChar == '/' || firstChar == '\\') {

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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