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.CmsImportParameters; 032import org.opencms.main.CmsLog; 033import org.opencms.main.OpenCms; 034import org.opencms.report.A_CmsReportThread; 035import org.opencms.util.CmsUUID; 036 037import org.apache.commons.logging.Log; 038 039/** 040 * Imports an OpenCms export file into the VFS.<p> 041 * 042 * @since 6.0.0 043 */ 044public class CmsDatabaseImportThread extends A_CmsReportThread { 045 046 /** The log object for this class. */ 047 private static final Log LOG = CmsLog.getLog(CmsDatabaseImportThread.class); 048 049 /** The import file name. */ 050 private String m_importFile; 051 052 /** The keep permissions flag. */ 053 private boolean m_keepPermissions; 054 055 /** 056 * Imports an OpenCms export file into the VFS.<p> 057 * 058 * @param cms the current OpenCms context object 059 * @param importFile the file to import 060 * @param keepPermissions if set, the permissions set on existing resources will not be modified 061 */ 062 public CmsDatabaseImportThread(CmsObject cms, String importFile, boolean keepPermissions) { 063 064 super(cms, Messages.get().getBundle().key(Messages.GUI_DB_IMPORT_THREAD_NAME_1, importFile)); 065 m_importFile = importFile; 066 m_keepPermissions = keepPermissions; 067 initHtmlReport(cms.getRequestContext().getLocale()); 068 } 069 070 /** 071 * @see org.opencms.report.A_CmsReportThread#getReportUpdate() 072 */ 073 @Override 074 public String getReportUpdate() { 075 076 return getReport().getReportUpdate(); 077 } 078 079 /** 080 * @see java.lang.Runnable#run() 081 */ 082 @Override 083 public void run() { 084 085 CmsImportParameters parameters = new CmsImportParameters(m_importFile, "/", m_keepPermissions); 086 CmsUUID pauseId = OpenCms.getSearchManager().pauseOfflineIndexing(); 087 try { 088 OpenCms.getImportExportManager().importData(getCms(), getReport(), parameters); 089 } catch (Throwable e) { 090 getReport().println(e); 091 if (LOG.isErrorEnabled()) { 092 LOG.error(Messages.get().getBundle().key(Messages.ERR_DB_IMPORT_0), e); 093 } 094 } finally { 095 OpenCms.getSearchManager().resumeOfflineIndexing(pauseId); 096 } 097 } 098}