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

📄 cmsworkplaceeditorconfiguration.java

📁 OpenCms 是一个J2EE的产品
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
 * File   : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/editors/CmsWorkplaceEditorConfiguration.java,v $
 * Date   : $Date: 2006/03/27 14:52:49 $
 * Version: $Revision: 1.14 $
 *
 * This library is part of OpenCms -
 * the Open Source Content Mananagement System
 *
 * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
 *
 * 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 Alkacon Software GmbH, please see the
 * company website: http://www.alkacon.com
 *
 * For further information about OpenCms, please see the
 * project 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 org.opencms.workplace.editors;

import org.opencms.main.CmsLog;
import org.opencms.util.CmsStringUtil;
import org.opencms.xml.CmsXmlException;
import org.opencms.xml.CmsXmlUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;

import org.apache.commons.logging.Log;

import org.dom4j.Document;
import org.dom4j.Element;

/**
 * Single editor configuration object.<p>
 * 
 * Holds all necessary information about an OpenCms editor which is stored in the
 * "editor_configuration.xml" file in each editor folder.<p>
 * 
 * Provides methods to get the editor information for the editor manager.<p>
 * 
 * @author Andreas Zahner 
 * 
 * @version $Revision: 1.14 $ 
 * 
 * @since 6.0.0 
 */
public class CmsWorkplaceEditorConfiguration {

    /** Name of the root document node. */
    public static final String DOCUMENT_NODE = "editor";

    /** Name of the single user agent node. */
    protected static final String N_AGENT = "agent";

    /** Name of the resource type class node. */
    protected static final String N_CLASS = "class";

    /** Name of the editor label node. */
    protected static final String N_LABEL = "label";

    /** Name of the resource type subnode mapto. */
    protected static final String N_MAPTO = "mapto";

    /** Name of the resource type subnode name. */
    protected static final String N_NAME = "name";

    /** Name of the resource type subnode ranking. */
    protected static final String N_RANKING = "ranking";

    /** Name of the resourcetypes node. */
    protected static final String N_RESOURCETYPES = "resourcetypes";

    /** Name of the resource type node. */
    protected static final String N_TYPE = "type";

    /** Name of the useragents node. */
    protected static final String N_USERAGENTS = "useragents";

    /** Name of the widgeteditor node. */
    protected static final String N_WIDGETEDITOR = "widgeteditor";

    /** The log object for this class. */
    private static final Log LOG = CmsLog.getLog(CmsWorkplaceEditorConfiguration.class);

    private List m_browserPattern;
    private String m_editorLabel;
    private String m_editorUri;
    private Map m_resTypes;
    private List m_userAgentsRegEx;
    private boolean m_validConfiguration;
    private String m_widgetEditor;

    /**
     * Constructor with xml data String.<p>
     * 
     * @param xmlData the XML data String containing the information about the editor
     * @param editorUri the editor workplace URI
     */
    public CmsWorkplaceEditorConfiguration(byte[] xmlData, String editorUri) {

        setValidConfiguration(true);
        try {
            initialize(CmsXmlUtils.unmarshalHelper(xmlData, null), editorUri);
        } catch (CmsXmlException e) {
            // xml String could not be parsed
            logConfigurationError(Messages.get().getBundle().key(Messages.ERR_XML_PARSE_0), e);
        }
    }

    /**
     * Returns the list of compiled browser patterns.<p>
     * 
     * @return the list of compiled browser patterns
     */
    public List getBrowserPattern() {

        return m_browserPattern;
    }

    /**
     * Returns the editor label key used for the localized nice name.<p>
     * 
     * @return the editor label key used for the localized nice name
     */
    public String getEditorLabel() {

        return m_editorLabel;
    }

    /**
     * Returns the editor workplace URI.<p>
     * 
     * @return the editor workplace URI
     */
    public String getEditorUri() {

        return m_editorUri;
    }

    /**
     * Returns the mapping for the given resource type.<p>
     * 
     * @param resourceType the resource type name to check
     * @return the mapping or null, if no mapping is specified
     */
    public String getMappingForResourceType(String resourceType) {

        String[] resourceTypeParams = (String[])getResourceTypes().get(resourceType);
        if (resourceTypeParams == null) {
            return null;
        } else {
            return resourceTypeParams[1];
        }
    }

    /**
     * Returns the ranking value for the given resource type.<p>
     * 
     * @param resourceType the current resource type
     * @return the ranking (the higher the better)
     */
    public float getRankingForResourceType(String resourceType) {

        String[] resourceTypeParams = (String[])getResourceTypes().get(resourceType);
        if (resourceTypeParams == null) {
            return -1.0f;
        } else {
            return Float.parseFloat(resourceTypeParams[0]);
        }
    }

    /**
     * Returns the valid resource types of the editor.<p>
     * 
     * A single map item has the resource type name as key, 
     * the value is a String array with two entries:
     * <ul>
     * <li>Entry 0: the ranking for the resource type</li>
     * <li>Entry 1: the mapping to another resource type or null</li>
     * </ul><p>
     * 
     * @return the valid resource types of the editor
     */
    public Map getResourceTypes() {

        return m_resTypes;
    }

    /**
     * Returns the valid user agents regular expressions of the editor.<p>
     * 
     * @return the valid user agents regular expressions of the editor
     */
    public List getUserAgentsRegEx() {

        return m_userAgentsRegEx;
    }

    /**
     * Returns the widget editor class for rich text editing.<p>
     * 
     * @return the widget editor class for rich text editing
     */
    public String getWidgetEditor() {

        return m_widgetEditor;
    }

    /**
     * Returns if the current configuration is valid.<p>
     * 
     * @return true if no configuration errors were found, otherwise false
     */
    public boolean isValidConfiguration() {

        return m_validConfiguration;
    }

    /**
     * Returns if the editor is usable as a widget editor for rich text editing.<p>
     * 
     * @return true if the editor is usable as a widget editor for rich text editing, otherwise false
     */
    public boolean isWidgetEditor() {

        return CmsStringUtil.isNotEmpty(m_widgetEditor);
    }

    /**

⌨️ 快捷键说明

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