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.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 * A bean representing a module zip file to be imported.<p> 041 */ 042public class CmsModuleImportFile { 043 044 /** The module data read from the zip. */ 045 private CmsModule m_module; 046 047 /** The path of the zip fiile. */ 048 private String m_path; 049 050 /** 051 * Creates a new instance.<p> 052 * 053 * @param path the path of the module zip file to import 054 */ 055 public CmsModuleImportFile(String path) { 056 m_path = path; 057 } 058 059 /** 060 * Gets the module data.<p> 061 * 062 * @return the module data 063 */ 064 public CmsModule getModule() { 065 066 return m_module; 067 } 068 069 /** 070 * Gets the path of the zip file.<p> 071 * 072 * @return the path of the zip file 073 */ 074 public String getPath() { 075 076 return m_path; 077 } 078 079 /** 080 * Loads the module data from the zip file and validates whether the module is importable, throwing an exception otherwise.<p> 081 * 082 * @throws CmsConfigurationException if the module is not importable for some reason 083 */ 084 public void loadAndValidate() throws CmsConfigurationException { 085 086 CmsModule module = CmsModuleImportExportHandler.readModuleFromImport(m_path); 087 m_module = module; 088 List<CmsModuleDependency> dependencies = OpenCms.getModuleManager().checkDependencies( 089 module, 090 CmsModuleManager.DEPENDENCY_MODE_IMPORT); 091 if (!dependencies.isEmpty()) { 092 StringBuffer dep = new StringBuffer(32); 093 for (int i = 0; i < dependencies.size(); i++) { 094 CmsModuleDependency dependency = dependencies.get(i); 095 dep.append("\n - "); 096 dep.append(dependency.getName()); 097 dep.append(" (Version: "); 098 dep.append(dependency.getVersion()); 099 dep.append(")"); 100 } 101 throw new CmsConfigurationException( 102 org.opencms.ui.apps.Messages.get().container( 103 org.opencms.ui.apps.Messages.ERR_MODULEMANAGER_ACTION_MODULE_DEPENDENCY_2, 104 m_path, 105 new String(dep))); 106 } 107 } 108 109}