📄 jahiaconfigurationwizard.java
字号:
* GET and POST (it works also with DELETE, TRACE and PUT) requests. * @author Alexandre Kraft * * @param request servlet request. * @param response servlet response. * @exception IOException an I/O exception occured during the process. * @exception ServletException a servlet exception occured during the process. */ private void dispatcher( HttpServletRequest request, HttpServletResponse response ) throws IOException, ServletException { // get the parameter *call*... String call = request.getParameter("call") == null ? "welcome" : request.getParameter("call"); // call the action handler... actionHandler.call( this, call, request, response ); } // end dispatcher( HttpServletRequest, HttpServletResponse ) /** * This method display the welcome page. * @author Alexandre Kraft * * @param request servlet request. * @param response servlet response. * @exception IOException an I/O exception occured during the process. * @exception ServletException a servlet exception occured during the process. */ public void displayWelcome( HttpServletRequest request, HttpServletResponse response ) throws IOException, ServletException { // get system properties... Properties sys = System.getProperties(); // set java infos on request... request.setAttribute( "javaversion", sys.getProperty("java.version") ); request.setAttribute( "javavendor", sys.getProperty("java.vendor") ); request.setAttribute( "os", sys.getProperty("os.name") ); // set server infos on request... request.setAttribute( "server", serverInfos.get("info") ); // forward to the jsp... doRedirect( request, response, JSP + "welcome" ); // force objects to garbage collector... sys = null; } // end displayWelcome( HttpServletRequest, HttpServletResponse ) /** * This method display the root settings page. * @author Alexandre Kraft * * @param request servlet request. * @param response servlet response. * @exception IOException an I/O exception occured during the process. * @exception ServletException a servlet exception occured during the process. */ public void displayRoot( HttpServletRequest request, HttpServletResponse response ) throws IOException, ServletException { // set focus it it's null... if( request.getAttribute("focus") == null ) { request.setAttribute( "focus", "pwd" ); } // set configuration step title... request.setAttribute( "title", "SuperUser (administrator) settings" ); // forward to the jsp... doRedirect( request, response, JSP + "root" ); } // end displayRoot( HttpServletRequest, HttpServletResponse ) /** * Process and check the validity of the root username, password, the * confirmation of the password, first name, last name and mail address * from the root settings page. If they are valid, display the server * settings page. Otherwise, re-display the root settings page to the user. * @author Alexandre Kraft * * @param request servlet request. * @param response servlet response. * @exception IOException an I/O exception occured during the process. * @exception ServletException a servlet exception occured during the process. */ public void processRoot( HttpServletRequest request, HttpServletResponse response ) throws IOException, ServletException { // by default, the user makes at least one error :o) boolean error = true; String msg = null; // save form values... values.put( "root_user", (String) request.getParameter("user").trim() ); values.put( "root_pwd", (String) request.getParameter("pwd").trim() ); values.put( "root_confirm", (String) request.getParameter("confirm").trim() ); values.put( "root_firstname", (String) request.getParameter("firstname").trim() ); values.put( "root_lastname", (String) request.getParameter("lastname").trim() ); values.put( "root_mail", (String) request.getParameter("mail").trim() ); // check root settings validity... if the user want to go next if( request.getParameter("go").equals("next") ) { if( ((String)values.get("root_user")).length() < 4 ) { // check username length [minimum 4 chars] request.setAttribute( "focus", "user" ); msg = "Username is too short. It must be at least 4 characters."; } else if( !JahiaTools.isAlphaValid(((String)values.get("root_user"))) ) { // check username is alpha valid request.setAttribute( "focus", "user" ); msg = "Please use only letters, digits or underscores in username."; } else if( ((String)values.get("root_pwd")).length() < 8 ) { // check password length [minimum 8 chars] request.setAttribute( "focus", "pwd" ); msg = "Password is too short. It must be at least 8 characters."; } else if( !JahiaTools.isAlphaValid(((String)values.get("root_pwd"))) ) { // check password is alpha valid request.setAttribute( "focus", "pwd" ); msg = "Please use only letters, digits or underscores in password."; } else if( ((String)values.get("root_confirm")).length() == 0 ) { // check confirmation length [minimum 8 chars] request.setAttribute( "focus", "confirm" ); msg = "Confirmation password must be the same as password."; } else if( !((String)values.get("root_pwd")).equals(((String)values.get("root_confirm"))) ) { // check password and confirmation must be equals request.setAttribute( "focus", "pwd" ); msg = "Confirmation password must be the same as password."; } else if( ((String)values.get("root_firstname")).length() == 0 ) { // check firstname length [minimum 1 char] request.setAttribute( "focus", "firstname" ); msg = "First name must be set."; } else if( ((String)values.get("root_lastname")).length() == 0 ) { // check lastname length [minimum 1 char] request.setAttribute( "focus", "lastname" ); msg = "Last name must be set."; } else { error = false; // everything is okay, continue... } } else { error = false; // default, the user want to go back. } // call the appropriate method... if( error ) { request.setAttribute( "msg", msg ); displayRoot( request, response ); } else { if( request.getParameter("go").equals("next") ) { // step next requested... displayServer( request, response ); } else if( request.getParameter("go").equals("back") ) { // step back requested... displayWelcome( request, response ); } } // force objects to garbage collector... msg = null; } // end processRoot( HttpServletRequest, HttpServletResponse ) /** * This method display the server settings page. * @author Alexandre Kraft * * @param request servlet request. * @param response servlet response. * @exception IOException an I/O exception occured during the process. * @exception ServletException a servlet exception occured during the process. */ public void displayServer( HttpServletRequest request, HttpServletResponse response ) throws IOException, ServletException { // determine the host url... now i've the request :o) if( ((String)values.get("server_url")) == null ) { values.put( "server_url", request.getScheme() +"://"+request.getHeader("host") ); } if( ((String)values.get("webapps_deploybaseurl")) == null ) { URL deployURL = null; try { deployURL = new java.net.URL( request.getScheme() +"://"+request.getHeader("host") ); } catch (MalformedURLException mue) { JahiaConsole.printe("JahiaConfigurationWizard.displayServer", mue); } values.put( "webapps_deploybaseurl", deployURL.toString() ); } // set focus it it's null... if( request.getAttribute("focus") == null ) { request.setAttribute( "focus", "home" ); } // set configuration step title... request.setAttribute( "title", "Server settings" ); // forward to the jsp... doRedirect( request, response, JSP + "server" ); } // end displayServer( HttpServletRequest, HttpServletResponse ) /** * Process and check the validity of the servlet container home disk path, * the host url and the path (filesystem or context-relative) to jahia * files, from the server settings page. If they are valid, display the * next page, but... the user can choose to display *advanced settings* or * to go back. Otherwise, re-display the server settings page to the user. * @author Alexandre Kraft * * @param request servlet request. * @param response servlet response. * @exception IOException an I/O exception occured during the process. * @exception ServletException a servlet exception occured during the process. */ public void processServer( HttpServletRequest request, HttpServletResponse response ) throws IOException, ServletException { // by default, the user makes at least one error :o) boolean error = true; boolean dbError = false; String msg = null; String dbMsg = null; // save form values... values.put( "server_home", (String) request.getParameter("home").trim() ); values.put( "server_url", (String) request.getParameter("hosturl").trim() ); values.put( "webapps_deploybaseurl", (String) request.getParameter("webappsdeploybaseurl").trim() ); values.put( "server_jahiafiles", (String) request.getParameter("jahiafiles").trim() ); // check server settings validity...if the user want to go next if( request.getParameter("go").equals("next") ) { if( ((String)values.get("server_home")).length() == 0 ) { // check servlet container home path request.setAttribute( "focus", "home" ); msg = "Servlet Container home disk path must be set."; } else if( ((String)values.get("server_url")).length() == 0 ) { // check host url request.setAttribute( "focus", "hosturl" ); msg = "Host URL must be set."; } else if( ((String)values.get("webapps_deploybaseurl")).length() == 0 ) { // check host url request.setAttribute( "focus", "webappsdeploybaseurl" ); msg = "Web applications deployment base URL must be set."; } else if( ((String)values.get("server_jahiafiles")).length() == 0 ) { // check jahia files path request.setAttribute( "focus", "jahiafiles" ); msg = "Path to Jahia Files must be set."; } else { error = false; // everything is okay, continue... } // check *slashs* validity of the inputs values... checkServerSlashs(); // try some operations which can return customs exceptions... try { // try the servlet container home disk path... tryServerHome(); // try the host url connection... tryHostURL(); // try the host url connection... tryWebAppsDeployBaseURL(); // try the path to jahia files (permissions, etc)... tryJahiaFilesPath(); } catch (Exception e) { msg = e.getMessage(); error = true; } // reset default values if the user has specified invalid database settings... if( ((Boolean)values.get("database_custom")) == Boolean.FALSE ) { fillDefaultValues( false, true ); } // test the database connection... (only if the user want continue by *next*) HashMap test = testDBConnection(); dbError = ((Boolean)test.get("testDatabaseConnectionError")).booleanValue(); dbMsg = (String)test.get("testDatabaseConnectionMessage"); request.setAttribute( "msg", dbMsg ); } else { error = false; // default, the user don't want to go next. } // call the appropriate method... if( error ) { // process generates errors... request.setAttribute( "msg", msg ); displayServer( request, response ); } else if( dbError ) { // database settings are not correct... request.setAttribute( "msg", dbMsg );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -