cmsadministration.java

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

JAVA
478
字号
/*
* File   : $Source: /usr/local/cvs/opencms/src/com/opencms/workplace/CmsAdministration.java,v $
* Date   : $Date: 2001/09/24 13:57:16 $
* Version: $Revision: 1.18 $
*
* 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.file.*;
import com.opencms.core.*;
import com.opencms.util.*;
import com.opencms.template.*;
import java.util.*;
import java.io.*;
import java.lang.reflect.*;
import javax.servlet.http.*;

/**
 * This class is used to display the administration view.
 *
 * Creation date: (09.08.00 14:01:21)
 * @author: Hanjo Riege
 * @version $Name:  $ $Revision: 1.18 $ $Date: 2001/09/24 13:57:16 $
 */

public class CmsAdministration extends CmsWorkplaceDefault implements I_CmsConstants {


    /** The number of elements per row */
    private static int C_ELEMENT_PER_ROW = 5;

    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)picsUrl(cms, "", null, null);
        if(sender.startsWith("/system/modules")) {

            // change the iconPicPath if the point is from a module
            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)) {
            CmsTemplateClassManager callingObject = new CmsTemplateClassManager();
            String className = iconActiveMethod.substring(0, iconActiveMethod.lastIndexOf("."));
            iconActiveMethod = iconActiveMethod.substring(iconActiveMethod.lastIndexOf(".") + 1);
            Method groupsMethod = null;
            try {
                Object o = callingObject.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)) {
            CmsTemplateClassManager callingObject = new CmsTemplateClassManager();
            String className = iconVisibleMethod.substring(0, iconVisibleMethod.lastIndexOf("."));
            iconVisibleMethod = iconVisibleMethod.substring(iconVisibleMethod.lastIndexOf(".") + 1);
            Method groupsMethod = null;
            try {
                Object o = callingObject.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", this.getServletPath(cms, "", null, null) + 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 cms, String templateFile, String elementName, Hashtable parameters)
     * @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));
        }
        I_CmsSession session = cms.getRequestContext().getSession(true);
        CmsXmlWpTemplateFile templateDocument = new CmsXmlWpTemplateFile(cms, templateFile);
        CmsXmlLanguageFile lang = templateDocument.getLanguageFile();
        String navPos = (String)session.getValue(C_SESSION_ADMIN_POS);
        templateDocument.setData("emptyPic", (String)picsUrl(cms, "empty.gif", null, null));
        CmsXmlWpConfigFile confFile = new CmsXmlWpConfigFile(cms);
        String sendBy = (String)parameters.get("sender");
        if(sendBy == null) {
            if(navPos == null) {
                sendBy = confFile.getWorkplaceAdministrationPath();
            }
            else {
                if(!navPos.endsWith("/")) {
                    navPos = navPos.substring(0, navPos.indexOf("/") + 1);
                }
                sendBy = navPos;
            }
        }
        Vector iconVector = new Vector();
        if(sendBy.endsWith("/administration/")) {

⌨️ 快捷键说明

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