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

📄 cmsproperty.java

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

        return list;
    }

    /**
     * Transforms a map with compound (String) values keyed by property names into a list of 
     * CmsProperty objects with structure values.<p>
     * 
     * This method is to prevent issues with backward incompatibilities in older code.
     * Use this method with caution, it might be removed without with being deprecated
     * before.<p>
     * 
     * @param map a map with compound (String) values keyed by property names
     * @return a list of CmsProperty objects
     */
    public static List toList(Map map) {

        String name = null;
        String value = null;
        CmsProperty property = null;
        List properties = null;
        Object[] names = null;

        if ((map == null) || (map.size() == 0)) {
            return Collections.EMPTY_LIST;
        }

        properties = new ArrayList(map.size());
        names = map.keySet().toArray();
        for (int i = 0; i < names.length; i++) {
            name = (String)names[i];
            value = (String)map.get(name);

            property = new CmsProperty();
            property.m_name = name;
            property.m_structureValue = value;
            properties.add(property);
        }

        return properties;
    }

    /**
     * Transforms a list of CmsProperty objects with structure and resource values into a map with
     * compound (String) values keyed by property names.<p>
     *
     * This method is to prevent issues with backward incompatibilities in older code.
     * Use this method with caution, it might be removed without with being deprecated
     * before.<p>
     * 
     * @param list a list of CmsProperty objects
     * @return a map with compound (String) values keyed by property names
     */
    public static Map toMap(List list) {

        Map result = null;
        String name = null;
        String value = null;
        CmsProperty property = null;

        if ((list == null) || (list.size() == 0)) {
            return Collections.EMPTY_MAP;
        }

        result = new HashMap();

        // choose the fastest method to traverse the list
        if (list instanceof RandomAccess) {
            for (int i = 0, n = list.size(); i < n; i++) {
                property = (CmsProperty)list.get(i);
                name = property.m_name;
                value = property.getValue();
                result.put(name, value);
            }
        } else {
            Iterator i = list.iterator();
            while (i.hasNext()) {
                property = (CmsProperty)i.next();
                name = property.m_name;
                value = property.getValue();
                result.put(name, value);
            }
        }

        return result;
    }

    /**
     * Checks if the property definition for this property will be 
     * created implicitly on any write operation if doesn't already exist.<p>
     * 
     * @return <code>true</code>, if the property definition for this property will be created implicitly on any write operation
     */
    public boolean autoCreatePropertyDefinition() {

        return m_autoCreatePropertyDefinition;
    }

    /**
     * Creates a clone of this property.<p>
     *  
     * @return a clone of this property
     * 
     * @see #cloneAsProperty()
     */
    public Object clone() {

        return cloneAsProperty();
    }

    /**
     * Creates a clone of this property that already is of type <code>{@link CmsProperty}</code>.<p>
     * 
     * The cloned property will not be frozen.<p>
     * 
     * @return a clone of this property that already is of type <code>{@link CmsProperty}</code>
     */
    public CmsProperty cloneAsProperty() {

        if (this == NULL_PROPERTY) {
            // null property must never be cloned
            return NULL_PROPERTY;
        }

        CmsProperty clone = new CmsProperty();

        clone.m_name = m_name;
        clone.m_structureValue = m_structureValue;
        clone.m_structureValueList = m_structureValueList;
        clone.m_resourceValue = m_resourceValue;
        clone.m_resourceValueList = m_resourceValueList;
        clone.m_autoCreatePropertyDefinition = m_autoCreatePropertyDefinition;
        // the value for m_frozen does not need to be set as it is false by default

        return clone;
    }

    /**
     * Compares this property to another Object.<p>
     * 
     * @param obj the other object to be compared
     * @return if the argument is a property object, returns zero if the name of the argument is equal to the name of this property object, 
     *      a value less than zero if the name of this property is lexicographically less than the name of the argument, 
     *      or a value greater than zero if the name of this property is lexicographically greater than the name of the argument 
     */
    public int compareTo(Object obj) {

        if (obj == this) {
            return 0;
        }
        if (obj instanceof CmsProperty) {
            return m_name.compareTo(((CmsProperty)obj).m_name);
        }
        return 0;
    }

    /**
     * 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
     * 
     * @deprecated use <code>{@link #isDeleteResourceValue()}</code> instead
     */
    public boolean deleteResourceValue() {

        return isDeleteResourceValue();
    }

    /**
     * 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
     * 
     * @deprecated use <code>{@link #isDeleteStructureValue()}</code> instead
     */
    public boolean deleteStructureValue() {

        return isDeleteStructureValue();
    }

    /**
     * Tests if a specified object is equal to this CmsProperty object.<p>
     * 
     * Two property objecs are equal if their names are equal.<p>
     * 
     * @param obj another object
     * @return true, if the specified object is equal to this CmsProperty object
     */
    public boolean equals(Object obj) {

        if (obj == this) {
            return true;
        }
        if (obj instanceof CmsProperty) {
            return ((CmsProperty)obj).m_name.equals(m_name);
        }
        return false;
    }

    /**
     * Returns the name of this property.<p>
     * 
     * @return name of this property
     * 
     * @deprecated use {@link #getName()} instead
     */
    public String getKey() {

        return getName();
    }

    /**
     * Returns the name of this property.<p>
     * 
     * @return the name of this property
     */
    public String getName() {

        return m_name;
    }

    /**
     * Returns the value of this property attached to the resource record.<p>
     * 
     * @return the value of this property attached to the resource record
     */
    public String getResourceValue() {

        return m_resourceValue;
    }

    /**
     * Returns the value of this property attached to the resource record, split as a list.<p>
     * 
     * This list is build form the resource value, which is split into separate values
     * using the <code>|</code> char as delimiter. If the delimiter is not found,
     * then the list will contain one entry which is equal to <code>{@link #getResourceValue()}</code>.<p>
     * 
     * @return the value of this property attached to the resource record, split as a (unmodifiable) list of Strings
     */
    public List getResourceValueList() {

        if ((m_resourceValueList == null) && (m_resourceValue != null)) {
            // use lazy initializing of the list
            m_resourceValueList = createListFromValue(m_resourceValue);
            m_resourceValueList = Collections.unmodifiableList(m_resourceValueList);
        }
        return m_resourceValueList;
    }

    /**
     * Returns the value of this property attached to the structure record.<p>
     * 
     * @return the value of this property attached to the structure record
     */
    public String getStructureValue() {

        return m_structureValue;
    }

    /**
     * Returns the value of this property attached to the structure record, split as a list.<p>
     * 
     * This list is build form the structure value, which is split into separate values
     * using the <code>|</code> char as delimiter. If the delimiter is not found,
     * then the list will contain one entry which is equal to <code>{@link #getStructureValue()}</code>.<p>
     * 
     * @return the value of this property attached to the structure record, split as a (unmodifiable) list of Strings
     */
    public List getStructureValueList() {

        if ((m_structureValueList == null) && (m_structureValue != null)) {
            // use lazy initializing of the list
            m_structureValueList = createListFromValue(m_structureValue);
            m_structureValueList = Collections.unmodifiableList(m_structureValueList);
        }
        return m_structureValueList;
    }

    /**
     * Returns the compound value of this property.<p>
     * 
     * The value returned is the value of {@link #getStructureValue()}, if it is not <code>null</code>.
     * Otherwise the value if {@link #getResourceValue()} is returned (which may also be <code>null</code>).<p>
     * 
     * @return the compound value of this property
     */
    public String getValue() {

        return (m_structureValue != null) ? m_structureValue : m_resourceValue;
    }

    /**
     * Returns the compound value of this property, or a specified default value,
     * 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 which is returned if both the structure and resource values are <code>null</code>
     * 
     * @return the compound value of this property, or the default value
     */
    public String getValue(String 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) ? m_structureValue : ((m_resourceValue != null) ? m_resourceValue
        : defaultValue);
    }

    /**
     * Returns the compound value of this property, split as a list.<p>
     * 
     * This list is build form the used value, which is split into separate values
     * using the <code>|</code> char as delimiter. If the delimiter is not found,
     * then the list will contain one entry.<p>
     * 
     * The value returned is the value of {@link #getStructureValueList()}, if it is not <code>null</code>.
     * Otherwise the value if {@link #getResourceValueList()} is returned (which may also be <code>null</code>).<p>
     * 
     * @return the compound value of this property, split as a (unmodifiable) list of Strings
     */
    public List getValueList() {

        return (m_structureValue != null) ? getStructureValueList() : getResourceValueList();

⌨️ 快捷键说明

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