浏览代码

prepare jfinal 1.5

JamesZhan 12 年之前
父节点
当前提交
cda9fe990c

+ 13 - 24
src/com/jfinal/core/ActionHandler.java

@@ -99,34 +99,23 @@ final class ActionHandler extends Handler {
 		}
 		catch (ActionException e) {
 			int errorCode = e.getErrorCode();
-			if (errorCode == 404) {
-				if (log.isWarnEnabled()) {
-					String qs = request.getQueryString();
-					log.warn("404 Not Found: " + (qs == null ? target : target + "?" + qs));
-				}
-				e.getErrorRender().setContext(request, response).render();
+			if (errorCode == 404 && log.isWarnEnabled()) {
+				String qs = request.getQueryString();
+				log.warn("404 Not Found: " + (qs == null ? target : target + "?" + qs));
 			}
-			else if (errorCode == 401) {
-				if (log.isWarnEnabled()) {
-					String qs = request.getQueryString();
-					log.warn("401 Unauthorized: " + (qs == null ? target : target + "?" + qs));
-				}
-				e.getErrorRender().setContext(request, response).render();
+			else if (errorCode == 401 && log.isWarnEnabled()) {
+				String qs = request.getQueryString();
+				log.warn("401 Unauthorized: " + (qs == null ? target : target + "?" + qs));
 			}
-			else if (errorCode == 403) {
-				if (log.isWarnEnabled()) {
-					String qs = request.getQueryString();
-					log.warn("403 Forbidden: " + (qs == null ? target : target + "?" + qs));
-				}
-				e.getErrorRender().setContext(request, response).render();
+			else if (errorCode == 403 && log.isWarnEnabled()) {
+				String qs = request.getQueryString();
+				log.warn("403 Forbidden: " + (qs == null ? target : target + "?" + qs));
 			}
-			else {
-				if (log.isErrorEnabled()) {
-					String qs = request.getQueryString();
-					log.error(qs == null ? target : target + "?" + qs, e);
-				}
-				e.getErrorRender().setContext(request, response).render();
+			else if (log.isErrorEnabled()) {
+				String qs = request.getQueryString();
+				log.error(qs == null ? target : target + "?" + qs, e);
 			}
+			e.getErrorRender().setContext(request, response).render();
 		}
 		catch (Exception e) {
 			if (log.isErrorEnabled()) {

+ 1 - 1
src/com/jfinal/core/Const.java

@@ -24,7 +24,7 @@ import com.jfinal.render.ViewType;
  */
 public interface Const {
 	
-	String JFINAL_VERSION = "1.4";
+	String JFINAL_VERSION = "1.5";
 	
 	ViewType DEFAULT_VIEW_TYPE = ViewType.FREE_MARKER;
 	

+ 2 - 2
src/com/jfinal/core/Controller.java

@@ -204,7 +204,7 @@ public abstract class Controller {
 	}
 	
 	private Integer toInt(String value, Integer defaultValue) {
-		if (value == null)
+		if (value == null || "".equals(value.trim()))
 			return defaultValue;
 		if (value.startsWith("N") || value.startsWith("n"))
 			return -Integer.parseInt(value.substring(1));
@@ -230,7 +230,7 @@ public abstract class Controller {
 	}
 	
 	private Long toLong(String value, Long defaultValue) {
-		if (value == null)
+		if (value == null || "".equals(value.trim()))
 			return defaultValue;
 		if (value.startsWith("N") || value.startsWith("n"))
 			return -Long.parseLong(value.substring(1));

+ 3 - 5
src/com/jfinal/plugin/ehcache/EvictInterceptor.java

@@ -18,7 +18,6 @@ package com.jfinal.plugin.ehcache;
 
 import com.jfinal.aop.Interceptor;
 import com.jfinal.core.ActionInvocation;
-import com.jfinal.core.Controller;
 
 /**
  * EvictInterceptor.
@@ -28,16 +27,15 @@ public class EvictInterceptor implements Interceptor {
 	final public void intercept(ActionInvocation ai) {
 		ai.invoke();
 		
-		String cacheName = buildCacheName(ai, ai.getController());
-		CacheKit.removeAll(cacheName);
+		CacheKit.removeAll(buildCacheName(ai));
 	}
 	
-	private String buildCacheName(ActionInvocation ai, Controller controller) {
+	private String buildCacheName(ActionInvocation ai) {
 		CacheName cacheName = ai.getMethod().getAnnotation(CacheName.class);
 		if (cacheName != null)
 			return cacheName.value();
 		
-		cacheName = controller.getClass().getAnnotation(CacheName.class);
+		cacheName = ai.getController().getClass().getAnnotation(CacheName.class);
 		if (cacheName == null)
 			throw new RuntimeException("EvictInterceptor need CacheName annotation in controller.");
 		return cacheName.value();

+ 15 - 0
src/com/jfinal/validate/Validator.java

@@ -16,6 +16,7 @@
 
 package com.jfinal.validate;
 
+import java.lang.reflect.Method;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.text.ParseException;
@@ -99,6 +100,20 @@ public abstract class Validator implements Interceptor {
 	}
 	
 	/**
+	 * Return the method of this action.
+	 */
+	protected Method getActionMethod() {
+		return invocation.getMethod();
+	}
+	
+	/**
+	 * Return view path of this controller.
+	 */
+	protected String getViewPath() {
+		return invocation.getViewPath();
+	}
+	
+	/**
 	 * Validate Required.
 	 */
 	protected void validateRequired(String field, String errorKey, String errorMessage) {