KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > file > CmsProject


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/file/CmsProject.java,v $
3  * Date : $Date: 2005/08/26 09:59:01 $
4  * Version: $Revision: 1.19 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * For further information about Alkacon Software GmbH, please see the
22  * company website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the
25  * project website: http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */

31
32 package org.opencms.file;
33
34 import org.opencms.main.CmsIllegalArgumentException;
35 import org.opencms.util.CmsStringUtil;
36 import org.opencms.util.CmsUUID;
37
38 import java.sql.ResultSet JavaDoc;
39 import java.sql.SQLException JavaDoc;
40 import java.util.List JavaDoc;
41
42 /**
43  * Describes an OpenCms project,
44  * which contains a set of VFS resources that are being worked on at the same time.<p>
45  *
46  * @author Alexander Kandzior
47  * @author Michael Emmerich
48  *
49  * @version $Revision: 1.19 $
50  *
51  * @since 6.0.0
52  */

53 public class CmsProject implements Cloneable JavaDoc, Comparable JavaDoc {
54
55     /** The id of the online project. */
56     public static final int ONLINE_PROJECT_ID = 1;
57
58     /** The name of the online project. */
59     public static final String JavaDoc ONLINE_PROJECT_NAME = "Online";
60
61     /** Indicates that a project is invisible in the workplace. */
62     public static final int PROJECT_STATE_INVISIBLE = 3;
63
64     /** Indicates an unlocked project. */
65     public static final int PROJECT_STATE_UNLOCKED = 0;
66
67     /** Indicates a normal project. */
68     public static final int PROJECT_TYPE_NORMAL = 0;
69
70     /** Indicates a temporary project that is deleted after it is published. */
71     public static final int PROJECT_TYPE_TEMPORARY = 1;
72
73     /** The creation date of this project. */
74     private long m_dateCreated;
75
76     /** The description of this project. */
77     private String JavaDoc m_description;
78
79     /** The state of this project. */
80     private int m_flags;
81
82     /** The manager group id of this project. */
83     private CmsUUID m_groupManagersId;
84
85     /** The id of the user group of this project. */
86     private CmsUUID m_groupUsersId;
87
88     /** The id of this project. */
89     private int m_id;
90
91     /** The name of this project. */
92     private String JavaDoc m_name;
93
94     /** The id of this projects owner. */
95     private CmsUUID m_ownerId;
96
97     /** The task id of this project. */
98     private int m_taskId;
99
100     /** The type of this project. */
101     private int m_type;
102
103     /**
104      * Default constructor for gui usage.<p>
105      */

106     public CmsProject() {
107
108         // noop
109
}
110
111     /**
112      * Creates a new CmsProject.<p>
113      *
114      * @param projectId the id to use for this project
115      * @param name the name for this project
116      * @param description the description for this project
117      * @param taskId the task id for this project
118      * @param ownerId the owner id for this project
119      * @param groupId the group id for this project
120      * @param managerGroupId the manager group id for this project
121      * @param flags the flags for this project
122      * @param dateCreated the creation date of this project
123      * @param type the type of this project
124      */

125     public CmsProject(
126         int projectId,
127         String JavaDoc name,
128         String JavaDoc description,
129         int taskId,
130         CmsUUID ownerId,
131         CmsUUID groupId,
132         CmsUUID managerGroupId,
133         int flags,
134         long dateCreated,
135         int type) {
136
137         m_id = projectId;
138         m_name = name;
139         m_description = description;
140         m_taskId = taskId;
141         m_ownerId = ownerId;
142         m_groupUsersId = groupId;
143         m_groupManagersId = managerGroupId;
144         m_flags = flags;
145         m_type = type;
146         m_dateCreated = dateCreated;
147     }
148
149     /**
150      * Construct a new CmsProject from a SQL ResultSet.<p>
151      *
152      * @param res the result set to create a project from
153      * @param sqlManager the SQL manager to use
154      * @throws SQLException in case something goes wrong
155      */

156     public CmsProject(ResultSet JavaDoc res, org.opencms.db.generic.CmsSqlManager sqlManager)
157     throws SQLException JavaDoc {
158
159         this(
160             res.getInt(sqlManager.readQuery("C_PROJECTS_PROJECT_ID")),
161             res.getString(sqlManager.readQuery("C_PROJECTS_PROJECT_NAME")),
162             res.getString(sqlManager.readQuery("C_PROJECTS_PROJECT_DESCRIPTION")),
163             res.getInt(sqlManager.readQuery("C_PROJECTS_TASK_ID")),
164             new CmsUUID(res.getString(sqlManager.readQuery("C_PROJECTS_USER_ID"))),
165             new CmsUUID(res.getString(sqlManager.readQuery("C_PROJECTS_GROUP_ID"))),
166             new CmsUUID(res.getString(sqlManager.readQuery("C_PROJECTS_MANAGERGROUP_ID"))),
167             res.getInt(sqlManager.readQuery("C_PROJECTS_PROJECT_FLAGS")),
168             res.getLong(sqlManager.readQuery("C_PROJECTS_DATE_CREATED")),
169             res.getInt(sqlManager.readQuery("C_PROJECTS_PROJECT_TYPE")));
170     }
171
172     /**
173      * Checks if the full resource name (including the site root) of a resource matches
174      * any of the project resources of a project.<p>
175      *
176      * @param projectResources a List of project resources as Strings
177      * @param resource the resource to check
178      * @return true, if the resource is "inside" the project resources
179      */

180     public static boolean isInsideProject(List JavaDoc projectResources, CmsResource resource) {
181
182         String JavaDoc resourcename = resource.getRootPath();
183         return isInsideProject(projectResources, resourcename);
184     }
185
186     /**
187      * Checks if the full resource name (including the site root) of a resource matches
188      * any of the project resources of a project.<p>
189      *
190      * @param projectResources a List of project resources as Strings
191      * @param resourcename the resource to check
192      * @return true, if the resource is "inside" the project resources
193      */

194     public static boolean isInsideProject(List JavaDoc projectResources, String JavaDoc resourcename) {
195
196         for (int i = (projectResources.size() - 1); i >= 0; i--) {
197             String JavaDoc projectResource = (String JavaDoc)projectResources.get(i);
198             if (CmsResource.isFolder(projectResource)) {
199                 if (resourcename.startsWith(projectResource)) {
200                     // folder - check only the prefix
201
return true;
202                 }
203             } else {
204                 if (resourcename.equals(projectResource)) {
205                     // file - check the full path
206
return true;
207                 }
208             }
209         }
210         return false;
211     }
212
213     /**
214      * Returns true if the given project id is the online project id.<p>
215      *
216      * @param projectId the project id to check
217      * @return true if the given project id is the online project id
218      */

219     public static boolean isOnlineProject(int projectId) {
220
221         return projectId == CmsProject.ONLINE_PROJECT_ID;
222     }
223
224     /**
225      * Returns a clone of this Objects instance.<p>
226      *
227      * @return a clone of this instance
228      */

229     public Object JavaDoc clone() {
230
231         return new CmsProject(
232             m_id,
233             m_name,
234             m_description,
235             m_taskId,
236             m_ownerId,
237             m_groupUsersId,
238             m_groupManagersId,
239             m_flags,
240             m_dateCreated,
241             m_type);
242     }
243
244     /**
245      * Compares this instance to another given object instance of this class .<p>
246      *
247      * @param o the other given object instance to compare with
248      * @return integer value for sorting the objects
249      */

250     public int compareTo(Object JavaDoc o) {
251
252         if (o == this) {
253             return 0;
254         }
255
256         if (o instanceof CmsProject) {
257             try {
258                 // compare the names
259
return m_name.compareTo(((CmsProject)o).getName());
260             } catch (Exception JavaDoc e) {
261                 // ignore, return 0
262
}
263         }
264         return 0;
265     }
266
267     /**
268      * @see java.lang.Object#equals(java.lang.Object)
269      */

270     public boolean equals(Object JavaDoc obj) {
271
272         if (obj == this) {
273             return true;
274         }
275         if (obj instanceof CmsProject) {
276             return ((CmsProject)obj).m_id == m_id;
277         }
278         return false;
279     }
280
281     /**
282      * Returns the creation date of this project.<p>
283      *
284      * @return the creation date of this project
285      */

286     public long getDateCreated() {
287
288         return m_dateCreated;
289     }
290
291     /**
292      * Returns the description of this project.
293      *
294      * @return the description of this project
295      */

296     public String JavaDoc getDescription() {
297
298         return m_description;
299     }
300
301     /**
302      * Returns the state of this project.<p>
303      *
304      * @return the state of this project
305      */

306     public int getFlags() {
307
308         return m_flags;
309     }
310
311     /**
312      * Returns the user group id of this project.<p>
313      *
314      * @return the user group id of this project
315      */

316     public CmsUUID getGroupId() {
317
318         return m_groupUsersId;
319     }
320
321     /**
322      * Returns the id of this project.<p>
323      *
324      * @return the id of this project
325      */

326     public int getId() {
327
328         return m_id;
329     }
330
331     /**
332      * Returns the manager group id of this project.<p>
333      *
334      * @return the manager group id of this project
335      */

336     public CmsUUID getManagerGroupId() {
337
338         return m_groupManagersId;
339     }
340
341     /**
342      * Returns the name of this project.<p>
343      *
344      * @return the name of this project
345      */

346     public String JavaDoc getName() {
347
348         return m_name;
349     }
350
351     /**
352      * Returns the user id of the project owner.<p>
353      *
354      * @return the user id of the project owner
355      */

356     public CmsUUID getOwnerId() {
357
358         return m_ownerId;
359     }
360
361     /**
362      * Returns the task id of this project.<p>
363      *
364      * @return the task id of this project
365      */

366     public int getTaskId() {
367
368         return m_taskId;
369     }
370
371     /**
372      * Returns the type of this project.<p>
373      *
374      * @return the type of this project
375      */

376     public int getType() {
377
378         return m_type;
379     }
380
381     /**
382      * @see java.lang.Object#hashCode()
383      */

384     public int hashCode() {
385
386         if (m_name != null) {
387             return m_name.hashCode();
388         }
389         return 0;
390     }
391
392     /**
393      * Returns the delete After Publishing flag.<p>
394      *
395      * @return the delete After Publishing flag
396      *
397      * @see #getType()
398      */

399     public boolean isDeleteAfterPublishing() {
400
401         return m_type == CmsProject.PROJECT_TYPE_TEMPORARY;
402     }
403
404     /**
405      * Returns <code>true</code> if this project is the Online project.<p>
406      *
407      * @return <code>true</code> if this project is the Online project
408      */

409     public boolean isOnlineProject() {
410
411         return isOnlineProject(m_id);
412     }
413
414     /**
415      * Sets the delete After Publishing flag.<p>
416      *
417      * @param deleteAfterPublishing the delete After Publishing flag to set
418      */

419     public void setDeleteAfterPublishing(boolean deleteAfterPublishing) {
420
421         m_type = deleteAfterPublishing ? CmsProject.PROJECT_TYPE_TEMPORARY : CmsProject.PROJECT_TYPE_NORMAL;
422     }
423
424     /**
425      * Sets the description of this project.<p>
426      *
427      * @param description the description to set
428      */

429     public void setDescription(String JavaDoc description) {
430
431         m_description = description;
432     }
433
434     /**
435      * Sets the flags of this project.<p>
436      *
437      * @param flags the flag to set
438      */

439     public void setFlags(int flags) {
440
441         m_flags = flags;
442     }
443
444     /**
445      * Sets the user group id of this project.<p>
446      *
447      * @param id the user group id of this project
448      */

449     public void setGroupId(CmsUUID id) {
450
451         CmsUUID.checkId(id, false);
452         m_groupUsersId = id;
453     }
454
455     /**
456      * Sets the manager group id of this project.<p>
457      *
458      * @param id the manager group id of this project
459      */

460     public void setManagerGroupId(CmsUUID id) {
461
462         CmsUUID.checkId(id, false);
463         m_groupManagersId = id;
464     }
465
466     /**
467      * Sets the name.<p>
468      *
469      * @param name the name to set
470      */

471     public void setName(String JavaDoc name) {
472
473         if (CmsStringUtil.isEmptyOrWhitespaceOnly(name)) {
474             throw new CmsIllegalArgumentException(Messages.get().container(Messages.ERR_PROJECTNAME_VALIDATION_0));
475         }
476         m_name = name;
477     }
478
479     /**
480      * @see java.lang.Object#toString()
481      */

482     public String JavaDoc toString() {
483
484         StringBuffer JavaDoc result = new StringBuffer JavaDoc();
485         result.append("[Project]:");
486         result.append(m_name);
487         result.append(" , Id=");
488         result.append(m_id);
489         result.append(" :");
490         result.append(m_description);
491         return result.toString();
492     }
493
494     /**
495      * Sets the type of this project.<p>
496      *
497      * @param id the type to set
498      */

499     void setType(int id) {
500
501         m_type = id;
502     }
503 }
504
Popular Tags