📄 cmsregistry.java
字号:
}
/**
* This method creates a new module in the repository.
*
* @param modulename the name of the module
* @param niceModulename another name of the module
* @param description the description of the module
* @param author the name of the author
* @param type the type of the module
* @param exportPoints a map of all export points of the module
* @param createDate the creation date of the module in the format: mm.dd.yyyy
* @param 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 type,
Map exportPoints,
String createDate,
float 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
StringBuffer moduleString = new StringBuffer();
moduleString.append(C_EMPTY_MODULE[0] + type);
moduleString.append(C_EMPTY_MODULE[1] + modulename);
moduleString.append(C_EMPTY_MODULE[2] + niceModulename);
moduleString.append(C_EMPTY_MODULE[3] + version);
moduleString.append(C_EMPTY_MODULE[4] + description);
moduleString.append(C_EMPTY_MODULE[5] + author);
moduleString.append(C_EMPTY_MODULE[6] + createDate);
moduleString.append(C_EMPTY_MODULE[7]);
Iterator i = exportPoints.keySet().iterator();
while (i.hasNext()) {
String key = (String)i.next();
String value = (String)exportPoints.get(key);
moduleString.append(C_EXPORTPOINT[0]);
moduleString.append(key);
moduleString.append(C_EXPORTPOINT[1]);
moduleString.append(value);
moduleString.append(C_EXPORTPOINT[2]);
}
moduleString.append(C_EMPTY_MODULE[8]);
// encoding project:
Document doc;
try {
doc = parse(moduleString.toString().getBytes(A_OpenCms.getDefaultEncoding()));
} catch (UnsupportedEncodingException uee) {
// use default system encoding
doc = parse(moduleString.toString().getBytes());
}
m_xmlReg.getElementsByTagName("modules").item(0).appendChild(
getXmlParser().importNode(m_xmlReg, doc.getFirstChild()));
saveRegistry();
}
/**
* @see com.opencms.file.I_CmsRegistry#deleteCheckDependencies(String, boolean)
*/
public Vector deleteCheckDependencies(String modulename, boolean replaceMode) throws CmsException {
Vector result = new Vector();
if (replaceMode) return result;
Enumeration names = getModuleNames();
Vector modules;
Vector minVersions;
Vector maxVersions;
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 {
// Module type SIMPLE? Just do nothing here, as SIMPLE modules do not support file conflicts
if (this.getModuleType(modulename).equals(CmsRegistry.C_MODULE_TYPE_SIMPLE)) return;
// the files and checksums for this module
Vector moduleFiles = new Vector();
Vector moduleChecksums = new Vector();
// the files and checksums for all other modules
Vector otherFiles = new Vector();
Vector otherChecksums = new Vector();
getModuleFiles(modulename, moduleFiles, moduleChecksums);
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);
}
}
for (int i = 0; i < moduleFiles.size(); i++) {
// get the current file and checksum
String currentFile = (String) moduleFiles.elementAt(i);
String currentChecksum = (String) moduleChecksums.elementAt(i);
CmsFile file = null;
try {
String resource = currentFile.substring(0, currentFile.indexOf("/",1) + 1);
if(!resourcesForProject.contains(resource)) {
// add the resource, if it dosen't already exist
resourcesForProject.addElement(resource);
}
} catch(StringIndexOutOfBoundsException exc) {
// this is a resource in root-folder: ignore the excpetion
}
// is it a file - then check all the possibilities
if (!currentFile.endsWith("/")) {
// exists the file in the cms?
try {
file = m_cms.readFile(currentFile);
} catch (CmsException exc) {
// the file dosen't exist - mark it as deleted
missingFiles.addElement(currentFile);
}
// is the file in use of another module?
if (otherFiles.contains(currentFile)) {
// yes - mark it as in use
filesInUse.addElement(currentFile);
}
// was the file changed?
if (file != null) {
// create the current digest-content for the file
// encoding project:
String digestContent;
try {
digestContent =
com.opencms.util.Encoder.escape(
new String(
m_digest.digest(file.getContents()),
m_cms.getRequestContext().getEncoding()),
m_cms.getRequestContext().getEncoding());
} catch (UnsupportedEncodingException e) {
digestContent =
com.opencms.util.Encoder.escape(
new String(
m_digest.digest(file.getContents())),
m_cms.getRequestContext().getEncoding());
}
if (!currentChecksum.equals(digestContent)) {
// the file was changed, the checksums are different
wrongChecksum.addElement(currentFile);
}
}
}
}
Vector files = m_cms.getFilesWithProperty("module", modulename + "_" + getModuleVersion(modulename));
int fileCount = files.size();
for(int i=0;i<fileCount;i++) {
String currentFile = (String)files.elementAt(i);
if(!moduleFiles.contains(currentFile)) {
// is the file in use of another module?
if (!otherFiles.contains(currentFile)) {
filesWithProperty.addElement(currentFile);
try {
String resource = currentFile.substring(0, currentFile.indexOf("/",1) + 1);
if(!resourcesForProject.contains(resource)) {
// add the resource, if it dosen't already exist
resourcesForProject.addElement(resource);
}
}
catch(StringIndexOutOfBoundsException exc) {
// this is a resource in root-folder: ignore the excpetion
}
}
}
}
}
/**
* @see com.opencms.file.I_CmsRegistry#deleteModule(String, Vector, boolean, I_CmsReport)
*/
public synchronized void deleteModule(String module, Vector exclusion, boolean replaceMode, I_CmsReport report) throws CmsException {
if (DEBUG > 2) System.err.println("[" + this.getClass().getName() + ".deleteModule()] Starting to delete module " + module);
// check if the module exists
if (!moduleExists(module)) {
throw new CmsException("Module '"+module+"' does not exist", 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 'deleteModule'", CmsException.C_REGISTRY_ERROR);
}
// check, if deletion is allowed
Vector deps = deleteCheckDependencies(module, replaceMode);
if (deps.size() != 0) {
// there are dependencies - throw exception
throw new CmsException(
"There are dependencies for the module " + module + ": deletion is not allowed.",
CmsException.C_REGISTRY_ERROR);
}
// try to invoke the event-method for delete on this calss.
Class eventClass = getModuleMaintenanceEventClass(module);
try {
Class declaration[] = {CmsObject.class};
Object arguments[] = {m_cms};
Method eventMethod = eventClass.getMethod(C_DELETE_EVENT_METHOD_NAME, declaration);
eventMethod.invoke(null, arguments);
} catch(Exception exc) {
// ignore the exception.
}
if (this.getModuleType(module).equals(CmsRegistry.C_MODULE_TYPE_SIMPLE)) {
// SIMPLE module: Just delete all the folders of the module
// check if additional resources outside the system/modules/{exportName} folder were
// specified as module resources by reading the module property {C_MODULE_PROPERTY_ADDITIONAL_RESOURCES}
// just delete these resources plus the "standard" module paths under system/modules
String additionalResources = this.getModuleParameterString( module, I_CmsConstants.C_MODULE_PROPERTY_ADDITIONAL_RESOURCES );
Vector resources = new Vector();
if (additionalResources!=null && !additionalResources.equals("")) {
// add each additonal folder/resource
StringTokenizer additionalResourceTokens = null;
additionalResourceTokens = new StringTokenizer( additionalResources, I_CmsConstants.C_MODULE_PROPERTY_ADDITIONAL_RESOURCES_SEPARATOR );
while (additionalResourceTokens.hasMoreTokens()) {
String currentResource = additionalResourceTokens.nextToken().trim();
if (! "-".equals(currentResource)) {
if (DEBUG > 0) {
System.err.println("Adding resource: " + currentResource);
}
resources.add( currentResource );
}
}
}
resources.add(I_CmsWpConstants.C_VFS_PATH_MODULES + module + "/");
// move through all resource-names and try to delete them
for (int i = resources.size() - 1; i >= 0; i--) {
String currentResource = null;
try {
currentResource = (String)resources.elementAt(i);
if (DEBUG > 1) System.err.println("[" + this.getClass().getName() + ".deleteModule()] Deleting resource " + currentResource);
// lock the resource
m_cms.lockResource(currentResource, true);
// delete the resource
m_cms.deleteResource(currentResource);
// update the report
report.print(report.key("report.deleting"), I_CmsReport.C_FORMAT_NOTE);
report.println(currentResource);
} catch (CmsException exc) {
// ignore the exception and delete the next resource
if (DEBUG > 0) System.err.println("[" + this.getClass().getName() + ".deleteModule()] Exception " + exc + " deleting resource " + currentResource);
report.println(exc);
}
}
} else {
// TRADITIONAL module: Check file dependencies
// get the files, that are belonging to the module.
Vector resourceNames = new Vector();
Vector missingFiles = new Vector();
Vector wrongChecksum = new Vector();
Vector filesInUse = new Vector();
Vector resourceCodes = new Vector();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -