1 package org.jahia.bin; 2 3 import java.util.Locale ; 4 5 import javax.servlet.http.HttpServletRequest ; 6 import javax.servlet.http.HttpServletResponse ; 7 import javax.servlet.http.HttpSession ; 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 27 public class AdminAction extends org.apache.struts.actions.DispatchAction { 28 29 protected static final String 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 41 protected void init(HttpServletRequest request, HttpServletResponse 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 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 ) 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 Locale defaultLocale = (Locale )session.getAttribute(ParamBean.SESSION_LOCALE); 73 if (defaultLocale == null) { 74 defaultLocale = Locale.ENGLISH; 75 } 76 77 String contentTypeStr = "text/html;charset="; 78 String 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.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 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 if( request.getAttribute("title") == null ) { 113 request.setAttribute("title", "No title"); 114 } 115 116 request.setAttribute( "url", request.getContextPath() + HTTP_FILES ); 118 119 String userAgent = request.getHeader("user-agent"); 121 122 Integer navigator = (userAgent.indexOf("IE")) 123 != -1 ? new Integer (0) : new Integer (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 (isLynx)); 132 133 134 } catch ( Throwable 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 152 public ActionForward continueForward(ActionMapping mapping, 153 HttpServletRequest 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 |