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.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 for the content conversion. */ 108 public static final String PROPERTY_CONTENT_CONVERSION = "content-conversion"; 109 110 /** Property for the content encoding. */ 111 public static final String PROPERTY_CONTENT_ENCODING = "content-encoding"; 112 113 /** Property for the content encoding. */ 114 public static final String PROPERTY_COPYRIGHT = "Copyright"; 115 116 /** Property for the default file in folders. */ 117 public static final String PROPERTY_DEFAULT_FILE = "default-file"; 118 119 /** Property for the days a resource has to be expired to be deleted by the <code>{@link org.opencms.scheduler.jobs.CmsDeleteExpiredResourcesJob}</code>. */ 120 public static final String PROPERTY_DELETE_EXPIRED = "delete.expired"; 121 122 /** Property for the description. */ 123 public static final String PROPERTY_DESCRIPTION = "Description"; 124 125 /** The name of the property which controls whether an element will be used as a copy model by the container page editor. */ 126 public static final String PROPERTY_ELEMENT_MODEL = "element.model"; 127 128 /** May contain a path to an element replacement configuration, for use in the 'copy page' dialog. */ 129 public static final String PROPERTY_ELEMENT_REPLACEMENTS = "element.replacements"; 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 stating where to create new gallery folders. */ 147 public static final String PROPERTY_GALLERIES_FOLDER = "galleries.folder"; 148 149 /** Property containing the maps API key. */ 150 public static final String PROPERTY_GOOGLE_API_KEY = "google.apikey"; 151 152 /** Property constant for <code>"image.size"</code>. */ 153 public static final String PROPERTY_IMAGE_SIZE = "image.size"; 154 155 /** Property for the keywords. */ 156 public static final String PROPERTY_KEYWORDS = "Keywords"; 157 158 /** Property for the current locale. */ 159 public static final String PROPERTY_LOCALE = "locale"; 160 161 /** Property for the 'do not translate' marking in the sitemap editor. */ 162 public static final String PROPERTY_LOCALE_NOTRANSLATION = "locale.notranslation"; 163 164 /** Property for the login form. */ 165 public static final String PROPERTY_LOGIN_FORM = "login-form"; 166 167 /** Property for the model group base element. */ 168 public static final String PROPERTY_MODEL_GROUP_BASE = "modelgroup.base"; 169 170 /** Property constant for <code>"NavImage"</code>. */ 171 public static final String PROPERTY_NAVIMAGE = "NavImage"; 172 173 /** Property constant for <code>"NavInfo"</code>. */ 174 public static final String PROPERTY_NAVINFO = "NavInfo"; 175 176 /** Property for the navigation position. */ 177 public static final String PROPERTY_NAVPOS = "NavPos"; 178 179 /** Property for the navigation text. */ 180 public static final String PROPERTY_NAVTEXT = "NavText"; 181 182 /** Property for the resource title. */ 183 public static final String PROPERTY_NOTIFICATION_INTERVAL = "notification-interval"; 184 185 /** Property for the relative root link substitution. */ 186 public static final String PROPERTY_RELATIVEROOT = "relativeroot"; 187 188 /** Property name that defines the available resource types for the "new" dialog. */ 189 public static final String PROPERTY_RESTYPES_AVAILABLE = "restypes.available"; 190 191 /** Property to sort search results in categories. */ 192 public static final String PROPERTY_SEARCH_CATEGORY = "category"; 193 194 /** Property to exclude individual resources from search index generation. */ 195 public static final String PROPERTY_SEARCH_EXCLUDE = "search.exclude"; 196 197 /** Property to boost certain search results. */ 198 public static final String PROPERTY_SEARCH_PRIORITY = "search.priority"; 199 200 /** Property for secondary locales for use in the locale compare view in the sitemap editor. */ 201 public static final String PROPERTY_SECONDARY_LOCALES = "locale.secondary"; 202 203 /** Property for the secure transmission of resources. */ 204 public static final String PROPERTY_SECURE = "secure"; 205 206 /** Property for the stylesheet of files. */ 207 public static final String PROPERTY_STYLESHEET = "stylesheet"; 208 209 /** Property to control the template. */ 210 public static final String PROPERTY_TEMPLATE = "template"; 211 212 /** Property to control the template elements. */ 213 public static final String PROPERTY_TEMPLATE_ELEMENTS = "template-elements"; 214 215 /** Property for the template image. */ 216 public static final String PROPERTY_TEMPLATE_IMAGE = "template.image"; 217 218 /** 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. */ 219 public static final String PROPERTY_TEMPLATE_PROVIDER = "template.provider"; 220 221 /** Property for the resource title. */ 222 public static final String PROPERTY_TITLE = "Title"; 223 224 /** Name of the property used to control whether mapped URL names should replace previous URL names. */ 225 public static final String PROPERTY_URLNAME_REPLACE = "urlname.replace"; 226 227 /** Property for the visible method in the administration view. */ 228 public static final String PROPERTY_VISIBLE = "visiblemethod"; 229 230 /** Property for the XML sitemap change frequency. */ 231 public static final String PROPERTY_XMLSITEMAP_CHANGEFREQ = "xmlsitemap.changefreq"; 232 233 /** Property for the XML sitemap priority. */ 234 public static final String PROPERTY_XMLSITEMAP_PRIORITY = "xmlsitemap.priority"; 235 236 /** The property definition type for resources. */ 237 public static final int PROPERYDEFINITION_RESOURCE = 1; 238 239 /** Property value is treated as a link or list of links. */ 240 public static final CmsPropertyType TYPE_LINK = CmsPropertyType.LINK; 241 242 /** Property value is not a link. */ 243 public static final CmsPropertyType TYPE_NORMAL = CmsPropertyType.NORMAL; 244 245 /** The null property definition object. */ 246 private static final CmsPropertyDefinition NULL_PROPERTY_DEFINITION = new CmsPropertyDefinition( 247 CmsUUID.getNullUUID(), 248 "", 249 TYPE_NORMAL); 250 251 /** The id of this property definition. */ 252 private CmsUUID m_id; 253 254 /** The name of this property definition. */ 255 private String m_name; 256 257 /** The type of this property definition.*/ 258 private CmsPropertyType m_type; 259 260 /** 261 * Creates a new property definition object with the type 262 * <code>{@link #TYPE_NORMAL}</code>.<p> 263 * 264 * @param id the id of the property definition 265 * @param name the name of the property definition 266 */ 267 public CmsPropertyDefinition(CmsUUID id, String name) { 268 269 this(id, name, TYPE_NORMAL); 270 } 271 272 /** 273 * Creates a new property definition object.<p> 274 * 275 * @param id the id of the property definition 276 * @param name the name of the property definition 277 * @param propertyType the type of the property 278 */ 279 public CmsPropertyDefinition(CmsUUID id, String name, CmsPropertyType propertyType) { 280 281 m_id = id; 282 m_name = name; 283 m_type = propertyType; 284 } 285 286 /** 287 * Checks if the provided property name is a valid property name, 288 * that is contains only valid characters.<p> 289 * 290 * A property name can only be composed of digits, 291 * standard ASCII letters and the symbols defined in {@link #NAME_CONSTRAINTS}.<p> 292 * 293 * @param name the property name to check 294 * 295 * @throws CmsIllegalArgumentException if the given property name is not valid 296 */ 297 public static void checkPropertyName(String name) throws CmsIllegalArgumentException { 298 299 if (CmsStringUtil.isEmptyOrWhitespaceOnly(name)) { 300 throw new CmsIllegalArgumentException( 301 Messages.get().container(Messages.ERR_BAD_PROPERTYNAME_EMPTY_0, name)); 302 } 303 304 CmsStringUtil.checkName(name, NAME_CONSTRAINTS, Messages.ERR_BAD_PROPERTYNAME_4, Messages.get()); 305 } 306 307 /** 308 * Returns the null property definition.<p> 309 * 310 * @return the null property definition 311 */ 312 public static CmsPropertyDefinition getNullPropertyDefinition() { 313 314 return CmsPropertyDefinition.NULL_PROPERTY_DEFINITION; 315 } 316 317 /** 318 * Returns a clone of this Objects instance.<p> 319 * 320 * @return a clone of this instance 321 */ 322 @Override 323 public Object clone() { 324 325 return new CmsPropertyDefinition(m_id, m_name, m_type); 326 } 327 328 /** 329 * @see java.lang.Comparable#compareTo(java.lang.Object) 330 */ 331 public int compareTo(CmsPropertyDefinition obj) { 332 333 if (obj == this) { 334 return 0; 335 } 336 return m_name.compareTo(obj.m_name); 337 } 338 339 /** 340 * @see java.lang.Object#equals(java.lang.Object) 341 */ 342 @Override 343 public boolean equals(Object obj) { 344 345 if (obj == this) { 346 return true; 347 } 348 if (obj instanceof CmsPropertyDefinition) { 349 return ((CmsPropertyDefinition)obj).m_id.equals(m_id); 350 } 351 return false; 352 } 353 354 /** 355 * Returns the id of this property definition.<p> 356 * 357 * @return id the id of this Propertydefinition 358 */ 359 public CmsUUID getId() { 360 361 return m_id; 362 } 363 364 /** 365 * Returns the name of this property definition.<p> 366 * 367 * @return name The name of this property definition 368 */ 369 public String getName() { 370 371 return m_name; 372 } 373 374 /** 375 * Returns the the type of this property definition.<p> 376 * 377 * @return the type of this property definition 378 */ 379 public CmsPropertyType getType() { 380 381 return m_type; 382 } 383 384 /** 385 * @see java.lang.Object#hashCode() 386 */ 387 @Override 388 public int hashCode() { 389 390 if (m_name != null) { 391 return m_name.hashCode(); 392 } 393 return 0; 394 } 395 396 /** 397 * Sets the type for this property definition.<p> 398 * 399 * @param type the type to set 400 */ 401 public void setType(CmsPropertyType type) { 402 403 m_type = type; 404 } 405 406 /** 407 * @see java.lang.Object#toString() 408 */ 409 @Override 410 public String toString() { 411 412 StringBuffer result = new StringBuffer(); 413 result.append("[Propertydefinition]"); 414 result.append(" name:"); 415 result.append(m_name); 416 result.append(" id:"); 417 result.append(m_id); 418 result.append(" type:"); 419 result.append(m_type); 420 return result.toString(); 421 } 422}