KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > forrest > forrestbot > webapp > action > BaseAction


1 /*
2 * Copyright 2002-2004 The Apache Software Foundation or its licensors,
3 * as applicable.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */

17 package org.apache.forrest.forrestbot.webapp.action;
18
19 import javax.servlet.http.HttpServletRequest JavaDoc;
20 import javax.servlet.http.HttpServletResponse JavaDoc;
21
22 import org.apache.forrest.forrestbot.webapp.Config;
23 import org.apache.forrest.forrestbot.webapp.Constants;
24 import org.apache.log4j.Logger;
25 import org.apache.struts.action.Action;
26 import org.apache.struts.action.ActionError;
27 import org.apache.struts.action.ActionErrors;
28 import org.apache.struts.action.ActionForm;
29 import org.apache.struts.action.ActionForward;
30 import org.apache.struts.action.ActionMapping;
31
32 public class BaseAction extends Action {
33     private static Logger log = Logger.getLogger(BaseAction.class);
34     
35     public BaseAction() {
36         super();
37         Config.getInstance(); // set up log4j
38
}
39
40     public ActionForward execute(
41         ActionMapping mapping,
42         ActionForm form,
43         HttpServletRequest JavaDoc request,
44         HttpServletResponse JavaDoc response)
45         throws Exception JavaDoc {
46         super.execute(mapping, form, request, response);
47         
48         /*
49          * Make the constants available to all JSP expressions
50          */

51         request.setAttribute("Constants", Constants.getConstantFieldsAsMap());
52         
53         response.setHeader("Pragma", "no-cache");
54
55         return mapping.findForward(Constants.FORWARD_NAME_SUCCESS);
56     }
57     
58     protected boolean checkAuthorized(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response, boolean setErrors) {
59         Object JavaDoc attr = request.getSession(true).getAttribute("auth");
60         if (attr != null && ((Boolean JavaDoc)attr).booleanValue()) {
61             return true;
62         } else {
63             if (setErrors) {
64                 ActionErrors errors = new ActionErrors();
65                 errors.add("authorize", new ActionError("error.authorization"));
66                 saveErrors(request, errors);
67             }
68             return false;
69         }
70     }
71     
72     protected boolean checkAuthorized(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) {
73         return checkAuthorized(request, response, true);
74     }
75
76 }
77
Popular Tags