KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opencms > defaults > A_CmsContentDefinition


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src-modules/com/opencms/defaults/A_CmsContentDefinition.java,v $
3  * Date : $Date: 2005/06/21 15:50:00 $
4  * Version: $Revision: 1.2 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (C) 2001 The OpenCms Group
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 OpenCms, please see the
22  * OpenCms Website: http://www.opencms.org
23  *
24  * You should have received a copy of the GNU Lesser General Public
25  * License along with this library; if not, write to the Free Software
26  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27  */

28
29 package com.opencms.defaults;
30
31 import org.opencms.file.CmsObject;
32 import org.opencms.file.CmsUser;
33 import org.opencms.main.CmsException;
34 import org.opencms.security.CmsPermissionSet;
35 import org.opencms.util.CmsUUID;
36
37 import com.opencms.defaults.master.CmsPlausibilizationException;
38 import com.opencms.template.I_CmsContent;
39
40 import java.lang.reflect.Method JavaDoc;
41 import java.util.Vector JavaDoc;
42
43 /**
44  * Abstract class for the content definition
45  * Creation date: (27.10.00 10:04:42)
46  *
47  * @author Michael Knoll
48  * @version $Revision: 1.2 $
49  *
50  * @deprecated Will not be supported past the OpenCms 6 release.
51  */

