KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/file/CmsFolder.java,v $
3  * Date : $Date: 2006/03/27 14:52:41 $
4  * Version: $Revision: 1.25 $
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.db.CmsSecurityManager;
35 import org.opencms.loader.CmsLoaderException;
36 import org.opencms.main.CmsIllegalArgumentException;
37 import org.opencms.main.CmsLog;
38 import org.opencms.main.OpenCms;
39 import org.opencms.util.CmsUUID;
40
41 import java.io.Serializable JavaDoc;
42
43 import org.apache.commons.logging.Log;
44
45 /**
46  * A folder resource in the OpenCms VFS.<p>
47  *
48  * A folder resource is a CmsResource object that can contain sub-resources.<p>
49  *
50  * @author Alexander Kandzior
51  * @author Michael Emmerich
52  *
53  * @version $Revision: 1.25 $
54  *
55  * @since 6.0.0
56  */

57 public class CmsFolder extends CmsResource implements Cloneable JavaDoc, Serializable JavaDoc, Comparable JavaDoc {
58
59     /** The log object for this class. */
60     private static final Log LOG = CmsLog.getLog(CmsSecurityManager.class);
61     /** Serial version UID required for safe serialization. */
62     private static final long serialVersionUID = 5527163725725725452L;
63
64     /**
65      * Constructor, creates a new CmsFolder Object from the given CmsResource.<p>
66      *
67      * @param resource the base resource object to create a folder from
68      */

69     public CmsFolder(CmsResource resource) {
70
71         this(
72             resource.getStructureId(),
73             resource.getResourceId(),
74             resource.getRootPath(),
75             resource.getTypeId(),
76             resource.getFlags(),
77             resource.getProjectLastModified(),
78             resource.getState(),
79             resource.getDateCreated(),
80             resource.getUserCreated(),
81             resource.getDateLastModified(),
82             resource.getUserLastModified(),
83             resource.getSiblingCount(),
84             resource.getDateReleased(),
85             resource.getDateExpired());
86     }
87
88     /**
89      * Constructor, creates a new CmsFolder object.<p>
90      * @param structureId the id of this resources structure record
91      * @param resourceId the id of this resources resource record
92      * @param path the filename of this resouce
93      * @param type the type of this resource
94      * @param flags the flags of this resource
95      * @param projectId the project id this resource was last modified in
96      * @param state the state of this resource
97      * @param dateCreated the creation date of this resource
98      * @param userCreated the id of the user who created this resource
99      * @param dateLastModified the date of the last modification of this resource
100      * @param userLastModified the id of the user who did the last modification of this resource * @param size the size of the file content of this resource
101      * @param linkCount the count of all siblings of this resource
102      * @param dateReleased the release date of this resource
103      * @param dateExpired the expiration date of this resource
104      */

105     public CmsFolder(
106         CmsUUID structureId,
107         CmsUUID resourceId,
108         String JavaDoc path,
109         int type,
110         int flags,
111         int projectId,
112         int state,
113         long dateCreated,
114         CmsUUID userCreated,
115         long dateLastModified,
116         CmsUUID userLastModified,
117         int linkCount,
118         long dateReleased,
119         long dateExpired) {
120
121         super(
122             structureId,
123             resourceId,
124             path,
125             type,
126             true,
127             flags,
128             projectId,
129             state,
130             dateCreated,
131             userCreated,
132             dateLastModified,
133             userLastModified,
134             dateReleased,
135             dateExpired,
136             linkCount,
137             -1);
138     }
139
140     /**
141      * Returns <code>true</code> if the given resource type id describes a folder type.<p>
142      *
143      * @param typeId the resource type id to check
144      *
145      * @return true if the given resource type id describes a folder type or false if it is no folder or an unknown type.
146      *
147      */

148     public static final boolean isFolderType(int typeId) {
149
150         try {
151             return OpenCms.getResourceManager().getResourceType(typeId).isFolder();
152         } catch (CmsLoaderException e) {
153             if (LOG.isWarnEnabled()) {
154                 LOG.warn(Messages.get().getBundle().key(Messages.ERR_UNKNOWN_RESOURCE_TYPE_1, new Integer JavaDoc(typeId)), e);
155             }
156         }
157         return false;
158     }
159
160     /**
161      * Returns <code>true</code> if the given resource type name describes a folder type.<p>
162      *
163      * @param typeName the resource type name to check
164      *
165      * @return true if the given resource type name describes a folder type
166      */

167     public static final boolean isFolderType(String JavaDoc typeName) {
168
169         try {
170             return OpenCms.getResourceManager().getResourceType(typeName).isFolder();
171         } catch (CmsLoaderException e) {
172             throw new CmsIllegalArgumentException(Messages.get().container(
173                 Messages.ERR_UNKNOWN_RESOURCE_TYPE_1,
174                 typeName), e);
175         }
176     }
177
178     /**
179      * Returns a clone of this Objects instance.<p>
180      *
181      * @return a clone of this instance
182      */

183     public Object JavaDoc clone() {
184
185         CmsResource clone = new CmsFolder(
186             getStructureId(),
187             getResourceId(),
188             getRootPath(),
189             getTypeId(),
190             getFlags(),
191             getProjectLastModified(),
192             getState(),
193             getDateCreated(),
194             getUserCreated(),
195             getDateLastModified(),
196             getUserLastModified(),
197             getSiblingCount(),
198             getDateReleased(),
199             getDateExpired());
200
201         if (isTouched()) {
202             clone.setDateLastModified(getDateLastModified());
203         }
204
205         return clone;
206     }
207
208     /**
209      * @see org.opencms.file.CmsResource#getLength()
210      */

211     public int getLength() {
212
213         return -1;
214     }
215
216     /**
217      * @see org.opencms.file.CmsResource#isFile()
218      */

219     public boolean isFile() {
220
221         return false;
222     }
223
224     /**
225      * @see org.opencms.file.CmsResource#isFolder()
226      */

227     public boolean isFolder() {
228
229         return true;
230     }
231 }
Popular Tags