1 | package edu.iu.uis.sit.portal.portlet.web; |
2 | |
3 | import java.lang.reflect.Method; |
4 | |
5 | import javax.portlet.ActionRequest; |
6 | import javax.portlet.ActionResponse; |
7 | import javax.portlet.PortletException; |
8 | import javax.portlet.RenderRequest; |
9 | import javax.portlet.RenderResponse; |
10 | |
11 | import org.springframework.web.portlet.ModelAndView; |
12 | import org.springframework.web.portlet.mvc.AbstractController; |
13 | |
14 | public abstract class MultiActionController extends AbstractController { |
15 | |
16 | protected void handleActionRequestInternal(ActionRequest request, ActionResponse response) throws Exception { |
17 | String dispatch = request.getParameter("_dispatch"); |
18 | if (dispatch == null) { |
19 | throw new PortletException("Must provide _dispatch for multi action controller"); |
20 | } |
21 | Method[] methods = this.getClass().getMethods(); |
22 | |
23 | for (int i = 0; i < methods.length; i++) { |
24 | Method method = methods[i]; |
25 | if (method.getName().equals(dispatch) && method.getReturnType().getName().equals("void") && method.getParameterTypes().length == 2) { |
26 | method.invoke(this, new Object[] { request, response }); |
27 | response.setRenderParameter("_dispatch", dispatch); |
28 | return; |
29 | } |
30 | } |
31 | throw new PortletException("Could not find method: " + dispatch); |
32 | } |
33 | |
34 | protected ModelAndView handleRenderRequestInternal(RenderRequest request, RenderResponse response) throws Exception { |
35 | String dispatch = request.getParameter("_dispatch"); |
36 | if (dispatch == null) { |
37 | dispatch = "start"; |
38 | // throw new PortletException("Must provide _dispatch for multi action controller"); |
39 | } |
40 | Method[] methods = this.getClass().getMethods(); |
41 | |
42 | for (int i = 0; i < methods.length; i++) { |
43 | Method method = methods[i]; |
44 | if (method.getName().equals(dispatch) && method.getReturnType().getName().equals("org.springframework.web.portlet.ModelAndView") && method.getParameterTypes().length == 2) { |
45 | return (ModelAndView) method.invoke(this, new Object[] { request, response }); |
46 | } |
47 | } |
48 | throw new PortletException("Could not find method: " + dispatch); |
49 | } |
50 | |
51 | public abstract ModelAndView start(RenderRequest request, RenderResponse response) throws Exception; |
52 | } |