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

📄 cmsimportversion5.java

📁 找了很久才找到到源代码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/*
 * File   : $Source: /usr/local/cvs/opencms/src/org/opencms/importexport/CmsImportVersion5.java,v $
 * Date   : $Date: 2007-08-23 10:12:14 $
 * Version: $Revision: 1.5 $
 *
 * This library is part of OpenCms -
 * the Open Source Content Management System
 *
 * Copyright (c) 2002 - 2007 Alkacon Software GmbH (http://www.alkacon.com)
 *
 * 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 Alkacon Software GmbH, please see the
 * company website: http://www.alkacon.com
 *
 * For further information about OpenCms, please see the
 * project 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 org.opencms.importexport;

import org.opencms.file.CmsFile;
import org.opencms.file.CmsObject;
import org.opencms.file.CmsResource;
import org.opencms.file.CmsResourceFilter;
import org.opencms.file.types.CmsResourceTypePlain;
import org.opencms.file.types.I_CmsResourceType;
import org.opencms.i18n.CmsMessageContainer;
import org.opencms.loader.CmsLoaderException;
import org.opencms.main.CmsException;
import org.opencms.main.CmsLog;
import org.opencms.main.OpenCms;
import org.opencms.relations.CmsRelation;
import org.opencms.relations.CmsRelationType;
import org.opencms.relations.I_CmsLinkParseable;
import org.opencms.report.I_CmsReport;
import org.opencms.security.CmsAccessControlEntry;
import org.opencms.security.CmsRole;
import org.opencms.security.I_CmsPasswordHandler;
import org.opencms.security.I_CmsPrincipal;
import org.opencms.util.CmsDateUtil;
import org.opencms.util.CmsUUID;

import java.io.File;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.zip.ZipFile;

import org.apache.commons.logging.Log;

import org.dom4j.Document;
import org.dom4j.Element;

/**
 * Implementation of the OpenCms Import Interface ({@link org.opencms.importexport.I_CmsImport}) for 
 * the import version 5.<p>
 * 
 * This import format is used in OpenCms since 7 dev branch.<p>
 *
 * @author Michael Moossen 
 * 
 * @version $Revision: 1.5 $ 
 * 
 * @since 6.3.0 
 * 
 * @see org.opencms.importexport.A_CmsImport
 */
public class CmsImportVersion5 extends A_CmsImport {

    /** The version number of this import implementation.<p> */
    public static final int IMPORT_VERSION = 5;

    /** The log object for this class. */
    private static final Log LOG = CmsLog.getLog(CmsImportVersion5.class);

    /** Stores all relations defined in the import file to be created after all resources has been imported. */
    private Map m_importedRelations;

    /** Stores all resources of any type that implements the {@link I_CmsLinkParseable} interface. */
    private List m_parseables;

    /**
     * Creates a new CmsImportVerion7 object.<p>
     */
    public CmsImportVersion5() {

        m_convertToXmlPage = true;
    }

    /**
     * @see org.opencms.importexport.I_CmsImport#getVersion()
     */
    public int getVersion() {

        return CmsImportVersion5.IMPORT_VERSION;
    }

    /**
     * @see org.opencms.importexport.I_CmsImport#importResources(org.opencms.file.CmsObject, java.lang.String, org.opencms.report.I_CmsReport, java.io.File, java.util.zip.ZipFile, org.dom4j.Document)
     */
    public void importResources(
        CmsObject cms,
        String importPath,
        I_CmsReport report,
        File importResource,
        ZipFile importZip,
        Document docXml) throws CmsImportExportException {

        // initialize the import       
        initialize();
        m_cms = cms;
        m_importPath = importPath;
        m_report = report;
        m_importResource = importResource;
        m_importZip = importZip;
        m_docXml = docXml;
        m_linkStorage = new HashMap();
        m_linkPropertyStorage = new HashMap();
        m_parseables = new ArrayList();
        m_importedRelations = new HashMap();

        try {
            // first import the user information
            if (OpenCms.getRoleManager().hasRole(cms, CmsRole.ACCOUNT_MANAGER)) {
                importGroups();
                importUsers();
            }
            // now import the VFS resources
            readResourcesFromManifest();
            convertPointerToSiblings();
            rewriteParseables();
            importRelations();
        } finally {
            cleanUp();
        }
    }

