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

📄 cmsselectwidgetoption.java

📁 cms是开源的框架
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        }

        // cut along the delimiter
        String[] parts = CmsStringUtil.splitAsArray(input, INPUT_DELIMITER);
        List result = new ArrayList();

        // indicates if a default of 'true' was already set in this result list
        boolean foundDefault = false;

        for (int i = 0; i < parts.length; i++) {

            String part = parts[i].trim();
            if (part.length() == 0) {
                // skip empty parts
                continue;
            }

            try {

                String value = null;
                String option = null;
                String help = null;
                boolean isDefault = false;

                int posValue = part.indexOf(KEY_VALUE);
                int posDefault = part.indexOf(KEY_DEFAULT);
                int posOption = part.indexOf(KEY_OPTION);
                int posHelp = part.indexOf(KEY_HELP);

                boolean shortValue = false;
                if (posValue < 0) {
                    // shortcut syntax, value key must be at first position
                    if ((posDefault == 0) || (posOption == 0) || (posHelp == 0)) {
                        // malformed part - no value given
                        throw new CmsWidgetException(Messages.get().container(
                            Messages.ERR_MALFORMED_SELECT_OPTIONS_1,
                            input));
                    }
                    posValue = 0;
                    shortValue = true;
                }

                // a 'value' must be always present
                int end = part.length();
                // check where the 'value' ends
                if (posHelp > posValue) {
                    end = posHelp;
                }
                if ((posDefault > posValue) && (posDefault < end)) {
                    end = posDefault;
                }
                if ((posOption > posValue) && (posOption < end)) {
                    end = posOption;
                }
                if (shortValue) {
                    // no explicit setting using the key, value must be at the first position
                    value = part.substring(0, end).trim();
                } else {
                    value = part.substring(posValue + KEY_VALUE.length(), end).trim();
                    // cut of trailing '
                    value = value.substring(0, value.length() - 1);
                }

                boolean shortOption = false;
                // check if the option is appended using the ':' shortcut
                if ((shortValue) && (posOption < 0)) {
                    int pos = value.indexOf(OPTION_DELIMITER);
                    if (pos >= 0) {
                        // shortcut syntax is used
                        posOption = pos;
                        shortOption = true;
                        value = value.substring(0, pos);
                    }
                }

                if (posDefault >= 0) {
                    // there was an explicit 'default' setting using the key, check where it ends
                    end = part.length();
                    if (posHelp > posDefault) {
                        end = posHelp;
                    }
                    if ((posOption > posDefault) && (posOption < end)) {
                        end = posOption;
                    }
                    if ((posValue > posDefault) && (posValue < end)) {
                        end = posValue;
                    }
                    String sub = part.substring(posDefault + KEY_DEFAULT.length(), end).trim();
                    // cut of trailing '
                    sub = sub.substring(0, sub.length() - 1);
                    isDefault = Boolean.valueOf(sub).booleanValue();
                } else {
                    // check for shortcut syntax, value must end with a '*'
                    if (value.charAt(value.length() - 1) == DEFAULT_MARKER) {
                        isDefault = true;
                        value = value.substring(0, value.length() - 1);
                    }
                }

                if (posOption >= 0) {
                    // an 'option' setting is available, check where it ends
                    end = part.length();
                    if (posHelp > posOption) {
                        end = posHelp;
                    }
                    if ((posDefault > posOption) && (posDefault < end)) {
                        end = posDefault;
                    }
                    if ((posValue > posOption) && (posValue < end)) {
                        end = posValue;
                    }
                    if (shortOption) {
                        // shortcut syntax used for option with ':' appended to value
                        option = part.substring(posOption + 1, end).trim();
                    } else {
                        option = part.substring(posOption + KEY_OPTION.length(), end).trim();
                        // cut of trailing '
                        option = option.substring(0, option.length() - 1);
                    }
                }

                if (posHelp >= 0) {
                    // a 'help' setting is available, check where it ends
                    end = part.length();
                    if (posOption > posHelp) {
                        end = posOption;
                    }
                    if ((posDefault > posHelp) && (posDefault < end)) {
                        end = posDefault;
                    }
                    if ((posValue > posHelp) && (posValue < end)) {
                        end = posValue;
                    }
                    help = part.substring(posHelp + KEY_HELP.length(), end).trim();
                    // cut of trailing '
                    help = help.substring(0, help.length() - 1);
                }

                // check if there was already a 'true' default, if so all other entries are 'false'
                if (foundDefault) {
                    isDefault = false;
                } else if (isDefault) {
                    foundDefault = true;
                }

                result.add(new CmsSelectWidgetOption(value, isDefault, option, help));

            } catch (Exception e) {
                if (LOG.isInfoEnabled()) {
                    LOG.info(Messages.get().getBundle().key(Messages.ERR_MALFORMED_SELECT_OPTIONS_1, input));
                }
            }
        }

        return result;
    }

    /**
     * @see java.lang.Object#equals(java.lang.Object)
     */
    public boolean equals(Object obj) {

        if (!(obj instanceof CmsSelectWidgetOption)) {
            return false;
        }
        CmsSelectWidgetOption other = (CmsSelectWidgetOption)obj;
        if (m_default != other.m_default) {
            return false;
        }
        if (m_value == null) {
            if (other.m_value != null) {
                return false;
            }
        } else if (!m_value.equals(other.m_value)) {
            return false;
        }
        if (m_option == null) {
            if (other.m_option != null) {
                return false;
            }
        } else if (!m_option.equals(other.m_option)) {
            return false;
        }
        if (m_help == null) {
            if (other.m_help != null) {
                return false;
            }
        } else if (!m_help.equals(other.m_help)) {
            return false;
        }
        return true;
    }

    /**
     * Returns the (optional) help text of this select option.<p>
     *
     * @return the (optional) help text of this select option
     */
    public String getHelp() {

        return m_help;
    }

    /**
     * Returns the option text of this select option.<p>
     *
     * If this has not been set, the result of <code>{@link #getValue()}</code> is returned,
     * there will always be a result other than <code>null</code> returned.<p>
     *
     * @return the option text of this select option
     */
    public String getOption() {

        if (m_option == null) {
            return getValue();
        }
        return m_option;
    }

    /**
     * Returns the value of this select option.<p>
     *
     * @return the value of this select option
     */
    public String getValue() {

        return m_value;
    }

    /**
     * @see java.lang.Object#hashCode()
     */
    public int hashCode() {

        if (m_hashcode == 0) {
            StringBuffer hash = new StringBuffer(128);
            hash.append(m_value);
            hash.append('|');
            hash.append(m_default);
            hash.append('|');
            hash.append(m_option);
            hash.append('|');
            hash.append(m_help);
            m_hashcode = hash.toString().hashCode();
        }
        return m_hashcode;
    }

    /**
     * Returns <code>true</code> if this is the default value of the selection.<p>
     *
     * @return <code>true</code> if this is the default value of the selection
     */
    public boolean isDefault() {

        return m_default;
    }

    /**
     * @see java.lang.Object#toString()
     */
    public String toString() {

        StringBuffer result = new StringBuffer(128);

        result.append(KEY_VALUE);
        result.append(m_value);
        result.append('\'');
        if (m_default) {
            result.append(' ');
            result.append(KEY_DEFAULT);
            result.append(m_default);
            result.append('\'');
        }
        if (m_option != null) {
            result.append(' ');
            result.append(KEY_OPTION);
            result.append(m_option);
            result.append('\'');
        }
        if (m_help != null) {
            result.append(' ');
            result.append(KEY_HELP);
            result.append(m_help);
            result.append('\'');
        }
        return result.toString();
    }
}

⌨️ 快捷键说明

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