cmsadmindatabase.java

来自「java 编写的程序」· Java 代码 · 共 441 行 · 第 1/2 页

JAVA
441
字号
                }
                Thread doExport = new CmsAdminDatabaseExportThread(cms, CmsBase.getAbsolutePath(cms.readExportPath()) + File.separator
                        + fileName, exportPaths, excludeSystem, excludeUnchanged, exportUserdata, session);
                doExport.start();
                session.putValue(C_DATABASE_THREAD, doExport);
                xmlTemplateDocument.setData("time", "10");
                templateSelector = "wait";

            } else if("exportmoduledata".equals(action)) {
                // export the channels and moduledata from database
                Vector channelNames = parseResources(allResources);
                String[] exportChannels = new String[channelNames.size()];
                CmsXmlLanguageFile lang = xmlTemplateDocument.getLanguageFile();
                for(int i = 0;i < channelNames.size();i++) {
                    // modify the foldername if nescessary (the root folder is always given
                    // as a nice name)
                    if(lang.getLanguageValue("title.rootfolder").equals(channelNames.elementAt(i))) {
                        channelNames.setElementAt("/", i);
                    }
                    exportChannels[i] = (String)channelNames.elementAt(i);
                }
                // get the selected modulenames
                Vector moduleNames = parseResources(allModules);
                String[] exportModules = new String[moduleNames.size()];
                for(int i = 0;i < moduleNames.size();i++) {
                    exportModules[i] = (String)moduleNames.elementAt(i);
                }
                // start the thread for: exportmodules
                // first clear the session entry if necessary
                if(session.getValue(C_SESSION_THREAD_ERROR) != null) {
                    session.removeValue(C_SESSION_THREAD_ERROR);
                }
                Thread doExport = new CmsAdminDatabaseExportThread(cms, CmsBase.getAbsolutePath(cms.readExportPath()) + File.separator
                        + fileName, exportChannels, exportModules, session);
                doExport.start();
                session.putValue(C_DATABASE_THREAD, doExport);
                xmlTemplateDocument.setData("time", "10");
                templateSelector = "wait";

            } else if("import".equals(action)) {
                // look for the step
                if("local".equals(step) || "server".equals(step)){
                    templateSelector = step;
                }else if("localupload".equals(step)){
                    // get the filename and set step to 'go'
                    existingFile = copyFileToServer(cms, session);
                    step = "go";
                }
                if("go".equals(step) ){
                    // start the thread for: import
                    // first clear the session entry if necessary
                    if(session.getValue(C_SESSION_THREAD_ERROR) != null) {
                        session.removeValue(C_SESSION_THREAD_ERROR);
                    }
                    Thread doImport = new CmsAdminDatabaseImportThread(cms, CmsBase.getAbsolutePath(cms.readExportPath()) + File.separator
                                + existingFile, session);
                    doImport.start();
                    session.putValue(C_DATABASE_THREAD, doImport);
                    xmlTemplateDocument.setData("time", "10");
                    templateSelector = "wait";
                }
            }
        }
        catch(CmsException exc) {
            xmlTemplateDocument.setData("details", Utils.getStackTrace(exc));
            templateSelector = "error";
        }

        // Now load the template file and start the processing
        return startProcessing(cms, xmlTemplateDocument, elementName, parameters,
                templateSelector);
    }

    /**
     * Gets all export-files from the export-path.
     * <P>
     * The given vectors <code>names</code> and <code>values</code> will
     * be filled with the appropriate information to be used for building
     * a select box.
     * <P>
     * <code>names</code> will contain language specific view descriptions
     * and <code>values</code> will contain the correspondig URL for each
     * of these views after returning from this method.
     * <P>
     *
     * @param cms CmsObject Object for accessing system resources.
     * @param lang reference to the currently valid language file
     * @param names Vector to be filled with the appropriate values in this method.
     * @param values Vector to be filled with the appropriate values in this method.
     * @param parameters Hashtable containing all user parameters <em>(not used here)</em>.
     * @return Index representing the user's current filter view in the vectors.
     * @exception CmsException
     */

    public Integer getExportFiles(CmsObject cms, CmsXmlLanguageFile lang, Vector values,
            Vector names, Hashtable parameters) throws CmsException {

        // get the systems-exportpath
        String exportpath = cms.readExportPath();
        exportpath = CmsBase.getAbsolutePath(exportpath);
        File folder = new File(exportpath);
        if (!folder.exists()){
            folder.mkdirs();
        }
        // get a list of all files
        String[] list = folder.list(new FilenameFilter() {
                public boolean accept(File dir, String fileName) {
                        return(fileName.endsWith(".zip"));
                }});
        for(int i = 0;i < list.length;i++) {
            File diskFile = new File(exportpath, list[i]);

            // check if it is a file
            if(diskFile.isFile()) {
                values.addElement(list[i]);
                names.addElement(list[i]);
            }
        }
        return new Integer(0);
    }

    /**
     * Indicates if the results of this class are cacheable.
     *
     * @param cms CmsObject Object for accessing system resources
     * @param templateFile Filename of the template file
     * @param elementName Element name of this template in our parent template.
     * @param parameters Hashtable with all template class parameters.
     * @param templateSelector template section that should be processed.
     * @return <EM>true</EM> if cacheable, <EM>false</EM> otherwise.
     */

    public boolean isCacheable(CmsObject cms, String templateFile, String elementName,
            Hashtable parameters, String templateSelector) {
        return false;
    }

    /**
     * Gets all exportable modules for a select box
     * <P>
     * The given vectors <code>names</code> and <code>values</code> will
     * be filled with the appropriate information to be used for building
     * a select box.
     *
     * @param cms CmsObject Object for accessing system resources.
     * @param names Vector to be filled with the appropriate values in this method.
     * @param values Vector to be filled with the appropriate values in this method.
     * @param parameters Hashtable containing all user parameters <em>(not used here)</em>.
     * @return Index representing the current value in the vectors.
     * @exception CmsException
     */
    public int getModules(CmsObject cms, CmsXmlLanguageFile lang, Vector names,
            Vector values, Hashtable parameters) throws CmsException {
        // get all exportable modules
        Hashtable modules = new Hashtable();
        cms.getRegistry().getModuleExportables(modules);
        Enumeration keys = modules.keys();
        // fill the names and values
        while(keys.hasMoreElements()) {
            String name = (String)keys.nextElement();
            String value = (String)modules.get(name);
            names.addElement(name);
            values.addElement(value);
        }
        return 0;
    }

    /**
     * Gets all exportable modules for a select box
     * <P>
     * The method returns a string with option tags that contains the module information
     * to be used for building a select box.
     *
     * @param cms CmsObject Object for accessing system resources.
     * @param template The current template
     * @return String with the modules optiontags.
     * @exception CmsException
     */
    public String getModuleSelectbox(CmsObject cms, CmsXmlWpTemplateFile template) throws CmsException {
        StringBuffer selectBox = new StringBuffer();
        if(template.hasData("selectoption")){
            // get all exportable modules
            Hashtable modules = new Hashtable();
            cms.getRegistry().getModuleExportables(modules);
            Enumeration keys = modules.keys();
            // fill the names and values
            while(keys.hasMoreElements()) {
                String name = (String)keys.nextElement();
                String value = (String)modules.get(name);
                template.setData("name",name);
                template.setData("value",value);
                try{
                    selectBox.append(template.getProcessedDataValue("selectoption",this));
                } catch (Exception e){
                    // do not throw exception because selectbox might not exist
                }
            }
        }
        return selectBox.toString();
    }

    /** Parse the string which holds all resources
     *
     * @param resources containts the full pathnames of all the resources, separated by semicolons
     * @return A vector with the same resources
     */

    private Vector parseResources(String resources) {
        Vector ret = new Vector();
        if(resources != null) {
            StringTokenizer resTokenizer = new StringTokenizer(resources, ";");
            while(resTokenizer.hasMoreElements()) {
                String path = (String)resTokenizer.nextElement();
                ret.addElement(path);
            }
        }
        return ret;
    }
}

⌨️ 快捷键说明

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