1 /* 2 * Copyright 2005-2008 The Kuali Foundation 3 * 4 * 5 * Licensed under the Educational Community License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.opensource.org/licenses/ecl2.php 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 package org.kuali.rice.kew.edl.components; 18 19 import java.util.List; 20 21 import org.apache.commons.lang.StringUtils; 22 import org.kuali.rice.kew.edl.EDLContext; 23 import org.kuali.rice.kew.edl.EDLModelComponent; 24 import org.kuali.rice.kew.edl.RequestParser; 25 import org.kuali.rice.kew.edl.UserAction; 26 import org.kuali.rice.kns.util.KNSConstants; 27 import org.w3c.dom.Document; 28 import org.w3c.dom.Element; 29 30 31 /** 32 * Handles establishing what action the user submitted. It's important to normalize this because 33 * the action could be submitted in the "userAction" request parameter, in the "command" request 34 * parameter or not passed at all. 35 * 36 * <p>This is primarily important in identifying whether the submission is the first-time "load" 37 * of a document or an action being executed against an already loaded document. 38 * 39 * @author Kuali Rice Team (rice.collab@kuali.org) 40 */ 41 public class EstablishUserAction implements EDLModelComponent { 42 43 public static final String USER_ACTION_PARAM = "userAction"; 44 public static final String COMMAND_PARAM = "command"; 45 46 public void updateDOM(Document dom, Element configElement, EDLContext edlContext) { 47 RequestParser requestParser = edlContext.getRequestParser(); 48 49 List<String> params = requestParser.getParameterNames(); 50 51 /** 52 * IE does not process image buttons in the same way as other browsers. If you have 53 * <input name="userAction" value="performAction.unit_1" type=image src="images/searchicon.gif"/> 54 * The actual request parameters that are sent are: userAction.x=9; userAction.y=22. The numbers 55 * correspond to the location of the button on the screen. NO OTHER DATA IS SENT. So in order 56 * for this to work for IE we need to change the name to include the value of userAction. 57 * So we're now sending 58 * <input name="userAction.performLookup.unit_1" value="This no longer matters" type=image src="images/searchicon.gif"/> 59 * So we now need to parse out the userAction, the action, and the value. Which is what happens below. 60 * The end result is a new parameter "userAction=performLookup.unit_1". 61 */ 62 for(String param: params){ 63 if(param.startsWith("userAction.performLookup") && param.endsWith(".y")){ 64 requestParser.setParameterValue(USER_ACTION_PARAM, param.substring("userAction.".length(), param.length()-2)); 65 } 66 } 67 String userAction = requestParser.getParameterValue(USER_ACTION_PARAM); 68 69 if (StringUtils.isEmpty(userAction)) { 70 String command = requestParser.getParameterValue(COMMAND_PARAM); 71 if (!StringUtils.isEmpty(command)) { 72 // from Workflow Quick Links, the "command" parameter will be passed with a value of "initiate" 73 if (UserAction.ACTION_CREATE.equals(command)) { 74 userAction = UserAction.ACTION_CREATE; 75 } 76 // from Document Search/Action List a command parameter is passed but we want to load the document 77 userAction = UserAction.ACTION_LOAD; 78 } else { 79 String methodToCall = requestParser.getParameterValue(KNSConstants.DISPATCH_REQUEST_PARAMETER); 80 if (StringUtils.equals(methodToCall, KNSConstants.RETURN_METHOD_TO_CALL)) { 81 userAction = UserAction.ACTION_REFRESH_FROM_LOOKUP; 82 } 83 else { 84 userAction = UserAction.ACTION_UNDEFINED; 85 } 86 } 87 } 88 edlContext.setUserAction(new UserAction(userAction)); 89 } 90 91 }