1 19 package org.jahia.admin.server; 20 21 import java.io.IOException ; 22 23 import javax.servlet.ServletException ; 24 import javax.servlet.http.HttpServletRequest ; 25 import javax.servlet.http.HttpServletResponse ; 26 import javax.servlet.http.HttpSession ; 27 28 import org.jahia.bin.Jahia; 29 import org.jahia.bin.JahiaAdministration; 30 import org.jahia.data.JahiaData; 31 import org.jahia.params.ParamBean; 32 import org.jahia.resourcebundle.JahiaResourceBundle; 33 import org.jahia.utils.DataValidator; 34 import org.jahia.utils.properties.PropertiesManager; 35 36 37 49 public class ManageServer 50 { 51 private static final String CLASS_NAME = JahiaAdministration.CLASS_NAME; 52 private static final String JSP_PATH = JahiaAdministration.JSP_PATH; 53 54 private static PropertiesManager properties; 55 56 57 58 66 public ManageServer( HttpServletRequest request, 67 HttpServletResponse response, 68 HttpSession session ) 69 throws Throwable 70 { 71 properties = new PropertiesManager( Jahia.getJahiaPropertiesFileName() ); 72 userRequestDispatcher( request, response, session ); 73 } 75 76 77 85 private void userRequestDispatcher( HttpServletRequest request, 86 HttpServletResponse response, 87 HttpSession session ) 88 throws Throwable 89 { 90 String operation = request.getParameter("sub"); 91 92 if(operation.equals("display")) { 93 displaySettings( request, response, session ); 94 } else if(operation.equals("process")) { 95 processSettings( request, response, session ); 96 } 97 } 99 100 101 109 private void displaySettings( HttpServletRequest request, 110 HttpServletResponse response, 111 HttpSession session ) 112 throws IOException , ServletException 113 { 114 String jahiaServerMailServer = (String ) session.getAttribute(CLASS_NAME + "jahiaServerMailServer"); 116 String jahiaServerMailAdministrator = (String ) session.getAttribute(CLASS_NAME + "jahiaServerMailAdministrator"); 117 String jahiaServerMailFrom = (String ) session.getAttribute(CLASS_NAME + "jahiaServerMailFrom"); 118 String jahiaServerNotificationLevel = (String ) session.getAttribute(CLASS_NAME + "jahiaServerNotificationLevel"); 119 120 if(jahiaServerMailServer == null) { jahiaServerMailServer = properties.getProperty("mail_server"); } 122 if(jahiaServerMailFrom == null) { jahiaServerMailFrom = properties.getProperty("mail_from"); } 123 if(jahiaServerMailAdministrator == null) { jahiaServerMailAdministrator = properties.getProperty("mail_administrator"); } 124 if(jahiaServerNotificationLevel == null) { jahiaServerNotificationLevel = properties.getProperty("mail_paranoia"); } 125 126 request.setAttribute("jahiaServerMailServer", jahiaServerMailServer); 128 request.setAttribute("jahiaServerMailAdministrator", jahiaServerMailAdministrator); 129 request.setAttribute("jahiaServerMailFrom", jahiaServerMailFrom); 130 request.setAttribute("jahiaServerNotificationLevel", jahiaServerNotificationLevel); 131 132 JahiaAdministration.doRedirect( request, response, session, JSP_PATH + "config_server.jsp" ); 133 } 135 136 137 146 private void processSettings( HttpServletRequest request, 147 HttpServletResponse response, 148 HttpSession session ) 149 throws IOException , ServletException 150 { 151 boolean processError = true; 152 153 String jahiaServerMailServer = (String ) request.getParameter("mailserver").trim(); 155 String jahiaServerMailAdministrator = (String ) request.getParameter("mailadministrator").trim(); 156 String jahiaServerMailFrom = (String ) request.getParameter("mailfrom").trim(); 157 String jahiaServerNotificationLevel = (String ) request.getParameter("mailparanoia").trim(); 158 JahiaData jData = (JahiaData) request.getAttribute("org.jahia.data.JahiaData"); 159 ParamBean jParams = null; 160 if (jData != null) { 161 jParams = jData.params(); 162 } 163 164 if(!jahiaServerNotificationLevel.equals("Disabled")) { 166 String jahiaDisplayMessage = ""; 167 if(jahiaServerMailServer.length() == 0) { 168 String dspMsg = JahiaResourceBundle.getAdminResource("org.jahia.admin.JahiaDisplayMessage.mailServer_mustSet.label", 169 jParams, jParams.getLocale()); 170 dspMsg += " " + JahiaResourceBundle.getAdminResource("org.jahia.admin.JahiaDisplayMessage.setLevleDisabled.label", 171 jParams, jParams.getLocale()); 172 session.setAttribute(CLASS_NAME + "jahiaDisplayMessage", dspMsg); 173 } else if(jahiaServerMailAdministrator.length() == 0) { 174 String dspMsg = JahiaResourceBundle.getAdminResource("org.jahia.admin.JahiaDisplayMessage.mailAdmin_mustSet.label", 175 jParams, jParams.getLocale()); 176 dspMsg += " " + JahiaResourceBundle.getAdminResource("org.jahia.admin.JahiaDisplayMessage.setLevleDisabled.label", 177 jParams, jParams.getLocale()); 178 session.setAttribute(CLASS_NAME + "jahiaDisplayMessage", dspMsg); 179 } else if(jahiaServerMailFrom.length() == 0) { 180 String dspMsg = JahiaResourceBundle.getAdminResource("org.jahia.admin.JahiaDisplayMessage.mailFrom_mustSet.label", 181 jParams, jParams.getLocale()); 182 dspMsg += " " + JahiaResourceBundle.getAdminResource("org.jahia.admin.JahiaDisplayMessage.setLevleDisabled.label", 183 jParams, jParams.getLocale()); 184 session.setAttribute(CLASS_NAME + "jahiaDisplayMessage", dspMsg); 185 } else if(!DataValidator.isValidEmail(jahiaServerMailAdministrator)) { 186 String dspMsg = JahiaResourceBundle.getAdminResource("org.jahia.admin.JahiaDisplayMessage.enterValidEmailAdmin.label", 187 jParams, jParams.getLocale()); 188 session.setAttribute(CLASS_NAME + "jahiaDisplayMessage", dspMsg); 189 } else if(!DataValidator.isValidEmail(jahiaServerMailFrom)) { 190 String dspMsg = JahiaResourceBundle.getAdminResource("org.jahia.admin.JahiaDisplayMessage.enterValidEmailFrom.label", 191 jParams, jParams.getLocale()); 192 session.setAttribute(CLASS_NAME + "jahiaDisplayMessage", dspMsg); 193 } else { 194 processError = false; 195 } 196 } else { 197 processError = false; 198 } 199 200 session.setAttribute(CLASS_NAME + "jahiaServerMailServer", jahiaServerMailServer); 202 session.setAttribute(CLASS_NAME + "jahiaServerMailAdministrator", jahiaServerMailAdministrator); 203 session.setAttribute(CLASS_NAME + "jahiaServerMailFrom", jahiaServerMailFrom); 204 session.setAttribute(CLASS_NAME + "jahiaServerNotificationLevel", jahiaServerNotificationLevel); 205 206 if(processError) { 207 displaySettings( request, response, session ); 208 } else { 209 storeSettings( request, response, session ); 210 } 211 } 213 214 215 223 private void storeSettings( HttpServletRequest request, 224 HttpServletResponse response, 225 HttpSession session ) 226 throws IOException , ServletException 227 { 228 JahiaData jData = (JahiaData) request.getAttribute("org.jahia.data.JahiaData"); 229 ParamBean jParams = null; 230 if (jData != null) { 231 jParams = jData.params(); 232 } 233 properties.setProperty("mail_server", (String ) session.getAttribute(CLASS_NAME + "jahiaServerMailServer")); 235 properties.setProperty("mail_administrator", (String ) session.getAttribute(CLASS_NAME + "jahiaServerMailAdministrator")); 236 properties.setProperty("mail_from", (String ) session.getAttribute(CLASS_NAME + "jahiaServerMailFrom")); 237 properties.setProperty("mail_paranoia", (String ) session.getAttribute(CLASS_NAME + "jahiaServerNotificationLevel")); 238 239 properties.storeProperties(); 241 242 String dspMsg = JahiaResourceBundle.getAdminResource("org.jahia.admin.JahiaDisplayMessage.restartJahiaAfterChange.label", 243 jParams, jParams.getLocale()); 244 request.setAttribute ("processMessage", dspMsg); 245 session.setAttribute (CLASS_NAME + "jahiaDisplayMessage", 246 JahiaResourceBundle.getAdminResource("org.jahia.admin.copyright", 247 jParams, jParams.getLocale())); 248 JahiaAdministration.doRedirect (request, response, session, JSP_PATH + "finish.jsp"); 249 } 251 252 } | Popular Tags |