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