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.file;
029
030import org.opencms.gwt.shared.CmsGwtConstants;
031import org.opencms.main.CmsIllegalArgumentException;
032import org.opencms.util.A_CmsModeIntEnumeration;
033import org.opencms.util.CmsStringUtil;
034import org.opencms.util.CmsUUID;
035
036/**
037 * Defines a property name, so that <code>{@link CmsProperty}</code> instances can be created with that name.<p>
038 *
039 * @since 6.0.0
040 */
041public class CmsPropertyDefinition implements Cloneable, Comparable<CmsPropertyDefinition> {
042
043    /**
044     *  Enumeration class for property types.<p>
045     */
046    public static final class CmsPropertyType extends A_CmsModeIntEnumeration {
047
048        /** Property value is treated as a link or list of links. */
049        protected static final CmsPropertyType LINK = new CmsPropertyType(1);
050
051        /** Property value is not a link. */
052        protected static final CmsPropertyType NORMAL = new CmsPropertyType(0);
053
054        /** serializable version id. */
055        private static final long serialVersionUID = 74746076708908673L;
056
057        /**
058         * Creates a new property type with the given identifier.<p>
059         *
060         * @param type the mode id to use
061         */
062        private CmsPropertyType(int type) {
063
064            super(type);
065        }
066
067        /**
068         * Returns the property definition type for the given type id. <p>
069         *
070         * If the given String matches no known type <code>{@link #NORMAL}</code>
071         * will be returned as the default.<p>
072         *
073         * @param type the type value to get the property type for
074         *
075         * @return the property type for the given type value
076         */
077        public static CmsPropertyType valueOf(int type) {
078
079            switch (type) {
080                case 1:
081                    return LINK;
082                case 0:
083                default:
084                    return NORMAL;
085            }
086
087        }
088    }
089
090    /** The name constraints when generating new properties. */
091    public static final String NAME_CONSTRAINTS = "-._~$";
092
093    /** Property for the active method in the administration view. */
094    public static final String PROPERTY_ACTIV = "activemethod";
095
096    /** Property for the allowed set of locales. */
097    public static final String PROPERTY_AVAILABLE_LOCALES = "locale-available";
098
099    /** Property to control the Java class for body. */
100    public static final String PROPERTY_BODY_CLASS = "templateclass";
101
102    /** The name of the VFS property that controls the caching. */
103    public static final String PROPERTY_CACHE = "cache";
104
105    /** The property to read an additional category folder from.  */
106    public static final String PROPERTY_CATEGORY_REPOSITORY = "category.repository";
107
108    /** Property to define the function detail container for a template. */
109    public static final String PROPERTY_CONTAINER_INFO = "container.info";
110
111    /** Property for the content conversion. */
112    public static final String PROPERTY_CONTENT_CONVERSION = "content-conversion";
113
114    /** Property for the content encoding. */
115    public static final String PROPERTY_CONTENT_ENCODING = "content-encoding";
116
117    /** Property for the content encoding. */
118    public static final String PROPERTY_COPYRIGHT = "Copyright";
119
120    /** Property for the default file in folders. */
121    public static final String PROPERTY_DEFAULT_FILE = "default-file";
122
123    /** Property for the days a resource has to be expired to be deleted by the <code>{@link  org.opencms.scheduler.jobs.CmsDeleteExpiredResourcesJob}</code>. */
124    public static final String PROPERTY_DELETE_EXPIRED = "delete.expired";
125
126    /** Property for the description. */
127    public static final String PROPERTY_DESCRIPTION = "Description";
128
129    /** Property for the description in HTML format. */
130    public static final String PROPERTY_DESCRIPTION_HTML = "Description.html";
131
132    /** Property to set the display order of a content in lists. */
133    public static final String PROPERTY_DISPLAY_ORDER = "display-order";
134
135    /** The name of the property which controls whether an element will be used as a copy model by the container page editor. */
136    public static final String PROPERTY_ELEMENT_MODEL = "element.model";
137
138    /** May contain a path to an element replacement configuration, for use in the 'copy page' dialog. */
139    public static final String PROPERTY_ELEMENT_REPLACEMENTS = "element.replacements";
140
141    /** Property for the resource title. */
142    public static final String PROPERTY_ENABLE_NOTIFICATION = "enable-notification";
143
144    /** Property for the static export. */
145    public static final String PROPERTY_EXPORT = "export";
146
147    /** Property used to record the resource type for resources whose type is unknown at import time, so they can be exported with that type later. */
148    public static final String PROPERTY_EXPORT_TYPE = "export.type";
149
150    /** Property for the resource export name, during export this name is used instead of the resource name. */
151    public static final String PROPERTY_EXPORTNAME = "exportname";
152
153    /** Property for JSP additional suffix during static export, default is "html". */
154    public static final String PROPERTY_EXPORTSUFFIX = "exportsuffix";
155
156    /** Property to control the folders where template or default bodies should be available. */
157    public static final String PROPERTY_FOLDERS_AVAILABLE = "folders.available";
158
159    /** Property stating where to create new gallery folders. */
160    public static final String PROPERTY_GALLERIES_FOLDER = "galleries.folder";
161
162    /** Property containing the maps API key. */
163    public static final String PROPERTY_GOOGLE_API_KEY = "google.apikey";
164
165    /** Property containing the maps API key. */
166    public static final String PROPERTY_GOOGLE_API_KEY_WORKPLACE = "google.apikey.workplace";
167
168    /** Property to control whether historic versions should be removed when deleted resources are published. */
169    public static final String PROPERTY_HISTORY_REMOVE_DELETED = "history.removedeleted";
170
171    /** Name of the property in which the focal point is stored. */
172    public static final String PROPERTY_IMAGE_FOCAL_POINT = CmsGwtConstants.PROPERTY_IMAGE_FOCALPOINT;
173
174    /** Property constant for <code>"image.size"</code>. */
175    public static final String PROPERTY_IMAGE_SIZE = "image.size";
176
177    /** The property for defining the date (as Solr field) that should be used for sorting in lists. */
178    public static final String PROPERTY_INSTANCEDATE_COPYFIELD = "instancedate.copyfield";
179
180    /** Property for the keywords. */
181    public static final String PROPERTY_KEYWORDS = "Keywords";
182
183    /** Property to enable __forceAbsoluteLinks request parameter for a resource. */
184    public static final String PROPERTY_LINKS_FORCEABSOLUTE_ENABLED = "links.forceabsolute.enabled";
185
186    /** Property for the current locale. */
187    public static final String PROPERTY_LOCALE = "locale";
188
189    /** Property to mark detail pages to have locale independent detail only containers. */
190    public static final String PROPERTY_LOCALE_INDEPENDENT_DETAILS = "locale.independent-details";
191
192    /** Property for the 'do not translate' marking in the sitemap editor. */
193    public static final String PROPERTY_LOCALE_NOTRANSLATION = "locale.notranslation";
194
195    /** Property for the login form. */
196    public static final String PROPERTY_LOGIN_FORM = "login-form";
197
198    /** Property constant for <code>"NavImage"</code>. */
199    public static final String PROPERTY_NAVIMAGE = "NavImage";
200
201    /** Property constant for <code>"NavInfo"</code>. */
202    public static final String PROPERTY_NAVINFO = "NavInfo";
203
204    /** Property for the navigation position. */
205    public static final String PROPERTY_NAVPOS = "NavPos";
206
207    /** Property for the navigation text. */
208    public static final String PROPERTY_NAVTEXT = "NavText";
209
210    /** Property for the resource title. */
211    public static final String PROPERTY_NOTIFICATION_INTERVAL = "notification-interval";
212
213    /** Property for the relative root link substitution. */
214    public static final String PROPERTY_RELATIVEROOT = "relativeroot";
215
216    /** Property name that defines the available resource types for the "new" dialog. */
217    public static final String PROPERTY_RESTYPES_AVAILABLE = "restypes.available";
218
219    /** Property to sort search results in categories. */
220    public static final String PROPERTY_SEARCH_CATEGORY = "category";
221
222    /** Property to exclude individual resources from search index generation. */
223    public static final String PROPERTY_SEARCH_EXCLUDE = "search.exclude";
224
225    /** Property to boost certain search results. */
226    public static final String PROPERTY_SEARCH_PRIORITY = "search.priority";
227
228    /** Property for secondary locales for use in the locale compare view in the sitemap editor. */
229    public static final String PROPERTY_SECONDARY_LOCALES = "locale.secondary";
230
231    /** Property for the secure transmission of resources. */
232    public static final String PROPERTY_SECURE = "secure";
233
234    /** Property for the stylesheet of files. */
235    public static final String PROPERTY_STYLESHEET = "stylesheet";
236
237    /** Property to control the template. */
238    public static final String PROPERTY_TEMPLATE = "template";
239
240    /** Property to customize for which templates elements should be displayed in the gallery when using the CmsTransformerTemplateProvider. */
241    public static final String PROPERTY_TEMPLATE_COMPATILIBITY = "template.compatibility";
242
243    /** Property for specifying a list of container types used to match formatters in the display formatter selection widget. */
244    public static final String PROPERTY_TEMPLATE_DISPLAY_TYPES = "template.display.types";
245
246    /** Property to control the template elements. */
247    public static final String PROPERTY_TEMPLATE_ELEMENTS = "template-elements";
248
249    /** Property for the template image. */
250    public static final String PROPERTY_TEMPLATE_IMAGE = "template.image";
251
252    /** 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.  */
253    public static final String PROPERTY_TEMPLATE_PROVIDER = "template.provider";
254
255    /** Property for the resource title. */
256    public static final String PROPERTY_TITLE = "Title";
257
258    /** Property for user data request configuration. */
259    public static final String PROPERTY_UDR_CONFIG = "udr.config";
260
261    /** Property used to configure default organizational unit. */
262    public static final String PROPERTY_UDR_DEFAULTOU = "udr.defaultou";
263
264    /** Name of the property used to control whether mapped URL names should replace previous URL names. */
265    public static final String PROPERTY_URLNAME_REPLACE = "urlname.replace";
266
267    /** Property for the visible method in the administration view. */
268    public static final String PROPERTY_VISIBLE = "visiblemethod";
269
270    /** Property for the XML sitemap change frequency. */
271    public static final String PROPERTY_XMLSITEMAP_CHANGEFREQ = "xmlsitemap.changefreq";
272
273    /** Property for the XML sitemap priority. */
274    public static final String PROPERTY_XMLSITEMAP_PRIORITY = "xmlsitemap.priority";
275
276    /** The property definition type for resources. */
277    public static final int PROPERYDEFINITION_RESOURCE = 1;
278
279    /** Property value is treated as a link or list of links. */
280    public static final CmsPropertyType TYPE_LINK = CmsPropertyType.LINK;
281
282    /** Property value is not a link. */
283    public static final CmsPropertyType TYPE_NORMAL = CmsPropertyType.NORMAL;
284
285    /** The null property definition object. */
286    private static final CmsPropertyDefinition NULL_PROPERTY_DEFINITION = new CmsPropertyDefinition(
287        CmsUUID.getNullUUID(),
288        "",
289        TYPE_NORMAL);
290
291    /** The id of this property definition. */
292    private CmsUUID m_id;
293
294    /** The name of this property definition. */
295    private String m_name;
296
297    /** The type of this property definition.*/
298    private CmsPropertyType m_type;
299
300    /**
301     * Creates a new property definition object with the type
302     * <code>{@link #TYPE_NORMAL}</code>.<p>
303     *
304     * @param id the id of the property definition
305     * @param name the name of the property definition
306     */
307    public CmsPropertyDefinition(CmsUUID id, String name) {
308
309        this(id, name, TYPE_NORMAL);
310    }
311
312    /**
313     * Creates a new property definition object.<p>
314     *
315     * @param id the id of the property definition
316     * @param name the name of the property definition
317     * @param propertyType the type of the property
318     */
319    public CmsPropertyDefinition(CmsUUID id, String name, CmsPropertyType propertyType) {
320
321        m_id = id;
322        m_name = name;
323        m_type = propertyType;
324    }
325
326    /**
327     * Checks if the provided property name is a valid property name,
328     * that is contains only valid characters.<p>
329     *
330     * A property name can only be composed of digits,
331     * standard ASCII letters and the symbols defined in {@link #NAME_CONSTRAINTS}.<p>
332     *
333     * @param name the property name to check
334     *
335     * @throws CmsIllegalArgumentException if the given property name is not valid
336     */
337    public static void checkPropertyName(String name) throws CmsIllegalArgumentException {
338
339        if (CmsStringUtil.isEmptyOrWhitespaceOnly(name)) {
340            throw new CmsIllegalArgumentException(
341                Messages.get().container(Messages.ERR_BAD_PROPERTYNAME_EMPTY_0, name));
342        }
343
344        CmsStringUtil.checkName(name, NAME_CONSTRAINTS, Messages.ERR_BAD_PROPERTYNAME_4, Messages.get());
345    }
346
347    /**
348     * Returns the null property definition.<p>
349     *
350     * @return the null property definition
351     */
352    public static CmsPropertyDefinition getNullPropertyDefinition() {
353
354        return CmsPropertyDefinition.NULL_PROPERTY_DEFINITION;
355    }
356
357    /**
358     * Returns a clone of this Objects instance.<p>
359     *
360     * @return a clone of this instance
361     */
362    @Override
363    public Object clone() {
364
365        return new CmsPropertyDefinition(m_id, m_name, m_type);
366    }
367
368    /**
369     * @see java.lang.Comparable#compareTo(java.lang.Object)
370     */
371    public int compareTo(CmsPropertyDefinition obj) {
372
373        if (obj == this) {
374            return 0;
375        }
376        return m_name.compareTo(obj.m_name);
377    }
378
379    /**
380     * @see java.lang.Object#equals(java.lang.Object)
381     */
382    @Override
383    public boolean equals(Object obj) {
384
385        if (obj == this) {
386            return true;
387        }
388        if (obj instanceof CmsPropertyDefinition) {
389            return ((CmsPropertyDefinition)obj).m_id.equals(m_id);
390        }
391        return false;
392    }
393
394    /**
395     * Returns the id of this property definition.<p>
396     *
397     * @return id the id of this Propertydefinition
398     */
399    public CmsUUID getId() {
400
401        return m_id;
402    }
403
404    /**
405     * Returns the name of this property definition.<p>
406     *
407     * @return name The name of this property definition
408     */
409    public String getName() {
410
411        return m_name;
412    }
413
414    /**
415     * Returns the the type of this property definition.<p>
416     *
417     * @return the type of this property definition
418     */
419    public CmsPropertyType getType() {
420
421        return m_type;
422    }
423
424    /**
425     * @see java.lang.Object#hashCode()
426     */
427    @Override
428    public int hashCode() {
429
430        if (m_name != null) {
431            return m_name.hashCode();
432        }
433        return 0;
434    }
435
436    /**
437     * Sets the type for this property definition.<p>
438     *
439     * @param type the type to set
440     */
441    public void setType(CmsPropertyType type) {
442
443        m_type = type;
444    }
445
446    /**
447     * @see java.lang.Object#toString()
448     */
449    @Override
450    public String toString() {
451
452        StringBuffer result = new StringBuffer();
453        result.append("[Propertydefinition]");
454        result.append(" name:");
455        result.append(m_name);
456        result.append(" id:");
457        result.append(m_id);
458        result.append(" type:");
459        result.append(m_type);
460        return result.toString();
461    }
462}