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

📄 cmsregistry.java

📁 内容管理
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
        
            // 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.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.
					report.println(exc);
				}
			}
        }
    
        // delete all entries for the module in the registry
        Element moduleElement = getModuleElement(module);
        moduleElement.getParentNode().removeChild(moduleElement);
        saveRegistry();
    
        try {
            init(false);
        } catch (Exception exc) {
            throw new CmsException("couldn't init registry", CmsException.C_REGISTRY_ERROR, exc);
        }
        
        if (DEBUG > 2) System.err.println("[" + this.getClass().getName() + ".deleteModule()] Finished for module " + module);    
    }
    
    /**
     * 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.<p>
     *
     * @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
     * @param report a report for the output 
     * 
     * @throws CmsException in case of an error during export
     */
    public void exportModule(String moduleName, String[] resources, String fileName, I_CmsReport report) 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);
        }
        // remove all "uploaddate" and "uploadby" nodes
        Element module = getModuleElement(moduleName);
        Element moduleCopy = (Element)module.cloneNode(true);
        NodeList list = moduleCopy.getChildNodes();
        for (int i=(list.getLength()-1); i>=0; i--) {
            Element e = (Element)list.item(i);
            if ("uploaddate".equals(e.getNodeName()) || "uploadedby".equals(e.getNodeName())) {
                moduleCopy.removeChild(e);
            }
        }                      
        // export the module using the standard export        
        new CmsExport(m_cms, fileName, resources, false, false, moduleCopy, false, 0, report);
    }
    
    /**
     * Gets a description of this content type.
     * For OpenCms internal use only.<p>
     * 
     * @return Content type description.
     */
    public String getContentDescription() {
        return "Registry";
    }
    
    /**
     * This method returns the author of the module.
     *
     * @param 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.
     *
     * @param 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.
     *
     * @param 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.
     * @return 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.
     *
     * @param 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.
     *
     * @param 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.
     * @return 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);
            // parse the manifest
            Document manifest = parse(stream);
            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.
     */
    public int getModuleFiles(String modulename, Vector retNames, Vector retCodes) {
        try {
            Element module = getModuleElement(modulename);
            Element files = (Element) (module.getElementsByTagName("files").item(0));
            NodeList file = files.getElementsByTagName("file");
            for (int i = 0; i < file.getLength(); i++) {
                retNames.addElement(
                    ((Element)file.item(i)).getElementsByTagName("name").item(0).getFirstChild().getNodeValue());
                retCodes.addElement(
                    ((Element)file.item(i)).getElementsByTagName("checksum").item(0).getFirstChild().getNodeValue());
            }
        } catch (Exception exc) {
            // ignore the exception - reg is not welformed
        }
        return retNames.size();
    }

    /**
     * Returns the class, that receives all maintenance-events for the module.
     *
     * @param String the name of the module.
     * @return java.lang.Class that receives all maintenance-events for the module.
     */
    public Class getModuleMaintenanceEventClass(String modulname) {
        try {
    
            Vector repositories = new Vector();
            String[] reposNoVector = getRepositories();
            for (int i = 0; i < reposNoVector.length; i++) {
                repositories.addElement(reposNoVector[i]);
            }
            ClassLoader loader = this.getClass().getClassLoader();
    
            return loader.loadClass(getModuleData(modulname, "maintenance_class"));
    
        } catch (Exception exc) {
            return null;
        }
    }
    
    /**
     * Returns the name of the class, that receives all maintenance-events for the module.
     *
     * @param String the name of the module.
     * @return java.lang.Class that receives all maintenance-events for the module.
     */
    public String getModuleMaintenanceEventName(String modulname) {
        return getModuleData(modulname, "maintenance_class");
    }
    
    /**
     * Returns the names of all available modules.
     *
     * @return Enumeration the names of all available modules.
     */
    public Enumeration getModuleNames() {
        return m_modules.keys();
    }
    
    /**
     * Returns the nice name of the module.
     *
     * @param String the name of the module.
     * @return java.lang.String the description of the module.
     */
    public String getModuleNiceName(String module) {

⌨️ 快捷键说明

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