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

📄 cmsimport.java

📁 内容管理
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
/*
* File   : $Source: /usr/local/cvs/opencms/src/com/opencms/file/Attic/CmsImport.java,v $
* Date   : $Date: 2003/04/16 10:53:53 $
* Version: $Revision: 1.91 $
*
* 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 com.opencms.boot.CmsBase;
import com.opencms.core.A_OpenCms;
import com.opencms.core.CmsException;
import com.opencms.core.I_CmsConstants;
import com.opencms.core.OpenCms;
import com.opencms.flex.util.CmsStringSubstitution;
import com.opencms.linkmanagement.CmsPageLinks;
import com.opencms.report.I_CmsReport;
import com.opencms.template.A_CmsXmlContent;
import com.opencms.template.CmsXmlXercesParser;
import com.opencms.util.LinkSubstitution;
import com.opencms.workplace.I_CmsWpConstants;

import java.io.*;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.Vector;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

import org.w3c.dom.CDATASection;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.NodeList;


/**
 * Holds the functionaility to import resources from the filesystem
 * or a zip file into the OpenCms VFS.
 *
 * @author Andreas Schouten
 * @author Andreas Zahner (a.zahner@alkacon.com)
 * @author Alexander Kandzior (a.kandzior@alkacon.com)
 * 
 * @version $Revision: 1.91 $ $Date: 2003/04/16 10:53:53 $
 */
public class CmsImport implements I_CmsConstants, I_CmsWpConstants, Serializable {
    
    /** The algorithm for the message digest */
    public static final String C_IMPORT_DIGEST = "MD5";
        
    /** The cms contect to do the operations on the VFS/COS with */
    protected CmsObject m_cms;
    
    /** The xml manifest-file */
    protected Document m_docXml;  
    
    /** The object to report the log messages */
    protected I_CmsReport m_report = null;
    
    /** The import-resource (folder) to load resources from */
    protected File m_importResource = null;

    /**  The import-resource (zip) to load resources from */
    protected ZipFile m_importZip = null;
    
    /** Indicates if module data is being imported */
    protected boolean m_importingChannelData;         
         
    /** The import-file to load resources from */
    protected String m_importFile;

    /** The import-path to write resources into the cms */
    protected String m_importPath;  
    
    /**
     * The version of this import, noted in the info tag of the manifest.xml.<p>
     * 
     * 0 indicates an export file without a version number, that is before version 4.3.23 of OpenCms.<br>
     * 1 indicates an export file of OpenCms with a version before 5.0.0
     * 2 is the current (since 5.0.0) version of the export file    
     */
    private int m_importVersion = 0;           
    
    /** The path to the bodies in OpenCms 4.x */
    private static final String C_VFS_PATH_OLD_BODIES = "/content/bodys/";   

    /** Web application names for conversion support */
    private List m_webAppNames = new ArrayList();
    
    /** Old webapp URL for import conversion */
    private String m_webappUrl = null;

    /** Digest for taking a fingerprint of the files */
    private MessageDigest m_digest = null;

    /** Groups to create during import are stored here */
    private Stack m_groupsToCreate = new Stack();

    /**
     * In this vector we store the imported pages (as Strings from getAbsolutePath()),
     * after the import we check them all to update the link tables for the linkmanagement.
     */
    private Vector m_importedPages = new Vector();    
   
    /** Debug flag to show debug output */
    private static final int DEBUG = 0;
       
    /**
     * Constructs a new uninitialized import, required for the module data import.<p>
     * 
     * @see CmsImportModuledata
     */
    public CmsImport () {
        // empty constructor
    }       
       
    /**
     * Constructs a new import object which imports the resources from an OpenCms 
     * export zip file or a folder in the "real" file system.<p>
     *
     * @param cms the current cms object
     * @param importFile the file or folder to import from
     * @param importPath the path in the cms VFS to import into
     * @param report a report object to output the progress information to
     * @throws CmsException if something goes wrong
     */
    public CmsImport(
        CmsObject cms, 
        String importFile, 
        String importPath, 
        I_CmsReport report
    ) throws CmsException {
        // set member variables
        m_cms = cms;
        m_importFile = importFile;
        m_importPath = importPath;        
        m_report = report;  
        m_importingChannelData = false;       
    }
    
