KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > bin > AdminAction


1 package org.jahia.bin;
2
3 import java.util.Locale JavaDoc;
4
5 import javax.servlet.http.HttpServletRequest JavaDoc;
6 import javax.servlet.http.HttpServletResponse JavaDoc;
7 import javax.servlet.http.HttpSession JavaDoc;
8
9 import org.apache.struts.action.ActionForward;
10 import org.apache.struts.action.ActionMapping;
11 import org.apache.struts.action.ActionMessages;
12 import org.jahia.data.JahiaData;
13 import org.jahia.exceptions.JahiaException;
14 import org.jahia.params.ParamBean;
15 import org.jahia.resourcebundle.JahiaResourceBundle;
16
17
18 /**
19  *
20  * <p>Title: Class that define some common initialization task for Admin Action</p>
21  * <p>Description: </p>
22  * <p>Copyright: Copyright (c) 2002</p>
23  * <p>Company: </p>
24  * @author Khue Nguyen
25  * @version 1.0
26  */

27 public class AdminAction extends org.apache.struts.actions.DispatchAction {
28
29     protected static final String JavaDoc HTTP_FILES = "/jsp/jahia/engines";
30
31     private static org.apache.log4j.Logger logger =
32             org.apache.log4j.Logger.getLogger(AdminAction.class);
33
34
35     /**
36      *
37      * @param request
38      * @param response
39      * @throws JahiaException
40      */

41     protected void init(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
42             throws JahiaException {
43
44         JahiaData jData = (JahiaData)request.getAttribute ("org.jahia.data.JahiaData");
45         ParamBean jParams = null;
46         if (jData != null) {
47             jParams = jData.params ();
48         }
49
50         try {
51             HttpSession JavaDoc session = request.getSession();
52             if(session.getAttribute(JahiaAdministration.CLASS_NAME + "jahiaDisplayMessage") == null) {
53                 request.setAttribute("jahiaDisplayMessage",
54                     JahiaResourceBundle.getAdminResource("org.jahia.admin.copyright",
55                         jParams, jParams.getLocale()));
56             } else {
57                 request.setAttribute("jahiaDisplayMessage",
58                                      (String JavaDoc) session.getAttribute(JahiaAdministration.CLASS_NAME + "jahiaDisplayMessage") );
59             }
60
61             session.setAttribute(JahiaAdministration.CLASS_NAME + "jahiaDisplayMessage",
62                 JahiaResourceBundle.getAdminResource("org.jahia.admin.copyright",
63                     jParams, jParams.getLocale()));
64
65             request.setAttribute("requestURI", request.getRequestURI());
66
67             if ( request.getAttribute("title")== null ){
68                 request.setAttribute("title","no title");
69             }
70
71             // set browser response content type
72
Locale JavaDoc defaultLocale = (Locale JavaDoc)session.getAttribute(ParamBean.SESSION_LOCALE);
73             if (defaultLocale == null) {
74                 defaultLocale = Locale.ENGLISH;
75             }
76
77             String JavaDoc contentTypeStr = "text/html;charset=";
78             String JavaDoc acceptCharset = request.getHeader("accept-charset");
79             boolean acceptsUTF8 = false;
80             if (acceptCharset != null) {
81                 if (acceptCharset.toLowerCase().indexOf("utf-8") != -1) {
82                     acceptsUTF8 = true;
83                 }
84             }
85             if (acceptsUTF8) {
86                 contentTypeStr = contentTypeStr + "UTF-8";
87             } else {
88                 contentTypeStr = contentTypeStr + "ISO8859-1";
89             }
90             request.setAttribute("content-type", contentTypeStr);
91
92             // response no-cache headers...
93
response.setHeader("Pragma", "no-cache");
94             response.setHeader("Cache-Control", "no-cache");
95             response.setDateHeader("Expires", 0);
96
97             request.setAttribute("currentSite",jData.params().getSite());
98             request.setAttribute("user",jData.params().getUser());
99
100             // check null jsp bottom message, and fill in if necessary...
101
if( request.getAttribute("msg") == null ) {
102                 request.setAttribute("msg",
103                     JahiaResourceBundle.getAdminResource("org.jahia.admin.copyright",
104                         jParams, jParams.getLocale()));
105             }
106
107             if( request.getAttribute("focus") == null ) {
108                 request.setAttribute("focus", "-none-");
109             }
110
111             // check null configuration step title, and fill in if necessary...
112
if( request.getAttribute("title") == null ) {
113                 request.setAttribute("title", "No title");
114             }
115
116             // add http files path in request...
117
request.setAttribute( "url", request.getContextPath() + HTTP_FILES );
118
119             // get browser entity...
120
String JavaDoc userAgent = request.getHeader("user-agent");
121
122             Integer JavaDoc navigator = (userAgent.indexOf("IE"))
123                                         != -1 ? new Integer JavaDoc(0) : new Integer JavaDoc(1);
124             request.setAttribute("navigator", navigator);
125
126             boolean isLynx = false;
127
128             if(userAgent.indexOf("Lynx") != -1) {
129                 isLynx = true;
130             }
131             request.setAttribute("isLynx", new Boolean JavaDoc(isLynx));
132
133
134         } catch ( Throwable JavaDoc t ){
135             t.printStackTrace();
136             throw new JahiaException("Exception occured initializing engine's objects",
137                                      "Exception occured initializing engine's objects",
138                                      JahiaException.ENGINE_ERROR,
139                                      JahiaException.ENGINE_ERROR);
140         }
141     }
142
143     /**
144      * Forward to errors if any or to continueForward
145      *
146      * @param mapping
147      * @param request
148      * @param errors
149      * @param continueForward
150      * @return
151      */

152     public ActionForward continueForward(ActionMapping mapping,
153             HttpServletRequest JavaDoc request, ActionMessages errors,
154             ActionForward continueForward){
155
156         if(errors != null && !errors.isEmpty()){
157             saveErrors(request,errors);
158             return mapping.findForward("error");
159         }
160         return continueForward;
161     }
162
163 }
164
Popular Tags