001/*
002 * This library is part of OpenCms -
003 * the Open Source Content Management System
004 *
005 * Copyright (c) Alkacon Software GmbH (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, 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.file;
029
030import org.opencms.main.CmsIllegalArgumentException;
031import org.opencms.util.A_CmsModeIntEnumeration;
032import org.opencms.util.CmsStringUtil;
033import org.opencms.util.CmsUUID;
034
035/**
036 * Defines a property name, so that <code>{@link CmsProperty}</code> instances can be created with that name.<p>
037 * 
038 * @since 6.0.0 
039 */
040public class CmsPropertyDefinition implements Cloneable, Comparable<CmsPropertyDefinition> {
041
042    /**
043     *  Enumeration class for property types.<p>
044     */
045    public static final class CmsPropertyType extends A_CmsModeIntEnumeration {
046
047        /** Property value is treated as a link or list of links. */
048        protected static final CmsPropertyType LINK = new CmsPropertyType(1);
049
050        /** Property value is not a link. */
051        protected static final CmsPropertyType NORMAL = new CmsPropertyType(0);
052
053        /** serializable version id. */
054        private static final long serialVersionUID = 74746076708908673L;
055
056        /**
057         * Creates a new property type with the given identifier.<p>
058         * 
059         * @param type the mode id to use
060         */
061        private CmsPropertyType(int type) {
062
063            super(type);
064        }
065
066        /**
067         * Returns the property definition type for the given type id. <p>
068         * 
069         * If the given String matches no known type <code>{@link #NORMAL}</code> 
070         * will be returned as the default.<p>
071         * 
072         * @param type the type value to get the property type for
073         * 
074         * @return the property type for the given type value
075         */
076        public static CmsPropertyType valueOf(int type) {
077
078            switch (type) {
079                case 1:
080                    return LINK;
081                case 0:
082                default:
083                    return NORMAL;
084            }
085
086        }
087    }
088
089    /** The name constraints when generating new properties. */
090    public static final String NAME_CONSTRAINTS = "-._~$";
091
092    /** Property for the active method in the administration view. */
093    public static final String PROPERTY_ACTIV = "activemethod";
094
095    /** Property for the allowed set of locales. */
096    public static final String PROPERTY_AVAILABLE_LOCALES = "locale-available";
097
098    /** Property to control the Java class for body. */
099    public static final String PROPERTY_BODY_CLASS = "templateclass";
100
101    /** The name of the VFS property that controls the caching. */
102    public static final String PROPERTY_CACHE = "cache";
103
104    /** Property to define the function detail container for a template. */
105    public static final String PROPERTY_CONTAINER_INFO = "container.info";
106
107    /** Property to configure the value which should be used instead of the template path when selecting the template in the GUI. Please note that this does not have to actually be a template provider configuration string, this is just the most common use case.  */
108    public static final String PROPERTY_TEMPLATE_PROVIDER = "template.provider";
109
110    /** Property for the content conversion. */
111    public static final String PROPERTY_CONTENT_CONVERSION = "content-conversion";
112
113    /** Property for the content encoding. */
114    public static final String PROPERTY_CONTENT_ENCODING = "content-encoding";
115
116    /** Property for the content encoding. */
117    public static final String PROPERTY_COPYRIGHT = "Copyright";
118
119    /** Property for the default file in folders. */
120    public static final String PROPERTY_DEFAULT_FILE = "default-file";
121
122    /** Property for the days a resource has to be expired to be deleted by the <code>{@link  org.opencms.scheduler.jobs.CmsDeleteExpiredResourcesJob}</code>. */
123    public static final String PROPERTY_DELETE_EXPIRED = "delete.expired";
124
125    /** Property for the description. */
126    public static final String PROPERTY_DESCRIPTION = "Description";
127
128    /** The name of the property which controls whether an element will be used as a copy model by the container page editor. */
129    public static final String PROPERTY_ELEMENT_MODEL = "element.model";
130
131    /** Property for the resource title. */
132    public static final String PROPERTY_ENABLE_NOTIFICATION = "enable-notification";
133
134    /** Property for the static export. */
135    public static final String PROPERTY_EXPORT = "export";
136
137    /** Property for the resource export name, during export this name is used instead of the resource name. */
138    public static final String PROPERTY_EXPORTNAME = "exportname";
139
140    /** Property for JSP additional suffix during static export, default is "html". */
141    public static final String PROPERTY_EXPORTSUFFIX = "exportsuffix";
142
143    /** Property to control the folders where template or default bodies should be available. */
144    public static final String PROPERTY_FOLDERS_AVAILABLE = "folders.available";
145
146    /** Property constant for <code>"image.size"</code>. */
147    public static final String PROPERTY_IMAGE_SIZE = "image.size";
148
149    /** Property for the keywords. */
150    public static final String PROPERTY_KEYWORDS = "Keywords";
151
152    /** Property for the current locale. */
153    public static final String PROPERTY_LOCALE = "locale";
154
155    /** Property for the login form. */
156    public static final String PROPERTY_LOGIN_FORM = "login-form";
157
158    /** Property constant for <code>"NavImage"</code>. */
159    public static final String PROPERTY_NAVIMAGE = "NavImage";
160
161    /** Property constant for <code>"NavInfo"</code>. */
162    public static final String PROPERTY_NAVINFO = "NavInfo";
163
164    /** Property for the navigation position. */
165    public static final String PROPERTY_NAVPOS = "NavPos";
166
167    /** Property for the navigation text. */
168    public static final String PROPERTY_NAVTEXT = "NavText";
169
170    /** Property for the resource title. */
171    public static final String PROPERTY_NOTIFICATION_INTERVAL = "notification-interval";
172
173    /** Property for the relative root link substitution. */
174    public static final String PROPERTY_RELATIVEROOT = "relativeroot";
175
176    /** Property name that defines the available resource types for the "new" dialog. */
177    public static final String PROPERTY_RESTYPES_AVAILABLE = "restypes.available";
178
179    /** Property to sort search results in categories. */
180    public static final String PROPERTY_SEARCH_CATEGORY = "category";
181
182    /** Property to exclude individual resources from search index generation. */
183    public static final String PROPERTY_SEARCH_EXCLUDE = "search.exclude";
184
185    /** Property to boost certain search results. */
186    public static final String PROPERTY_SEARCH_PRIORITY = "search.priority";
187
188    /** Property for the secure transmission of resources. */
189    public static final String PROPERTY_SECURE = "secure";
190
191    /** Property for the stylesheet of files. */
192    public static final String PROPERTY_STYLESHEET = "stylesheet";
193
194    /** Property to control the template. */
195    public static final String PROPERTY_TEMPLATE = "template";
196
197    /** Property to control the template elements. */
198    public static final String PROPERTY_TEMPLATE_ELEMENTS = "template-elements";
199
200    /** Property for the template image. */
201    public static final String PROPERTY_TEMPLATE_IMAGE = "template.image";
202
203    /** Property for the resource title. */
204    public static final String PROPERTY_TITLE = "Title";
205
206    /** Property for the visible method in the administration view. */
207    public static final String PROPERTY_VISIBLE = "visiblemethod";
208
209    /** Property for the XML sitemap change frequency. */
210    public static final String PROPERTY_XMLSITEMAP_CHANGEFREQ = "xmlsitemap.changefreq";
211
212    /** Property for the XML sitemap priority. */
213    public static final String PROPERTY_XMLSITEMAP_PRIORITY = "xmlsitemap.priority";
214
215    /** The property definition type for resources. */
216    public static final int PROPERYDEFINITION_RESOURCE = 1;
217
218    /** Property value is treated as a link or list of links. */
219    public static final CmsPropertyType TYPE_LINK = CmsPropertyType.LINK;
220
221    /** Property value is not a link. */
222    public static final CmsPropertyType TYPE_NORMAL = CmsPropertyType.NORMAL;
223
224    /** The null property definition object. */
225    private static final CmsPropertyDefinition NULL_PROPERTY_DEFINITION = new CmsPropertyDefinition(
226        CmsUUID.getNullUUID(),
227        "",
228        TYPE_NORMAL);
229
230    /** The id of this property definition. */
231    private CmsUUID m_id;
232
233    /** The name of this property definition. */
234    private String m_name;
235
236    /** The type of this property definition.*/
237    private CmsPropertyType m_type;
238
239    /**
240     * Creates a new property definition object with the type 
241     * <code>{@link #TYPE_NORMAL}</code>.<p>
242     * 
243     * @param id the id of the property definition
244     * @param name the name of the property definition 
245     */
246    public CmsPropertyDefinition(CmsUUID id, String name) {
247
248        this(id, name, TYPE_NORMAL);
249    }
250
251    /**
252     * Creates a new property definition object.<p>
253     * 
254     * @param id the id of the property definition
255     * @param name the name of the property definition 
256     * @param propertyType the type of the property
257     */
258    public CmsPropertyDefinition(CmsUUID id, String name, CmsPropertyType propertyType) {
259
260        m_id = id;
261        m_name = name;
262        m_type = propertyType;
263    }
264
265    /**
266     * Checks if the provided property name is a valid property name, 
267     * that is contains only valid characters.<p>
268     * 
269     * A property name can only be composed of digits, 
270     * standard ASCII letters and the symbols defined in {@link #NAME_CONSTRAINTS}.<p>
271     *
272     * @param name the property name to check
273     * 
274     * @throws CmsIllegalArgumentException if the given property name is not valid
275     */
276    public static void checkPropertyName(String name) throws CmsIllegalArgumentException {
277
278        if (CmsStringUtil.isEmptyOrWhitespaceOnly(name)) {
279            throw new CmsIllegalArgumentException(Messages.get().container(Messages.ERR_BAD_PROPERTYNAME_EMPTY_0, name));
280        }
281
282        CmsStringUtil.checkName(name, NAME_CONSTRAINTS, Messages.ERR_BAD_PROPERTYNAME_4, Messages.get());
283    }
284
285    /**
286     * Returns the null property definition.<p>
287     * 
288     * @return the null property definition
289     */
290    public static CmsPropertyDefinition getNullPropertyDefinition() {
291
292        return CmsPropertyDefinition.NULL_PROPERTY_DEFINITION;
293    }
294
295    /**
296     * Returns a clone of this Objects instance.<p>
297     * 
298     * @return a clone of this instance
299     */
300    @Override
301    public Object clone() {
302
303        return new CmsPropertyDefinition(m_id, m_name, m_type);
304    }
305
306    /**
307     * @see java.lang.Comparable#compareTo(java.lang.Object)
308     */
309    public int compareTo(CmsPropertyDefinition obj) {
310
311        if (obj == this) {
312            return 0;
313        }
314        return m_name.compareTo(obj.m_name);
315    }
316
317    /**
318     * @see java.lang.Object#equals(java.lang.Object)
319     */
320    @Override
321    public boolean equals(Object obj) {
322
323        if (obj == this) {
324            return true;
325        }
326        if (obj instanceof CmsPropertyDefinition) {
327            return ((CmsPropertyDefinition)obj).m_id.equals(m_id);
328        }
329        return false;
330    }
331
332    /**
333     * Returns the id of this property definition.<p>
334     *
335     * @return id the id of this Propertydefinition
336     */
337    public CmsUUID getId() {
338
339        return m_id;
340    }
341
342    /**
343     * Returns the name of this property definition.<p>
344     *
345     * @return name The name of this property definition
346     */
347    public String getName() {
348
349        return m_name;
350    }
351
352    /**
353     * Returns the the type of this property definition.<p> 
354     * 
355     * @return the type of this property definition
356     */
357    public CmsPropertyType getType() {
358
359        return m_type;
360    }
361
362    /**
363     * @see java.lang.Object#hashCode()
364     */
365    @Override
366    public int hashCode() {
367
368        if (m_name != null) {
369            return m_name.hashCode();
370        }
371        return 0;
372    }
373
374    /**
375     * Sets the type for this property definition.<p>
376     * 
377     * @param type the type to set
378     */
379    public void setType(CmsPropertyType type) {
380
381        m_type = type;
382    }
383
384    /**
385     * @see java.lang.Object#toString()
386     */
387    @Override
388    public String toString() {
389
390        StringBuffer result = new StringBuffer();
391        result.append("[Propertydefinition]");
392        result.append(" name:");
393        result.append(m_name);
394        result.append(" id:");
395        result.append(m_id);
396        result.append(" type:");
397        result.append(m_type);
398        return result.toString();
399    }
400}