001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (c) Alkacon Software GmbH & Co. KG (https://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: https://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: https://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.dbmanager; 029 030import org.opencms.configuration.CmsConfigurationException; 031import org.opencms.main.OpenCms; 032import org.opencms.module.CmsModule; 033import org.opencms.module.CmsModuleDependency; 034import org.opencms.module.CmsModuleImportExportHandler; 035import org.opencms.module.CmsModuleManager; 036 037import java.util.List; 038 039/** 040 * 041 */ 042public class CmsImportFile { 043 044 /**Path of the file (on the server).*/ 045 private String m_path; 046 047 /**Module in OpenCms.*/ 048 private CmsModule m_module; 049 050 /** 051 * public constructor.<p> 052 * 053 * @param path of the file 054 */ 055 public CmsImportFile(String path) { 056 057 m_path = path; 058 } 059 060 /** 061 * Gets the module to import.<p> 062 * 063 * @return the CmsModule 064 */ 065 public CmsModule getModule() { 066 067 return m_module; 068 } 069 070 /** 071 * Gets the path of the file.<p> 072 * 073 * @return the server path 074 */ 075 public String getPath() { 076 077 return m_path; 078 } 079 080 /** 081 * 082 *Class to load and validate import module file.<p> 083 * 084 * @throws CmsConfigurationException gets thrown when validation fails 085 */ 086 public void loadAndValidate() throws CmsConfigurationException { 087 088 CmsModule module = CmsModuleImportExportHandler.readModuleFromImport(m_path); 089 m_module = module; 090 List<CmsModuleDependency> dependencies = OpenCms.getModuleManager().checkDependencies( 091 module, 092 CmsModuleManager.DEPENDENCY_MODE_IMPORT); 093 if (!dependencies.isEmpty()) { 094 StringBuffer dep = new StringBuffer(32); 095 for (int i = 0; i < dependencies.size(); i++) { 096 CmsModuleDependency dependency = dependencies.get(i); 097 dep.append("\n - "); 098 dep.append(dependency.getName()); 099 dep.append(" (Version: "); 100 dep.append(dependency.getVersion()); 101 dep.append(")"); 102 } 103 // throw new CmsConfigurationException( 104 // org.opencms.ui.apps.Messages.get().container( 105 // org.opencms.ui.apps.Messages.ERR_MODULEMANAGER_ACTION_MODULE_DEPENDENCY_2, 106 // m_path, 107 // new String(dep))); 108 } 109 } 110 111}