52 public abstract class A_CmsContentDefinition implements I_CmsContent {
53
54     /**
55      * The owner of this resource.
56      */

57     private CmsUUID m_userId;
58
59     /**
60      * The group of this resource.
61      */

62     private String JavaDoc m_group;
63
64     /**
65      * The access flags of this resource.
66      */

67     private int m_accessFlags;
68
69     /**
70      * Applies the filter method.<p>
71      *
72      * @param cms the cms object
73      * @param filterMethod the filter method
74      * @return an Vector containing the method
75      * @throws Exception if something goes wrong
76      */

77     public static Vector JavaDoc applyFilter(CmsObject cms, CmsFilterMethod filterMethod) throws Exception JavaDoc {
78
79         return applyFilter(cms, filterMethod, null);
80     }
81
82     /**
83      * applies the filter through the method object and the user parameters.<p>
84      *
85      * @param cms the cms object
86      * @param filterMethod the filter method
87      * @param userParameter additional filter parameter
88      * @return a vector with the filtered content
89      * @throws Exception if something goes wrong
90      */

91     public static Vector JavaDoc applyFilter(CmsObject cms, CmsFilterMethod filterMethod, String JavaDoc userParameter)
92     throws Exception JavaDoc {
93
94         Method JavaDoc method = filterMethod.getFilterMethod();
95         Object JavaDoc[] defaultParams = filterMethod.getDefaultParameter();
96         Vector JavaDoc allParameters = new Vector JavaDoc();
97         Object JavaDoc[] allParametersArray;
98         Class JavaDoc[] paramTypes = method.getParameterTypes();
99
100         if ((paramTypes.length > 0) && (paramTypes[0] == CmsObject.class)) {
101             allParameters.addElement(cms);
102         }
103
104         for (int i = 0; i < defaultParams.length; i++) {
105             allParameters.addElement(defaultParams[i]);
106         }
107
108         if (filterMethod.hasUserParameter()) {
109             allParameters.addElement(userParameter);
110         }
111
112         allParametersArray = new Object JavaDoc[allParameters.size()];
113         allParameters.copyInto(allParametersArray);
114         return (Vector JavaDoc)method.invoke(null, allParametersArray);
115     }
116
117     /**
118      * Checks the current values of a content definition.<p>
119      *
120      * @param finalcheck flag to indicate the check when leaving the dialogue
121      * @throws CmsPlausibilizationException if a value check fails
122      */

123     public void check(boolean finalcheck) throws CmsPlausibilizationException {
124
125         // do nothing here, just an empty method for compatibility reasons.
126
}
127
128     /**
129      * abstract delete method
130      * for delete instance of content definition
131      * must be overwritten in your content definition
132      *
133      * @param cms the cms object
134      * @throws Exception if something goes wrong
135      */

136     public abstract void delete(CmsObject cms) throws Exception JavaDoc;
137
138     /**
139      * Gets the getXXX methods
140      * You have to override this method in your content definition.<p>
141      *
142      * @param cms the cms object
143      * @return a Vector with the filed methods.
144      */

145     public static Vector JavaDoc getFieldMethods(CmsObject cms) {
146
147         return new Vector JavaDoc();
148     }
149
150     /**
151      * Gets the headlines of the table
152      * You have to override this method in your content definition.<p>
153      *
154      * @param cms the cms object
155      * @return a Vector with the colum names.
156      */

157     public static Vector JavaDoc getFieldNames(CmsObject cms) {
158
159         return new Vector JavaDoc();
160     }
161
162     /**
163      * Gets the filter methods.
164      * You have to override this method in your content definition.<p>
165      *
166      * @param cms the cms object
167      * @return a Vector of FilterMethod objects containing the methods, names and default parameters
168      */

169     public static Vector JavaDoc getFilterMethods(CmsObject cms) {
170
171         return new Vector JavaDoc();
172     }
173
174     /**
175      * Gets the lockstates
176      * You have to override this method in your content definition, if you have overwritten
177      * the isLockable method with true.<p>
178      *
179      * @return a int with the lockstate
180      */

181     public CmsUUID getLockstate() {
182
183         return CmsUUID.getNullUUID();
184     }
185
186     /**
187      * gets the unique Id of a content definition instance.<p>
188      *
189      * @param cms the cms object
190      * @return a string with the Id
191      */

192     public abstract String JavaDoc getUniqueId(CmsObject cms);
193
194     /**
195      * Gets the url of the field entry
196      * You have to override this method in your content definition,
197      * if you wish to link urlīs to the field entries
198      * @return a String with the url
199      */

200     public String JavaDoc getUrl() {
201
202         return null;
203     }
204
205     /**
206      * if the content definition objects should be lockable
207      * this method has to be overwritten with value true
208      * @return a boolean
209      */

210     public static boolean isLockable() {
211
212         return false;
213     }
214
215     /**
216      * Sets the lockstates
217      * You have to override this method in your content definition,
218      * if you have overwritten the isLockable method with true.<p>
219      *
220      * @param lockedByUserId the id of the user who is locking the content
221      */

222     public void setLockstate(CmsUUID lockedByUserId) {
223
224     }
225
226     /**
227      * abstract write method
228      * must be overwritten in content definition.<p>
229      *
230      * @param cms ths cms object
231      * @throws Exception if something goes wrong
232      */

233     public abstract void write(CmsObject cms) throws Exception JavaDoc;
234
235     /**
236      * returns true if the CD is readable for the current user
237      * @return true
238      */

239     public boolean isReadable() {
240
241         return true;
242     }
243
244     /**
245      * returns true if the CD is writeable for the current user
246      * @return true
247      */

248     public boolean isWriteable() {
249
250         return true;
251     }
252
253     /**
254      * Set the owner of the CD.<p>
255      *
256      * @param userId the id of the owner
257      */

258     public void setOwner(CmsUUID userId) {
259
260         m_userId = userId;
261     }
262
263     /**
264      * get the owner of the CD
265      * @return id of the owner (int)
266      */

267     public CmsUUID getOwner() {
268
269         return m_userId;
270     }
271
272     /**
273      * set the group of the CD
274      * @param group the group ID
275      */

276     public void setGroup(String JavaDoc group) {
277
278         m_group = group;
279     }
280
281     /**
282      * get the group of the CD
283      * @return the group ID
284      */

285     public String JavaDoc getGroup() {
286
287         return m_group;
288     }
289
290     /**
291      * set the accessFlag for the CD
292      * @param accessFlags the accessFlag
293      */

294     public void setAccessFlags(int accessFlags) {
295
296         m_accessFlags = accessFlags;
297     }
298
299     /**
300      * get the accessFlag for the CD
301      * @return the accessFlag
302      */

303     public int getAccessFlags() {
304
305         return m_accessFlags;
306     }
307
308     /**
309      * has the current user the right to read the CD.<p>
310      *
311      * @param cms the cms object
312      * @return a boolean
313      * @throws CmsException if something goes wrong
314      */

315     protected boolean hasReadAccess(CmsObject cms) throws CmsException {
316
317         CmsUser currentUser = cms.getRequestContext().currentUser();
318
319         if (!accessOther(com.opencms.core.I_CmsConstants.C_ACCESS_PUBLIC_READ)
320             && !accessOwner(cms, currentUser, CmsPermissionSet.PERMISSION_READ)
321             && !accessGroup(cms, currentUser, com.opencms.core.I_CmsConstants.C_ACCESS_GROUP_READ)) {
322             return false;
323         }
324         return true;
325     }
326
327     /**
328      * has the current user the right to write the CD.<p>
329      *
330      * @param cms the cms object
331      * @return a boolean
332      * @throws CmsException if something goes wrong
333      */

334     public boolean hasWriteAccess(CmsObject cms) throws CmsException {
335
336         CmsUser currentUser = cms.getRequestContext().currentUser();
337         // check, if the resource is locked by the current user
338

339         if (isLockable() && (!getLockstate().equals(currentUser.getId()))) {
340             // resource is not locked by the current user, no writing allowed
341
return false;
342         }
343
344         // check the rights for the current resource
345
if (!(accessOther(com.opencms.core.I_CmsConstants.C_ACCESS_PUBLIC_WRITE)
346             || accessOwner(cms, currentUser, CmsPermissionSet.PERMISSION_WRITE) || accessGroup(
347             cms,
348             currentUser,
349             com.opencms.core.I_CmsConstants.C_ACCESS_GROUP_WRITE))) {
350             // no write access to this resource!
351
return false;
352         }
353         return true;
354     }
355
356     /**
357      * Checks, if the owner may access this resource.<p>
358      *
359      * @param cms the cmsObject
360      * @param currentUser The user who requested this method
361      * @param flags The flags to check
362      *
363      * @return wether the user has access, or not.
364      * @throws CmsException if something goes wrong
365      */

366     protected boolean accessOwner(CmsObject cms, CmsUser currentUser, int flags) throws CmsException {
367
368         // is the resource owned by this user?
369
if (currentUser.getId().equals(getOwner())) {
370             if ((getAccessFlags() & flags) == flags) {
371                 return true;
372             }
373         }
374
375         // the resource isn't accesible by the user.
376
return false;
377     }
378
379     /**
380      * Checks, if the group may access this resource.<p>
381      *
382      * @param cms the cmsObject
383      * @param currentUser The user who requested this method
384      * @param flags The flags to check
385      *
386      * @return wether the user has access, or not
387      * @throws CmsException if something goes wrong
388      */

389     protected boolean accessGroup(CmsObject cms, CmsUser currentUser, int flags) throws CmsException {
390
391         // is the user in the group for the resource?
392
if (cms.userInGroup(currentUser.getName(), getGroup())) {
393             if ((getAccessFlags() & flags) == flags) {
394                 return true;
395             }
396         }
397
398         // the resource isn't accesible by the user.
399
return false;
400     }
401
402     /**
403      * Checks, if others may access this resource.<p>
404      *
405      * @param flags The flags to check
406      * @return wether the user has access, or not.
407      * @throws CmsException if something goes wrong
408      */

409     protected boolean accessOther(int flags) throws CmsException {
410
411         return ((getAccessFlags() & flags) == flags);
412     }
413
414     /**
415      * if the content definition objects should be displayed
416      * in an extended list with projectflags and state
417      * this method must be overwritten with value true
418      * @return a boolean
419      */

420     public static boolean isExtendedList() {
421
422         return false;
423     }
424
425     /**
426      * if the content definition objects are timecritical
427      * this method must be overwritten with value true.
428      * @return a boolean
429      */

430     public boolean isTimedContent() {
431
432         return false;
433     }
434 }
Popular Tags