⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cmsregistry.java

📁 java 编写的程序
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
    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
                String digestContent = com.opencms.util.Encoder.escape(new String(m_digest.digest(file.getContents())));
                if (!currentChecksum.equals(digestContent)) {
                    // the file was changed, the checksums are different
                    wrongChecksum.addElement(currentFile);
                }
            }
        }
    }

    // determine the files with the property for this module.

    Vector files = m_cms.getFilesWithProperty("module", modulename + "_" + getModuleVersion(modulename));
    for(int i = 0; i < files.size(); 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
                }
            }
        }

    }
}
/**
 *  Deletes a module. This method is synchronized, so only one module can be deleted at one time.
 *
 *  @param module-name the name of the module that should be deleted.
 *  @param exclusion a Vector with resource-names that should be excluded from this deletion.
 */
public synchronized void deleteModule(String module, Vector exclusion) throws CmsException {
    // 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);
    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.
    }

    // 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();

    // get files by property
    deleteGetConflictingFileNames(module, resourceNames, missingFiles, wrongChecksum, filesInUse, new Vector());

    // get files by registry
    getModuleFiles(module, resourceNames, resourceCodes);

    // move through all resource-names and try to delete them
    for (int i = resourceNames.size() - 1; i >= 0; i--) {
        try {
            String currentResource = (String) resourceNames.elementAt(i);
            if ((!exclusion.contains(currentResource)) && (!filesInUse.contains(currentResource))) {
                m_cms.lockResource(currentResource, true);
                if(currentResource.endsWith("/") ) {
                    // this is a folder
                    m_cms.deleteEmptyFolder(currentResource);
                } else {
                    // this is a file
                    m_cms.deleteFile(currentResource);
                }
            }
        } catch (CmsException exc) {
            // ignore the exception and delete the next resource.
        }
    }

    // delete all entries for the module in the registry
    Element moduleElement = getModuleElement(module);
    moduleElement.getParentNode().removeChild(moduleElement);
    saveRegistry();

    try {
        init();
    } catch (Exception exc) {
        throw new CmsException("couldn't init registry", CmsException.C_REGISTRY_ERROR, exc);
    }
}
/**
 * Deletes the view for a module.
 *
 * @param String the name of the module.
 */
public void deleteModuleView(String modulename) throws CmsException {
    // check if the user is allowed to perform this action
    if (!hasAccess()) {
        throw new CmsException("No access to perform the action 'deleteModuleView'", CmsException.C_REGISTRY_ERROR);
    }
    try {
        Element module = getModuleElement(modulename);
        Element view = (Element) (module.getElementsByTagName("view").item(0));

        // delete all subnodes
        while(view.hasChildNodes()) {
            view.removeChild(view.getFirstChild());
        }
        saveRegistry();
    } catch (Exception exc) {
        // ignore the exception - reg is not welformed
    }
}
/**
 * This method exports a module to the filesystem.
 *
 * @param moduleName the name of the module to be exported.
 * @param String[] an array of resources to be exported.
 * @param fileName the name of the file to write the export to.
 */
public void exportModule(String moduleName, String[] resources, String fileName) throws CmsException {
    // check if the user is allowed to import a module.

    if (!hasAccess()) {
        throw new CmsException("No access to perform the action 'exportModule'", CmsException.C_REGISTRY_ERROR);
    }

    CmsExport exp = new CmsExport(fileName, resources, m_cms, getModuleElement(moduleName));
}
    /**
     * Gets a description of this content type.
     * For OpenCms internal use only.
     * @return Content type description.
     */
    public String getContentDescription() {
        return "Registry";
    }
/**
 * This method returns the author of the module.
 *
 * @parameter String the name of the module.
 * @return java.lang.String the author of the module.
 */
public String getModuleAuthor(String modulename) {
    return getModuleData(modulename, "author");
}
/**
 * This method returns the email of author of the module.
 *
 * @parameter String the name of the module.
 * @return java.lang.String the email of author of the module.
 */
public String getModuleAuthorEmail(String modulename) {
    return getModuleData(modulename, "email");
}
/**
 * Gets the create date of the module.
 *
 * @parameter String the name of the module.
 * @return long the create date of the module.
 */
public long getModuleCreateDate(String modulname) {
    long retValue = -1;
    try {
        String value = getModuleData(modulname, "creationdate");
        retValue = m_dateFormat.parse(value).getTime();
    } catch (Exception exc) {
        // ignore the exception - reg is not welformed
    }
    return retValue;
}
/**
 *  Private method to return module data like author.
 *
 * @param String modulename the name of the module.
 * @param String dataName the name of the tag to get the data from.
 * @returns String the value for the requested data.
 */
private String getModuleData(String module, String dataName) {
    String retValue = null;
    try {
        Element moduleElement = getModuleElement(module);
        retValue = moduleElement.getElementsByTagName(dataName).item(0).getFirstChild().getNodeValue();
    } catch (Exception exc) {
        // ignore the exception - registry is not wellformed
    }
    return retValue;
}
/**
 * Returns the module dependencies for the module.
 *
 * @param module String the name of the module to check.
 * @param modules Vector in this parameter the names of the dependend modules will be returned.
 * @param minVersions Vector in this parameter the minimum versions of the dependend modules will be returned.
 * @param maxVersions Vector in this parameter the maximum versions of the dependend modules will be returned.
 * @return int the amount of dependencies for the module will be returned.
 */
public int getModuleDependencies(String modulename, Vector modules, Vector minVersions, Vector maxVersions) {
    try {
        Element module = getModuleElement(modulename);
        Element dependencies = (Element) (module.getElementsByTagName("dependencies").item(0));
        NodeList deps = dependencies.getElementsByTagName("dependency");
        for (int i = 0; i < deps.getLength(); i++) {
            modules.addElement(((Element) deps.item(i)).getElementsByTagName("name").item(0).getFirstChild().getNodeValue());
            minVersions.addElement(((Element) deps.item(i)).getElementsByTagName("minversion").item(0).getFirstChild().getNodeValue());
            maxVersions.addElement(((Element) deps.item(i)).getElementsByTagName("maxversion").item(0).getFirstChild().getNodeValue());
        }
    } catch (Exception exc) {
        // ignore the exception - reg is not welformed
    }
    return modules.size();
}
/**
 * Returns the description of the module.
 *
 * @parameter String the name of the module.
 * @return java.lang.String the description of the module.
 */
public String getModuleDescription(String module) {
    return getModuleData(module, "description");
}
/**
 * Gets the url to the documentation of the module.
 *
 * @parameter String the name of the module.
 * @return java.lang.String the url to the documentation of the module.
 */
public String getModuleDocumentPath(String modulename) {
    return getModuleData(modulename, "documentation");
}
/**
 *  Private method to get the Element representing a module.
 *
 * @param String the name of the module.
 *
 */
private Element getModuleElement(String name) {
    return (Element) m_modules.get(name);
}
/**
 * Reads the module-element from the manifest in the zip-file.
 * @param string the name of the zip-file to read from.
 * @returns the module-element or null if it dosen't exist.
 */
private Element getModuleElementFromImport(String filename) {
    try {
        // get the zip-file
        ZipFile importZip = new ZipFile(filename);
        // read the minifest
        ZipEntry entry = importZip.getEntry("manifest.xml");
        InputStream stream = importZip.getInputStream(entry);
        BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
        String content = "";
        String buffer = "";
        do {
            content += buffer;
            buffer = reader.readLine();
        } while (buffer != null);
        // parse the manifest
        Document manifest = parse(content);
        reader.close();
        importZip.close();
        // get the module-element
        return (Element)(manifest.getElementsByTagName("module").item(0));
    } catch (Exception exc) {
        return null;
    }
}
/**
 * Returns all filenames and hashcodes belonging to the module.
 *
 * @param String modulname the name of the module.
 * @param retNames the names of the resources belonging to the module.
 * @param retCodes the hashcodes of the resources belonging to the module.
 * @return the amount of entrys.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -