Browse Source

Merge branch 'master' into jfinal-java8

James 8 years ago
parent
commit
5cfe7ad3cc

+ 2 - 2
pom.xml

@@ -60,8 +60,8 @@
 		</dependency>
 		</dependency>
 		<!-- dependency>
 		<!-- dependency>
 			<groupId>javax.servlet</groupId>
 			<groupId>javax.servlet</groupId>
-			<artifactId>servlet-api</artifactId>
-			<version>2.5</version>
+			<artifactId>javax.servlet-api</artifactId>
+			<version>3.1.0</version>
 			<scope>provided</scope>
 			<scope>provided</scope>
 		</dependency -->
 		</dependency -->
 		<!-- jsp support by jetty -->
 		<!-- jsp support by jetty -->

+ 4 - 4
src/main/java/com/jfinal/core/Controller.java

@@ -241,7 +241,7 @@ public abstract class Controller {
 			return Integer.parseInt(value);
 			return Integer.parseInt(value);
 		}
 		}
 		catch (Exception e) {
 		catch (Exception e) {
-			throw new ActionException(404, renderManager.getRenderFactory().getErrorRender(404),  "Can not parse the parameter \"" + value + "\" to Integer value.");
+			throw new ActionException(400, renderManager.getRenderFactory().getErrorRender(400),  "Can not parse the parameter \"" + value + "\" to Integer value.");
 		}
 		}
 	}
 	}
 	
 	
@@ -273,7 +273,7 @@ public abstract class Controller {
 			return Long.parseLong(value);
 			return Long.parseLong(value);
 		}
 		}
 		catch (Exception e) {
 		catch (Exception e) {
-			throw new ActionException(404, renderManager.getRenderFactory().getErrorRender(404),  "Can not parse the parameter \"" + value + "\" to Long value.");
+			throw new ActionException(400, renderManager.getRenderFactory().getErrorRender(400),  "Can not parse the parameter \"" + value + "\" to Long value.");
 		}
 		}
 	}
 	}
 	
 	
@@ -303,7 +303,7 @@ public abstract class Controller {
 			return Boolean.TRUE;
 			return Boolean.TRUE;
 		else if ("0".equals(value) || "false".equals(value))
 		else if ("0".equals(value) || "false".equals(value))
 			return Boolean.FALSE;
 			return Boolean.FALSE;
-		throw new ActionException(404, renderManager.getRenderFactory().getErrorRender(404), "Can not parse the parameter \"" + value + "\" to Boolean value.");
+		throw new ActionException(400, renderManager.getRenderFactory().getErrorRender(400), "Can not parse the parameter \"" + value + "\" to Boolean value.");
 	}
 	}
 	
 	
 	/**
 	/**
@@ -351,7 +351,7 @@ public abstract class Controller {
 				return defaultValue;
 				return defaultValue;
 			return new java.text.SimpleDateFormat("yyyy-MM-dd").parse(value.trim());
 			return new java.text.SimpleDateFormat("yyyy-MM-dd").parse(value.trim());
 		} catch (Exception e) {
 		} catch (Exception e) {
-			throw new ActionException(404, renderManager.getRenderFactory().getErrorRender(404),  "Can not parse the parameter \"" + value + "\" to Date value.");
+			throw new ActionException(400, renderManager.getRenderFactory().getErrorRender(400),  "Can not parse the parameter \"" + value + "\" to Date value.");
 		}
 		}
 	}
 	}
 	
 	

+ 3 - 5
src/main/java/com/jfinal/core/JFinal.java

@@ -54,11 +54,11 @@ public final class JFinal {
 		return me;
 		return me;
 	}
 	}
 	
 	
-	boolean init(JFinalConfig jfinalConfig, ServletContext servletContext) {
+	void init(JFinalConfig jfinalConfig, ServletContext servletContext) {
 		this.servletContext = servletContext;
 		this.servletContext = servletContext;
 		this.contextPath = servletContext.getContextPath();
 		this.contextPath = servletContext.getContextPath();
 		
 		
-		initPathUtil();
+		initPathKit();
 		
 		
 		Config.configJFinal(jfinalConfig);	// start plugin, init log factory and init engine in this method
 		Config.configJFinal(jfinalConfig);	// start plugin, init log factory and init engine in this method
 		constants = Config.getConstants();
 		constants = Config.getConstants();
@@ -68,8 +68,6 @@ public final class JFinal {
 		initRender();
 		initRender();
 		initOreillyCos();
 		initOreillyCos();
 		initTokenManager();
 		initTokenManager();
-		
-		return true;
 	}
 	}
 	
 	
 	private void initTokenManager() {
 	private void initTokenManager() {
@@ -88,7 +86,7 @@ public final class JFinal {
 		OreillyCos.init(constants.getBaseUploadPath(), constants.getMaxPostSize(), constants.getEncoding());
 		OreillyCos.init(constants.getBaseUploadPath(), constants.getMaxPostSize(), constants.getEncoding());
 	}
 	}
 	
 	
-	private void initPathUtil() {
+	private void initPathKit() {
 		String path = servletContext.getRealPath("/");
 		String path = servletContext.getRealPath("/");
 		PathKit.setWebRootPath(path);
 		PathKit.setWebRootPath(path);
 	}
 	}

+ 7 - 6
src/main/java/com/jfinal/core/JFinalFilter.java

@@ -46,17 +46,16 @@ public class JFinalFilter implements Filter {
 	public void init(FilterConfig filterConfig) throws ServletException {
 	public void init(FilterConfig filterConfig) throws ServletException {
 		createJFinalConfig(filterConfig.getInitParameter("configClass"));
 		createJFinalConfig(filterConfig.getInitParameter("configClass"));
 		
 		
-		if (jfinal.init(jfinalConfig, filterConfig.getServletContext()) == false) {
-			throw new RuntimeException("JFinal init error!");
-		}
+		jfinal.init(jfinalConfig, filterConfig.getServletContext());
+		
+		String contextPath = filterConfig.getServletContext().getContextPath();
+		contextPathLength = (contextPath == null || "/".equals(contextPath) ? 0 : contextPath.length());
 		
 		
-		handler = jfinal.getHandler();
 		constants = Config.getConstants();
 		constants = Config.getConstants();
 		encoding = constants.getEncoding();
 		encoding = constants.getEncoding();
 		jfinalConfig.afterJFinalStart();
 		jfinalConfig.afterJFinalStart();
 		
 		
-		String contextPath = filterConfig.getServletContext().getContextPath();
-		contextPathLength = (contextPath == null || "/".equals(contextPath) ? 0 : contextPath.length());
+		handler = jfinal.getHandler();		// 开始接受请求
 	}
 	}
 	
 	
 	public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
 	public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
@@ -86,6 +85,8 @@ public class JFinalFilter implements Filter {
 	}
 	}
 	
 	
 	public void destroy() {
 	public void destroy() {
+		handler = null;		// 停止接受请求
+		
 		jfinalConfig.beforeJFinalStop();
 		jfinalConfig.beforeJFinalStop();
 		jfinal.stopPlugins();
 		jfinal.stopPlugins();
 	}
 	}

+ 3 - 2
src/main/java/com/jfinal/template/expr/ExprLexer.java

@@ -339,10 +339,11 @@ class ExprLexer {
 		Sym sym = null;
 		Sym sym = null;
 		if (c == '.') {							// 以 '.' 字符结尾是合法的浮点数
 		if (c == '.') {							// 以 '.' 字符结尾是合法的浮点数
 			next();
 			next();
-			if (peek() == '.') {				// 处理 [0..9] 这样的表达式
+			if (peek() == '.' ||				// 处理 [0..9] 这样的表达式
+				CharTable.isLetter(peek())) {	// 处理 123.toInt() 这样的表达式,1.2.toInt() 及 1D.toInt() 可正常处理
 				StringBuilder n = subBuf(numStart, forward - 2);
 				StringBuilder n = subBuf(numStart, forward - 2);
 				if (n == null /* && radix == 16 */) {
 				if (n == null /* && radix == 16 */) {
-					// 16 进制数格式错误,前缀 0x 后缺少 16 进制数字
+					// 16 进制数格式错误,前缀 0x 后缺少 16 进制数字(16 进制时 numStart 已增加了 2, n 为 null 必是 16 进制解析出错)
 					throw new ParseException("Error hex format", location);
 					throw new ParseException("Error hex format", location);
 				}
 				}
 				NumTok tok = new NumTok(Sym.INT, n.toString(), radix, false, location);
 				NumTok tok = new NumTok(Sym.INT, n.toString(), radix, false, location);

+ 10 - 5
src/main/java/com/jfinal/template/expr/ast/MethodKit.java

@@ -25,6 +25,11 @@ import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentHashMap;
 import com.jfinal.kit.HashKit;
 import com.jfinal.kit.HashKit;
 import com.jfinal.kit.ReflectKit;
 import com.jfinal.kit.ReflectKit;
+import com.jfinal.template.ext.extensionmethod.DoubleExt;
+import com.jfinal.template.ext.extensionmethod.FloatExt;
+import com.jfinal.template.ext.extensionmethod.IntegerExt;
+import com.jfinal.template.ext.extensionmethod.LongExt;
+import com.jfinal.template.ext.extensionmethod.StringExt;
 
 
 /**
 /**
  * MethodKit
  * MethodKit
@@ -242,11 +247,11 @@ public class MethodKit {
 	
 	
 	// 添加 jfinal 官方扩展方法 extension method
 	// 添加 jfinal 官方扩展方法 extension method
 	static {
 	static {
-		addExtensionMethod(String.class, new com.jfinal.template.ext.extensionmethod.StringExt());
-		addExtensionMethod(Integer.class, new com.jfinal.template.ext.extensionmethod.IntegerExt());
-		addExtensionMethod(Long.class, new com.jfinal.template.ext.extensionmethod.LongExt());
-		addExtensionMethod(Float.class, new com.jfinal.template.ext.extensionmethod.FloatExt());
-		addExtensionMethod(Double.class, new com.jfinal.template.ext.extensionmethod.DoubleExt());
+		addExtensionMethod(String.class, new StringExt());
+		addExtensionMethod(Integer.class, new IntegerExt());
+		addExtensionMethod(Long.class, new LongExt());
+		addExtensionMethod(Float.class, new FloatExt());
+		addExtensionMethod(Double.class, new DoubleExt());
 	}
 	}
 	
 	
 	public synchronized static void addExtensionMethod(Class<?> targetClass, Object objectOfExtensionClass) {
 	public synchronized static void addExtensionMethod(Class<?> targetClass, Object objectOfExtensionClass) {