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

📄 cmsworkplaceeditorconfiguration.java

📁 OpenCms 是一个J2EE的产品
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     * Tests if the current browser is matching the configuration.<p>
     * 
     * @param currentBrowser the users browser String to test
     * @return true if the browser matches the configuration, otherwise false
     */
    public boolean matchesBrowser(String currentBrowser) {

        if (currentBrowser == null) {
            return false;
        }
        for (int i = 0; i < getBrowserPattern().size(); i++) {
            boolean matches = ((Pattern)getBrowserPattern().get(i)).matcher(currentBrowser.trim()).matches();
            if (matches) {
                if (LOG.isDebugEnabled()) {
                    LOG.debug(Messages.get().getBundle().key(Messages.LOG_BROWSER_MATCHES_CONFIG_1, currentBrowser));
                }
                return true;
            }
        }
        return false;
    }

    /**
     * Returns if the configuration is suitable for the given resource type.<p>
     * 
     * @param resourceType the resource type to check
     * @return true if the configuration matches the resource type
     */
    public boolean matchesResourceType(String resourceType) {

        return m_resTypes.containsKey(resourceType);
    }

    /**
     * Initializes all member variables.<p>
     * 
     * @param document the XML configuration document
     * @param editorUri the editor workplace URI
     */
    private void initialize(Document document, String editorUri) {

        // get the root element of the configuration
        Element rootElement = document.getRootElement();

        // set the label of the editor
        setEditorLabel(rootElement.elementText(N_LABEL));

        // set the widget editor class if available
        String widgetClass = rootElement.elementText(N_WIDGETEDITOR);
        if (CmsStringUtil.isNotEmpty(widgetClass)) {
            setWidgetEditor(widgetClass);
        }

        // set the URI of the editor
        setEditorUri(editorUri);

        // create the map of valid resource types
        Iterator i = rootElement.element(N_RESOURCETYPES).elementIterator(N_TYPE);
        Map resTypes = new HashMap();
        while (i.hasNext()) {
            Element currentType = (Element)i.next();
            float ranking;
            String name = currentType.elementText(N_NAME);
            if (CmsStringUtil.isEmpty(name)) {
                logConfigurationError(Messages.get().getBundle().key(Messages.ERR_INVALID_RESTYPE_NAME_0), null);
                continue;
            }
            try {
                ranking = Float.parseFloat(currentType.elementText(N_RANKING));
            } catch (Throwable t) {
                logConfigurationError(Messages.get().getBundle().key(Messages.ERR_INVALID_RESTYPE_RANKING_1, name), t);
                continue;
            }
            String mapTo = currentType.elementText(N_MAPTO);
            if (CmsStringUtil.isEmpty(mapTo)) {
                mapTo = null;
            }
            resTypes.put(name, new String[] {"" + ranking, mapTo});
        }
        // add the additional resource types
        i = rootElement.element(N_RESOURCETYPES).elementIterator(N_CLASS);
        while (i.hasNext()) {
            Element currentClass = (Element)i.next();
            String name = currentClass.elementText(N_NAME);
            List assignedTypes = new ArrayList();
            try {
                // get the editor type matcher class
                I_CmsEditorTypeMatcher matcher = (I_CmsEditorTypeMatcher)Class.forName(name).newInstance();
                assignedTypes = matcher.getAdditionalResourceTypes();
            } catch (Throwable t) {
                logConfigurationError(Messages.get().getBundle().key(Messages.ERR_INVALID_RESTYPE_CLASS_1, name), t);
                continue;
            }
            float ranking;
            try {
                ranking = Float.parseFloat(currentClass.elementText(N_RANKING));
            } catch (Throwable t) {
                logConfigurationError(Messages.get().getBundle().key(Messages.ERR_INVALID_RESTYPE_RANKING_1, name), t);
                continue;
            }
            String mapTo = currentClass.elementText(N_MAPTO);
            if ("".equals(mapTo)) {
                mapTo = null;
            }
            // now loop through all types found and add them 
            Iterator j = assignedTypes.iterator();
            while (j.hasNext()) {
                String typeName = (String)j.next();
                resTypes.put(typeName, new String[] {"" + ranking, mapTo});
            }
        }

        setResourceTypes(resTypes);

        // create the list of user agents & compiled patterns for editor
        i = document.getRootElement().element(N_USERAGENTS).elementIterator(N_AGENT);
        List pattern = new ArrayList();
        List userAgents = new ArrayList();
        while (i.hasNext()) {
            Element currentAgent = (Element)i.next();
            String agentName = currentAgent.getText();
            if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(agentName)) {
                userAgents.add(agentName);
                try {
                    pattern.add(Pattern.compile(agentName));
                } catch (PatternSyntaxException e) {
                    logConfigurationError(
                        Messages.get().getBundle().key(Messages.ERR_COMPILE_EDITOR_REGEX_1, agentName),
                        e);
                }
            } else {
                logConfigurationError(Messages.get().getBundle().key(Messages.ERR_INVALID_USERAGENT_DEF_0), null);
            }
        }
        setBrowserPattern(pattern);
        setUserAgentsRegEx(userAgents);
    }

    /**
     * Logs configuration errors and invalidates the current configuration.<p>
     * 
     * @param message the message specifying the configuration error
     * @param t the Throwable object or null
     */
    private void logConfigurationError(String message, Throwable t) {

        setValidConfiguration(false);
        if (LOG.isErrorEnabled()) {
            if (t == null) {
                LOG.error(Messages.get().getBundle().key(Messages.LOG_EDITOR_CONFIG_ERROR_1, message));
            } else {
                LOG.error(Messages.get().getBundle().key(Messages.LOG_EDITOR_CONFIG_ERROR_1, message), t);
            }
        }
    }

    /**
     * Sets the list of compiled browser patterns.<p>
     * 
     * @param pattern the list of compiled browser patterns
     */
    private void setBrowserPattern(List pattern) {

        if (pattern == null || pattern.size() == 0) {
            setValidConfiguration(false);
            LOG.error(Messages.get().getBundle().key(Messages.LOG_EDITOR_CONFIG_NO_PATTERN_0));
        }
        m_browserPattern = pattern;
    }

    /**
     * Sets the editor label key used for the localized nice name.<p>
     * 
     * @param label the editor label key used for the localized nice name
     */
    private void setEditorLabel(String label) {

        if (CmsStringUtil.isEmptyOrWhitespaceOnly(label)) {
            setValidConfiguration(false);
            LOG.error(Messages.get().getBundle().key(Messages.LOG_EDITOR_CONFIG_NO_LABEL_0));
        }
        m_editorLabel = label;
    }

    /**
     * Sets the editor workplace URI.<p>
     * @param uri the editor workplace URI
     */
    private void setEditorUri(String uri) {

        if (CmsStringUtil.isEmptyOrWhitespaceOnly(uri)) {
            setValidConfiguration(false);
            LOG.error(Messages.get().getBundle().key(Messages.LOG_EDITOR_CONFIG_NO_URI_0));
        }
        m_editorUri = uri;
    }

    /**
     * Sets the valid resource types of the editor.<p>
     * 
     * @param types the valid resource types of the editor
     */
    private void setResourceTypes(Map types) {

        if (types == null || types.size() == 0) {
            setValidConfiguration(false);
            LOG.error(Messages.get().getBundle().key(Messages.LOG_NO_RESOURCE_TYPES_0));
        }
        m_resTypes = types;
    }

    /**
     * Sets the valid user agents regular expressions of the editor.<p>
     * 
     * @param agents the valid user agents regular expressions of the editor
     */
    private void setUserAgentsRegEx(List agents) {

        if (agents == null || agents.size() == 0) {
            setValidConfiguration(false);
            LOG.error(Messages.get().getBundle().key(Messages.LOG_NO_USER_AGENTS_0));
        }
        m_userAgentsRegEx = agents;
    }

    /**
     * Sets if the current configuration is valid.<p>
     * 
     * @param isValid true if no configuration errors were found, otherwise false
     */
    private void setValidConfiguration(boolean isValid) {

        m_validConfiguration = isValid;
    }

    /**
     * Sets the widget editor class for rich text editing.<p>
     * 
     * @param widgetEditor the widget editor class for rich text editing
     */
    private void setWidgetEditor(String widgetEditor) {

        m_widgetEditor = widgetEditor;
    }

}

⌨️ 快捷键说明

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