📄 cmsmodule.java
字号:
/*
* File : $Source: /usr/local/cvs/opencms/src/org/opencms/module/CmsModule.java,v $
* Date : $Date: 2006/03/27 14:53:03 $
* Version: $Revision: 1.30 $
*
* This library is part of OpenCms -
* the Open Source Content Mananagement System
*
* Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* For further information about Alkacon Software GmbH, please see the
* company website: http://www.alkacon.com
*
* For further information about OpenCms, please see the
* project website: http://www.opencms.org
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.opencms.module;
import org.opencms.file.CmsObject;
import org.opencms.main.CmsIllegalArgumentException;
import org.opencms.main.CmsLog;
import org.opencms.security.CmsRole;
import org.opencms.security.CmsRoleViolationException;
import org.opencms.util.CmsFileUtil;
import org.opencms.util.CmsStringUtil;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.SortedMap;
import java.util.StringTokenizer;
import java.util.TreeMap;
import org.apache.commons.logging.Log;
/**
* Describes an OpenCms module.<p>
*
* OpenCms modules provide a standard mechanism to extend the OpenCms functionality.
* Modules can contain VFS data, Java classes and a number of configuration options.<p>
*
* @author Alexander Kandzior
*
* @version $Revision: 1.30 $
*
* @since 6.0.0
*
* @see org.opencms.module.I_CmsModuleAction
* @see org.opencms.module.A_CmsModuleAction
*/
public class CmsModule implements Comparable {
/** The default date for module created / installed if not provided. */
public static final long DEFAULT_DATE = 0L;
/** The log object for this class. */
private static final Log LOG = CmsLog.getLog(CmsModule.class);
/**
* The module property key name to specifiy additional resources which are
* part of a module outside of {system/modules}.
*/
private static final String MODULE_PROPERTY_ADDITIONAL_RESOURCES = "additionalresources";
/** Character to separate additional resources specified in the module properties. */
private static final String MODULE_PROPERTY_ADDITIONAL_RESOURCES_SEPARATOR = ";";
/** The module action class name. */
private String m_actionClass;
/** Initialized module action instance. */
private I_CmsModuleAction m_actionInstance;
/** The email of the author of this module. */
private String m_authorEmail;
/** The name of the author of this module. */
private String m_authorName;
/** Flag to create the classes folders when creating the module. */
private boolean m_createClassesFolder;
/** Flag to create the elements folder when creating the module. */
private boolean m_createElementsFolder;
/** Flag to create the lib folder when creating the module. */
private boolean m_createLibFolder;
/** Flag to create the module folder when creating the module. */
private boolean m_createModuleFolder;
/** Flag to create the resources folder when creating the module. */
private boolean m_createResourcesFolder;
/** Flag to create the template folder when creating the module. */
private boolean m_createTemplateFolder;
/** The date this module was created by the author. */
private long m_dateCreated;
/** The date this module was installed. */
private long m_dateInstalled;
/** List of dependencies of this module. */
private List m_dependencies;
/** The description of this module. */
private String m_description;
/** The explorer type settings. */
private List m_explorerTypeSettings;
/** List of export points added by this module. */
private List m_exportPoints;
/** Indicates if this modules configuration has already been frozen. */
private boolean m_frozen;
/** The group of the module. */
private String m_group;
/** The name of this module, must be a valid Java package name. */
private String m_name;
/** The "nice" display name of this module. */
private String m_niceName;
/** The additional configuration parameters of this module. */
private SortedMap m_parameters;
/** List of VFS resources that belong to this module. */
private List m_resources;
/** The list of additional resource types. */
private List m_resourceTypes;
/** The name of the user who installed this module. */
private String m_userInstalled;
/** The version of this module. */
private CmsModuleVersion m_version;
/**
* Creates a new, empty CmsModule object.<p>
*/
public CmsModule() {
m_version = new CmsModuleVersion(CmsModuleVersion.DEFAULT_VERSION);
m_resources = Collections.EMPTY_LIST;
m_exportPoints = Collections.EMPTY_LIST;
m_dependencies = Collections.EMPTY_LIST;
}
/**
* Creates a new module description with the specified values.<p>
*
* @param name the name of this module, must be a valid Java package name
* @param niceName the "nice" display name of this module
* @param group the group of this module
* @param actionClass the (optional) module class name
* @param description the description of this module
* @param version the version of this module
* @param authorName the name of the author of this module
* @param authorEmail the email of the author of this module
* @param dateCreated the date this module was created by the author
* @param userInstalled the name of the user who uploaded this module
* @param dateInstalled the date this module was uploaded
* @param dependencies a list of dependencies of this module
* @param exportPoints a list of export point added by this module
* @param resources a list of VFS resources that belong to this module
* @param parameters the parameters for this module
*/
public CmsModule(
String name,
String niceName,
String group,
String actionClass,
String description,
CmsModuleVersion version,
String authorName,
String authorEmail,
long dateCreated,
String userInstalled,
long dateInstalled,
List dependencies,
List exportPoints,
List resources,
Map parameters) {
super();
m_name = name;
setNiceName(niceName);
setActionClass(actionClass);
setGroup(group);
if (CmsStringUtil.isEmpty(description)) {
m_description = "";
} else {
m_description = description;
}
m_version = version;
if (CmsStringUtil.isEmpty(authorName)) {
m_authorName = "";
} else {
m_authorName = authorName;
}
if (CmsStringUtil.isEmpty(authorEmail)) {
m_authorEmail = "";
} else {
m_authorEmail = authorEmail;
}
// remove milisecounds
m_dateCreated = (dateCreated / 1000L) * 1000L;
if (CmsStringUtil.isEmpty(userInstalled)) {
m_userInstalled = "";
} else {
m_userInstalled = userInstalled;
}
m_dateInstalled = (dateInstalled / 1000L) * 1000L;
if (dependencies == null) {
m_dependencies = Collections.EMPTY_LIST;
} else {
m_dependencies = Collections.unmodifiableList(dependencies);
}
if (exportPoints == null) {
m_exportPoints = Collections.EMPTY_LIST;
} else {
m_exportPoints = Collections.unmodifiableList(exportPoints);
}
if (resources == null) {
m_resources = Collections.EMPTY_LIST;
} else {
m_resources = Collections.unmodifiableList(resources);
}
if (parameters == null) {
//m_parameters = Collections.EMPTY_MAP;
m_parameters = new TreeMap();
} else {
m_parameters = new TreeMap(parameters);
}
initOldAdditionalResources();
if (LOG.isDebugEnabled()) {
LOG.debug(Messages.get().getBundle().key(Messages.LOG_MODULE_INSTANCE_CREATED_1, m_name));
}
m_resourceTypes = Collections.EMPTY_LIST;
m_explorerTypeSettings = Collections.EMPTY_LIST;
}
/**
* Checks if this module depends on another given module,
* will return the dependency, or <code>null</code> if no dependency was found.<p>
*
* @param module the other module to check against
* @return the dependency, or null if no dependency was found
*/
public CmsModuleDependency checkDependency(CmsModule module) {
CmsModuleDependency otherDepdendency = new CmsModuleDependency(module.getName(), module.getVersion());
// loop through all the dependencies
for (int i = 0; i < m_dependencies.size(); i++) {
CmsModuleDependency dependency = (CmsModuleDependency)m_dependencies.get(i);
if (dependency.dependesOn(otherDepdendency)) {
// short circuit here
return dependency;
}
}
// no dependency was found
return null;
}
/**
* Checks if all resources of the module are present.<p>
*
* @param cms an initialized OpenCms user context which must have read access to all module resources
*
* @throws CmsIllegalArgumentException in case not all module resources exist or can be read with the given OpenCms user context
*/
public void checkResources(CmsObject cms) throws CmsIllegalArgumentException {
CmsFileUtil.checkResources(cms, getResources());
}
/**
* Clones a CmsModule which is not set to frozen.<p>
* This clones module can be used to be update the module information.
*
* @see java.lang.Object#clone()
*/
public Object clone() {
// create a copy of the module
CmsModule result = new CmsModule(
m_name,
m_niceName,
m_group,
m_actionClass,
m_description,
m_version,
m_authorName,
m_authorEmail,
m_dateCreated,
m_userInstalled,
m_dateInstalled,
m_dependencies,
m_exportPoints,
m_resources,
m_parameters);
// and set its frozen state to false
result.m_frozen = false;
if (getExplorerTypes() != null) {
result.setExplorerTypes(new ArrayList(getExplorerTypes()));
}
if (getResourceTypes() != null) {
result.setResourceTypes(new ArrayList(getResourceTypes()));
}
if (getDependencies() != null) {
result.setDependencies(new ArrayList(getDependencies()));
}
result.setCreateClassesFolder(m_createClassesFolder);
result.setCreateElementsFolder(m_createElementsFolder);
result.setCreateLibFolder(m_createLibFolder);
result.setCreateModuleFolder(m_createModuleFolder);
result.setCreateResourcesFolder(m_createResourcesFolder);
result.setCreateTemplateFolder(m_createTemplateFolder);
result.setResources(new ArrayList(m_resources));
result.setExportPoints(new ArrayList(m_exportPoints));
return result;
}
/**
* @see java.lang.Comparable#compareTo(java.lang.Object)
*/
public int compareTo(Object obj) {
if (obj == this) {
return 0;
}
if (obj instanceof CmsModule) {
return m_name.compareTo(((CmsModule)obj).m_name);
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -