001/*
002 * This library is part of OpenCms -
003 * the Open Source Content Management System
004 *
005 * Copyright (c) Alkacon Software GmbH & Co. KG (https://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: https://www.alkacon.com
019 *
020 * For further information about OpenCms, please see the
021 * project website: https://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    /**
106     * Property for configuring background color for a category in the explorer's category column.
107     **/
108    public static final String PROPERTY_CATEGORY_BACKGROUND = "category.background";
109
110    /** Property used to hide categories from the category widgets in the page/content editor.
111     *
112     * <p>If this property is set to 'true' on a category, it should never be set to 'false' on one of its subcategory.
113     * */
114    public static final String PROPERTY_CATEGORY_HIDDEN = "category.hidden";
115
116    /** The property to read an additional category folder from.  */
117    public static final String PROPERTY_CATEGORY_REPOSITORY = "category.repository";
118
119    /** Property to define the function detail container for a template. */
120    public static final String PROPERTY_CONTAINER_INFO = "container.info";
121
122    /** Property for the content conversion. */
123    public static final String PROPERTY_CONTENT_CONVERSION = "content-conversion";
124
125    /** Property for the content encoding. */
126    public static final String PROPERTY_CONTENT_ENCODING = "content-encoding";
127
128    /** If configured on a folder, when copying contents in the folder or any of its subfolders through ADE, the copies will be placed in the same folder as the original, and given a file name according to the name pattern. */
129    public static final String PROPERTY_CONTENT_NAME_PATTERN = "content.namepattern";
130
131    /** Property for the content encoding. */
132    public static final String PROPERTY_COPYRIGHT = "Copyright";
133
134    /** Property for the default file in folders. */
135    public static final String PROPERTY_DEFAULT_FILE = "default-file";
136
137    /** Property for the days a resource has to be expired to be deleted by the <code>{@link  org.opencms.scheduler.jobs.CmsDeleteExpiredResourcesJob}</code>. */
138    public static final String PROPERTY_DELETE_EXPIRED = "delete.expired";
139
140    /** Property for the description. */
141    public static final String PROPERTY_DESCRIPTION = "Description";
142
143    /** Property for the description in HTML format. */
144    public static final String PROPERTY_DESCRIPTION_HTML = "Description.html";
145
146    /** Property to set the display order of a content in lists. */
147    public static final String PROPERTY_DISPLAY_ORDER = "display-order";
148
149    /** The name of the property which controls whether an element will be used as a copy model by the container page editor. */
150    public static final String PROPERTY_ELEMENT_MODEL = "element.model";
151
152    /** May contain a path to an element replacement configuration, for use in the 'copy page' dialog. */
153    public static final String PROPERTY_ELEMENT_REPLACEMENTS = "element.replacements";
154
155    /** Property for the resource title. */
156    public static final String PROPERTY_ENABLE_NOTIFICATION = "enable-notification";
157
158    /** Property for the static export. */
159    public static final String PROPERTY_EXPORT = "export";
160
161    /** 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. */
162    public static final String PROPERTY_EXPORT_TYPE = "export.type";
163
164    /** Property for the resource export name, during export this name is used instead of the resource name. */
165    public static final String PROPERTY_EXPORTNAME = "exportname";
166
167    /** Property for JSP additional suffix during static export, default is "html". */
168    public static final String PROPERTY_EXPORTSUFFIX = "exportsuffix";
169
170    /** Property to control the folders where template or default bodies should be available. */
171    public static final String PROPERTY_FOLDERS_AVAILABLE = "folders.available";
172
173    /** Property stating where to create new gallery folders. */
174    public static final String PROPERTY_GALLERIES_FOLDER = "galleries.folder";
175
176    /** Property containing the maps API key. */
177    public static final String PROPERTY_GOOGLE_API_KEY = "google.apikey";
178
179    /** Property containing the maps API key. */
180    public static final String PROPERTY_GOOGLE_API_KEY_WORKPLACE = "google.apikey.workplace";
181
182    /** Property to control whether historic versions should be removed when deleted resources are published. */
183    public static final String PROPERTY_HISTORY_REMOVE_DELETED = "history.removedeleted";
184
185    /** Name of the property in which the focal point is stored. */
186    public static final String PROPERTY_IMAGE_FOCAL_POINT = CmsGwtConstants.PROPERTY_IMAGE_FOCALPOINT;
187
188    /** Property constant for <code>"image.size"</code>. */
189    public static final String PROPERTY_IMAGE_SIZE = "image.size";
190
191    /** The property for defining the date (as Solr field) that should be used for sorting in lists. */
192    public static final String PROPERTY_INSTANCEDATE_COPYFIELD = "instancedate.copyfield";
193
194    /** Property for the keywords. */
195    public static final String PROPERTY_KEYWORDS = "Keywords";
196
197    /** Property to enable __forceAbsoluteLinks request parameter for a resource. */
198    public static final String PROPERTY_LINKS_FORCEABSOLUTE_ENABLED = "links.forceabsolute.enabled";
199
200    /** Property for the current locale. */
201    public static final String PROPERTY_LOCALE = "locale";
202
203    /** Property to mark detail pages to have locale independent detail only containers. */
204    public static final String PROPERTY_LOCALE_INDEPENDENT_DETAILS = "locale.independent-details";
205
206    /** Property for the 'do not translate' marking in the sitemap editor. */
207    public static final String PROPERTY_LOCALE_NOTRANSLATION = "locale.notranslation";
208
209    /** Property for the login form. */
210    public static final String PROPERTY_LOGIN_FORM = "login-form";
211
212    /** Property constant for <code>"NavImage"</code>. */
213    public static final String PROPERTY_NAVIMAGE = "NavImage";
214
215    /** Property constant for <code>"NavInfo"</code>. */
216    public static final String PROPERTY_NAVINFO = "NavInfo";
217
218    /** Property for the navigation position. */
219    public static final String PROPERTY_NAVPOS = "NavPos";
220
221    /** Property for the navigation text. */
222    public static final String PROPERTY_NAVTEXT = "NavText";
223
224    /** Property for the resource title. */
225    public static final String PROPERTY_NOTIFICATION_INTERVAL = "notification-interval";
226
227    /** Property for the relative root link substitution. */
228    public static final String PROPERTY_RELATIVEROOT = "relativeroot";
229
230    /** Property name that defines the available resource types for the "new" dialog. */
231    public static final String PROPERTY_RESTYPES_AVAILABLE = "restypes.available";
232
233    /** Property to sort search results in categories. */
234    public static final String PROPERTY_SEARCH_CATEGORY = "category";
235
236    /** Property to exclude individual resources from search index generation. */
237    public static final String PROPERTY_SEARCH_EXCLUDE = "search.exclude";
238
239    /** Property to exclude individual resources from search results online (Solr only). */
240    public static final String PROPERTY_SEARCH_EXCLUDE_ONLINE = "search.exclude.online";
241
242    /** Property to boost certain search results. */
243    public static final String PROPERTY_SEARCH_PRIORITY = "search.priority";
244
245    /** Property for secondary locales for use in the locale compare view in the sitemap editor. */
246    public static final String PROPERTY_SECONDARY_LOCALES = "locale.secondary";
247
248    /** Property for the secure transmission of resources. */
249    public static final String PROPERTY_SECURE = "secure";
250
251    /** Property for the stylesheet of files. */
252    public static final String PROPERTY_STYLESHEET = "stylesheet";
253
254    /** Property to control the template. */
255    public static final String PROPERTY_TEMPLATE = "template";
256
257    /** Property to customize for which templates elements should be displayed in the gallery when using the CmsTransformerTemplateProvider. */
258    public static final String PROPERTY_TEMPLATE_COMPATILIBITY = "template.compatibility";
259
260    /** Property for specifying a list of container types used to match formatters in the display formatter selection widget. */
261    public static final String PROPERTY_TEMPLATE_DISPLAY_TYPES = "template.display.types";
262
263    /** Property to control the template elements. */
264    public static final String PROPERTY_TEMPLATE_ELEMENTS = "template-elements";
265
266    /** Property for the template image. */
267    public static final String PROPERTY_TEMPLATE_IMAGE = "template.image";
268
269    /** 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.  */
270    public static final String PROPERTY_TEMPLATE_PROVIDER = "template.provider";
271
272    /** Property for the resource title. */
273    public static final String PROPERTY_TITLE = "Title";
274
275    /** Property for user data request configuration. */
276    public static final String PROPERTY_UDR_CONFIG = "udr.config";
277
278    /** Property used to configure default organizational unit. */
279    public static final String PROPERTY_UDR_DEFAULTOU = "udr.defaultou";
280
281    /** Name of the property used to control whether mapped URL names should replace previous URL names. */
282    public static final String PROPERTY_URLNAME_REPLACE = "urlname.replace";
283
284    /** Property for the visible method in the administration view. */
285    public static final String PROPERTY_VISIBLE = "visiblemethod";
286
287    /** Property for the XML sitemap change frequency. */
288    public static final String PROPERTY_XMLSITEMAP_CHANGEFREQ = "xmlsitemap.changefreq";
289
290    /** Property for the XML sitemap priority. */
291    public static final String PROPERTY_XMLSITEMAP_PRIORITY = "xmlsitemap.priority";
292
293    /** The property definition type for resources. */
294    public static final int PROPERYDEFINITION_RESOURCE = 1;
295
296    /** Property value is treated as a link or list of links. */
297    public static final CmsPropertyType TYPE_LINK = CmsPropertyType.LINK;
298
299    /** Property value is not a link. */
300    public static final CmsPropertyType TYPE_NORMAL = CmsPropertyType.NORMAL;
301
302    /** The null property definition object. */
303    private static final CmsPropertyDefinition NULL_PROPERTY_DEFINITION = new CmsPropertyDefinition(
304        CmsUUID.getNullUUID(),
305        "",
306        TYPE_NORMAL);
307
308    /** The id of this property definition. */
309    private CmsUUID m_id;
310
311    /** The name of this property definition. */
312    private String m_name;
313
314    /** The type of this property definition.*/
315    private CmsPropertyType m_type;
316
317    /**
318     * Creates a new property definition object with the type
319     * <code>{@link #TYPE_NORMAL}</code>.<p>
320     *
321     * @param id the id of the property definition
322     * @param name the name of the property definition
323     */
324    public CmsPropertyDefinition(CmsUUID id, String name) {
325
326        this(id, name, TYPE_NORMAL);
327    }
328
329    /**
330     * Creates a new property definition object.<p>
331     *
332     * @param id the id of the property definition
333     * @param name the name of the property definition
334     * @param propertyType the type of the property
335     */
336    public CmsPropertyDefinition(CmsUUID id, String name, CmsPropertyType propertyType) {
337
338        m_id = id;
339        m_name = name;
340        m_type = propertyType;
341    }
342
343    /**
344     * Checks if the provided property name is a valid property name,
345     * that is contains only valid characters.<p>
346     *
347     * A property name can only be composed of digits,
348     * standard ASCII letters and the symbols defined in {@link #NAME_CONSTRAINTS}.<p>
349     *
350     * @param name the property name to check
351     *
352     * @throws CmsIllegalArgumentException if the given property name is not valid
353     */
354    public static void checkPropertyName(String name) throws CmsIllegalArgumentException {
355
356        if (CmsStringUtil.isEmptyOrWhitespaceOnly(name)) {
357            throw new CmsIllegalArgumentException(
358                Messages.get().container(Messages.ERR_BAD_PROPERTYNAME_EMPTY_0, name));
359        }
360
361        CmsStringUtil.checkName(name, NAME_CONSTRAINTS, Messages.ERR_BAD_PROPERTYNAME_4, Messages.get());
362    }
363
364    /**
365     * Returns the null property definition.<p>
366     *
367     * @return the null property definition
368     */
369    public static CmsPropertyDefinition getNullPropertyDefinition() {
370
371        return CmsPropertyDefinition.NULL_PROPERTY_DEFINITION;
372    }
373
374    /**
375     * Returns a clone of this Objects instance.<p>
376     *
377     * @return a clone of this instance
378     */
379    @Override
380    public Object clone() {
381
382        return new CmsPropertyDefinition(m_id, m_name, m_type);
383    }
384
385    /**
386     * @see java.lang.Comparable#compareTo(java.lang.Object)
387     */
388    public int compareTo(CmsPropertyDefinition obj) {
389
390        if (obj == this) {
391            return 0;
392        }
393        return m_name.compareTo(obj.m_name);
394    }
395
396    /**
397     * @see java.lang.Object#equals(java.lang.Object)
398     */
399    @Override
400    public boolean equals(Object obj) {
401
402        if (obj == this) {
403            return true;
404        }
405        if (obj instanceof CmsPropertyDefinition) {
406            return ((CmsPropertyDefinition)obj).m_id.equals(m_id);
407        }
408        return false;
409    }
410
411    /**
412     * Returns the id of this property definition.<p>
413     *
414     * @return id the id of this Propertydefinition
415     */
416    public CmsUUID getId() {
417
418        return m_id;
419    }
420
421    /**
422     * Returns the name of this property definition.<p>
423     *
424     * @return name The name of this property definition
425     */
426    public String getName() {
427
428        return m_name;
429    }
430
431    /**
432     * Returns the the type of this property definition.<p>
433     *
434     * @return the type of this property definition
435     */
436    public CmsPropertyType getType() {
437
438        return m_type;
439    }
440
441    /**
442     * @see java.lang.Object#hashCode()
443     */
444    @Override
445    public int hashCode() {
446
447        if (m_name != null) {
448            return m_name.hashCode();
449        }
450        return 0;
451    }
452
453    /**
454     * Sets the type for this property definition.<p>
455     *
456     * @param type the type to set
457     */
458    public void setType(CmsPropertyType type) {
459
460        m_type = type;
461    }
462
463    /**
464     * @see java.lang.Object#toString()
465     */
466    @Override
467    public String toString() {
468
469        StringBuffer result = new StringBuffer();
470        result.append("[Propertydefinition]");
471        result.append(" name:");
472        result.append(m_name);
473        result.append(" id:");
474        result.append(m_id);
475        result.append(" type:");
476        result.append(m_type);
477        return result.toString();
478    }
479}