    /**
     * Imports the relations.<p>
     */
    protected void importRelations() {

        if (m_importedRelations.isEmpty()) {
            return;
        }

        m_report.println(Messages.get().container(Messages.RPT_START_IMPORT_RELATIONS_0), I_CmsReport.FORMAT_HEADLINE);

        int i = 0;
        Iterator it = m_importedRelations.entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry entry = (Entry)it.next();
            String resourcePath = (String)entry.getKey();
            List relations = (List)entry.getValue();

            m_report.print(org.opencms.report.Messages.get().container(
                org.opencms.report.Messages.RPT_SUCCESSION_2,
                String.valueOf(i + 1),
                String.valueOf(m_importedRelations.size())), I_CmsReport.FORMAT_NOTE);

            m_report.print(Messages.get().container(
                Messages.RPT_IMPORTING_RELATIONS_FOR_2,
                resourcePath,
                new Integer(relations.size())), I_CmsReport.FORMAT_NOTE);
            m_report.print(org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_DOTS_0));

            boolean withErrors = false;
            Iterator itRelations = relations.iterator();
            while (itRelations.hasNext()) {
                CmsRelation relation = (CmsRelation)itRelations.next();
                try {
                    // Add the relation to the resource
                    m_cms.importRelation(
                        m_cms.getSitePath(relation.getSource(m_cms, CmsResourceFilter.ALL)),
                        m_cms.getSitePath(relation.getTarget(m_cms, CmsResourceFilter.ALL)),
                        relation.getType().getName());
                } catch (CmsException e) {
                    m_report.addWarning(e);
                    withErrors = true;
                    if (LOG.isWarnEnabled()) {
                        LOG.warn(e.getLocalizedMessage());
                    }
                    if (LOG.isDebugEnabled()) {
                        LOG.debug(e.getLocalizedMessage(), e);
                    }
                }
            }
            if (!withErrors) {
                m_report.println(
                    org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_OK_0),
                    I_CmsReport.FORMAT_OK);
            } else {
                m_report.println(
                    org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_FAILED_0),
                    I_CmsReport.FORMAT_ERROR);
            }
            i++;
        }

        m_report.println(Messages.get().container(Messages.RPT_END_IMPORT_RELATIONS_0), I_CmsReport.FORMAT_HEADLINE);
    }

    /**
     * Reads all the relations of the resource from the <code>manifest.xml</code> file
     * and adds them to the according resource.<p>
     * 
     * @param resource the resource to import the relations for 
     * @param parentElement the current element
     */
    protected void importRelations(CmsResource resource, Element parentElement) {

        // Get the nodes for the relations        
        List relationElements = parentElement.selectNodes("./"
            + CmsImportExportManager.N_RELATIONS
            + "/"
            + CmsImportExportManager.N_RELATION);

        List relations = new ArrayList();
        // iterate over the nodes
        Iterator itRelations = relationElements.iterator();
        while (itRelations.hasNext()) {
            Element relationElement = (Element)itRelations.next();
            String structureID = CmsImport.getChildElementTextValue(
                relationElement,
                CmsImportExportManager.N_RELATION_ATTRIBUTE_ID);
            String targetPath = CmsImport.getChildElementTextValue(
                relationElement,
                CmsImportExportManager.N_RELATION_ATTRIBUTE_PATH);
            String relationType = CmsImport.getChildElementTextValue(
                relationElement,
                CmsImportExportManager.N_RELATION_ATTRIBUTE_TYPE);
            CmsUUID targetId = new CmsUUID(structureID);
            CmsRelationType type = CmsRelationType.valueOf(relationType);

            CmsRelation relation = new CmsRelation(
                resource.getStructureId(),
                resource.getRootPath(),
                targetId,
                targetPath,
                type);

            relations.add(relation);
        }

        if (!relations.isEmpty()) {
            m_importedRelations.put(resource.getRootPath(), relations);
        }
    }

    /**

⌨️ 快捷键说明

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