⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cmsadmindatabase.java

📁 OpenCms 是一个J2EE的产品
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
* File   : $Source: /usr/local/cvs/opencms/src-modules/com/opencms/workplace/CmsAdminDatabase.java,v $
* Date   : $Date: 2005/06/27 23:22:07 $
* Version: $Revision: 1.7 $
*
* This library is part of OpenCms -
* the Open Source Content Mananagement System
*
* Copyright (C) 2001  The OpenCms Group
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
* Lesser General Public License for more details.
*
* For further information about OpenCms, please see the
* OpenCms Website: http://www.opencms.org
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

package com.opencms.workplace;

import org.opencms.file.CmsObject;
import org.opencms.importexport.CmsVfsImportExportHandler;
import org.opencms.main.CmsException;
import org.opencms.main.CmsLog;
import org.opencms.main.OpenCms;
import org.opencms.report.A_CmsReportThread;
import org.opencms.workplace.threads.CmsDatabaseImportThread;
import org.opencms.workplace.threads.CmsExportThread;

import com.opencms.core.I_CmsSession;
import com.opencms.legacy.CmsCosImportExportHandler;
import com.opencms.legacy.CmsLegacyException;
import com.opencms.legacy.CmsLegacyModuleAction;
import com.opencms.legacy.CmsXmlTemplateLoader;

import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.StringTokenizer;
import java.util.Vector;

/**
 * This class manages the templates for import and export of the database.<p>
 *
 * @author Alexander Kandzior (a.kandzior@alkacon.com)
 * @author Andreas Schouten
 * @version $Revision: 1.7 $ 
 * @see com.opencms.workplace.CmsXmlWpTemplateFile
 * 
 * @deprecated Will not be supported past the OpenCms 6 release.
 */
public class CmsAdminDatabase extends CmsWorkplaceDefault {

    private static String C_DATABASE_THREAD = "databse_im_export_thread";

    /**
     * Gets a database importfile from the client and copys it to the server.<p>
     *
     * @param cms The CmsObject.
     * @param session The session.
     *
     * @return the name of the file.
     */
    private String copyFileToServer(
        CmsObject cms, 
        I_CmsSession session ) 
    throws CmsException{
        // get the filename
        String filename = null;
        Enumeration files = CmsXmlTemplateLoader.getRequest(cms.getRequestContext()).getFileNames();
        while(files.hasMoreElements()) {
            filename = (String)files.nextElement();
        }
        if(filename != null) {
            session.putValue(CmsWorkplaceDefault.C_PARA_RESOURCE, filename);
        }
        filename = (String)session.getValue(CmsWorkplaceDefault.C_PARA_RESOURCE);

        // get the filecontent
        byte[] filecontent = new byte[0];
        if(filename != null) {
            filecontent = CmsXmlTemplateLoader.getRequest(cms.getRequestContext()).getFile(filename);
        }
        if(filecontent != null) {
            session.putValue(CmsWorkplaceDefault.C_PARA_FILECONTENT, filecontent);
        }
        filecontent = (byte[])session.getValue(CmsWorkplaceDefault.C_PARA_FILECONTENT);
        // first create the folder if it doesnt exists
        File discFolder = new File(OpenCms.getSystemInfo().getAbsoluteRfsPathRelativeToWebInf(OpenCms.getSystemInfo().getPackagesRfsPath() + File.separator));
        if(!discFolder.exists()) {
            boolean success = discFolder.mkdir();
            if(CmsLog.getLog(this).isWarnEnabled() && (!success)) {
                CmsLog.getLog(this).warn("Couldn't create folder " + discFolder.getAbsolutePath());
            }
        }

        // now write the file into the modules dierectory in the exportpaht
        File discFile = new File(OpenCms.getSystemInfo().getAbsoluteRfsPathRelativeToWebInf(OpenCms.getSystemInfo().getPackagesRfsPath() + File.separator + filename));
        try {

            // write the new file to disk
            OutputStream s = new FileOutputStream(discFile);
            s.write(filecontent);
            s.close();
        }
        catch(Exception e) {
            throw new CmsLegacyException("[" + this.getClass().getName() + "] " + e.getMessage());
        }
        return filename;
    }

