1 | package edu.iu.uis.sit.portal.web.common; |
2 | |
3 | import java.text.NumberFormat; |
4 | import java.util.Iterator; |
5 | import java.util.Map; |
6 | |
7 | import javax.servlet.http.HttpServletRequest; |
8 | import javax.servlet.http.HttpServletResponse; |
9 | |
10 | import org.springframework.beans.propertyeditors.CustomNumberEditor; |
11 | import org.springframework.beans.propertyeditors.StringTrimmerEditor; |
12 | import org.springframework.web.bind.ServletRequestDataBinder; |
13 | import org.springframework.web.servlet.ModelAndView; |
14 | import org.springframework.web.servlet.mvc.multiaction.MultiActionController; |
15 | import org.springframework.web.servlet.mvc.multiaction.NoSuchRequestHandlingMethodException; |
16 | |
17 | public class OneStartMultiController extends MultiActionController { |
18 | private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OneStartMultiController.class); |
19 | |
20 | protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { |
21 | try { |
22 | LOG.info(request.getQueryString()); |
23 | String methodName = null; |
24 | if (request.getParameterMap() != null) { |
25 | for (Iterator iter = request.getParameterMap().entrySet().iterator(); iter.hasNext();) { |
26 | String parameterName = (String) ((Map.Entry) iter.next()).getKey(); |
27 | if (parameterName.startsWith("dispatch.") && parameterName.endsWith(".x")) { |
28 | String methodToCall = parameterName.substring(parameterName.indexOf("dispatch.") + 9, parameterName.lastIndexOf(".x")); |
29 | if (methodToCall != null && methodToCall.length() > 0) { |
30 | methodName = methodToCall; |
31 | } |
32 | } |
33 | } |
34 | } |
35 | if (methodName == null) { |
36 | methodName = getMethodNameResolver().getHandlerMethodName(request); |
37 | } |
38 | if (methodName == null) { |
39 | methodName = "start"; |
40 | } |
41 | return invokeNamedMethod(methodName, request, response); |
42 | } catch (NoSuchRequestHandlingMethodException ex) { |
43 | return handleNoSuchRequestHandlingMethod(ex, request, response); |
44 | } |
45 | } |
46 | |
47 | protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) { |
48 | NumberFormat nf = NumberFormat.getInstance(); |
49 | binder.registerCustomEditor(Integer.class, new CustomNumberEditor(Integer.class, nf, true)); |
50 | binder.registerCustomEditor(Long.class, new CustomNumberEditor(Long.class, nf, true)); |
51 | binder.registerCustomEditor(String.class, new StringTrimmerEditor(true)); |
52 | } |
53 | } |