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

📄 cmsadministration.java

📁 内容管理
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
* File   : $Source: /usr/local/cvs/opencms/src/com/opencms/workplace/CmsAdministration.java,v $
* Date   : $Date: 2003/03/04 17:26:34 $
* Version: $Revision: 1.29 $
*
* 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.CmsFile;
import com.opencms.file.CmsFolder;
import com.opencms.file.CmsGroup;
import com.opencms.file.CmsObject;
import com.opencms.file.CmsResource;
import com.opencms.template.CmsTemplateClassManager;
import com.opencms.template.CmsXmlTemplateFile;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Map;
import java.util.Vector;

/**
 * This class is used to display the administration view.
 *
 * Creation date: (09.08.00 14:01:21)
 * @author Hanjo Riege
 * @version $Name:  $ $Revision: 1.29 $ $Date: 2003/03/04 17:26:34 $
 */

public class CmsAdministration extends CmsWorkplaceDefault implements I_CmsConstants {

    private static String C_ADMIN_PATH = "system/workplace/action/administration_content_top.html";

    /**
     * Returns the complete Icon.
     *
     * @param cms CmsObject Object for accessing system resources
     * @param templateDocument contains the icondefinition.
     * @param parameters Hashtable containing all user parameters.
     * @param lang CmsXmlLanguageFile conataining the currently valid language file.
     * @param picName the basic name of the picture.
     * @param sender the name of the icon incl. path.
     * @param languageKey the the key for the languagefile.
     * @param iconActiveMethod the method for decision if icon is active, or null.
     * @param iconVisibleMethod the method for decision if icon is visible,  or null.
     */

    private String generateIcon(CmsObject cms, CmsXmlTemplateFile templateDocument, Hashtable parameters,
            CmsXmlLanguageFile lang, String picName, String sender, String languageKey,
                    String iconActiveMethod, String iconVisibleMethod, String accessVisible) throws CmsException {

        boolean hasAccessVisible = (new Boolean(accessVisible)).booleanValue();
        String iconPicPath = (String)resourcesUri(cms, "", null, null);
        // change the iconPicPath if the point is from a module
        if(sender.startsWith("/system/modules")) {
            if (picName.startsWith("/")) {
                iconPicPath = cms.getRequestContext().getRequest().getServletUrl() + sender.substring(0, sender.indexOf("/administration/"));
            }
            else {
                iconPicPath = cms.getRequestContext().getRequest().getServletUrl() + sender.substring(0, sender.indexOf("administration/")) + "pics/";
            }
        }

        // call the method for activation decision
        boolean activate = true;
        if(iconActiveMethod != null && !"".equals(iconActiveMethod)) {
            String className = iconActiveMethod.substring(0, iconActiveMethod.lastIndexOf("."));
            iconActiveMethod = iconActiveMethod.substring(iconActiveMethod.lastIndexOf(".") + 1);
            Method groupsMethod = null;
            try {
                Object o = CmsTemplateClassManager.getClassInstance(cms, className);
                groupsMethod = o.getClass().getMethod(iconActiveMethod, new Class[] {
                    CmsObject.class, CmsXmlLanguageFile.class, Hashtable.class
                });
                activate = ((Boolean)groupsMethod.invoke(o, new Object[] {
                    cms, lang, parameters
                })).booleanValue();

            }
            catch(NoSuchMethodException exc) {

                // The requested method was not found.
                throwException("Could not find icon activation method " + iconActiveMethod
                        + " in calling class " + className + " for generating icon.", CmsException.C_NOT_FOUND);
            }
            catch(InvocationTargetException targetEx) {

                // the method could be invoked, but throwed a exception
                // itself. Get this exception and throw it again.
                Throwable e = targetEx.getTargetException();
                if(!(e instanceof CmsException)) {

                    throwException("Icon activation method " + iconActiveMethod + " in calling class "
                            + className + " throwed an exception. " + e, CmsException.C_UNKNOWN_EXCEPTION);
                }
                else {

                    // This is a CmsException
                    // Error printing should be done previously.
                    throw (CmsException)e;
                }
            }
            catch(Exception exc2) {
                throwException("Icon activation method " + iconActiveMethod + " in calling class "
                        + className + " was found but could not be invoked. " + exc2, CmsException.C_UNKNOWN_EXCEPTION);
            }
        }

        // call the method for the visibility decision
        boolean visible = true;
        if(iconVisibleMethod != null && !"".equals(iconVisibleMethod)) {
            String className = iconVisibleMethod.substring(0, iconVisibleMethod.lastIndexOf("."));
            iconVisibleMethod = iconVisibleMethod.substring(iconVisibleMethod.lastIndexOf(".") + 1);
            Method groupsMethod = null;
            try {
                Object o = CmsTemplateClassManager.getClassInstance(cms, className);
                groupsMethod = o.getClass().getMethod(iconVisibleMethod, new Class[] {
                    CmsObject.class, CmsXmlLanguageFile.class, Hashtable.class
                });
                visible = ((Boolean)groupsMethod.invoke(o, new Object[] {
                    cms, lang, parameters
                })).booleanValue();
            }
            catch(NoSuchMethodException exc) {

                // The requested method was not found.
                throwException("Could not find icon activation method " + iconVisibleMethod
                        + " in calling class " + className + " for generating icon.", CmsException.C_NOT_FOUND);
            }
            catch(InvocationTargetException targetEx) {

                // the method could be invoked, but throwed a exception

                // itself. Get this exception and throw it again.
                Throwable e = targetEx.getTargetException();
                if(!(e instanceof CmsException)) {

                    throwException("Icon activation method " + iconVisibleMethod + " in calling class "
                            + className + " throwed an exception. " + e, CmsException.C_UNKNOWN_EXCEPTION);
                }
                else {

                    // This is a CmsException

                    // Error printing should be done previously.
                    throw (CmsException)e;
                }
            }
            catch(Exception exc2) {
                throwException("Icon activation method " + iconVisibleMethod + " in calling class "
                        + className + " was found but could not be invoked. " + exc2, CmsException.C_UNKNOWN_EXCEPTION);
            }
        }
        templateDocument.setData("linkTo", cms.getRequestContext().getRequest().getServletUrl() + "/" + C_ADMIN_PATH
                + "?" + "sender=" + sender);
        StringBuffer iconLabelBuffer = new StringBuffer(lang.getLanguageValue(languageKey));

        // Insert a html-break, if needed
        if(iconLabelBuffer.toString().indexOf("- ") != -1) {
            iconLabelBuffer.insert(iconLabelBuffer.toString().indexOf("- ") + 1, "<BR>");
        }
        templateDocument.setData("linkName", iconLabelBuffer.toString());
        if(visible && hasAccessVisible) {
            if(activate) {
                templateDocument.setData("picture", iconPicPath + picName + ".gif");
                return templateDocument.getProcessedDataValue("defaulticon");
            }
            else {
                templateDocument.setData("picture", iconPicPath + picName + "_in.gif");
                return templateDocument.getProcessedDataValue("deactivatedicon");
            }
        }
        else {
            return templateDocument.getProcessedDataValue("noicon");
        }
    } // of generateIcon

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

⌨️ 快捷键说明

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