    /**
     * Gets the content of a defined section in a given template file and its subtemplates
     * with the given parameters.
     *
     * @see #getContent(CmsObject, String, String, Hashtable, String)
     * @param cms CmsObject Object for accessing system resources.
     * @param templateFile Filename of the template file.
     * @param elementName Element name of this template in our parent template.
     * @param parameters Hashtable with all template class parameters.
     * @param templateSelector template section that should be processed.
     */
    public byte[] getContent(
        CmsObject cms, 
        String templateFile, 
        String elementName,
        Hashtable parameters, 
        String templateSelector
    ) throws CmsException {               
        if(C_DEBUG && CmsLog.getLog(this).isDebugEnabled()) {
            CmsLog.getLog(this).debug("Getting content of element "
                            + ((elementName == null) ? "<root>" : elementName));
            CmsLog.getLog(this).debug("Template file is: " + templateFile);
            CmsLog.getLog(this).debug("Delected template section is: "
                            + ((templateSelector == null) ? "<default>" : templateSelector));
        }

        CmsXmlWpTemplateFile xmlTemplateDocument = new CmsXmlWpTemplateFile(cms, templateFile);
        I_CmsSession session = CmsXmlTemplateLoader.getSession(cms.getRequestContext(), true);
        CmsXmlLanguageFile lang = xmlTemplateDocument.getLanguageFile();

        // get the parameters
        // String folder = (String)parameters.get("selectallfolders");
        String fileName = (String)parameters.get("filename");
        String existingFile = (String)parameters.get("existingfile");
        String action = (String)parameters.get("action");
        String allResources = (String)parameters.get("ALLRES");
        String allModules = (String)parameters.get("ALLMOD");
        String step = (String)parameters.get("step");
 
        // here we show the report updates when the threads are allready running.
        // This is used for import (action=showResult) and for export (action=showExportResult).
        if("showResult".equals(action)){
            // thread for import is started and we need to update the report information
            A_CmsReportThread doTheWork = (A_CmsReportThread)session.getValue(C_DATABASE_THREAD);
            //still working?
            if(doTheWork.isAlive()){
                xmlTemplateDocument.setData("endMethod", "");
                xmlTemplateDocument.setData("text", "");
            }else{
                xmlTemplateDocument.setData("endMethod", xmlTemplateDocument.getDataValue("endMethod"));
                xmlTemplateDocument.setData("autoUpdate","");
                xmlTemplateDocument.setData("text", lang.getLanguageValue("database.label.importend"));
                session.removeValue(C_DATABASE_THREAD);
            }
            xmlTemplateDocument.setData("data", doTheWork.getReportUpdate());
            return startProcessing(cms, xmlTemplateDocument, elementName, parameters, "updateReport");
        }else if("showExportResult".equals(action)){
            // thread for emport is started and we need to update the report information
            A_CmsReportThread doTheWork = (A_CmsReportThread)session.getValue(C_DATABASE_THREAD);
            //still working?
            if(doTheWork.isAlive()){
                xmlTemplateDocument.setData("endMethod", "");
                xmlTemplateDocument.setData("text", "");
            }else{
                xmlTemplateDocument.setData("endMethod", xmlTemplateDocument.getDataValue("endMethod"));
                xmlTemplateDocument.setData("autoUpdate","");
                xmlTemplateDocument.setData("text", lang.getLanguageValue("database.label.exportend"));
                session.removeValue(C_DATABASE_THREAD);
            }
            xmlTemplateDocument.setData("data", doTheWork.getReportUpdate());
            return startProcessing(cms, xmlTemplateDocument, elementName, parameters, "updateReport");
        }

        if(action == null) {
            // this is an initial request of the database administration page
            // generate datablocks for checkboxes in the HTML form
            if(!cms.getRequestContext().currentProject().isOnlineProject()) {
                xmlTemplateDocument.setData("nounchanged",
                        xmlTemplateDocument.getProcessedDataValue("nounchangedbox", this, parameters));
            }
            if(cms.isAdmin()) {
                xmlTemplateDocument.setData("userdata",
                        xmlTemplateDocument.getProcessedDataValue("userdatabox", this, parameters));
            }
            xmlTemplateDocument.setData("moduleselect", this.getModuleSelectbox(cms, xmlTemplateDocument));
        }

        try {
            if("export".equals(action)) {
                // export the VFS 
                Vector resourceNames = parseResources(allResources);
                String[] exportPaths = new String[resourceNames.size()];
                for(int i = 0;i < resourceNames.size();i++) {
                    // modify the foldername if nescessary (the root folder is always given
                    // as a nice name)
                    if(lang.getLanguageValue("title.rootfolder").equals(resourceNames.elementAt(i))) {
                        resourceNames.setElementAt("/", i);
                    }
                    exportPaths[i] = (String)resourceNames.elementAt(i);
                }
                
                // default content age is 0 (Unix 1970 time, this should export all resources)
                long contentAge = 0;                
                String contentAgePara = (String)parameters.get("contentage");
                if (contentAgePara != null && (! "".equals(contentAgePara)) && (! "(none)".equals(contentAgePara))) {
                    try {
                        contentAge = Long.parseLong(contentAgePara);
                    } catch (NumberFormatException numEx) {
                        // in case a invalid number was returned, use 0 (ie. export all files)
                        contentAge = 0;
                    }
                }
                
                boolean excludeSystem = false;
                if (parameters.get("nosystem") != null) {
                    excludeSystem = true;
                }
                boolean excludeUnchanged = false;
                if (parameters.get("nounchanged") != null) {
                    excludeUnchanged = true;
                }
                boolean exportUserdata = false;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -