📄 cmsregistry.java
字号:
/*
* File : $Source: /usr/local/cvs/opencms/src/com/opencms/file/CmsRegistry.java,v $
* Date : $Date: 2002/02/14 14:26:42 $
* Version: $Revision: 1.42 $
*
* This library is part of OpenCms -
* the Open Source Content Mananagement System
*
* Copyright (C) 2001 The OpenCms Group
*
* 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 OpenCms, please see the
* OpenCms 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 com.opencms.file;
import java.io.*;
import java.util.*;
import java.util.zip.*;
import java.text.*;
import java.security.*;
import java.lang.reflect.*;
import org.w3c.dom.*;
import com.opencms.template.*;
import com.opencms.core.*;
/**
* This class implements the registry for OpenCms.
*
* @author Andreas Schouten
* @version $Revision: 1.42 $ $Date: 2002/02/14 14:26:42 $
*
*/
public class CmsRegistry extends A_CmsXmlContent implements I_CmsRegistry {
/**
* The xml-document representing the registry.
*/
private Document m_xmlReg;
/**
* The filename for the registry.
*/
private String m_regFileName;
/**
* A hashtable with shortcuts into the dom-structure for each module.
*/
private Hashtable m_modules = new Hashtable();
/**
* The cms-object to get access to the system with the context of the current user.
*/
private CmsObject m_cms = null;
/**
* The date-format to use.
*/
private SimpleDateFormat m_dateFormat = new java.text.SimpleDateFormat("MM.dd.yyyy");
/**
* A message digest to check the resource-codes
*/
private MessageDigest m_digest;
/**
* Declaration of Module event-method names.
*/
private static final String C_UPLOAD_EVENT_METHOD_NAME = "moduleWasUploaded";
private static final String C_UPDATE_PARAMETER_EVENT_METHOD_NAME = "moduleParameterWasUpdated";
private static final String C_DELETE_EVENT_METHOD_NAME = "moduleWasDeleted";
/**
* Declaration of an empty module in the registry.
*/
private static final String[] C_EMPTY_MODULE = { "<module><name>", "</name><nicename>", "</nicename><version>", "</version><description>", "</description><author>", "</author><email/><creationdate>", "</creationdate><view/><publishclass/><documentation/><dependencies/><maintenance_class/><parameters/><repository/></module>" };
/**
* Creates a new CmsRegistry for a user. The cms-object represents the current state of the current user.
*
* @param CmsObject the cms-object to get access to the system
*/
public CmsRegistry(CmsRegistry reg, CmsObject cms) {
super();
// there is no need of a real copy for this parameters
m_modules = reg.m_modules;
m_regFileName = reg.m_regFileName;
m_xmlReg = reg.m_xmlReg;
// store the cms-object for this instance.
m_cms = cms;
try {
m_digest = MessageDigest.getInstance(CmsImport.C_IMPORT_DIGEST);
} catch (NoSuchAlgorithmException e) {
m_digest = null;
}
}
/**
* Creates a new CmsRegistry. The regFileName is the path to the registry-file in
* the server filesystem.
*
* @param String regFileName the path to the registry-file in the server fs.
*/
public CmsRegistry(String regFileName) throws CmsException {
super();
try {
// store the filename
m_regFileName = regFileName;
// get the file
File xmlFile = new File(m_regFileName);
// get a buffered reader
BufferedReader reader = new BufferedReader(new FileReader(xmlFile));
StringBuffer content = new StringBuffer();
String buffer = "";
do {
content.append(buffer);
buffer = reader.readLine();
} while (buffer != null);
reader.close();
// parse the registry-xmlfile and store it.
m_xmlReg = parse(content.toString());
init();
} catch (Exception exc) {
throw new CmsException("couldn't init registry", CmsException.C_REGISTRY_ERROR, exc);
}
}
/**
* Checks, if the dependencies are fullfilled.
* @param module the dom-element describing the new module.
* @returns, if the dependencies are fullfilled, or not.
*/
private Vector checkDependencies(Element module) throws CmsException {
Vector retValue = new Vector();
try {
Element dependencies = (Element) (module.getElementsByTagName("dependencies").item(0));
NodeList deps = dependencies.getElementsByTagName("dependency");
for (int i = 0; i < deps.getLength(); i++) {
String name = ((Element) deps.item(i)).getElementsByTagName("name").item(0).getFirstChild().getNodeValue();
int minVersion = Integer.parseInt(((Element) deps.item(i)).getElementsByTagName("minversion").item(0).getFirstChild().getNodeValue());
int maxVersion = Integer.parseInt(((Element) deps.item(i)).getElementsByTagName("maxversion").item(0).getFirstChild().getNodeValue());
// get the version of the needed repository
int currentVersion = getModuleVersion(name);
if( currentVersion == -1 ) {
retValue.addElement("The needed module " + name + " dosen't exists");
} else if( currentVersion < minVersion ) {
retValue.addElement("Module " + name + " version " + minVersion + " is not high enougth" );
} else if( ( maxVersion != C_ANY_VERSION ) && (currentVersion > maxVersion) ) {
retValue.addElement("Module " + name + " version " + maxVersion + " is to high");
}
}
} catch (Exception exc) {
throw new CmsException("Could not check the dependencies", CmsException.C_REGISTRY_ERROR, exc);
}
return retValue;
}
/**
* Checks if the type of the value is correct.
* @param type the type that the value should have..
* @param value the value to check.
*/
private boolean checkType(String type, String value) {
type = type.toLowerCase();
try {
if("string".equals(type) ) {
if( value != null) {
return true;
} else {
return false;
}
} else if("int".equals(type) || "integer".equals(type)) {
Integer.parseInt(value);
return true;
} else if("float".equals(type)) {
Float.valueOf(value);
return true;
} else if("boolean".equals(type)) {
Boolean.valueOf(value);
return true;
} else if("long".equals(type)) {
Long.valueOf(value);
return true;
} else if("double".equals(type)) {
Double.valueOf(value);
return true;
} else if("byte".equals(type)) {
Byte.valueOf(value);
return true;
} else {
// the type dosen't exist
return false;
}
} catch(Exception exc) {
// the type of the value was wrong
return false;
}
}
/**
* This method clones the registry.
*
* @param CmsObject the current cms-object to get access to the system.
* @return the cloned registry.
*/
public I_CmsRegistry clone(CmsObject cms) {
return new CmsRegistry(this, cms);
}
/**
* This method creates a new module in the repository.
*
* @param String modulename the name of the module.
* @param String niceModulename another name of the module.
* @param String description the description of the module.
* @param String author the name of the author.
* @param long createDate the creation date of the module
* @param int version the version number of the module.
* @throws CmsException if the user has no right to create a new module.
*/
public void createModule(String modulename, String niceModulename, String description, String author, long createDate, int version) throws CmsException {
createModule(modulename, niceModulename, description, author, m_dateFormat.format(new Date(createDate)), version);
}
/**
* This method creates a new module in the repository.
*
* @param String modulename the name of the module.
* @param String niceModulename another name of the module.
* @param String description the description of the module.
* @param String author the name of the author.
* @param String createDate the creation date of the module in the format: mm.dd.yyyy
* @param int version the version number of the module.
* @throws CmsException if the user has no right to create a new module.
*/
public void createModule(String modulename, String niceModulename, String description, String author, String createDate, int version) throws CmsException {
// find out if the module exists already
if (moduleExists(modulename)) {
throw new CmsException("Module exists already " + modulename, CmsException.C_REGISTRY_ERROR);
}
// check if the user is allowed to perform this action
if (!hasAccess()) {
throw new CmsException("No access to perform the action 'createModule'", CmsException.C_REGISTRY_ERROR);
}
// create the new module in the registry
String moduleString = C_EMPTY_MODULE[0] + modulename;
moduleString += C_EMPTY_MODULE[1] + niceModulename;
moduleString += C_EMPTY_MODULE[2] + version;
moduleString += C_EMPTY_MODULE[3] + description;
moduleString += C_EMPTY_MODULE[4] + author;
moduleString += C_EMPTY_MODULE[5] + createDate;
moduleString += C_EMPTY_MODULE[6];
Document doc = parse(moduleString);
m_xmlReg.getElementsByTagName("modules").item(0).appendChild(getXmlParser().importNode(m_xmlReg, doc.getFirstChild()));
saveRegistry();
}
/**
* This method checks which modules need this module. If a module depends on this the name
* will be returned in the vector.
* @param modulename The name of the module to check.
* @returns a Vector with modulenames that depends on the overgiven module.
*/
public Vector deleteCheckDependencies(String modulename) throws CmsException {
Enumeration names = getModuleNames();
Vector modules;
Vector minVersions;
Vector maxVersions;
Vector result = new Vector();
while (names.hasMoreElements()) {
String name = (String) names.nextElement();
modules = new Vector();
minVersions = new Vector();
maxVersions = new Vector();
getModuleDependencies(name, modules, minVersions, maxVersions);
// needs this module the module to test?
if (modules.contains(modulename)) {
// yes - store it in the result
result.addElement(name);
}
}
return result;
}
/**
* This method checks for conflicting files before the deletion of a module.
* It uses several Vectors to return the different conflicting files.
*
* @param modulename the name of the module that should be deleted.
* @param filesWithProperty a return value. The files that are marked with the module-property for this module.
* @param missingFiles a return value. The files that are missing.
* @param wrongChecksum a return value. The files that should be deleted but have another checksum as at import-time.
* @param filesInUse a return value. The files that should be deleted but are in use by other modules.
* @param resourcesForProject a return value. The files that should be copied to a project to delete.
*/
public void deleteGetConflictingFileNames(String modulename, Vector filesWithProperty, Vector missingFiles, Vector wrongChecksum, Vector filesInUse, Vector resourcesForProject) throws CmsException {
// the files and checksums for this module
Vector moduleFiles = new Vector();
Vector moduleChecksums = new Vector();
getModuleFiles(modulename, moduleFiles, moduleChecksums);
// the files and checksums for all other modules
Vector otherFiles = new Vector();
Vector otherChecksums = new Vector();
Enumeration modules = getModuleNames();
while (modules.hasMoreElements()) {
String module = (String) modules.nextElement();
// get the files only for modules that are not for the current module.
if (!module.equals(modulename)) {
// get the files
getModuleFiles(module, otherFiles, otherChecksums);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -