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

📄 cmsadminmodulecreate.java

📁 内容管理
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
* File   : $Source: /usr/local/cvs/opencms/src/com/opencms/workplace/CmsAdminModuleCreate.java,v $
* Date   : $Date: 2003/02/18 14:32:07 $
* Version: $Revision: 1.28 $
*
* This library is part of OpenCms -
* the Open Source Content Mananagement System
*
* Copyright (C) 2001  The OpenCms Group
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
* Lesser General Public License for more details.
*
* For further information about OpenCms, please see the
* OpenCms Website: http://www.opencms.org
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

package com.opencms.workplace;

import com.opencms.boot.I_CmsLogChannels;
import com.opencms.core.A_OpenCms;
import com.opencms.core.CmsException;
import com.opencms.core.I_CmsConstants;
import com.opencms.core.I_CmsSession;
import com.opencms.file.CmsObject;
import com.opencms.file.CmsRegistry;
import com.opencms.file.I_CmsRegistry;
import com.opencms.template.CmsXmlTemplateFile;
import com.opencms.util.Utils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Vector;

/**
 * Template class for displaying OpenCms workplace administration module create.
 *
 * Creation date: (27.10.00 10:28:08)
 * @author Hanjo Riege
 */
public class CmsAdminModuleCreate extends CmsWorkplaceDefault implements I_CmsConstants {
    private final String C_PACKETNAME = "packetname";
    private final String C_STEP = "step";
    private final String C_VERSION = "version";
    private final String C_MODULENAME = "modulename";
    private final String C_DESCRIPTION = "description";
    private final String C_VIEW = "view";
    private final String C_ADMINPOINT = "adminpoint";
    private final String C_MAINTENANCE = "maintenance";
    private final String C_PUBLISHCLASS = "publishclass";    
    private final String C_AUTHOR = "author";
    private final String C_EMAIL = "email";
    private final String C_DATE = "date";
    private final String C_SESSION_DATA = "module_create_data";
    private final String C_MODULE_TYPE = "moduletype";
    private final String C_EXPORTCLASSES = "exportclasses";
    private final String C_EXPORTLIB = "exportlib";
        
    /**
     *  Checks if the name is correct.
     *  @param name the name to check..
     */
    private boolean checkName(String name) {
        if(name == null || name.length() == 0 || name.trim().length() == 0) {
            return false;
        }
        for(int i = 0;i < name.length();i++) {
            char c = name.charAt(i);
            if(((c < 'a') || (c > 'z')) && ((c < '0') || (c > '9')) && ((c < 'A') || (c > 'Z')) && (c != '-') && (c != '.') && (c != '_') && (c != '~')) {
                return false;
            }
        }
        return true;
    }

    /**
     * Gets the content of a defined section in a given template file and its subtemplates
     * with the given parameters.
     *
     * @see #getContent(CmsObject, String, String, Hashtable, String)
     * @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.
     */
    public byte[] getContent(CmsObject cms, String templateFile, String elementName, Hashtable parameters, String templateSelector) throws CmsException {
        if(I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() && C_DEBUG) {
            A_OpenCms.log(C_OPENCMS_DEBUG, this.getClassName() + "getting content of element " + ((elementName == null) ? "<root>" : elementName));
            A_OpenCms.log(C_OPENCMS_DEBUG, this.getClassName() + "template file is: " + templateFile);
            A_OpenCms.log(C_OPENCMS_DEBUG, this.getClassName() + "selected template section is: " + ((templateSelector == null) ? "<default>" : templateSelector));
        }
        CmsXmlTemplateFile templateDocument = getOwnTemplateFile(cms, templateFile, elementName, parameters, templateSelector);
        //CmsRequestContext reqCont = cms.getRequestContext();
        I_CmsRegistry reg = cms.getRegistry();
        I_CmsSession session = cms.getRequestContext().getSession(true);
        String step = (String)parameters.get(C_STEP);
        SimpleDateFormat dateFormat = new java.text.SimpleDateFormat("dd.MM.yyyy");
        if((step == null) || "".equals(step)) {
            templateDocument.setData(C_PACKETNAME, "");
            templateDocument.setData(C_VERSION, "1");
            templateDocument.setData(C_MODULENAME, "");
            templateDocument.setData(C_DESCRIPTION, "");
            templateDocument.setData(C_VIEW, "");
            templateDocument.setData(C_ADMINPOINT, "");
            templateDocument.setData(C_MAINTENANCE, "");
            templateDocument.setData(C_PUBLISHCLASS, "");            
            templateDocument.setData(C_AUTHOR, "");
            templateDocument.setData(C_EMAIL, "");
            templateDocument.setData(C_MODULE_TYPE, "checked");
            templateDocument.setData(C_EXPORTCLASSES, "checked");
            templateDocument.setData(C_EXPORTLIB, "checked");                        
            //  set the current date:
            templateDocument.setData(C_DATE, dateFormat.format(new Date()));
        }else {
            if("OK".equals(step) || "Ok".equals(step)) {
                String packagename = (String)parameters.get(C_PACKETNAME);
                String modulename = (String)parameters.get(C_MODULENAME);
                String version = (String)parameters.get(C_VERSION);
                String description = (String)parameters.get(C_DESCRIPTION);
                String view = (String)parameters.get(C_VIEW);
                String adminpoint = (String)parameters.get(C_ADMINPOINT);
                String maintenance = (String)parameters.get(C_MAINTENANCE);
                String publishclass = (String)parameters.get(C_PUBLISHCLASS);
                String author = (String)parameters.get(C_AUTHOR);
                String email = (String)parameters.get(C_EMAIL);
                String createDate = (String)parameters.get(C_DATE);
                String moduleType = (String)parameters.get(C_MODULE_TYPE);
                String exportClasses = (String)parameters.get(C_EXPORTCLASSES);
                String exportLib = (String)parameters.get(C_EXPORTLIB);
                    
                boolean isSimpleModule = ((moduleType != null) && moduleType.equals("checked"));
                boolean mustExportClasses = ((exportClasses != null) && exportClasses.equals("checked"));
                boolean mustExportLib = ((exportLib != null) && exportLib.equals("checked"));
                
                boolean moduleExists = reg.moduleExists(packagename);
                float v = -1;
                try {
                    v = Float.parseFloat(version);
                }catch(Exception e) {
                }
                if((!checkName(packagename)) || (version == null) || ("".equals(version)) || moduleExists || (v < 0)) {
                    Hashtable sessionData = new Hashtable();
                    sessionData.put(C_MODULENAME, getStringValue(modulename));
                    sessionData.put(C_VERSION, getStringValue(version));
                    sessionData.put(C_DESCRIPTION, getStringValue(description));
                    sessionData.put(C_VIEW, getStringValue(view));
                    sessionData.put(C_ADMINPOINT, getStringValue(adminpoint));
                    sessionData.put(C_MAINTENANCE, getStringValue(maintenance));
                    sessionData.put(C_PUBLISHCLASS, getStringValue(publishclass));                    
                    sessionData.put(C_AUTHOR, getStringValue(author));
                    sessionData.put(C_EMAIL, getStringValue(email));
                    sessionData.put(C_DATE, getStringValue(createDate));
                    sessionData.put(C_MODULE_TYPE, getStringValue(moduleType));
                    session.putValue(C_SESSION_DATA, sessionData);
                    if(moduleExists) {
                        templateSelector = "errorexists";
                    }else {
                        templateSelector = "errornoname";
                    }
                }else {
                    tryToCreateFolder(cms, "/system/", "modules");
                    // create the module (first test if we are in a project including /system/

⌨️ 快捷键说明

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