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

📄 cmsregistry.java

📁 java 编写的程序
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
    }
    return retValue;
}

/**
 * Returns all views and korresponding urls for all modules.
 *
 * @parameter String[] views in this parameter the views will be returned.
 * @parameter String[] urls in this parameters the urls vor the views will be returned.
 * @return int the amount of views.
 */
public int getViews(Vector views, Vector urls) {
    try {
        NodeList viewList = m_xmlReg.getElementsByTagName("view");
        for (int x = 0; x < viewList.getLength(); x++) {
            try {
                String name = ((Element) viewList.item(x)).getElementsByTagName("name").item(0).getFirstChild().getNodeValue();
                String url = ((Element) viewList.item(x)).getElementsByTagName("url").item(0).getFirstChild().getNodeValue();
                views.addElement(name);
                urls.addElement(url);
            } catch(Exception exc) {
                // ignore the exception and try the next view-pair.
            }
        }
        return views.size();
    } catch (Exception exc) {
        // no return-vaules
        return 0;
    }
}

    /**
     * Gets the expected tagname for the XML documents of this content type
     * @return Expected XML tagname.
     */
    public String getXmlDocumentTagName() {
        return "registry";
    }
/**
 * Returns true if the user has write-access to the registry. Otherwise false.
 * @returns true if access is granted, else false.
 */
private boolean hasAccess() {
    // check the access - only the admin has write access.
    boolean retValue = false;
    try{
        retValue = m_cms.isAdmin();
    } catch(CmsException exc) {
        // ignore the exception - no access granted
    }
    return retValue;
}
/**
 * Checks the dependencies for a new Module.
 * @param moduleZip the name of the zipfile for the new module.
 * @return a Vector with dependencies that are not fullfilled.
 */
public Vector importCheckDependencies(String moduleZip) throws CmsException {
    Element newModule = getModuleElementFromImport(moduleZip);
    return checkDependencies(newModule);
}
/**
 *  Checks for files that already exist in the system but should be replaced by the module.
 *
 *  @param moduleZip The name of the zip-file to import.
 *  @returns The complete paths to the resources that have conflicts.
 */
public Vector importGetConflictingFileNames(String moduleZip) throws CmsException {
    if (!hasAccess()) {
        throw new CmsException("No access to perform the action 'getConflictingFileNames'", CmsException.C_REGISTRY_ERROR);
    }

    CmsImport cmsImport = new CmsImport(moduleZip, "/", m_cms);
    return cmsImport.getConflictingFilenames();
}
/**
 *  Returns the name of the module to be imported.
 *
 *  @param moduleZip the name of the zip-file to import from.
 *  @return The name of the module to be imported.
 */
public String importGetModuleName(String moduleZip) {
    Element newModule = getModuleElementFromImport(moduleZip);
    return newModule.getElementsByTagName("name").item(0).getFirstChild().getNodeValue();
}
/**
 *  Returns all files that are needed to create a project for the module-import.
 *
 *  @param moduleZip The name of the zip-file to import.
 *  @returns The complete paths for resources that should be in the import-project.
 */
public Vector importGetResourcesForProject(String moduleZip) throws CmsException {
    if (!hasAccess()) {
        throw new CmsException("No access to perform the action 'importGetResourcesForProject'", CmsException.C_REGISTRY_ERROR);
    }

    CmsImport cmsImport = new CmsImport(moduleZip, "/", m_cms);
    return cmsImport.getResourcesForProject();
}
/**
 *  Imports a module. This method is synchronized, so only one module can be imported at on time.
 *
 *  @param moduleZip the name of the zip-file to import from.
 *  @param exclusion a Vector with resource-names that should be excluded from this import.
 */
public synchronized void importModule(String moduleZip, Vector exclusion) throws CmsException {
    // check if the user is allowed to import a module.

    if (!hasAccess()) {
        throw new CmsException("No access to perform the action 'importModule'", CmsException.C_REGISTRY_ERROR);
    }
    Element newModule = getModuleElementFromImport(moduleZip);
    String newModuleName = newModule.getElementsByTagName("name").item(0).getFirstChild().getNodeValue();
    String newModuleVersion = newModule.getElementsByTagName("version").item(0).getFirstChild().getNodeValue();

    // exists the module already?
    if (moduleExists(newModuleName)) {
        throw new CmsException("The module " + newModuleName + " exists already", CmsException.C_REGISTRY_ERROR);
    }
    Vector dependencies = checkDependencies(newModule);

    // are there any dependencies not fulfilled?
    if (dependencies.size() != 0) {
        throw new CmsException("the dependencies for the module are not fulfilled.", CmsException.C_REGISTRY_ERROR);
    }
    Vector resourceNames = new Vector();
    Vector resourceCodes = new Vector();
    CmsImport cmsImport = new CmsImport(moduleZip, "/", m_cms);
    cmsImport.importResources(exclusion, resourceNames, resourceCodes, "module", newModuleName + "_" + newModuleVersion);
    // import the module data into the registry
    Element regModules = (Element) (m_xmlReg.getElementsByTagName("modules").item(0));
    // set the import-date
    Node uploadDate = newModule.getOwnerDocument().createElement("uploaddate");

    uploadDate.appendChild(newModule.getOwnerDocument().createTextNode(m_dateFormat.format(new java.util.Date())));
    newModule.appendChild(uploadDate);

    // set the import-user
    Node uploadBy = newModule.getOwnerDocument().createElement("uploadedby");
    uploadBy.appendChild(newModule.getOwnerDocument().createTextNode(m_cms.getRequestContext().currentUser().getName()));
    newModule.appendChild(uploadBy);

    // set the files
    Node files = newModule.getOwnerDocument().createElement("files");

    // store the resources-names that are depending to the module
    for (int i = 0; i < resourceNames.size(); i++) {
        Node file = newModule.getOwnerDocument().createElement("file");
        files.appendChild(file);
        Node name = newModule.getOwnerDocument().createElement("name");
        file.appendChild(name);
        Node checksum = newModule.getOwnerDocument().createElement("checksum");
        file.appendChild(checksum);
        name.appendChild(newModule.getOwnerDocument().createTextNode((String) resourceNames.elementAt(i)));
        checksum.appendChild(newModule.getOwnerDocument().createTextNode(com.opencms.util.Encoder.escape( (String) resourceCodes.elementAt(i))));
    }

    // append the files to the module-entry
    newModule.appendChild(files);

    // append the module data to the registry
    Node newNode = getXmlParser().importNode(m_xmlReg, newModule);
    regModules.appendChild(newNode);
    saveRegistry();

    try {
        init();
    } catch (Exception exc) {
        throw new CmsException("couldn't init registry", CmsException.C_REGISTRY_ERROR, exc);
    }

    // try to invoke the event-method for upload on this calss.
    Class eventClass = getModuleMaintenanceEventClass(newModuleName);

    try {
        Class declaration[] = {CmsObject.class};
        Object arguments[] = {m_cms};
        Method eventMethod = eventClass.getMethod(C_UPLOAD_EVENT_METHOD_NAME, declaration);
        eventMethod.invoke(null, arguments);
    } catch(Exception exc) {
        // ignore the exception.
    }
}
/**
 *  Inits all member-variables for the instance.
 */
private void init() throws Exception {
    // get the entry-points for the modules
    NodeList modules = m_xmlReg.getElementsByTagName("module");
    // create the hashtable for the shortcuts
    m_modules.clear();
    // walk throug all modules
    for (int i = 0; i < modules.getLength(); i++) {
        Element module = (Element) modules.item(i);
        String moduleName = module.getElementsByTagName("name").item(0).getFirstChild().getNodeValue();

        // store the shortcuts to the modules
        m_modules.put(moduleName, module);
    }
}
/**
 * Checks if the module exists already in the repository.
 *
 * @parameter String the name of the module.
 * @return true if the module exists, else false.
 */
public boolean moduleExists(String modulename) {
    return m_modules.containsKey(modulename);
}
/**
 *  Saves the registry and stores it to the registry-file.
 */
private void saveRegistry() throws CmsException {
    try {
        // get the file
        File xmlFile = new File(m_regFileName);

        // get a buffered writer
        BufferedWriter xmlWriter = new BufferedWriter(new FileWriter(xmlFile));

        // parse the registry-xmlfile and store it.
        A_CmsXmlContent.getXmlParser().getXmlText(m_xmlReg, xmlWriter);

        // reinit the modules-hashtable
        init();
    } catch (Exception exc) {
        throw new CmsException("couldn't save registry", CmsException.C_REGISTRY_ERROR, exc);
    }
}
/**
 * This method sets the author of the module.
 *
 * @param String the name of the module.
 * @param String the name of the author.
 */
public void setModuleAuthor(String modulename, String author) throws CmsException {
    setModuleData(modulename, "author", author);
}
/**
 * This method sets the email of author of the module.
 *
 * @param String the name of the module.
 * @param String the email of author of the module.
 */
public void setModuleAuthorEmail(String modulename, String email) throws CmsException {
    setModuleData(modulename, "email", email);
}
/**
 * Sets the create date of the module.
 *
 * @param String the name of the module.
 * @param long the create date of the module.
 */
public void setModuleCreateDate(String modulname, long createdate) throws CmsException {
    setModuleData(modulname, "creationdate", m_dateFormat.format(new Date(createdate)));
}
/**
 * Sets the create date of the module.
 *
 * @param String the name of the module.
 * @param String the create date of the module. Format: mm.dd.yyyy
 */
public void setModuleCreateDate(String modulname, String createdate) throws CmsException {
    setModuleData(modulname, "creationdate", createdate);
}
/**
 * Private method to set module data like author.
 *
 * @param String modulename the name of the module.
 * @param String dataName the name of the tag to set the data for.
 * @param String the value to be set.
 */
private void setModuleData(String module, String dataName, String value) throws CmsException {
    if (!hasAccess()) {
        throw new CmsException("No access to perform the action 'setModuleData'", CmsException.C_REGISTRY_ERROR);
    }
    try {
        Element moduleElement = getModuleElement(module);
        Node tag = moduleElement.getElementsByTagName(dataName).item(0);
        setTagValue(tag, value);
        // save the registry
        saveRegistry();
    } catch (Exception exc) {
        // ignore the exception - registry is not wellformed
    }
}
/**
 * Sets 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.
 */
public void setModuleDependencies(String modulename, Vector modules, Vector minVersions, Vector maxVersions) throws CmsException {
    if (!hasAccess()) {
        throw new CmsException("No access to perform the action 'setModuleDependencies'", CmsException.C_REGISTRY_ERROR);
    }
    try {
        Element module = getModuleElement(modulename);
        Element dependencies = (Element) (module.getElementsByTagName("dependencies").item(0));

        // delete all subnodes
        while(dependencies.hasChildNodes()) {
            dependencies.removeChild(dependencies.getFirstChild());
        }

        // create the new dependencies
        for (int i = 0; i < modules.size(); i++) {
            Element dependency = m_xmlReg.createElement("dependency");
            dependencies.appendChild(dependency);
            Element name = m_xmlReg.createElement("name");
            Element min = m_xmlReg.createElement("minversion");
            Element max = m_xmlReg.createElement("maxversion");
            name.appendChild(m_xmlReg.createTextNode(modules.elementAt(i).toString()));
            min.appendChild(m_xmlReg.createTextNode(minVersions.elementAt(i).toString()));
            max.appendChild(m_xmlReg.createTextNode(maxVersions.elementAt(i).toString()));
            dependency.appendChild(name);
            dependency.appendChild(min);
            dependency.appendChild(max);
        }

        // save the registry
        saveRegistry();
    } catch (Exception exc) {
        // ignore the exception - reg is not welformed
  

⌨️ 快捷键说明

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