001/*
002 * This library is part of OpenCms -
003 * the Open Source Content Management System
004 *
005 * Copyright (C)  Alkacon Software (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, 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.ade.configuration;
029
030import org.opencms.xml.content.CmsXmlContentProperty;
031
032import org.apache.commons.lang.builder.ReflectionToStringBuilder;
033
034/**
035 * This class represents the property configuration for a sitemap region.<p>
036 *
037 * (This is mostly a wrapper around CmsXmlContentProperty. We don't use that class directly because
038 *  we may want to put server-specific logic in here, and CmsXmlContentProperty is used as a bean for
039 *  RPC data transfer to the client.)
040 *
041 * @author Georg Westenberger
042 *
043 * @version $Revision: 1.0 $
044 *
045 * @since 8.0.1
046 */
047public class CmsPropertyConfig implements I_CmsConfigurationObject<CmsPropertyConfig>, Cloneable {
048
049    /** True if this property is disabled. */
050    private boolean m_disabled;
051
052    /** The order. **/
053    private int m_order;
054
055    /** The internal property data. */
056    private CmsXmlContentProperty m_propData;
057
058    /** Is top property (should be displayed near the top of a property list). */
059    private boolean m_top;
060
061    /**
062     * Creates a new propery configuration bean.<p>
063     *
064     * @param propData the property data
065     * @param disabled true if this property is disabled
066     */
067    public CmsPropertyConfig(CmsXmlContentProperty propData, boolean disabled) {
068
069        this(propData, disabled, I_CmsConfigurationObject.DEFAULT_ORDER);
070    }
071
072    /**
073     * Creates a new property configuration bean.<p>
074     *
075     * @param propData the property data
076     * @param disabled true if this property is disabled
077     * @param order the number used for sorting the property configurations
078     */
079    public CmsPropertyConfig(CmsXmlContentProperty propData, boolean disabled, int order) {
080
081        m_propData = propData;
082        m_disabled = disabled;
083        m_order = order;
084    }
085
086    /**
087     * @see java.lang.Object#clone()
088     */
089    @Override
090    public CmsPropertyConfig clone() {
091
092        try {
093            return (CmsPropertyConfig)(super.clone());
094        } catch (CloneNotSupportedException e) {
095            return null;
096        }
097    }
098
099    /**
100     * Creates a clone and sets the 'top' property in the clone.
101     *
102     * @param top the value for the top property in the clone
103     *
104     * @return the clone
105     */
106    public CmsPropertyConfig cloneWithTop(boolean top) {
107
108        CmsPropertyConfig result = (this.clone());
109        result.m_top = top;
110        return result;
111    }
112
113    /**
114     * @see org.opencms.ade.configuration.I_CmsConfigurationObject#getKey()
115     */
116    public String getKey() {
117
118        return getName();
119    }
120
121    /**
122     * Gets the name of the property.<p>
123     *
124     * @return the name of the property
125     */
126    public String getName() {
127
128        return m_propData.getName();
129    }
130
131    /**
132     * Gets the order.<p>
133     *
134     * @return the order
135     */
136    public int getOrder() {
137
138        return m_order;
139    }
140
141    /**
142     * Returns the property configuration data.<p>
143     *
144     * @return the property configuration data
145     */
146    public CmsXmlContentProperty getPropertyData() {
147
148        return m_propData;
149    }
150
151    /**
152     * Returns true if the entry disables a property, rather than adding it.<p>
153     *
154     * @return true if the property should be disabled
155     */
156    public boolean isDisabled() {
157
158        return m_disabled;
159    }
160
161    /**
162     * Returns true if this is a 'top property' which should be displayed near the top of a property list.
163     *
164     * @return true if this is a top property
165     */
166    public boolean isTop() {
167
168        return m_top;
169    }
170
171    /**
172     * @see org.opencms.ade.configuration.I_CmsConfigurationObject#merge(org.opencms.ade.configuration.I_CmsConfigurationObject)
173     */
174    public CmsPropertyConfig merge(CmsPropertyConfig child) {
175
176        return child.cloneWithTop(m_top);
177    }
178
179    /**
180     * @see java.lang.Object#toString()
181     */
182    @Override
183    public String toString() {
184
185        return ReflectionToStringBuilder.toString(this);
186    }
187}