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

📄 cmsexport.java

📁 java 编写的程序
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/*
* File   : $Source: /usr/local/cvs/opencms/src/com/opencms/file/CmsExport.java,v $
* Date   : $Date: 2001/10/15 09:58:55 $
* Version: $Revision: 1.26 $
*
* 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.file;

import java.io.*;
import java.util.*;
import java.util.zip.*;
import com.opencms.core.*;
import com.opencms.template.*;
import org.w3c.dom.*;

import com.opencms.util.*;

/**
 * This class holds the functionaility to export resources from the cms
 * to the filesystem.
 *
 * @author Andreas Schouten
 * @version $Revision: 1.26 $ $Date: 2001/10/15 09:58:55 $
 */
public class CmsExport implements I_CmsConstants, Serializable {

    /**
     * The export-zipfile to store resources to
     */
    private String m_exportFile;

    /**
     * The export-stream (zip) to store resources to
     */
    private ZipOutputStream m_exportZipStream = null;

    /**
     * The export-path to read resources from the cms.
     */
    private String m_exportPath;

    /**
     * The cms-object to do the operations.
     */
    private CmsObject m_cms;

    /**
     * The xml manifest-file.
     */
    private Document m_docXml;

    /**
     * The xml-elemtent to store fileinformations to.
     */
    private Element m_filesElement;

    /**
     * The xml-elemtent to store userdatainformations to.
     */
    private Element m_userdataElement;

    /**
     * Decides, if the system should be included to the export.
     */
    private boolean m_excludeSystem;

    /**
     * Decides, if the unchanged resources should be included to the export.
     */
    private boolean m_excludeUnchanged;

    /**
     * Decides, if the userdata and groupdata should be included to the export.
     */
    private boolean m_exportUserdata;

    /**
     * Is the current project the online project?
     */
    private boolean m_isOnlineProject;

    /**
     * Cache for previously added super folders
     */
    private Vector m_superFolders;

    /**
     * This constructs a new CmsImport-object which imports the resources.
     *
     * @param importFile the file or folder to import from.
     * @param importPath the path to the cms to import into.
     * @param cms the cms-object to work with.
     * @exception CmsException the CmsException is thrown if something goes wrong.
     */
    public CmsExport(String exportFile, String[] exportPaths, CmsObject cms)
        throws CmsException {
        this(exportFile, exportPaths, cms, false, false);
    }
    /**
     * This constructs a new CmsImport-object which imports the resources.
     *
     * @param importFile the file or folder to import from.
     * @param importPath the path to the cms to import into.
     * @param cms the cms-object to work with.
     * @param Node moduleNode module informations in a Node for module-export.
     * @exception CmsException the CmsException is thrown if something goes wrong.
     */
    public CmsExport(String exportFile, String[] exportPaths, CmsObject cms, Node moduleNode)
        throws CmsException {
        this(exportFile, exportPaths, cms, false, false, moduleNode);
    }
/**
 * This constructs a new CmsImport-object which imports the resources.
 *
 * @param importFile the file or folder to import from.
 * @param exportPaths the paths of folders and files to write into the exportFile
 * @param cms the cms-object to work with.
 * @param excludeSystem if true, the system folder is excluded, if false exactly the resources in
 *        exportPaths are included
 * @param excludeUnchanged <code>true</code>, if unchanged files should be excluded.
 * @exception CmsException the CmsException is thrown if something goes wrong.
 */
public CmsExport(String exportFile, String[] exportPaths, CmsObject cms, boolean excludeSystem, boolean excludeUnchanged) throws CmsException {
    this(exportFile, exportPaths, cms, excludeSystem, excludeUnchanged, null);
}
    /**
     * This constructs a new CmsImport-object which imports the resources.
     *
     * @param importFile the file or folder to import from.
     * @param exportPaths the paths of folders and files to write into the exportFile
     * @param cms the cms-object to work with.
     * @param excludeSystem if true, the system folder is excluded, if false exactly the resources in
     *        exportPaths are included
     * @param excludeUnchanged <code>true</code>, if unchanged files should be excluded.
     * @param Node moduleNode module informations in a Node for module-export.
     * @exception CmsException the CmsException is thrown if something goes wrong.
     */
    public CmsExport(String exportFile, String[] exportPaths, CmsObject cms, boolean excludeSystem, boolean excludeUnchanged, Node moduleNode)
        throws CmsException {
        this(exportFile, exportPaths, cms, excludeSystem, excludeUnchanged, moduleNode, false);
    }
    /**
     * This constructs a new CmsImport-object which imports the resources.
     *
     * @param importFile the file or folder to import from.
     * @param exportPaths the paths of folders and files to write into the exportFile
     * @param cms the cms-object to work with.
     * @param excludeSystem if true, the system folder is excluded, if false exactly the resources in
     *        exportPaths are included
     * @param excludeUnchanged <code>true</code>, if unchanged files should be excluded.
     * @param Node moduleNode module informations in a Node for module-export.
     * @param exportUserdata if true, the userdata and groupdata are exported
     * @exception CmsException the CmsException is thrown if something goes wrong.
     */
    public CmsExport(String exportFile, String[] exportPaths, CmsObject cms, boolean excludeSystem, boolean excludeUnchanged, Node moduleNode, boolean exportUserdata)
        throws CmsException {

        m_exportFile = exportFile;
        m_cms = cms;
        m_excludeSystem = excludeSystem;
        m_excludeUnchanged = excludeUnchanged;
        m_exportUserdata = exportUserdata;
        m_isOnlineProject = cms.getRequestContext().currentProject().equals(cms.onlineProject());

        Vector folderNames = new Vector();
        Vector fileNames = new Vector();
        for (int i=0; i<exportPaths.length; i++) {
            if (exportPaths[i].endsWith(C_ROOT)) {
                folderNames.addElement(exportPaths[i]);
            } else {
                fileNames.addElement(exportPaths[i]);
            }
        }

        // open the import resource
        getExportResource();

        // create the xml-config file
        getXmlConfigFile(moduleNode);

        // remove the possible redundancies in the list of paths
        checkRedundancies(folderNames, fileNames);
        // export the folders
        for (int i=0; i<folderNames.size(); i++) {
            String path = (String) folderNames.elementAt(i);
            // first add superfolders to the xml-config file
            addSuperFolders(path);
            exportResources(path);
        }

        // export the single files
        addSingleFiles(fileNames);

        // export userdata and groupdata if desired
        if(m_exportUserdata){
            exportGroups();
            exportUsers();
        }

        // write the document to the zip-file
        writeXmlConfigFile( );

        try {
            m_exportZipStream.close();
        } catch(IOException exc) {
            throw new CmsException(CmsException.C_UNKNOWN_EXCEPTION, exc);
        }
    }
    /**
     * Adds a element to the xml-document.
     * @param element The element to add the subelement to.
     * @param name The name of the new subelement.
     * @param value The value of the element.
     */
    private void addCdataElement(Element element, String name, String value) {
        Element newElement = m_docXml.createElement(name);
        element.appendChild(newElement);
        CDATASection text = m_docXml.createCDATASection(value);
        newElement.appendChild(text);
    }
    /**
     * Adds a element to the xml-document.
     * @param element The element to add the subelement to.
     * @param name The name of the new subelement.
     * @param value The value of the element.
     */
    private void addElement(Element element, String name, String value) {
        Element newElement = m_docXml.createElement(name);
        element.appendChild(newElement);
        Text text = m_docXml.createTextNode(value);
        newElement.appendChild(text);
    }

⌨️ 快捷键说明

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