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, 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.ugc; 029 030import org.opencms.file.CmsGroup; 031import org.opencms.file.CmsResource; 032import org.opencms.file.CmsUser; 033import org.opencms.util.CmsUUID; 034 035import java.util.List; 036import java.util.Locale; 037 038import org.apache.commons.lang3.builder.ToStringBuilder; 039 040import com.google.common.base.Optional; 041 042/** 043 * The configuration for 'user generated content' forms.<p> 044 */ 045public class CmsUgcConfiguration { 046 047 /** The user to user for VFS operations caused by guests who submit the XML content form. */ 048 private Optional<CmsUser> m_userForGuests; 049 050 /** An id that should uniquely identify the configuration. */ 051 private CmsUUID m_id; 052 053 /** The manager group for the project in which VFS operations should be performed. */ 054 private CmsGroup m_projectGroup; 055 056 /** The optional wait interval for the queue. */ 057 private Optional<Long> m_queueInterval; 058 059 /** The optional maximum queue length. */ 060 private Optional<Integer> m_maxQueueLength; 061 062 /** The name pattern for XML contents. */ 063 private String m_namePattern; 064 065 /** The parent folder in which contents should be created. */ 066 private CmsResource m_contentParentFolder; 067 068 /** The optional parent folder in which uploaded files should be created. */ 069 private Optional<CmsResource> m_uploadParentFolder; 070 071 /** The maximum upload size (optional). */ 072 private Optional<Long> m_maxUploadSize; 073 074 /** The maximum content number (optional). */ 075 private Optional<Integer> m_maxContentNumber; 076 077 /** Flag which determines whether contents should automatically be published. */ 078 private boolean m_isAutoPublish; 079 080 /** The valid file name extensions. */ 081 private Optional<List<String>> m_validExtensions; 082 083 /** The locale in which to save the content. */ 084 private Locale m_locale; 085 086 /** The resource type for new XML contents. */ 087 private String m_resourceType; 088 089 /** The path of the configuration. */ 090 private String m_path; 091 092 /** 093 * Creates a new form configuration.<p> 094 * 095 * @param id the id for the form configuration 096 * @param userForGuests the user to use for VFS operations caused by guests who submit the XML content form 097 * @param projectGroup the group to be used as the manager group for projects based on this configuration 098 * @param resourceType the resource type for new XML contents 099 * @param contentParentFolder the parent folder for XML contents 100 * @param namePattern the name pattern for XML contents 101 * @param locale the locale to use 102 * @param uploadParent the parent folder for uploads 103 * @param maxUploadSize the maximum upload file size 104 * @param maxContents the maximum number of XML contents 105 * @param queueTimeout the wait time for the queue 106 * @param maxQueueLength the maximum queue length 107 * @param autoPublish enables/disables automatic publishing 108 * @param validExtensions the list of valid extensions 109 */ 110 public CmsUgcConfiguration( 111 CmsUUID id, 112 Optional<CmsUser> userForGuests, 113 CmsGroup projectGroup, 114 String resourceType, 115 CmsResource contentParentFolder, 116 String namePattern, 117 Locale locale, 118 Optional<CmsResource> uploadParent, 119 Optional<Long> maxUploadSize, 120 Optional<Integer> maxContents, 121 Optional<Long> queueTimeout, 122 Optional<Integer> maxQueueLength, 123 boolean autoPublish, 124 Optional<List<String>> validExtensions) { 125 126 m_id = id; 127 m_userForGuests = userForGuests; 128 m_projectGroup = projectGroup; 129 m_resourceType = resourceType; 130 m_contentParentFolder = contentParentFolder; 131 m_namePattern = namePattern; 132 m_locale = locale; 133 m_uploadParentFolder = uploadParent; 134 m_maxUploadSize = maxUploadSize; 135 m_maxContentNumber = maxContents; 136 m_queueInterval = queueTimeout; 137 m_maxQueueLength = maxQueueLength; 138 m_isAutoPublish = autoPublish; 139 m_validExtensions = validExtensions; 140 141 } 142 143 /** 144 * Returns the folder for XML contents.<p> 145 * 146 * @return the folder for XML contents 147 */ 148 public CmsResource getContentParentFolder() { 149 150 return m_contentParentFolder; 151 } 152 153 /** 154 * Gets the id.<p> 155 * 156 * The id is a UUID that should uniquely identify this configuration.<p> 157 * 158 * @return the id for this configuration 159 */ 160 public CmsUUID getId() { 161 162 return m_id; 163 } 164 165 /** 166 * Returns the locale.<p> 167 * 168 * @return the locale 169 */ 170 public Locale getLocale() { 171 172 return m_locale; 173 } 174 175 /** 176 * Returns the maximum number of XML contents.<p> 177 * 178 * @return the maximum number of XML contents 179 */ 180 public Optional<Integer> getMaxContentNumber() { 181 182 return m_maxContentNumber; 183 } 184 185 /** 186 * Returns the maximum queue length.<p> 187 * 188 * @return the maximum queue length 189 */ 190 public Optional<Integer> getMaxQueueLength() { 191 192 return m_maxQueueLength; 193 } 194 195 /** 196 * Returns the maximum upload size.<p> 197 * 198 * @return the maximum upload size 199 */ 200 public Optional<Long> getMaxUploadSize() { 201 202 return m_maxUploadSize; 203 } 204 205 /** 206 * Returns the name pattern for XML contents.<p> 207 * 208 * @return the name pattern for XML contents 209 */ 210 public String getNamePattern() { 211 212 return m_namePattern; 213 } 214 215 /** 216 * Gets the path of the configuration.<p> 217 * 218 * @return the path of the configuration 219 */ 220 public String getPath() { 221 222 return m_path; 223 } 224 225 /** 226 * Returns the group which should be used as the manager groups for projects based on this configuration.<p> 227 * 228 * @return the project manager group for this configuration 229 */ 230 public CmsGroup getProjectGroup() { 231 232 return m_projectGroup; 233 } 234 235 /** 236 * Returns the wait time for acquiring sessions for the same configuration.<p> 237 * 238 * @return the wait time 239 */ 240 public Optional<Long> getQueueInterval() { 241 242 return m_queueInterval; 243 } 244 245 /** 246 * Returns the resource type for XML contents.<p> 247 * 248 * @return the resource type for XML contents 249 */ 250 public String getResourceType() { 251 252 return m_resourceType; 253 } 254 255 /** 256 * Returns the folder for uploads.<p> 257 * 258 * @return the folder for uploads 259 */ 260 public Optional<CmsResource> getUploadParentFolder() { 261 262 return m_uploadParentFolder; 263 } 264 265 /** 266 * Returns the user which should be used for VFS operations when guests submit the XML content form.<p> 267 * 268 * @return the user to use for VFS operations instead of the guest user 269 */ 270 public Optional<CmsUser> getUserForGuests() { 271 272 return m_userForGuests; 273 } 274 275 /** 276 * Returns the list of valid extensions for uploads.<p> 277 * 278 * @return the list of valid extensions for uploads 279 */ 280 public Optional<List<String>> getValidExtensions() { 281 282 return m_validExtensions; 283 } 284 285 /** 286 * Returns true if XML contents should automatically be published.<p> 287 * 288 * @return true if XML contents should automatically be published 289 */ 290 public boolean isAutoPublish() { 291 292 return m_isAutoPublish; 293 } 294 295 /** 296 * Checks if a queue is needed for creating sessions for this configuration.<p> 297 * 298 * @return true if a queue is needed for this configuration 299 */ 300 public boolean needsQueue() { 301 302 return m_maxQueueLength.isPresent() || m_queueInterval.isPresent(); 303 } 304 305 /** 306 * Sets the path.<p> 307 * 308 * @param path the path of the configuration.<p> 309 */ 310 public void setPath(String path) { 311 312 m_path = path; 313 } 314 315 /** 316 * @see java.lang.Object#toString() 317 */ 318 @Override 319 public String toString() { 320 321 return ToStringBuilder.reflectionToString(this); 322 } 323 324}