📄 managedatabase.java
字号:
// get script lists... Vector scriptsListInfos = scriptsManager.getDatabaseScriptsInfos( scriptsManager.getDatabaseScriptsFileObjects() ); // retrieve previous form values... String jahiaDBScript = (String) session.getAttribute(CLASS_NAME + "jahiaDBScript"); String jahiaDBDriver = (String) session.getAttribute(CLASS_NAME + "jahiaDBDriver"); String jahiaDBUrl = (String) session.getAttribute(CLASS_NAME + "jahiaDBUrl"); String jahiaDBUsername = (String) session.getAttribute(CLASS_NAME + "jahiaDBUsername"); String jahiaDBPassword = (String) session.getAttribute(CLASS_NAME + "jahiaDBPassword"); String jahiaDBMinConnections = (String) session.getAttribute(CLASS_NAME + "jahiaDBMinConnections"); String jahiaDBMaxConnections = (String) session.getAttribute(CLASS_NAME + "jahiaDBMaxConnections"); String jahiaDBWaitIfBusy = (String) session.getAttribute(CLASS_NAME + "jahiaDBWaitIfBusy"); String jahiaDBVerbose = (String) session.getAttribute(CLASS_NAME + "jahiaDBVerbose"); // set default values... if(jahiaDBScript == null) { jahiaDBScript = (String) properties.getProperty("db_script"); } if(jahiaDBDriver == null) { jahiaDBDriver = (String) properties.getProperty("db_driver"); } if(jahiaDBUrl == null) { jahiaDBUrl = (String) properties.getProperty("db_url"); } if(jahiaDBUsername == null) { jahiaDBUsername = (String) properties.getProperty("db_username"); } if(jahiaDBPassword == null) { jahiaDBPassword = (String) properties.getProperty("db_password"); } if(jahiaDBMinConnections == null) { jahiaDBMinConnections = (String) properties.getProperty("db_min_connections"); } if(jahiaDBMaxConnections == null) { jahiaDBMaxConnections = (String) properties.getProperty("db_max_connections"); } if(jahiaDBWaitIfBusy == null) { jahiaDBWaitIfBusy = (String) properties.getProperty("db_waitIfBusy"); } if(jahiaDBVerbose == null) { jahiaDBVerbose = (String) properties.getProperty("db_verbose"); } // set request attributes... request.setAttribute("jahiaDBWhichAction", jahiaDBWhichAction); request.setAttribute("jahiaScriptsInfos", scriptsListInfos.elements()); request.setAttribute("jahiaScriptsJavaScript", scriptsListInfos.elements()); request.setAttribute("jahiaDBScript", jahiaDBScript); request.setAttribute("jahiaDBDriver", jahiaDBDriver); request.setAttribute("jahiaDBUrl", jahiaDBUrl); request.setAttribute("jahiaDBUsername", jahiaDBUsername); request.setAttribute("jahiaDBPassword", jahiaDBPassword); request.setAttribute("jahiaDBMinConnections", jahiaDBMinConnections); request.setAttribute("jahiaDBMaxConnections", jahiaDBMaxConnections); request.setAttribute("jahiaDBWaitIfBusy", jahiaDBWaitIfBusy); request.setAttribute("jahiaDBVerbose", jahiaDBVerbose); JahiaAdministration.doRedirect( request, response, session, JSP_PATH + "config_database.jsp" ); } // end displaySettings /** * Process the choice of database action. Determine if the user has choosed * to change database connection settings, transfer the current database * to an another database, create a backup, or manage previous backup (like * delete/flush and restore). * @author Alexandre Kraft * * @param request Servlet request. * @param response Servlet response. * @param session Servlet session for the current user. */ private void processChoice( HttpServletRequest request, HttpServletResponse response, HttpSession session ) throws IOException, ServletException { // get form values... Integer action = new Integer( (String) request.getParameter("which_action").trim() ); // store the action that the user want... session.setAttribute(CLASS_NAME + "jahiaDBWhichAction", action); // determine which action are requested... if(action.intValue() == 3) { displayBackup( request, response, session ); } else if(action.intValue() == 4) { displayRestore(request, response, session ); } else { displaySettings( request, response, session ); } } // end processChoice /** * Process and check the validity of the database backup page. If input(s) * are not valid, display the backup page to the user. * @author Alexandre Kraft * * @param request Servlet request. * @param response Servlet response. * @param session Servlet session for the current user. */ private void processBackup( HttpServletRequest request, HttpServletResponse response, HttpSession session ) throws IOException, ServletException { synchronized ( mLock ){ JahiaUser user = (JahiaUser)session.getAttribute(ParamBean.SESSION_USER); if ( user == null || !user.isAdminMember(0) ){ session.setAttribute(CLASS_NAME + "jahiaDisplayMessage", "Illegal Access Operation"); JahiaAdministration.doRedirect( request, response, session, JSP_PATH + "menu.jsp" ); return; } byte[] jahiaLock = null; try { jahiaLock = Jahia.getLock(user,session); if ( jahiaLock == null ){ session.setAttribute(CLASS_NAME + "jahiaDisplayMessage", "Cannot get exclusieve lock on Jahia"); JahiaAdministration.doRedirect( request, response, session, JSP_PATH + "menu.jsp" ); return; } } catch ( JahiaException je ){ session.setAttribute(CLASS_NAME + "jahiaDisplayMessage", je.getMessage() ); JahiaAdministration.doRedirect( request, response, session, JSP_PATH + "menu.jsp" ); return; } try { boolean processError = true; // get form values... String jahiaBackupName = (String) request.getParameter("backupname").trim(); String jahiaBackupDesc = (String) request.getParameter("backupdesc").trim(); String jahiaBackupType = (String) request.getParameter("backuptype").trim(); // check form validity... if(jahiaBackupName.length() == 0) { session.setAttribute(CLASS_NAME + "jahiaDisplayMessage", "Backup name must be set."); } else { processError = false; } if(processError) { session.setAttribute(CLASS_NAME + "jahiaBackupName", jahiaBackupName); displayBackup( request, response, session ); } else { // grab current database data... String sqlGrab = grabDatabaseData( properties.getProperty("db_driver"), properties.getProperty("db_url"), properties.getProperty("db_username"), properties.getProperty("db_password") ); Enumeration allGrabbedData = JahiaTools.string2Enumeration( sqlGrab, false ); // get current epoch time... String epochTime = new Long( JahiaTools.getCurrentDateInMs() ).toString(); // format paths... String originDataJahiaFilesPath = JahiaTools.convertContexted( properties.getProperty("jahiaFilesBigTextDiskPath").trim(), context ); String originTemplatesJahiaFilesPath = JahiaTools.convertContexted( properties.getProperty("jahiaFilesTemplatesDiskPath").trim(), context ); String originTemplatesJSPPath = JahiaTools.convertContexted( "$context/"+properties.getProperty("jahiaTemplatesDiskPath").trim(), context ); String backupJahiaFilesPath = JahiaTools.convertContexted( properties.getProperty("jahiaVarDiskPath").trim() + File.separator + "backup", context ); String thisBackupJahiaFilesPath = backupJahiaFilesPath + File.separator + epochTime; String backupDataJahiaFilesPath = thisBackupJahiaFilesPath + File.separator + "data"; String backupTemplatesJahiaFilesPath = thisBackupJahiaFilesPath + File.separator + "templates" + File.separator + "xml"; String backupTemplatesJSPPath = thisBackupJahiaFilesPath + File.separator + "templates" + File.separator + "jsp"; // backup jahiafiles (data and templates folders)... JahiaTools.copyFolderContent( originDataJahiaFilesPath, backupDataJahiaFilesPath ); JahiaTools.copyFolderContent( originTemplatesJahiaFilesPath, backupTemplatesJahiaFilesPath ); JahiaTools.copyFolderContent( originTemplatesJSPPath, backupTemplatesJSPPath ); // create infos text... StringBuffer nfoText = new StringBuffer(); nfoText.append("epoch=" + epochTime + "\n"); nfoText.append("name=" + JahiaTools.string2Property(jahiaBackupName) + "\n"); nfoText.append("desc=" + JahiaTools.string2Property(jahiaBackupDesc) + "\n"); nfoText.append("type=" + jahiaBackupType + "\n"); nfoText.append("build=" + Jahia.BUILD_NUMBER + "\n"); nfoText.append("release=" + Jahia.RELEASE_NUMBER + "\n"); // create backup sql runtime text... JahiaTools.writeStringInFile( thisBackupJahiaFilesPath + File.separator + "sqldata.backup", sqlGrab ); JahiaTools.writeStringInFile( backupJahiaFilesPath + File.separator + "backup_" + epochTime + ".info", nfoText.toString() ); // display final... /* request.setAttribute( "processMessage", "Your database backup has completed successfully." ); session.setAttribute( CLASS_NAME + "jahiaDisplayMessage", Jahia.COPYRIGHT ); JahiaAdministration.doRedirect( request, response, session, JSP_PATH + "finish.jsp" ); */ session.setAttribute( CLASS_NAME + "jahiaDisplayMessage", "Your database backup has completed successfully." ); displayRestore( request, response, session ); } } catch ( Throwable t ){ t.printStackTrace(); session.setAttribute(CLASS_NAME + "jahiaDisplayMessage", "Error occured"); JahiaAdministration.doRedirect( request, response, session, JSP_PATH + "menu.jsp" ); return; } finally { Jahia.releaseLock(jahiaLock); } } } // end processBackup /** * Process the restoration of a database backup. * @author Alexandre Kraft * * @param request Servlet request. * @param response Servlet response. * @param session Servlet session for the current user. */ private void processRestore( HttpServletRequest request, HttpServletResponse response, HttpSession session ) throws IOException, ServletException { synchronized ( mLock ){ boolean processError = true; byte[] jahiaLock = null; boolean freeLock = true; JahiaUser user = (JahiaUser)session.getAttribute(ParamBean.SESSION_USER); if ( user == null || !user.isAdminMember(0) ){ session.setAttribute(CLASS_NAME + "jahiaDisplayMessage", "Illegal Access Operation"); JahiaAdministration.doRedirect( request, response, session, JSP_PATH + "menu.jsp" ); return; } try { jahiaLock = Jahia.getLock(user,session); if ( jahiaLock == null ){ session.setAttribute(CLASS_NAME + "jahiaDisplayMessage", "Cannot get Jahia Lock"); JahiaAdministration.doRedirect( request, response, session, JSP_PATH + "menu.jsp" ); return; } } catch ( JahiaException je ){ session.setAttribute(CLASS_NAME + "jahiaDisplayMessage", je.getMessage()); JahiaAdministration.doRedirect( request, response, session, JSP_PATH + "menu.jsp" ); return; } try { // get url epoch values... String jahiaBackupEpoch = ""; if ( request.getParameter("epoch") != null ){ jahiaBackupEpoch = (String) request.getParameter("epoch").trim(); } // get parameters String backupBuild = ""; if ( request.getParameter("build") != null ){ backupBuild = (String) request.getParameter("build").trim(); } String backupRelease = ""; if ( request.getParameter("release") != null ){ backupRelease = (String) request.getParameter("release").trim(); } if ( backupBuild == null || backupBuild.equals("") ){ backupBuild="-1"; } if ( backupRelease == null || backupRelease.equals("") ){ backupRelease="-1.0"; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -