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

📄 cmsworkplacedefault.java

📁 内容管理
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
* File   : $Source: /usr/local/cvs/opencms/src/com/opencms/workplace/CmsWorkplaceDefault.java,v $
* Date   : $Date: 2003/03/02 18:43:54 $
* Version: $Revision: 1.56 $
*
* 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.core.CmsException;
import com.opencms.core.I_CmsSession;
import com.opencms.file.CmsObject;
import com.opencms.file.CmsRequestContext;
import com.opencms.template.A_CmsXmlContent;
import com.opencms.template.CmsCacheDirectives;
import com.opencms.template.CmsXmlTemplate;
import com.opencms.template.CmsXmlTemplateFile;
import com.opencms.util.Encoder;
import com.opencms.util.Utils;

import java.util.Enumeration;
import java.util.Hashtable;
import java.util.StringTokenizer;
import java.util.Vector;

/**
 * Common template class for displaying OpenCms workplace screens.
 * <P>
 * Reads template files of the content type <code>CmsXmlWpTemplateFile</code>.
 * <P>
 * Most special workplace classes may extend this class.
 *
 * @author Alexander Lucas
 * @version $Revision: 1.56 $ $Date: 2003/03/02 18:43:54 $
 * @see com.opencms.workplace.CmsXmlWpTemplateFile
 */

public class CmsWorkplaceDefault extends CmsXmlTemplate implements I_CmsWpConstants {

    /** URL of the pics folder in the webserver's docroot */
    private static String m_resourcesUri = null;

    /** URL of the pics folder in the webserver's docroot */
    private static String m_scriptsUri = null;

    /** Reference to the config file */
    private CmsXmlWpConfigFile m_configFile = null;

    /**
     * Sorts two vectors using bubblesort. This is a quick hack to display templates sorted by title instead of
     * by name in the template dropdown, because it is the title that is shown in the dropdown.
     * Creation date: (10/24/00 13:55:12)
     * @param names The vector to sort
     * @param data Vector with data that accompanies names.
     */
    public void bubblesort(Vector names, Vector data) {
        Utils.bubblesort(names, data);
    }

    /**
     * Checks a Java System property for containing the given value
     * @param propertyName Name of the property
     * @param value Value that should be checked
     * @return <code>true</code> if the property contains the value, <code>false</code> otherwise
     */
    protected boolean checkJavaProperty(String propertyName, String value) {
        boolean result = false;
        String prop = null;
        try {
            prop = System.getProperty(propertyName);
            if(prop != null && prop.equals(value)) {
                result = true;
            }
            return result;
        }
        catch(Exception e) {
            return false;
        }
    }

    /**
     * Used by workplace icons to decide whether the icon should
     * be activated or not. Icons will use this method if the attribute <code>method="doNotShow"</code>
     * is defined in the <code>&lt;ICON&gt;</code> tag.
     * <P>
     * This method always returns <code>false</code> thus icons controlled by
     * this method will never be activated.
     *
     * @param cms CmsObject Object for accessing system resources <em>(not used here)</em>.
     * @param lang reference to the currently valid language file <em>(not used here)</em>.
     * @param parameters Hashtable containing all user parameters <em>(not used here)</em>.
     * @return <code>false</code>.
     */
    public Boolean doNotShow(CmsObject cms, CmsXmlLanguageFile lang, Hashtable parameters) {
        return new Boolean(false);
    }

    /**
     * Gets a reference to the default config file.
     * The path to this file ist stored in <code>C_WORKPLACE_INI</code>
     *
     * @param cms CmsObject Object for accessing system resources.
     * @return Reference to the config file.
     * @throws CmsException
     */
    public CmsXmlWpConfigFile getConfigFile(CmsObject cms) throws CmsException {

        //if(m_configFile == null) {
        m_configFile = new CmsXmlWpConfigFile(cms);

        //}
        return m_configFile;
    }

    /**
     * Help method used to fill the vectors returned to
     * <code>CmsSelectBox</code> with constant values.
     * @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 content String array containing the elements to be set.
     * @param lang reference to the currently valid language file
     */
    protected void getConstantSelectEntries(Vector names, Vector values, String[] contents,
            CmsXmlLanguageFile lang) throws CmsException {
        for(int i = 0;i < contents.length;i++) {
            String value = contents[i];
            values.addElement(value);
            String s = lang.getLanguageValue("select." + value);
            if ((s == null) || s.startsWith("???")) s = value;
            names.addElement(s);
        }
    }

    /**
     * Gets all fonts available in the WYSIWYG editor.
     * 
     * 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 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 workplace view in the vectors.
     * @throws CmsException
     */
    public Integer getFonts(CmsObject cms, CmsXmlLanguageFile lang, Vector names, Vector values,
            Hashtable parameters) throws CmsException {
        for(int i = 0;i < C_SELECTBOX_FONTS.length; i++) {
            String value = C_SELECTBOX_FONTS[i];
            values.addElement(value);
            names.addElement(value);
        }        
        return new Integer(0);
    }

    /**
     * Gets the key that should be used to cache the results of
     * this template class.
     *
     * @param cms CmsObject Object for accessing system resources
     * @param templateFile Filename of the template file
     * @param parameters Hashtable with all template class parameters.
     * @param templateSelector template section that should be processed.
     * @return key that can be used for caching
     */
    public Object getKey(CmsObject cms, String templateFile, Hashtable parameters, String templateSelector) {

        CmsRequestContext reqContext = cms.getRequestContext();

        String result = "" + reqContext.currentProject().getId() + ":"
                + reqContext.currentUser().getName() + templateFile;
        Enumeration keys = parameters.keys();

        // select the right language to use
        String currentLanguage = null;
        Hashtable startSettings = null;
        startSettings = (Hashtable)cms.getRequestContext().currentUser().getAdditionalInfo(C_ADDITIONAL_INFO_STARTSETTINGS);
        if(startSettings != null) {
            currentLanguage = (String)startSettings.get(C_START_LANGUAGE);
        }
        else {
            currentLanguage = C_DEFAULT_LANGUAGE;
        }
        while(keys.hasMoreElements()) {
            String key = (String)keys.nextElement();
            result = result + key + parameters.get(key);
        }
        result = result + templateSelector + currentLanguage;
        return result;
    }

    /**
     * Get the currently valid <code>lasturl</code> parameter that can be
     * used for redirecting to the previous workplace screen.
     * @param cms Cms object for accessing system resources.
     * @param parameters User parameters.
     * @return <code>lasturl</code> parameter.
     */
    protected String getLastUrl(CmsObject cms, Hashtable parameters) {
        I_CmsSession session = cms.getRequestContext().getSession(true);
        String lasturl = (String)parameters.get("lasturl");

        // Lasturl parameter will be taken either from the parameter hashtable
        // (if exists) or from the session storage.
        // If neccessary, session storage will be updated.
        StringBuffer encLasturl = new StringBuffer();
        boolean notfirst = false;
        if(lasturl != null) {

            // Fine. A lasturl parameter was found in session or parameter hashtable.
            // Check, if the URL parameters of the last url have to be encoded.
            int asteriskIdx = lasturl.indexOf("?");
            if(asteriskIdx > -1 && (asteriskIdx < (lasturl.length() - 1))) {

                // In fact, there are URL parameters
                encLasturl.append(lasturl.substring(0, asteriskIdx + 1));
                String queryString = lasturl.substring(asteriskIdx + 1);
                StringTokenizer st = new StringTokenizer(queryString, "&");
                while(st.hasMoreTokens()) {

                    // Loop through all URL parameters
                    String currToken = st.nextToken();
                    if(currToken != null && !"".equals(currToken)) {

                        // Look for the "=" character to divide parameter name and value
                        int idx = currToken.indexOf("=");
                        if(notfirst) {
                            encLasturl.append("&");
                        }
                        else {
                            notfirst = true;
                        }
                        if(idx > -1) {

                            // A parameter name/value pair was found.
                            // Encode the parameter value and write back!
                            String key = currToken.substring(0, idx);
                            String value = (idx < (currToken.length() - 1)) ? currToken.substring(idx + 1) : "";
                            encLasturl.append(key);
                            encLasturl.append("=");
                            encLasturl.append(Encoder.escape(value,
                                cms.getRequestContext().getEncoding()));
                        }
                        else {

                            // Something strange happened.
                            // Maybe a parameter without "=" ?
                            // Write back without encoding!
                            encLasturl.append(currToken);
                        }
                    }
                }
                lasturl = encLasturl.toString();
            }
            session.putValue("lasturl", lasturl);
        }
        else {
            lasturl = (String)session.getValue("lasturl");
        }
        return lasturl;
    }

    /**
     * Reads in the template file and starts the XML parser for the expected
     * content type <class>CmsXmlWpTemplateFile</code>
     *
     * @param cms CmsObject Object for accessing system resources.

⌨️ 快捷键说明

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