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 java.util.Collection;
19  
20  import javax.servlet.http.HttpServletRequest;
21  import javax.servlet.http.HttpServletResponse;
22  
23  import org.apache.struts.action.ActionForm;
24  import org.apache.struts.action.ActionForward;
25  import org.apache.struts.action.ActionMapping;
26  import org.apache.struts.actions.MappingDispatchAction;
27  import org.seasar.tuigwaa.cms.ContentsStoreService;
28  import org.seasar.tuigwaa.logic.LogicService;
29  import org.seasar.tuigwaa.logic.TgwLogic;
30  import org.seasar.tuigwaa.model.DAOService;
31  import org.seasar.tuigwaa.model.ModelService;
32  import org.seasar.tuigwaa.system.Constants;
33  import org.seasar.tuigwaa.util.TgwContext;
34  
35  import com.isenshi.util.extlib.StrutsUtil;
36  
37  public class LogicAction extends MappingDispatchAction {
38  
39  	private LogicService logicService;
40  
41  	private ContentsStoreService slideService;
42  
43  	private ModelService entityService;
44  
45  	private DAOService daoSerivce;
46  
47  	public LogicAction(LogicService logicService, ModelService entityService,
48  			ContentsStoreService slideService, DAOService daoService) {
49  		this.logicService = logicService;
50  		this.entityService = entityService;
51  		this.slideService = slideService;
52  		this.daoSerivce = daoService;
53  	}
54  
55  	public ActionForward create(ActionMapping mapping, ActionForm form,
56  			HttpServletRequest request, HttpServletResponse response)
57  			throws Exception {
58  		String siteName = TgwContext.getSiteName();
59  		LogicForm logicForm = new LogicForm(siteName, entityService,
60  				slideService, daoSerivce);
61  		request.getSession().setAttribute("logicForm", logicForm);
62  		return mapping.findForward("success");
63  	}
64  
65  	public ActionForward save(ActionMapping mapping, ActionForm form,
66  			HttpServletRequest request, HttpServletResponse response)
67  			throws Exception {
68  		LogicForm logicForm = (LogicForm) form;
69  		String siteName = TgwContext.getSiteName();
70  		TgwLogic tlogic = logicForm.getLogic();
71  		if (logicForm.isSaved()) {
72  			logicService.editLogic(siteName, tlogic);
73  		} else {
74  			logicService.addLogic(siteName, tlogic);
75  		}
76  		logicService.saveLogics(siteName);
77  		return doList(mapping, form, request, response);
78  	}
79  
80  	public ActionForward edit(ActionMapping mapping, ActionForm form,
81  			HttpServletRequest request, HttpServletResponse response)
82  			throws Exception {
83  		String siteName = TgwContext.getSiteName();
84  		String logicName = StrutsUtil.getURLDecodedParameter(request,
85  				Constants.PARAM_LOGIC_NAME);
86  		TgwLogic logic = logicService.getLogic(siteName, logicName);
87  		LogicForm logicForm = new LogicForm(siteName, logic, entityService,
88  				slideService, daoSerivce);
89  		request.getSession().setAttribute("logicForm", logicForm);
90  		return mapping.findForward("success");
91  	}
92  
93  	public ActionForward delete(ActionMapping mapping, ActionForm form,
94  			HttpServletRequest request, HttpServletResponse response)
95  			throws Exception {
96  		String siteName = TgwContext.getSiteName();
97  		String logicName = StrutsUtil.getURLDecodedParameter(request,
98  				Constants.PARAM_LOGIC_NAME);
99  		logicService.deleteLogic(siteName, logicName);
100 		logicService.saveLogics(siteName);
101 		return doList(mapping, form, request, response);
102 	}
103 
104 	public ActionForward list(ActionMapping mapping, ActionForm form,
105 			HttpServletRequest request, HttpServletResponse response)
106 			throws Exception {
107 		return doList(mapping, form, request, response);
108 	}
109 
110 	private ActionForward doList(ActionMapping mapping, ActionForm form,
111 			HttpServletRequest request, HttpServletResponse response)
112 			throws Exception {
113 		String siteName = TgwContext.getSiteName();
114 		Collection logicCol = logicService.getLogicList(siteName);
115 		request.setAttribute(Constants.RATTR_LOGICCOL, logicCol);
116 		return mapping.findForward("success");
117 	}
118 }