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