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