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

📄 cmsrelationtype.java

📁 找了很久才找到到源代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:

    /**
     * Returns all internally defined relation types.<p>
     * 
     * @return a list of {@link CmsRelationType} objects
     */
    public static List getAllInternal() {

        return Collections.unmodifiableList(Arrays.asList(VALUE_ARRAY));
    }

    /**
     * Returns all relation types for relations that are not defined in the content.<p>
     * 
     * @return a list of {@link CmsRelationType} objects
     */
    public static List getAllNotDefinedInContent() {

        return filterNotDefinedInContent(getAll());
    }

    /**
     * Returns all strong relation types.<p>
     * 
     * @return a list of {@link CmsRelationType} objects
     */
    public static List getAllStrong() {

        return filterStrong(getAll());
    }

    /**
     * Returns all user defined relation types.<p>
     * 
     * @return a list of {@link CmsRelationType} objects
     */
    public static List getAllUserDefined() {

        return OpenCms.getResourceManager().getRelationTypes();
    }

    /**
     * Returns all weak relation types.<p>
     * 
     * @return a list of {@link CmsRelationType} objects
     */
    public static List getAllWeak() {

        return filterWeak(getAll());
    }

    /**
     * Parses an <code>int</code> into a relation type.<p>
     *
     * @param id the internal representation number to parse
     * 
     * @return the enumeration element
     * 
     * @throws CmsIllegalArgumentException if the given value could not be matched against a 
     *         <code>{@link CmsRelationType}</code> object.
     */
    public static CmsRelationType valueOf(int id) throws CmsIllegalArgumentException {

        if ((id > 0) && (id <= VALUE_ARRAY.length)) {
            return VALUE_ARRAY[id - 1];
        }
        id -= USER_DEFINED_MODE_LIMIT;
        if ((id > 0) && (id <= OpenCms.getResourceManager().getRelationTypes().size())) {
            return (CmsRelationType)getAllUserDefined().get(id);
        }
        throw new CmsIllegalArgumentException(org.opencms.db.Messages.get().container(
            org.opencms.db.Messages.ERR_MODE_ENUM_PARSE_2,
            new Integer(id),
            CmsRelationType.class.getName()));
    }

    /**
     * Parses an <code>String</code> into a relation type.<p>
     *
     * @param name the relation type name
     * 
     * @return the enumeration element
     * 
     * @throws CmsIllegalArgumentException if the given value could not be matched against a 
     *         <code>{@link CmsRelationType}</code> object
     *         
     * @see #valueOfXml(String)
     * @see #valueOfJsp(String)
     */
    public static CmsRelationType valueOf(String name) throws CmsIllegalArgumentException {

        CmsRelationType result = valueOfInternal(name);
        if (result == null) {
            // no type found
            throw new CmsIllegalArgumentException(org.opencms.db.Messages.get().container(
                org.opencms.db.Messages.ERR_MODE_ENUM_PARSE_2,
                name,
                CmsRelationType.class.getName()));
        }
        return result;
    }

    /**
     * Parses the given value into a valid enumeration element for a JSP relation type.<p>
     * 
     * This should be used to extend Strings like "weak" or "strong" to full relation type descriptors
     * for JSP pages like "JSP_WEAK" or "JSP_STRONG".<p> 
     * 
     * @param name the name to get the JSP type for
     * 
     * @return the JSP enumeration element
     * 
     * @see #valueOf(String)
     */
    public static CmsRelationType valueOfJsp(String name) {

        CmsRelationType result = valueOfInternal(name);
        if (result == null) {
            result = valueOf(PREFIX_JSP + name);
        }
        return result;
    }

    /**
     * Parses the given value into a valid enumeration element for a XML relation type.<p>
     * 
     * This should be used to extend Strings like "weak" or "strong" to full relation type descriptors
     * for XML documents like "XML_WEAK" or "XML_STRONG".<p> 
     * 
     * @param name the name to get the XML type for
     * 
     * @return the XML enumeration element
     * 
     * @see #valueOf(String)
     */
    public static CmsRelationType valueOfXml(String name) {

        CmsRelationType result = valueOfInternal(name);
        if (result == null) {
            result = valueOf(PREFIX_XML + name);
        }
        return result;
    }

    /**
     * Internal parse method.<p>
     * 
     * @param name the type to parse
     * 
     * @return the enumeration element, or <code>null</code> if no matching element is found
     */
    private static CmsRelationType valueOfInternal(String name) {

        if (name != null) {
            String valueUp = name.toUpperCase();
            for (int i = 0; i < VALUE_ARRAY.length; i++) {
                if (valueUp.equals(VALUE_ARRAY[i].m_name)) {
                    return VALUE_ARRAY[i];
                }
            }
            // deprecated types
            if (valueUp.equals("REFERENCE") || valueUp.equals("XML_REFERENCE")) {
                return XML_WEAK;
            } else if (valueUp.equals("ATTACHMENT") || valueUp.equals("XML_ATTACHMENT")) {
                return XML_STRONG;
            }
            // user defined
            for (int i = 0; i < getAllUserDefined().size(); i++) {
                if (valueUp.equals(((CmsRelationType)getAllUserDefined().get(i)).m_name)) {
                    return VALUE_ARRAY[i];
                }
            }
        }
        return null;
    }

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

        if (this == obj) {
            return true;
        }
        if (obj instanceof CmsRelationType) {
            return (m_id == ((CmsRelationType)obj).m_id);
        }
        return false;
    }

    /**
     * Returns the internal representation of this type.<p>
     *
     * @return the internal representation of this type
     */
    public int getId() {

        return m_id;
    }

    /**
     * Returns a localized name for the given relation type.<p>
     * 
     * @param locale the locale
     * 
     * @return a localized name
     */
    public String getLocalizedName(Locale locale) {

        String nameKey = "GUI_RELATION_TYPE_" + getName() + "_0";
        return Messages.get().getBundle(locale).key(nameKey);
    }

    /**
     * Returns the type name.<p>
     * 
     * @return the type name
     * 
     * @see CmsRelationType#valueOf(String) 
     */
    public String getName() {

        return m_name;
    }

    /**
     * Returns the type name for xml output.<p>
     * 
     * The short type name of XML or JSP types is only <code>"WEAK"</code> or <code>"STRONG"</code>.
     * For other types the short name is equal to the name.<p> 
     * 
     * In case you need the full type name, use {@link #getName()}.<p>
     * 
     * @return the short type name
     * 
     * @see #getName()
     * @see CmsRelationType#valueOfJsp(String)
     * @see CmsRelationType#valueOfXml(String)
     */
    public String getNameForXml() {

        String result;
        switch (getId()) {
            case 3: // xml strong
                result = VALUE_STRONG;
                break;
            case 4: // xml weak
                result = VALUE_WEAK;
                break;
            case 5: // jsp strong
                result = VALUE_STRONG;
                break;
            case 6: // jsp weak
                result = VALUE_WEAK;
                break;
            default:
                result = getName();
        }
        return result;
    }

    /**
     * Returns the string strong or weak.<p>
     * 
     * @return the string strong or weak
     * 
     * @see #isStrong()
     */
    public String getType() {

        return isStrong() ? VALUE_STRONG : VALUE_WEAK;
    }

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

        return m_id;
    }

    /**
     * Checks if this relation type is defined in the content of a resource or not.<p>
     *
     * @return <code>true</code> if this relation type is defined in the content of a resource
     */
    public boolean isDefinedInContent() {

        return m_defInContent;
    }

    /**
     * Checks if this is an internal relation type.<p>
     * 
     * @return <code>true</code> if this is an internal relation type
     */
    public boolean isInternal() {

        return (getId() < USER_DEFINED_MODE_LIMIT);
    }

    /**
     * Checks if the relation type is strong or weak.<p>
     *
     * @return <code>true</code> if the relation type is strong
     */
    public boolean isStrong() {

        return m_strong;
    }

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

        return m_name;
    }
}

⌨️ 快捷键说明

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