001: /*
002: * File : $Source: /usr/local/cvs/opencms/src/org/opencms/file/CmsProject.java,v $
003: * Date : $Date: 2008-02-27 12:05:38 $
004: * Version: $Revision: 1.23 $
005: *
006: * This library is part of OpenCms -
007: * the Open Source Content Management System
008: *
009: * Copyright (c) 2002 - 2008 Alkacon Software GmbH (http://www.alkacon.com)
010: *
011: * This library is free software; you can redistribute it and/or
012: * modify it under the terms of the GNU Lesser General Public
013: * License as published by the Free Software Foundation; either
014: * version 2.1 of the License, or (at your option) any later version.
015: *
016: * This library is distributed in the hope that it will be useful,
017: * but WITHOUT ANY WARRANTY; without even the implied warranty of
018: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019: * Lesser General Public License for more details.
020: *
021: * For further information about Alkacon Software GmbH, please see the
022: * company website: http://www.alkacon.com
023: *
024: * For further information about OpenCms, please see the
025: * project website: http://www.opencms.org
026: *
027: * You should have received a copy of the GNU Lesser General Public
028: * License along with this library; if not, write to the Free Software
029: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
030: */
031:
032: package org.opencms.file;
033:
034: import org.opencms.main.CmsIllegalArgumentException;
035: import org.opencms.security.CmsOrganizationalUnit;
036: import org.opencms.util.A_CmsModeIntEnumeration;
037: import org.opencms.util.CmsStringUtil;
038: import org.opencms.util.CmsUUID;
039:
040: import java.util.List;
041:
042: /**
043: * Describes an OpenCms project,
044: * which contains a set of VFS resources that are being worked on at the same time.<p>
045: *
046: * @author Alexander Kandzior
047: * @author Michael Emmerich
048: *
049: * @version $Revision: 1.23 $
050: *
051: * @since 6.0.0
052: */
053: public class CmsProject implements Cloneable, Comparable {
054:
055: /**
056: * Enumeration class for project types.<p>
057: */
058: public static final class CmsProjectType extends
059: A_CmsModeIntEnumeration {
060:
061: /** Project type normal. */
062: protected static final CmsProjectType MODE_PROJECT_NORMAL = new CmsProjectType(
063: 0);
064:
065: /** Project type temporary. */
066: protected static final CmsProjectType MODE_PROJECT_TEMPORARY = new CmsProjectType(
067: 1);
068:
069: /** Serializable version id. */
070: private static final long serialVersionUID = -8701314451776599534L;
071:
072: /**
073: * Private constructor.<p>
074: *
075: * @param mode the copy mode integer representation
076: */
077: private CmsProjectType(int mode) {
078:
079: super (mode);
080: }
081:
082: /**
083: * Returns the copy mode object from the old copy mode integer.<p>
084: *
085: * @param mode the old copy mode integer
086: *
087: * @return the copy mode object
088: */
089: public static CmsProjectType valueOf(int mode) {
090:
091: switch (mode) {
092: case 0:
093: return CmsProjectType.MODE_PROJECT_NORMAL;
094: case 1:
095: return CmsProjectType.MODE_PROJECT_TEMPORARY;
096: default:
097: return CmsProjectType.MODE_PROJECT_NORMAL;
098: }
099: }
100: }
101:
102: /** The name of the online project. */
103: public static final String ONLINE_PROJECT_NAME = "Online";
104:
105: /** The id of the online project. */
106: public static final CmsUUID ONLINE_PROJECT_ID = CmsUUID
107: .getConstantUUID(ONLINE_PROJECT_NAME);
108:
109: /** Indicates that a project is invisible in the workplace. */
110: public static final int PROJECT_FLAG_HIDDEN = 4;
111:
112: /** Indicates that a normal project. */
113: public static final int PROJECT_FLAG_NONE = 0;
114:
115: /** Indicates a normal project. */
116: public static final CmsProjectType PROJECT_TYPE_NORMAL = CmsProjectType.MODE_PROJECT_NORMAL;
117:
118: /** Indicates a temporary project that is deleted after it is published. */
119: public static final CmsProjectType PROJECT_TYPE_TEMPORARY = CmsProjectType.MODE_PROJECT_TEMPORARY;
120:
121: /** The creation date of this project. */
122: private long m_dateCreated;
123:
124: /** The description of this project. */
125: private String m_description;
126:
127: /** The state of this project. */
128: private int m_flags;
129:
130: /** The manager group id of this project. */
131: private CmsUUID m_groupManagersId;
132:
133: /** The id of the user group of this project. */
134: private CmsUUID m_groupUsersId;
135:
136: /** The id of this project. */
137: private CmsUUID m_id;
138:
139: /** The name of this project. */
140: private String m_name;
141:
142: /** The id of this projects owner. */
143: private CmsUUID m_ownerId;
144:
145: /** The type of this project. */
146: private CmsProjectType m_type;
147:
148: /**
149: * Default constructor for gui usage.<p>
150: */
151: public CmsProject() {
152:
153: // empty
154: }
155:
156: /**
157: * Creates a new CmsProject.<p>
158: *
159: * @param projectId the id to use for this project
160: * @param projectFqn the name for this project
161: * @param description the description for this project
162: * @param ownerId the owner id for this project
163: * @param groupId the group id for this project
164: * @param managerGroupId the manager group id for this project
165: * @param flags the flags for this project
166: * @param dateCreated the creation date of this project
167: * @param type the type of this project
168: */
169: public CmsProject(CmsUUID projectId, String projectFqn,
170: String description, CmsUUID ownerId, CmsUUID groupId,
171: CmsUUID managerGroupId, int flags, long dateCreated,
172: CmsProjectType type) {
173:
174: m_id = projectId;
175: m_name = projectFqn;
176: m_description = description;
177: m_ownerId = ownerId;
178: m_groupUsersId = groupId;
179: m_groupManagersId = managerGroupId;
180: m_flags = flags;
181: m_type = type;
182: m_dateCreated = dateCreated;
183: }
184:
185: /**
186: * Throws a runtime exception if name is empty.<p>
187: *
188: * @param name the project name to check
189: */
190: public static void checkProjectName(String name) {
191:
192: if (CmsStringUtil.isEmptyOrWhitespaceOnly(name)) {
193: throw new CmsIllegalArgumentException(Messages.get()
194: .container(Messages.ERR_PROJECTNAME_VALIDATION_0));
195: }
196: }
197:
198: /**
199: * Checks if the full resource name (including the site root) of a resource matches
200: * any of the project resources of a project.<p>
201: *
202: * @param projectResources a List of project resources as Strings
203: * @param resource the resource to check
204: * @return true, if the resource is "inside" the project resources
205: */
206: public static boolean isInsideProject(List projectResources,
207: CmsResource resource) {
208:
209: String resourcename = resource.getRootPath();
210: return isInsideProject(projectResources, resourcename);
211: }
212:
213: /**
214: * Checks if the full resource name (including the site root) of a resource matches
215: * any of the project resources of a project.<p>
216: *
217: * @param projectResources a List of project resources as Strings
218: * @param resourcename the resource to check
219: * @return true, if the resource is "inside" the project resources
220: */
221: public static boolean isInsideProject(List projectResources,
222: String resourcename) {
223:
224: for (int i = (projectResources.size() - 1); i >= 0; i--) {
225: String projectResource = (String) projectResources.get(i);
226: if (CmsResource.isFolder(projectResource)) {
227: if (resourcename.startsWith(projectResource)) {
228: // folder - check only the prefix
229: return true;
230: }
231: } else {
232: if (resourcename.equals(projectResource)) {
233: // file - check the full path
234: return true;
235: }
236: }
237: }
238: return false;
239: }
240:
241: /**
242: * Returns true if the given project id is the online project id.<p>
243: *
244: * @param projectId the project id to check
245: * @return true if the given project id is the online project id
246: */
247: public static boolean isOnlineProject(CmsUUID projectId) {
248:
249: return projectId.equals(CmsProject.ONLINE_PROJECT_ID);
250: }
251:
252: /**
253: * @see java.lang.Object#clone()
254: */
255: public Object clone() {
256:
257: return new CmsProject(m_id, m_name, m_description, m_ownerId,
258: m_groupUsersId, m_groupManagersId, m_flags,
259: m_dateCreated, m_type);
260: }
261:
262: /**
263: * Compares this instance to another given object instance of this class .<p>
264: *
265: * @param o the other given object instance to compare with
266: * @return integer value for sorting the objects
267: */
268: public int compareTo(Object o) {
269:
270: if (o == this ) {
271: return 0;
272: }
273:
274: if (o instanceof CmsProject) {
275: try {
276: // compare the names
277: return m_name.compareTo(((CmsProject) o).getName());
278: } catch (Exception e) {
279: // ignore, return 0
280: }
281: }
282: return 0;
283: }
284:
285: /**
286: * @see java.lang.Object#equals(java.lang.Object)
287: */
288: public boolean equals(Object obj) {
289:
290: if (obj == this ) {
291: return true;
292: }
293: if (obj instanceof CmsProject) {
294: return ((CmsProject) obj).m_id.equals(m_id);
295: }
296: return false;
297: }
298:
299: /**
300: * Returns the creation date of this project.<p>
301: *
302: * @return the creation date of this project
303: */
304: public long getDateCreated() {
305:
306: return m_dateCreated;
307: }
308:
309: /**
310: * Returns the description of this project.
311: *
312: * @return the description of this project
313: */
314: public String getDescription() {
315:
316: return m_description;
317: }
318:
319: /**
320: * Returns the state of this project.<p>
321: *
322: * @return the state of this project
323: */
324: public int getFlags() {
325:
326: return m_flags;
327: }
328:
329: /**
330: * Returns the user group id of this project.<p>
331: *
332: * @return the user group id of this project
333: */
334: public CmsUUID getGroupId() {
335:
336: return m_groupUsersId;
337: }
338:
339: /**
340: * Returns the id of this project.<p>
341: *
342: * @return the id of this project
343: *
344: * @deprecated Use {@link #getUuid()} instead
345: */
346: public int getId() {
347:
348: return getUuid().hashCode();
349: }
350:
351: /**
352: * Returns the manager group id of this project.<p>
353: *
354: * @return the manager group id of this project
355: */
356: public CmsUUID getManagerGroupId() {
357:
358: return m_groupManagersId;
359: }
360:
361: /**
362: * Returns the name of this project.<p>
363: *
364: * @return the name of this project
365: */
366: public String getName() {
367:
368: return m_name;
369: }
370:
371: /**
372: * Returns the fully qualified name of the associated organizational unit.<p>
373: *
374: * @return the fully qualified name of the associated organizational unit
375: */
376: public String getOuFqn() {
377:
378: return CmsOrganizationalUnit.getParentFqn(m_name);
379: }
380:
381: /**
382: * Returns the user id of the project owner.<p>
383: *
384: * @return the user id of the project owner
385: */
386: public CmsUUID getOwnerId() {
387:
388: return m_ownerId;
389: }
390:
391: /**
392: * Returns the simple name of this organizational unit.
393: *
394: * @return the simple name of this organizational unit.
395: */
396: public String getSimpleName() {
397:
398: return CmsOrganizationalUnit.getSimpleName(m_name);
399: }
400:
401: /**
402: * Returns the type of this project.<p>
403: *
404: * @return the type of this project
405: */
406: public CmsProjectType getType() {
407:
408: return m_type;
409: }
410:
411: /**
412: * Returns the id of this project.<p>
413: *
414: * @return the id of this project
415: */
416: public CmsUUID getUuid() {
417:
418: return m_id;
419: }
420:
421: /**
422: * @see java.lang.Object#hashCode()
423: */
424: public int hashCode() {
425:
426: if (m_name != null) {
427: return m_name.hashCode();
428: }
429: return 0;
430: }
431:
432: /**
433: * Returns the delete After Publishing flag.<p>
434: *
435: * @return the delete After Publishing flag
436: *
437: * @see #getType()
438: */
439: public boolean isDeleteAfterPublishing() {
440:
441: return (m_type == CmsProject.PROJECT_TYPE_TEMPORARY);
442: }
443:
444: /**
445: * Returns the 'hidden' flag.<p>
446: *
447: * @return the 'hidden' flag
448: *
449: * @see #getFlags()
450: */
451: public boolean isHidden() {
452:
453: return (getFlags() & PROJECT_FLAG_HIDDEN) == PROJECT_FLAG_HIDDEN;
454: }
455:
456: /**
457: * Returns <code>true</code> if this project is the Online project.<p>
458: *
459: * @return <code>true</code> if this project is the Online project
460: */
461: public boolean isOnlineProject() {
462:
463: return isOnlineProject(m_id);
464: }
465:
466: /**
467: * Sets the delete After Publishing flag.<p>
468: *
469: * @param deleteAfterPublishing the delete After Publishing flag to set
470: */
471: public void setDeleteAfterPublishing(boolean deleteAfterPublishing) {
472:
473: m_type = deleteAfterPublishing ? CmsProject.PROJECT_TYPE_TEMPORARY
474: : CmsProject.PROJECT_TYPE_NORMAL;
475: }
476:
477: /**
478: * Sets the description of this project.<p>
479: *
480: * @param description the description to set
481: */
482: public void setDescription(String description) {
483:
484: m_description = description;
485: }
486:
487: /**
488: * Sets the flags of this project.<p>
489: *
490: * @param flags the flag to set
491: */
492: public void setFlags(int flags) {
493:
494: m_flags = flags;
495: }
496:
497: /**
498: * Sets the user group id of this project.<p>
499: *
500: * @param id the user group id of this project
501: */
502: public void setGroupId(CmsUUID id) {
503:
504: CmsUUID.checkId(id, false);
505: m_groupUsersId = id;
506: }
507:
508: /**
509: * Sets the 'hidden' flag.<p>
510: *
511: * @param value the value to set
512: */
513: public void setHidden(boolean value) {
514:
515: if (isHidden() != value) {
516: setFlags(getFlags() ^ PROJECT_FLAG_HIDDEN);
517: }
518: }
519:
520: /**
521: * Sets the manager group id of this project.<p>
522: *
523: * @param id the manager group id of this project
524: */
525: public void setManagerGroupId(CmsUUID id) {
526:
527: CmsUUID.checkId(id, false);
528: m_groupManagersId = id;
529: }
530:
531: /**
532: * Sets the name.<p>
533: *
534: * @param name the name to set
535: */
536: public void setName(String name) {
537:
538: checkProjectName(name);
539: m_name = name;
540: }
541:
542: /**
543: * Sets the owner id of this project.<p>
544: *
545: * @param id the id of the new owner
546: */
547: public void setOwnerId(CmsUUID id) {
548:
549: CmsUUID.checkId(id, false);
550: m_ownerId = id;
551: }
552:
553: /**
554: * @see java.lang.Object#toString()
555: */
556: public String toString() {
557:
558: StringBuffer result = new StringBuffer();
559: result.append("[Project]:");
560: result.append(m_name);
561: result.append(" , Id=");
562: result.append(m_id);
563: result.append(", Desc=");
564: result.append(m_description);
565: return result.toString();
566: }
567:
568: /**
569: * Sets the type of this project.<p>
570: *
571: * @param type the type to set
572: */
573: void setType(CmsProjectType type) {
574:
575: m_type = type;
576: }
577: }
|