KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > dlog4j > action > AdminActionBase


1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 2 of the License, or
5  * (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU Library General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software
14  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15  */

16 package dlog4j.action;
17
18 import javax.servlet.http.HttpServletRequest JavaDoc;
19 import javax.servlet.http.HttpServletResponse JavaDoc;
20
21 import org.apache.struts.action.ActionErrors;
22 import org.apache.struts.action.ActionForm;
23 import org.apache.struts.action.ActionForward;
24 import org.apache.struts.action.ActionMapping;
25
26 import dlog4j.Globals;
27 import dlog4j.formbean.UserForm;
28
29 /**
30  * 管理类Action的基类
31  * @author Winter Lau
32  */

33 public class AdminActionBase extends DlogActionBase {
34
35     /**
36      * 该方法覆盖了父类的功能,验证用户身份的有效性
37      */

38     public ActionForward execute(ActionMapping mapping, ActionForm form,
39             HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res) throws Exception JavaDoc
40     {
41         UserForm user = getLoginUser(req);
42         if(user==null || !user.isAdmin())
43             return mapping.findForward("admin_access_deny");
44         
45         ActionForward forward = null;
46         //统一validate
47
if(form!=null){
48             ActionErrors errors = form.validate(mapping, req);
49             if(errors!=null && !errors.isEmpty()){
50                 saveErrors(req, errors);
51                 forward = mapping.getInputForward();
52             }
53         }
54         if(forward==null)
55             forward = super.execute(mapping,form,req,res);
56         //处理resin 3.0.x 的兼容性问题 -> jspe小服务程序
57
if(!forward.getRedirect()){
58             //传递要forward的路径给jspe小服务程序
59
req.setAttribute(Globals.ACTION_PATH_KEY, forward.getPath());
60         }
61         return forward;
62     }
63
64 }
65
Popular Tags