001/*
002 * This library is part of OpenCms -
003 * the Open Source Content Management System
004 *
005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com)
006 *
007 * This library is free software; you can redistribute it and/or
008 * modify it under the terms of the GNU Lesser General Public
009 * License as published by the Free Software Foundation; either
010 * version 2.1 of the License, or (at your option) any later version.
011 *
012 * This library is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015 * Lesser General Public License for more details.
016 *
017 * For further information about Alkacon Software GmbH & Co. KG, please see the
018 * company website: http://www.alkacon.com
019 *
020 * For further information about OpenCms, please see the
021 * project website: http://www.opencms.org
022 *
023 * You should have received a copy of the GNU Lesser General Public
024 * License along with this library; if not, write to the Free Software
025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
026 */
027
028package org.opencms.workplace.comparison;
029
030import org.opencms.util.CmsStringUtil;
031
032/**
033 * Comparison of resource attributes.<p>
034 */
035public class CmsAttributeComparison {
036
037    /** The name of the property.<p> */
038    private String m_name;
039
040    /** The type of the attribute comparison.<p> */
041    private String m_status;
042
043    /** The first value of the attribute.<p> */
044    private String m_version1;
045
046    /** The second value of the attribute.<p> */
047    private String m_version2;
048
049    /**
050     * Constructs a new attribute object.<p>
051     */
052    public CmsAttributeComparison() {
053
054        // empty
055    }
056
057    /**
058     * Creates a new attribute comparison.<p>
059     *
060     * @param name the name to set
061     * @param version1 the first value of the property
062     * @param version2 the second value of the property
063     */
064    public CmsAttributeComparison(String name, String version1, String version2) {
065
066        m_name = name;
067        m_version1 = version1;
068        m_version2 = version2;
069        boolean v1Empty = CmsStringUtil.isEmptyOrWhitespaceOnly(version1);
070        boolean v2Empty = CmsStringUtil.isEmptyOrWhitespaceOnly(version2);
071        if (v1Empty && !v2Empty) {
072            m_status = CmsResourceComparison.TYPE_ADDED;
073        } else if (!v1Empty && v2Empty) {
074            m_status = CmsResourceComparison.TYPE_REMOVED;
075        } else if ((v1Empty && v2Empty) || version1.equals(version2)) {
076            m_status = CmsResourceComparison.TYPE_UNCHANGED;
077        } else {
078            m_status = CmsResourceComparison.TYPE_CHANGED;
079        }
080    }
081
082    /**
083     * Creates a new attribute comparison.<p>
084     *
085     * @param name the name to set
086     * @param version1 the first value of the property
087     * @param version2 the second value of the property
088     * @param type the type indicating if the element value has been added, removed, modified or is unchanged
089     *
090     * @see CmsResourceComparison#TYPE_ADDED
091     * @see CmsResourceComparison#TYPE_CHANGED
092     * @see CmsResourceComparison#TYPE_REMOVED
093     * @see CmsResourceComparison#TYPE_UNCHANGED
094     */
095    public CmsAttributeComparison(String name, String version1, String version2, String type) {
096
097        m_name = name;
098        m_version1 = version1;
099        m_version2 = version2;
100        m_status = type;
101    }
102
103    /**
104     * Returns the locale.<p>
105     *
106     * @return the locale
107     */
108    public String getName() {
109
110        return m_name;
111    }
112
113    /**
114     * Returns the type.<p>
115     *
116     * @return the type
117     */
118    public String getStatus() {
119
120        return m_status;
121    }
122
123    /**
124     * Returns the attribute.<p>
125     *
126     * @return the attribute
127     */
128    public String getVersion1() {
129
130        return m_version1;
131    }
132
133    /**
134     * Returns the type.<p>
135     *
136     * @return the type
137     */
138    public String getVersion2() {
139
140        return m_version2;
141    }
142
143    /**
144     * Sets the name.<p>
145     *
146     * @param name the name to set
147     */
148    public void setName(String name) {
149
150        m_name = name;
151    }
152
153    /**
154     * Sets the type.<p>
155     *
156     * @param type the type to set
157     */
158    public void setStatus(String type) {
159
160        m_status = type;
161    }
162
163    /**
164     * Sets the version1.<p>
165     *
166     * @param version1 the version1 to set
167     */
168    public void setVersion1(String version1) {
169
170        m_version1 = version1;
171    }
172
173    /**
174     * Sets the type.<p>
175     *
176     * @param type the type to set
177     */
178    public void setVersion2(String type) {
179
180        m_version2 = type;
181    }
182}