001/*
002 * This library is part of OpenCms -
003 * the Open Source Content Management System
004 *
005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com)
006 *
007 * This library is free software; you can redistribute it and/or
008 * modify it under the terms of the GNU Lesser General Public
009 * License as published by the Free Software Foundation; either
010 * version 2.1 of the License, or (at your option) any later version.
011 *
012 * This library is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015 * Lesser General Public License for more details.
016 *
017 * For further information about Alkacon Software, please see the
018 * company website: http://www.alkacon.com
019 *
020 * For further information about OpenCms, please see the
021 * project website: http://www.opencms.org
022 *
023 * You should have received a copy of the GNU Lesser General Public
024 * License along with this library; if not, write to the Free Software
025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
026 */
027
028package org.opencms.ui.apps.modules;
029
030import org.opencms.file.CmsObject;
031import org.opencms.main.CmsLog;
032import org.opencms.main.OpenCms;
033import org.opencms.module.CmsModule;
034import org.opencms.module.CmsModuleManager;
035import org.opencms.report.A_CmsReportThread;
036import org.opencms.report.I_CmsReport;
037
038import org.apache.commons.logging.Log;
039
040/**
041 * Report thread for importing a module.<p>
042 */
043public class CmsModuleImportThread extends A_CmsReportThread {
044
045    /** The logger instance for this class. */
046    private static final Log LOG = CmsLog.getLog(CmsModuleImportThread.class);
047
048    /** The cms object used for the import. */
049    private CmsObject m_cms;
050
051    /** The module metadata. */
052    private CmsModule m_module;
053
054    /** The module file path. */
055    private String m_path;
056
057    /**
058     * Creates a new instance.<p>
059     *
060     * @param cms the cms object used for the import
061     * @param module the module
062     * @param path the module file path
063     */
064    public CmsModuleImportThread(CmsObject cms, CmsModule module, String path) {
065
066        super(cms, "Import of " + path);
067        m_module = module;
068        m_path = path;
069        m_cms = cms;
070        initHtmlReport(OpenCms.getWorkplaceManager().getWorkplaceLocale(cms));
071    }
072
073    /**
074     * @see org.opencms.report.A_CmsReportThread#getReportUpdate()
075     */
076    @Override
077    public String getReportUpdate() {
078
079        return getReport().getReportUpdate();
080    }
081
082    /**
083     * @see java.lang.Thread#run()
084     */
085    @Override
086    public void run() {
087
088        LOG.info("Starting import thread for " + m_module.getName() + ", import =  " + m_path);
089        I_CmsReport report = getReport();
090
091        try {
092            CmsObject cms = m_cms;
093            CmsModuleManager manager = OpenCms.getModuleManager();
094            manager.replaceModule(cms, m_path, report);
095        } catch (Exception e) {
096            LOG.error(e.getLocalizedMessage(), e);
097            report.addError(e);
098        }
099
100    }
101
102}