1 /* 2 * Copyright 2004-2005 the original author or authors. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package org.codehaus.groovy.grails.commons; 17 18 import groovy.lang.Closure; 19 import groovy.lang.GroovyObject; 20 21 import java.util.Map; 22 import java.util.Set; 23 24 /** 25 * Represents a controller class in Grails. 26 * 27 * @author Steven Devijver 28 */ 29 public interface GrailsControllerClass extends InjectableGrailsClass { 30 31 /** 32 * The name of the index action. 33 */ 34 String INDEX_ACTION = "index"; 35 36 /** 37 * The name of the before interceptor property. 38 */ 39 String BEFORE_INTERCEPTOR = "beforeInterceptor"; 40 41 /** 42 * The name of the after interceptor property. 43 */ 44 String AFTER_INTERCEPTOR = "afterInterceptor"; 45 46 /** 47 * The general name to use when referring to controller artefacts. 48 */ 49 String CONTROLLER = "controller"; 50 51 /** 52 * The general name to use when referring to action artefacts. 53 */ 54 String ACTION = "action"; 55 56 /** 57 * The general name to use when referring to action view. 58 */ 59 String VIEW = "view"; 60 61 /** 62 * Checks to see if an action is accessible via a particular http method. 63 * 64 * @param controller The instance of the controller 65 * @param httpMethod The http request method 66 * @param actionName The action to check 67 * @return true if the action is accessible via the specified http method 68 */ isHttpMethodAllowedForAction(GroovyObject controller, String httpMethod, String actionName)69 boolean isHttpMethodAllowedForAction(GroovyObject controller, String httpMethod, String actionName); 70 71 /** 72 * Checks whether the specified action is intercepted for the 73 * specified controller instance. 74 * 75 * @param controller The instance of the controller 76 * @param action The action to check 77 * @return True if it is intercepted 78 */ isInterceptedBefore(GroovyObject controller, String action)79 boolean isInterceptedBefore(GroovyObject controller, String action); 80 81 /** 82 * Checks whether the specified action is intercepted after for the specified 83 * controller instance. 84 * 85 * @param controller The controller instance 86 * @param action The action to check 87 * @return True if it is intercepted 88 */ isInterceptedAfter(GroovyObject controller, String action)89 boolean isInterceptedAfter(GroovyObject controller, String action); 90 91 /** 92 * Retrieves the before interceptor for the specified controller instance. 93 * 94 * @param controller The controller instance 95 * @return The before interceptor as a Closure or null if non exists 96 */ getBeforeInterceptor(GroovyObject controller)97 Closure getBeforeInterceptor(GroovyObject controller); 98 99 /** 100 * Retrieves the after interceptor for the specified controller instance. 101 * 102 * @param controller The controller instance 103 * @return The after interceptor as a Closure or null if non exists 104 */ getAfterInterceptor(GroovyObject controller)105 Closure getAfterInterceptor(GroovyObject controller); 106 107 /** 108 * Gets the list of all possible URI's available in this controller. 109 * 110 * @return list of all possible URI's 111 */ getURIs()112 String[] getURIs(); 113 114 /** 115 * Tests if a controller maps to a given URI. 116 * 117 * @return true if controller maps to URI 118 */ mapsToURI(String uri)119 boolean mapsToURI(String uri); 120 121 /** 122 * Retrieves the view name for the specified URI. 123 * 124 * @param uri the name of URI 125 * @return the view name of null if not found 126 */ getViewByURI(String uri)127 String getViewByURI(String uri); 128 129 /** 130 * Retrieves the view name for the specified closure name. 131 * 132 * @param closureName The name of the closure 133 * @return The view for the specified closure action 134 */ getViewByName(String closureName)135 String getViewByName(String closureName); 136 137 /** 138 * Returns a closure property name for a specific URI or null if the URI does not map to a closure. 139 * 140 * @param uri the URI of the request 141 * @return the closure property name mapped to the URI or null is no closure was found 142 */ getClosurePropertyName(String uri)143 String getClosurePropertyName(String uri); 144 145 /** 146 * @return A Set of names of actions with command objects presented in this controller 147 */ 148 @SuppressWarnings("rawtypes") getCommandObjectActions()149 Set getCommandObjectActions(); 150 151 /** 152 * @return command object classes used by this controller 153 */ 154 @SuppressWarnings("rawtypes") getCommandObjectClasses()155 Set getCommandObjectClasses(); 156 157 /** 158 * <p>Returns a map of the flows for this controller. A flow is an action that ends with the convention "Flow". 159 * The keys in the map are the flow ids which are the text before the "Flow" suffix. For example a flow called 160 * "bookFlow" would have a key of "book" 161 * <p>The values within the Map are Groovy closures (@see groovy.lang.Closure) which represent the flow definition 162 * 163 * @return A Map of flows for this controller 164 */ 165 @SuppressWarnings("rawtypes") getFlows()166 Map getFlows(); 167 168 /** 169 * Returns true if the given action name is a flow action. 170 * 171 * @param actionName The name of the action 172 * @return True if it is a flow action 173 */ isFlowAction(String actionName)174 boolean isFlowAction(String actionName); 175 176 /** 177 * Returns the default action for this Controller. 178 * 179 * @return The default action 180 */ getDefaultAction()181 String getDefaultAction(); 182 183 /** 184 * Registers a new mapping onto this controller for the given actionName. 185 * @param actionName The actionName 186 */ registerMapping(String actionName)187 void registerMapping(String actionName); 188 189 /** 190 * Sets the name of the default action. 191 * @param defaultActionName The default action name 192 */ setDefaultActionName(String defaultActionName)193 void setDefaultActionName(String defaultActionName); 194 } 195