    /**
     * Imports the resources and writes them to the cms VFS, even if there 
     * already exist files with the same name.<p>
     * 
     * @throws CmsException if something goes wrong
     */
    public void importResources() throws CmsException {
        // initialize the import
        openImportFile();
        try {
            // first import the user information
            if (m_cms.isAdmin()) {
                importGroups();
                importUsers();
            }
            
            // now import the VFS resources
            importAllResources(null, null, null, null, null);
        } catch (CmsException e) {
            throw e;
        } finally {
            // close the import file
            closeImportFile();
        }
    }

    /**
     * Imports the resources for a module.<p>
     * 
     * @param excludeList filenames of files and folders which should not 
     *      be (over)written in the virtual file system (not used when null)
     * @param writtenFilenames filenames of the files and folder which have actually been 
     *      successfully written (not used when null)
     * @param fileCodes code of the written files (for the registry)
     *      (not used when null)
     * @param propertyName name of a property to be added to all resources
     * @param propertyValue value of that property
     * @throws CmsException if something goes wrong
     */
    public void importResources(
        Vector excludeList, 
        Vector writtenFilenames, 
        Vector fileCodes, 
        String propertyName, 
        String propertyValue
    ) throws CmsException {
        // initialize the import
        openImportFile();
        try {            
            // now import the VFS resources
            importAllResources(excludeList, writtenFilenames, fileCodes, propertyName, propertyValue);
        } catch (CmsException e) {
            throw e;
        } finally {
            // close the import file
            closeImportFile();
        }
    }
            
    /**
     * Initilizes the import.<p>
     * 
     * @throws CmsException if something goes wrong
     */
    protected void openImportFile() throws CmsException {        
        // create the digest
        createDigest();

        // open the import resource
        getImportResource();

        // read the xml-config file
        getXmlConfigFile();

        // try to read the export version nummber
        try{
            m_importVersion = Integer.parseInt(
                getTextNodeValue((Element)m_docXml.getElementsByTagName(
                    C_EXPORT_TAG_INFO).item(0), C_EXPORT_TAG_VERSION));
        } catch(Exception e){
            //ignore the exception, the export file has no version nummber (version 0).
        }        
    }
    
    /**
     * Closes the import file.<p>
     * 
     * @throws CmsException if something goes wrong
     */
    protected void closeImportFile() throws CmsException {  
        if (m_importZip != null) {
            try {
                m_importZip.close();
            } catch (IOException exc) {
                m_report.println(exc);
                throw new CmsException(CmsException.C_UNKNOWN_EXCEPTION, exc);
            }
        }        
    }
        
    /**
     * Read infos from the properties and create a MessageDigest.<p>
     * 
     * @throws CmsException if something goes wrong
     */
    private void createDigest() throws CmsException {
        // Configurations config = m_cms.getConfigurations();
    
        String digest = C_IMPORT_DIGEST;
        // create the digest
        try {
            m_digest = MessageDigest.getInstance(digest);
        } catch (NoSuchAlgorithmException e) {
            throw new CmsException("Could'nt create MessageDigest with algorithm " + digest);
        }
    }

    /**
     * Creates missing property definitions if needed.<p>
     *
     * @param name the name of the property.
     * @param propertyType the type of the property.
     * @param resourceType the type of the resource.
     *
     * @throws throws CmsException if something goes wrong.
     */
    private void createPropertydefinition(String name, String resourceType) throws CmsException {
        // does the propertydefinition exists already?
        try {
            m_cms.readPropertydefinition(name, resourceType);
        } catch(CmsException exc) {
            // no: create it
            m_cms.createPropertydefinition(name, resourceType);
        }
    }

    /**
     * Returns a list of files which are both in the import and in the virtual file system.<p>
     * 
     * @return Vector of Strings, complete path of the files
     */
    public Vector getConflictingFilenames() throws CmsException {
        NodeList fileNodes;
        Element currentElement;
        String source, destination;
        Vector conflictNames = new Vector();
        try {
            // get all file-nodes
            fileNodes = m_docXml.getElementsByTagName(C_EXPORT_TAG_FILE);
    
            // walk through all files in manifest
            for (int i = 0; i < fileNodes.getLength(); i++) {
                currentElement = (Element)fileNodes.item(i);
                source = getTextNodeValue(currentElement, C_EXPORT_TAG_SOURCE);
                destination = getTextNodeValue(currentElement, C_EXPORT_TAG_DESTINATION);
                if (source != null) {
                    // only consider files

⌨️ 快捷键说明

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