cmsproperty.java

来自「找了很久才找到到源代码」· Java 代码 · 共 1,248 行 · 第 1/4 页

JAVA
1,248
字号
            }
        }

        return list;
    }

    /**
     * Calls <code>{@link #setFrozen(boolean)}</code> for each
     * {@link CmsProperty} object in the given List if it is not already frozen.<p>
     * 
     * This method will modify the objects in the input list directly.<p>
     * 
     * @param list a list of {@link CmsProperty} objects
     * 
     * @return the modified list of properties
     * 
     * @see #setFrozen(boolean)
     */
    public static final List setFrozen(List list) {

        CmsProperty property;

        // 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);
                if (!property.isFrozen()) {
                    property.setFrozen(true);
                }
            }
        } else {
            Iterator i = list.iterator();
            while (i.hasNext()) {
                property = (CmsProperty)i.next();
                if (!property.isFrozen()) {
                    property.setFrozen(true);
                }
            }
        }

        return list;
    }

    /**
     * Transforms a Map of String values into a list of 
     * {@link CmsProperty} objects with the property name set from the
     * Map key, and the structure value set from the Map value.<p>
     * 
     * @param map a Map with String keys and String values
     * 
     * @return a list of {@link CmsProperty} objects
     */
    public static List toList(Map map) {

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

        List result = new ArrayList(map.size());
        Iterator i = map.entrySet().iterator();
        while (i.hasNext()) {
            Map.Entry e = (Map.Entry)i.next();
            String name = String.valueOf(e.getKey());
            String value = String.valueOf(e.getValue());

            CmsProperty property = new CmsProperty(name, value, null);
            result.add(property);
        }

        return result;
    }

    /**
     * Transforms a list of {@link CmsProperty} objects into a Map which uses the property name as
     * Map key (String), and the property value as Map value (String).<p>
     * 
     * @param list a list of {@link CmsProperty} objects
     * 
     * @return a Map which uses the property names as
     *      Map keys (String), and the property values as Map values (String)
     */
    public static Map toMap(List list) {

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

        String name = null;
        String value = null;
        CmsProperty property = null;
        Map result = new HashMap(list.size());

        // 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 objects are equal if their names are equal.<p>
     * 
     * In case you want to compare the values as well as the name, 
     * use {@link #isIdentical(CmsProperty)} instead.<p>
     * 
     * @param obj another object
     * @return true, if the specified object is equal to this CmsProperty object
     * 
     * @see #isIdentical(CmsProperty)
     */
    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 resource record as a map.<p>
     * 
     * This map is build from the used value, which is split into separate key/value pairs
     * using the <code>|</code> char as delimiter. If the delimiter is not found,
     * then the map will contain one entry.<p>
     * 
     * The key/value pairs are separated with the <code>=</code>.<p>
     * 
     * @return the value of this property attached to the resource record, as an (unmodifiable) map of Strings
     */
    public Map getResourceValueMap() {

        if ((m_resourceValueMap == null) && (m_resourceValue != null)) {
            // use lazy initializing of the map
            m_resourceValueMap = createMapFromValue(m_resourceValue);
            m_resourceValueMap = Collections.unmodifiableMap(m_resourceValueMap);
        }
        return m_resourceValueMap;
    }

    /**
     * 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;

⌨️ 快捷键说明

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