diff --git a/framework/src/play/mvc/ActionInvoker.java b/framework/src/play/mvc/ActionInvoker.java index df3cbc35..b5596d06 100644 --- a/framework/src/play/mvc/ActionInvoker.java +++ b/framework/src/play/mvc/ActionInvoker.java @@ -130,7 +130,7 @@ public void invoke(Http.Request request, Http.Response response) { // Check the cache (only for GET or HEAD) if ((request.method.equals("GET") || request.method.equals("HEAD")) && actionMethod.isAnnotationPresent(CacheFor.class)) { cacheKey = actionMethod.getAnnotation(CacheFor.class).id(); - if ("".equals(cacheKey)) { + if (cacheKey != null && cacheKey.isEmpty()) { cacheKey = "urlcache:" + request.path + '?' + request.querystring; } actionResult = Cache.get(cacheKey); @@ -184,8 +184,8 @@ boolean actionNeedsSession(Http.Request request) { private PlayController createController(ActionContext context) { PlayController controller = Injector.getBeanOfType(context.request.controllerClass); - if (controller instanceof Controller) { - ((Controller) controller).setContext(context); + if (controller instanceof PlayContextController) { + ((PlayContextController) controller).setContext(context); } return controller; } @@ -403,7 +403,6 @@ static void handleFinallies(Http.Request request, Session session, Throwable cau } } - @SuppressWarnings("unchecked") public static void inferResult(Object o) { // Return type inference if (o != null) { @@ -468,8 +467,8 @@ public static Object[] getActionMethod(String fullAction) { if (!fullAction.startsWith("controllers.")) { fullAction = "controllers." + fullAction; } - String controller = fullAction.substring(0, fullAction.lastIndexOf(".")); - String action = fullAction.substring(fullAction.lastIndexOf(".") + 1); + String controller = fullAction.substring(0, fullAction.lastIndexOf('.')); + String action = fullAction.substring(fullAction.lastIndexOf('.') + 1); controllerClass = Play.classes.getClassIgnoreCase(controller); if (controllerClass == null) { throw new ActionNotFoundException(fullAction, new Exception("Controller " + controller + " not found")); diff --git a/framework/src/play/mvc/Controller.java b/framework/src/play/mvc/Controller.java index 0410657b..0ddc76b1 100644 --- a/framework/src/play/mvc/Controller.java +++ b/framework/src/play/mvc/Controller.java @@ -5,7 +5,7 @@ import play.mvc.results.Forbidden; import play.rebel.View; -public class Controller implements PlayController { +public class Controller implements PlayContextController { protected ActionContext actionContext; protected Http.Request request; protected Http.Response response; @@ -15,7 +15,7 @@ public class Controller implements PlayController { protected Scope.RenderArgs renderArgs; protected Validation validation; - protected void setContext(ActionContext actionContext) { + public void setContext(ActionContext actionContext) { this.actionContext = actionContext; request = actionContext.request; response = actionContext.response; diff --git a/framework/src/play/mvc/PlayContextController.java b/framework/src/play/mvc/PlayContextController.java new file mode 100644 index 00000000..93feae7c --- /dev/null +++ b/framework/src/play/mvc/PlayContextController.java @@ -0,0 +1,12 @@ +package play.mvc; + +/** + * Interface for play controllers with ActionContext provided to them by the {@link play.mvc.ActionInvoker}. + * + * This class your controllers should implement, when they need access to the {@link play.mvc.ActionContext}. + * In most cases, you can extend {@link play.mvc.Controller} which provides a basic set of features + * useful when implementing controllers. + */ +public interface PlayContextController extends PlayController { + void setContext(ActionContext actionContext); +} diff --git a/framework/src/play/mvc/PlayController.java b/framework/src/play/mvc/PlayController.java index 69d70296..0a512959 100644 --- a/framework/src/play/mvc/PlayController.java +++ b/framework/src/play/mvc/PlayController.java @@ -3,8 +3,8 @@ /** * Marker interface for play controllers * - * This is the class that your controllers should implement. - * In most cases, you can extend play.mvc.Controller that contains all needed methods for controllers. + * This is the class that your controllers should implement when they need very few capabilities.. + * In most cases, you can extend {@link play.mvc.Controller} which provides a basic set of features for controllers. */ public interface PlayController { }