View Javadoc

1   /*
2    * Copyright 2004-2006 the Seasar Foundation and the Others.
3    *
4    * Licensed under the Apache 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.apache.org/licenses/LICENSE-2.0
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, 
13   * either express or implied. See the License for the specific language
14   * governing permissions and limitations under the License.
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  }