1 package com.sri.common.controller;
2
3 import com.jcorporate.expresso.core.controller.Controller;
4 import com.jcorporate.expresso.core.controller.Transition;
5
6 import java.util.Iterator;
7 import java.util.Map;
8
9 /***
10 * Utility and convenience methods that are related to controllers.
11 *
12 * @author Michael Rimov
13 * @version 1.0
14 */
15 final public class ControllerUtil {
16
17 /***
18 * Default constructor -- never call.
19 */
20 private ControllerUtil() {
21
22 }
23
24
25 /***
26 * Generate a Transition that if invoked would result in a redirection directly
27 * back to self with identical parameters as when a transition was first invoked.
28 * This function is useful for generating 'returnToSender' referral URLs
29 *
30 * @param requestParameters Call <tt>ControllerRequest.getParameters()</tt> to
31 * populate thie method.
32 * @param currentControllerClass The current controller class we're in. this.getClass()
33 * should mostly suffice
34 * @param invokedState The currently invoked State ControllerResponse.getState() should do
35 * the trick.
36 * @return Transition that is populated. Must call setControllerResponse() if
37 * <p/>
38 * you just want to extract the URL.
39 */
40 public static Transition generateReflextiveTransition(final Map requestParameters,
41 final Class currentControllerClass,
42 final String invokedState) {
43 Transition returnTrans = new Transition();
44
45 for (Iterator i = requestParameters.keySet().iterator(); i.hasNext();) {
46 String paramKey = (String) i.next();
47 if (!Controller.STATE_PARAM_KEY.equals(paramKey) && !Controller.CONTROLLER_PARAM_KEY.equals(paramKey)) {
48 returnTrans.addParam(paramKey, (String) requestParameters.get(paramKey));
49 }
50 }
51 returnTrans.setState(invokedState);
52 returnTrans.setControllerObject(currentControllerClass);
53
54 return returnTrans;
55 }
56 }