1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.seasar.tuigwaa.controller;
17
18 import javax.servlet.http.HttpServletRequest;
19 import javax.servlet.http.HttpServletResponse;
20
21 import org.apache.commons.beanutils.PropertyUtils;
22 import org.apache.struts.action.Action;
23 import org.apache.struts.action.ActionForm;
24 import org.apache.struts.action.ActionForward;
25 import org.apache.struts.action.ActionMapping;
26 import org.seasar.tuigwaa.cms.core.CmsContainer;
27 import org.seasar.tuigwaa.plugin.Plugin;
28 import org.seasar.tuigwaa.system.Constants;
29 import org.seasar.tuigwaa.util.TgwUtils;
30
31 public class PluginProxyAction extends Action {
32
33 private ControllerService controller;
34
35 public PluginProxyAction(ControllerService controller){
36 this.controller = controller;
37 }
38
39 public ActionForward execute(ActionMapping mapping, ActionForm form,
40 HttpServletRequest request, HttpServletResponse response)
41 throws Exception {
42 if (mapping.getPath().equals("/plugin")) {
43 return executeDoAction(mapping, form, request, response);
44 } else {
45 return executeCustomAction(mapping, form, request, response);
46 }
47 }
48
49 public ActionForward executeDoAction(ActionMapping mapping,
50 ActionForm form, HttpServletRequest request,
51 HttpServletResponse response) throws Exception {
52 String pluginName = request.getParameter(Constants.PARAM_PLUGINNAME);
53 Plugin plugin = CmsContainer.INSTANCE.getPlugin(pluginName);
54 String pageName = plugin.doAction(request, response);
55
56 return doForward(request, pageName);
57 }
58
59 public ActionForward executeCustomAction(ActionMapping mapping,
60 ActionForm form, HttpServletRequest request,
61 HttpServletResponse response) throws Exception {
62 String dtoClassName = mapping.getParameter();
63 Class dtoClass = Class.forName(dtoClassName);
64 Object dto = dtoClass.newInstance();
65
66 PropertyUtils.copyProperties(dto, form);
67
68 String pageName = controller.proxyAction(mapping.getPath(), dto, request, response);
69 return doForward(request, pageName);
70 }
71
72 private ActionForward doForward(HttpServletRequest request, String pageName){
73 if (pageName == null) {
74 return null;
75 } else {
76 return TgwUtils.forwardPage(request, pageName);
77 }
78 }
79 }