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

📄 cmsproperty.java

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

    /**
     * Returns the compound value of this property, split as a list, or a specified default value list,
     * if both the structure and resource values are null.<p>
     * 
     * In other words, this method returns the defaultValue if this property object 
     * is the null property (see {@link CmsProperty#getNullProperty()}).<p>
     * 
     * @param defaultValue a default value list which is returned if both the structure and resource values are <code>null</code>
     * 
     * @return the compound value of this property, split as a (unmodifiable) list of Strings
     */
    public List getValueList(List defaultValue) {

        if (this == CmsProperty.NULL_PROPERTY) {
            // return the default value if this property is the null property
            return defaultValue;
        }

        // somebody might have set both values to null manually
        // on a property object different from the null property...
        return (m_structureValue != null) ? getStructureValueList()
        : ((m_resourceValue != null) ? getResourceValueList() : defaultValue);
    }

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

        StringBuffer strBuf = new StringBuffer();

        strBuf.append(m_name);
        strBuf.append("_");
        strBuf.append(m_structureValue);
        strBuf.append("_");
        strBuf.append(m_resourceValue);

        return strBuf.toString().hashCode();
    }

    /**
     * Checks if the resource value of this property should be deleted when this
     * property object is written to the database.<p>
     * 
     * @return true, if the resource value of this property should be deleted
     * @see CmsProperty#DELETE_VALUE
     */
    public boolean isDeleteResourceValue() {

        return (m_resourceValue == DELETE_VALUE) || ((m_resourceValue != null) && (m_resourceValue.length() == 0));
    }

    /**
     * Checks if the structure value of this property should be deleted when this
     * property object is written to the database.<p>
     * 
     * @return true, if the structure value of this property should be deleted
     * @see CmsProperty#DELETE_VALUE
     */
    public boolean isDeleteStructureValue() {

        return (m_structureValue == DELETE_VALUE) || ((m_structureValue != null) && (m_structureValue.length() == 0));
    }

    /**
     * Returns <code>true</code> if this property is frozen, that is read only.<p>
     *
     * @return <code>true</code> if this property is frozen, that is read only
     */
    public boolean isFrozen() {

        return m_frozen;
    }

    /**
     * Tests if a given CmsProperty is identical to this CmsProperty object.<p>
     * 
     * The property object are identical if their name, structure and 
     * resource values are all equals.<p>
     * 
     * @param property another property object
     * @return true, if the specified object is equal to this CmsProperty object
     */
    public boolean isIdentical(CmsProperty property) {

        boolean isEqual;

        // compare the name
        if (m_name == null) {
            isEqual = (property.getName() == null);
        } else {
            isEqual = m_name.equals(property.getName());
        }

        // compare the structure value
        if (m_structureValue == null) {
            isEqual &= (property.getStructureValue() == null);
        } else {
            isEqual &= m_structureValue.equals(property.getStructureValue());
        }

        // compare the resource value
        if (m_resourceValue == null) {
            isEqual &= (property.getResourceValue() == null);
        } else {
            isEqual &= m_resourceValue.equals(property.getResourceValue());
        }

        return isEqual;
    }

    /**
     * Checks if this property object is the null property object.<p>
     * 
     * @return true if this property object is the null property object
     */
    public boolean isNullProperty() {

        return NULL_PROPERTY.equals(this);
    }

    /**
     * Sets the boolean flag to decide if the property definition for this property should be 
     * created implicitly on any write operation if doesn't exist already.<p>
     * 
     * @param value true, if the property definition for this property should be created implicitly on any write operation
     */
    public void setAutoCreatePropertyDefinition(boolean value) {

        checkFrozen();
        m_autoCreatePropertyDefinition = value;
    }

    /**
     * Sets the frozen state of the property, if set to <code>true</code> then this property is read only.<p>
     *
     * If the property is already frozen, then setting the frozen state to <code>true</code> again is allowed, 
     * but seeting the value to <code>false</code> causes a <code>{@link CmsRuntimeException}</code>.<p>
     *
     * @param frozen the frozen state to set
     */
    public void setFrozen(boolean frozen) {

        if (!frozen) {
            checkFrozen();
        }
        m_frozen = frozen;
    }

    /**
     * Sets the name of this property.<p>
     * 
     * @param name the name of this property
     * 
     * @deprecated use {@link #setName(String)} instead
     */
    public void setKey(String name) {

        checkFrozen();
        setName(name);
    }

    /**
     * Sets the name of this property.<p>
     * 
     * @param name the name to set
     */
    public void setName(String name) {

        checkFrozen();
        m_name = name;
    }

    /**
     * Sets the value of this property attached to the resource record.<p>
     * 
     * @param resourceValue the value of this property attached to the resource record
     */
    public void setResourceValue(String resourceValue) {

        checkFrozen();
        m_resourceValue = resourceValue;
        m_resourceValueList = null;
    }

    /**
     * Sets the value of this property attached to the resource record form the given list of Strings.<p>
     * 
     * The value will be created form the individual values of the given list, which are appended
     * using the <code>|</code> char as delimiter.<p>
     * 
     * @param valueList the list of value (Strings) to attach to the resource record
     */
    public void setResourceValueList(List valueList) {

        checkFrozen();
        if (valueList != null) {
            m_resourceValueList = new ArrayList(valueList);
            m_resourceValueList = Collections.unmodifiableList(m_resourceValueList);
            m_resourceValue = createValueFromList(m_resourceValueList);
        } else {
            m_resourceValueList = null;
            m_resourceValue = null;
        }
    }

    /**
     * Sets the value of this property attached to the structure record.<p>
     * 
     * @param structureValue the value of this property attached to the structure record
     */
    public void setStructureValue(String structureValue) {

        checkFrozen();
        m_structureValue = structureValue;
        m_structureValueList = null;
    }

    /**
     * Sets the value of this property attached to the structure record form the given list of Strings.<p>
     * 
     * The value will be created form the individual values of the given list, which are appended
     * using the <code>|</code> char as delimiter.<p>
     * 
     * @param valueList the list of value (Strings) to attach to the structure record
     */
    public void setStructureValueList(List valueList) {

        checkFrozen();
        if (valueList != null) {
            m_structureValueList = new ArrayList(valueList);
            m_structureValueList = Collections.unmodifiableList(m_structureValueList);
            m_structureValue = createValueFromList(m_structureValueList);
        } else {
            m_structureValueList = null;
            m_structureValue = null;
        }
    }

    /**
     * Sets the value of this property as either shared or 
     * individual value.<p>
     * 
     * If the given type equals {@link CmsProperty#TYPE_SHARED} then
     * the value is set as a shared (resource) value, otherwise it
     * is set as individual (structure) value.<p>
     * 
     * @param value the value to set
     * @param type the value type to set
     */
    public void setValue(String value, String type) {

        checkFrozen();
        setAutoCreatePropertyDefinition(true);
        if (TYPE_SHARED.equalsIgnoreCase(type)) {
            // set the provided value as shared (resource) value
            setResourceValue(value);
        } else {
            // set the provided value as individual (structure) value
            setStructureValue(value);
        }
    }

    /**
     * Returns a string representation of this property object.<p>
     * 
     * @see java.lang.Object#toString()
     */
    public String toString() {

        StringBuffer strBuf = new StringBuffer();

        strBuf.append("[").append(getClass().getName()).append(": ");
        strBuf.append("name: '").append(m_name).append("'");
        strBuf.append(", value: '").append(getValue()).append("'");
        strBuf.append(", structure value: '").append(m_structureValue).append("'");
        strBuf.append(", resource value: '").append(m_resourceValue).append("'");
        strBuf.append(", frozen: ").append(m_frozen);
        strBuf.append("]");

        return strBuf.toString();
    }

    /**
     * Checks if this property is frozen, that is read only.<p> 
     */
    private void checkFrozen() {

        if (m_frozen) {
            throw new CmsRuntimeException(Messages.get().container(Messages.ERR_PROPERTY_FROZEN_1, toString()));
        }
    }

    /**
     * Returns the list value representation for the given String.<p>
     * 
     * The given value is split along the <code>|</code> char.<p>
     * 
     * @param value the value list to create the list representation for
     * 
     * @return the list value representation for the given String
     */
    private List createListFromValue(String value) {

        if (value == null) {
            return null;
        }
        return CmsStringUtil.splitAsList(value, VALUE_LIST_DELIMITER);
    }

    /**
     * Returns the single String value representation for the given value list.<p>
     * 
     * @param valueList the value list to create the single String value for
     * 
     * @return the single String value representation for the given value list
     */
    private String createValueFromList(List valueList) {

        if (valueList == null) {
            return null;
        }
        StringBuffer result = new StringBuffer(valueList.size() * 32);
        Iterator i = valueList.iterator();
        while (i.hasNext()) {
            result.append(i.next().toString());
            if (i.hasNext()) {
                result.append(VALUE_LIST_DELIMITER);
            }
        }
        return result.toString();
    }
}

⌨️ 快捷键说明

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