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 GmbH & Co. KG, 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.workplace.threads;
029
030import org.opencms.file.CmsObject;
031import org.opencms.importexport.I_CmsImportExportHandler;
032import org.opencms.main.CmsLog;
033import org.opencms.main.OpenCms;
034import org.opencms.report.A_CmsReportThread;
035
036import org.apache.commons.logging.Log;
037
038/**
039 * Exports selected resources of the OpenCms into an OpenCms export file.<p>
040 *
041 * @since 6.0.0
042 */
043public class CmsExportThread extends A_CmsReportThread {
044
045    /** The log object for this class. */
046    private static final Log LOG = CmsLog.getLog(CmsExportThread.class);
047
048    /** The import export handler. */
049    private I_CmsImportExportHandler m_handler;
050
051    /**
052     * Creates a new data export thread.<p>
053     *
054     * @param cms the current OpenCms context object
055     * @param handler export handler containing the export data
056     * @param old flag for old report mode
057     */
058    public CmsExportThread(CmsObject cms, I_CmsImportExportHandler handler, boolean old) {
059
060        super(cms, "OpenCms: " + handler.getDescription());
061        m_handler = handler;
062        if (old) {
063            initOldHtmlReport(cms.getRequestContext().getLocale());
064        } else {
065            initHtmlReport(cms.getRequestContext().getLocale());
066        }
067    }
068
069    /**
070     * @see org.opencms.report.A_CmsReportThread#getReportUpdate()
071     */
072    @Override
073    public String getReportUpdate() {
074
075        return getReport().getReportUpdate();
076    }
077
078    /**
079     * @see java.lang.Runnable#run()
080     */
081    @Override
082    public void run() {
083
084        try {
085            OpenCms.getImportExportManager().exportData(getCms(), m_handler, getReport());
086        } catch (Throwable e) {
087            getReport().println(e);
088            LOG.error(Messages.get().getBundle().key(Messages.ERR_DB_EXPORT_0), e);
089        }
090    }
091}