📄 managedatabase.java
字号:
// $Id: ManageDatabase.java,v 1.7 2002/06/13 15:07:22 knguyen Exp $//// ____.// __/\ ______| |__/\. _______// __ .____| | \ | +----+ \// _______| /--| | | - \ _ | : - \_________// \\______: :---| : : | : | \________>// |__\---\_____________:______: :____|____:_____\// /_____|//// . . . i n j a h i a w e t r u s t . . .////// ManageDatabase//// 01.04.2001 AK added in jahia.// 23.05.2001 NK bug with new line corrected.//package org.jahia.admin.database;import java.io.*;import java.util.*;import java.sql.*;import javax.servlet.*;import javax.servlet.http.*;import org.jahia.bin.*;import org.jahia.utils.*;import org.jahia.utils.properties.*;import org.jahia.services.usermanager.*;import org.jahia.params.*;import org.jahia.exceptions.*;import org.jahia.registries.ServicesRegistry;/** * desc: This class is used by the administration to manage the * database settings, like the database connection settings, or is also * used by jahia to transfer jahia data to an another database. Backup * and restore are alse executed by this class. * * Copyright: Copyright (c) 2002 * Company: Jahia Ltd * * @author Alexandre Kraft * @version 1.0 */public class ManageDatabase{ private static final String CLASS_NAME = JahiaAdministration.CLASS_NAME; private static final String JSP_PATH = JahiaAdministration.JSP_PATH; private static DatabaseConnection dbConnect = new DatabaseConnection(); private static DatabaseScripts scriptsManager; private static PropertiesManager properties; private static ServletContext context; private static byte[] mLock = new byte[1]; /** * Default constructor. * @author Alexandre Kraft * * @param request Servlet request. * @param response Servlet response. * @param session Servlet session for the current user. * @param context Servlet context. */ public ManageDatabase( HttpServletRequest request, HttpServletResponse response, HttpSession session, ServletContext context ) throws Throwable { this.context = context; properties = new PropertiesManager( Jahia.getJahiaPropertiesFileName() ); scriptsManager = new DatabaseScripts(); userRequestDispatcher( request, response, session ); } // end constructor /** * This method is used like a dispatcher for user requests. * @author Alexandre Kraft * * @param request Servlet request. * @param response Servlet response. * @param session Servlet session for the current user. */ private void userRequestDispatcher( HttpServletRequest request, HttpServletResponse response, HttpSession session ) throws Throwable { String operation = request.getParameter("sub"); if(operation.equals("display")) { displayChoice( request, response, session ); } else if(operation.equals("choice")) { processChoice( request, response, session ); } else if(operation.equals("backup")) { processBackup( request, response, session ); } else if(operation.equals("restore")) { processRestore( request, response, session ); } else if(operation.equals("flush")) { processFlush( request, response, session ); } else if(operation.equals("transfer")) { processSettings( request, response, session, true ); } else if(operation.equals("change")) { processSettings( request, response, session, false ); } } // userRequestDispatcher /** * Display the page where the user can choose what he want to do. He can * choice to change the database connection settings, transfer the data * from the current database to another database, backup the database * and manage the backup (like restore and flush). * @author Alexandre Kraft * * @param request Servlet request. * @param response Servlet response. * @param session Servlet session for the current user. */ private void displayChoice( HttpServletRequest request, HttpServletResponse response, HttpSession session ) throws IOException, ServletException { JahiaAdministration.doRedirect( request, response, session, JSP_PATH + "config_database_which.jsp" ); } // end displayChoice /** * Display a page where the user can choose a name and a desc * for the backup that he have requested. * @author Alexandre Kraft * * @param request Servlet request. * @param response Servlet response. * @param session Servlet session for the current user. */ private void displayBackup( HttpServletRequest request, HttpServletResponse response, HttpSession session ) throws IOException, ServletException { // retrieve previous form values... String jahiaBackupName = (String) session.getAttribute(CLASS_NAME + "jahiaBackupName"); String jahiaBackupDesc = (String) session.getAttribute(CLASS_NAME + "jahiaBackupDesc"); String jahiaBackupType = (String) session.getAttribute(CLASS_NAME + "jahiaBackupType"); // set default values (if necessary)... if(jahiaBackupName == null) { jahiaBackupName = ""; } if(jahiaBackupDesc == null) { jahiaBackupDesc = ""; } if(jahiaBackupType == null) { jahiaBackupType = "manual"; } // set request attributes... request.setAttribute("jahiaBackupName", jahiaBackupName); request.setAttribute("jahiaBackupDesc", jahiaBackupDesc); request.setAttribute("jahiaBackupType", jahiaBackupType); JahiaAdministration.doRedirect( request, response, session, JSP_PATH + "backup_database.jsp" ); } // end displayBackup /** * Display a page where the user can restore a backup or flush/delete * an unwanted backup. This method display the full list of backups. * @author Alexandre Kraft * * @param request Servlet request. * @param response Servlet response. * @param session Servlet session for the current user. */ private void displayRestore( HttpServletRequest request, HttpServletResponse response, HttpSession session ) throws IOException, ServletException { int backupCount = 0; // get backups path... StringBuffer constructBackupPath = new StringBuffer(); constructBackupPath.append( properties.getProperty("jahiaVarDiskPath").trim() ); constructBackupPath.append( File.separator ); constructBackupPath.append( "backup" ); String backupJahiaFilesPath = JahiaTools.convertContexted( constructBackupPath.toString(), context ); // get backups list... TreeSet backupListTree = new TreeSet(); File backupJahiaFilesObject = new File(backupJahiaFilesPath); File[] filesInThisDirectory = backupJahiaFilesObject.listFiles(); try { for(int i=0; i<filesInThisDirectory.length; i++) { if(filesInThisDirectory[i].isFile()) { backupListTree.add( filesInThisDirectory[i].getPath() ); } } } catch (NullPointerException npe) { } // get infos from files... Iterator iteration = backupListTree.iterator(); Vector backupListVector = new Vector(); while(iteration.hasNext()) { String pathBackupFile = (String) iteration.next(); HashMap backupHash = new HashMap(); PropertiesManager backupProperties = new PropertiesManager( pathBackupFile ); String epochTime = backupProperties.getProperty("epoch"); backupHash.put("backup.epoch", epochTime); backupHash.put("backup.date", JahiaTools.formatDateFromEpoch(epochTime)); backupHash.put("backup.name", backupProperties.getProperty("name")); backupHash.put("backup.desc", backupProperties.getProperty("desc")); backupHash.put("backup.type", backupProperties.getProperty("type")); if ( backupProperties.getProperty("build") == null ){ backupHash.put("backup.build", "0"); } else { backupHash.put("backup.build", backupProperties.getProperty("build")); } if ( backupProperties.getProperty("release") == null ){ backupHash.put("backup.release", "0.0"); } else { backupHash.put("backup.release", backupProperties.getProperty("release")); } backupListVector.add( backupHash ); backupCount++; } backupListVector = JahiaTools.inverseVector(backupListVector); // set request attributes... request.setAttribute("jahiaBackupList", backupListVector.elements()); request.setAttribute("jahiaBackupCount", new Integer(backupCount)); JahiaAdministration.doRedirect( request, response, session, JSP_PATH + "restore_database.jsp" ); } // end displayRestore /** * Display the settings page. This page is viewed two times. One time for * change the settings for the database connection and other database * settings. The second time, this page is viewed to transfer the database * to an another database. In this case, the inputs values are used like * the destination database connection settings. * @author Alexandre Kraft * * @param request Servlet request. * @param response Servlet response. * @param session Servlet session for the current user. */ private void displaySettings( HttpServletRequest request, HttpServletResponse response, HttpSession session ) throws IOException, ServletException { // get which action is requested... Integer jahiaDBWhichAction = (Integer) session.getAttribute(CLASS_NAME + "jahiaDBWhichAction");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -