KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > db > CmsSecurityManager


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/db/CmsSecurityManager.java,v $
3  * Date : $Date: 2006/10/27 13:39:29 $
4  * Version: $Revision: 1.99 $
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.db;
33
34 import org.opencms.configuration.CmsConfigurationManager;
35 import org.opencms.configuration.CmsSystemConfiguration;
36 import org.opencms.file.CmsBackupProject;
37 import org.opencms.file.CmsBackupResource;
38 import org.opencms.file.CmsFile;
39 import org.opencms.file.CmsFolder;
40 import org.opencms.file.CmsGroup;
41 import org.opencms.file.CmsObject;
42 import org.opencms.file.CmsProject;
43 import org.opencms.file.CmsProperty;
44 import org.opencms.file.CmsPropertyDefinition;
45 import org.opencms.file.CmsRequestContext;
46 import org.opencms.file.CmsResource;
47 import org.opencms.file.CmsResourceFilter;
48 import org.opencms.file.CmsUser;
49 import org.opencms.file.CmsVfsException;
50 import org.opencms.file.CmsVfsResourceNotFoundException;
51 import org.opencms.file.types.CmsResourceTypeJsp;
52 import org.opencms.i18n.CmsMessageContainer;
53 import org.opencms.lock.CmsLock;
54 import org.opencms.lock.CmsLockException;
55 import org.opencms.main.CmsException;
56 import org.opencms.main.CmsInitException;
57 import org.opencms.main.CmsLog;
58 import org.opencms.main.CmsMultiException;
59 import org.opencms.main.OpenCms;
60 import org.opencms.report.I_CmsReport;
61 import org.opencms.security.CmsAccessControlEntry;
62 import org.opencms.security.CmsAccessControlList;
63 import org.opencms.security.CmsPermissionSet;
64 import org.opencms.security.CmsPermissionSetCustom;
65 import org.opencms.security.CmsPermissionViolationException;
66 import org.opencms.security.CmsRole;
67 import org.opencms.security.CmsRoleViolationException;
68 import org.opencms.security.CmsSecurityException;
69 import org.opencms.security.I_CmsPrincipal;
70 import org.opencms.util.CmsFileUtil;
71 import org.opencms.util.CmsStringUtil;
72 import org.opencms.util.CmsUUID;
73 import org.opencms.workflow.CmsTask;
74 import org.opencms.workflow.CmsTaskLog;
75
76 import java.util.ArrayList JavaDoc;
77 import java.util.Collections JavaDoc;
78 import java.util.Date JavaDoc;
79 import java.util.Iterator JavaDoc;
80 import java.util.List JavaDoc;
81 import java.util.Map JavaDoc;
82 import java.util.Set JavaDoc;
83 import java.util.regex.Pattern JavaDoc;
84 import java.util.regex.PatternSyntaxException JavaDoc;
85
86 import org.apache.commons.collections.map.LRUMap;
87 import org.apache.commons.logging.Log;
88
89 /**
90  * The OpenCms security manager.<p>
91  *
92  * The security manager checks the permissions required for a user action invoke by the Cms object. If permissions
93  * are granted, the security manager invokes a method on the OpenCms driver manager to access the database.<p>
94  *
95  * @author Thomas Weckert
96  * @author Michael Moossen
97  *
98  * @since 6.0.0
99  */

100 public final class CmsSecurityManager {
101
102     /** Indicates allowed permissions. */
103     public static final int PERM_ALLOWED = 0;
104
105     /** Indicates denied permissions. */
106     public static final int PERM_DENIED = 1;
107
108     /** Indicates a resource was filtered during permission check. */
109     public static final int PERM_FILTERED = 2;
110
111     /** Indicates a resource was not locked for a write / control operation. */
112     public static final int PERM_NOTLOCKED = 3;
113
114     /** The log object for this class. */
115     private static final Log LOG = CmsLog.getLog(CmsSecurityManager.class);
116
117     /** Indicates allowed permissions. */
118     private static final Integer JavaDoc PERM_ALLOWED_INTEGER = new Integer JavaDoc(PERM_ALLOWED);
119
120     /** Indicates denied permissions. */
121     private static final Integer JavaDoc PERM_DENIED_INTEGER = new Integer JavaDoc(PERM_DENIED);
122
123     /** The factory to create runtime info objects. */
124     protected I_CmsDbContextFactory m_dbContextFactory;
125
126     /** The initialized OpenCms driver manager to access the database. */
127     protected CmsDriverManager m_driverManager;
128
129     /** The class used for cache key generation. */
130     private I_CmsCacheKey m_keyGenerator;
131
132     /** Cache for permission checks. */
133     private Map JavaDoc m_permissionCache;
134
135     /**
136      * Default constructor.<p>
137      */

138     private CmsSecurityManager() {
139
140         // intentionally left blank
141
}
142
143     /**
144      * Creates a new instance of the OpenCms security manager.<p>
145      *
146      * @param configurationManager the configuation manager
147      * @param runtimeInfoFactory the initialized OpenCms runtime info factory
148      *
149      * @return a new instance of the OpenCms security manager
150      *
151      * @throws CmsInitException if the securtiy manager could not be initialized
152      */

153     public static CmsSecurityManager newInstance(
154         CmsConfigurationManager configurationManager,
155         I_CmsDbContextFactory runtimeInfoFactory) throws CmsInitException {
156
157         if (OpenCms.getRunLevel() > OpenCms.RUNLEVEL_2_INITIALIZING) {
158             // OpenCms is already initialized
159
throw new CmsInitException(org.opencms.main.Messages.get().container(
160                 org.opencms.main.Messages.ERR_ALREADY_INITIALIZED_0));
161         }
162
163         CmsSecurityManager securityManager = new CmsSecurityManager();
164         securityManager.init(configurationManager, runtimeInfoFactory);
165
166         return securityManager;
167     }
168
169     /**
170      * Updates the state of the given task as accepted by the current user.<p>
171      *
172      * @param context the current request context
173      * @param taskId the Id of the task to accept
174      *
175      * @throws CmsException if something goes wrong
176      */

177     public void acceptTask(CmsRequestContext context, int taskId) throws CmsException {
178
179         CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
180         try {
181             m_driverManager.acceptTask(dbc, taskId);
182         } catch (Exception JavaDoc e) {
183             dbc.report(null, Messages.get().container(Messages.ERR_ACCEPT_TASK_1, new Integer JavaDoc(taskId)), e);
184         } finally {
185             dbc.clear();
186         }
187     }
188
189     /**
190      * Adds a user to a group.<p>
191      *
192      * @param context the current request context
193      * @param username the name of the user that is to be added to the group
194      * @param groupname the name of the group
195      *
196      * @throws CmsException if operation was not succesfull
197      */

198     public void addUserToGroup(CmsRequestContext context, String JavaDoc username, String JavaDoc groupname) throws CmsException {
199
200         CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
201         try {
202             checkRole(dbc, CmsRole.ACCOUNT_MANAGER);
203             m_driverManager.addUserToGroup(dbc, username, groupname);
204         } catch (Exception JavaDoc e) {
205             dbc.report(null, Messages.get().container(Messages.ERR_ADD_USER_GROUP_FAILED_2, username, groupname), e);
206         } finally {
207             dbc.clear();
208         }
209     }
210
211     /**
212      * Creates a new web user.<p>
213      *
214      * A web user has no access to the workplace but is able to access personalized
215      * functions controlled by the OpenCms.<br>
216      *
217      * Moreover, a web user can be created by any user, the intention being that
218      * a "Guest" user can create a personalized account for himself.<p>
219      *
220      * @param context the current request context
221      * @param name the new name for the user
222      * @param password the new password for the user
223      * @param group the default groupname for the user
224      * @param description the description for the user
225      * @param additionalInfos a <code>{@link Map}</code> with additional infos for the user
226      *
227      * @return the new user will be returned
228      *
229      * @throws CmsException if operation was not succesfull
230      */

231     public CmsUser addWebUser(
232         CmsRequestContext context,
233         String JavaDoc name,
234         String JavaDoc password,
235         String JavaDoc group,
236         String JavaDoc description,
237         Map JavaDoc additionalInfos) throws CmsException {
238
239         CmsUser result = null;
240         CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
241         try {
242             result = m_driverManager.addWebUser(dbc, name, password, group, description, additionalInfos);
243         } catch (Exception JavaDoc e) {
244             dbc.report(null, Messages.get().container(Messages.ERR_ADD_USER_WEB_1, name), e);
245         } finally {
246             dbc.clear();
247         }
248         return result;
249     }
250
251     /**
252      * Adds a web user to the Cms.<p>
253      *
254      * A web user has no access to the workplace but is able to access personalized
255      * functions controlled by the OpenCms.<p>
256      *
257      * @param context the current request context
258      * @param name the new name for the user
259      * @param password the new password for the user
260      * @param group the default groupname for the user
261      * @param additionalGroup an additional group for the user
262      * @param description the description for the user
263      * @param additionalInfos a Hashtable with additional infos for the user, these infos may be stored into the Usertables (depending on the implementation)
264      *
265      * @return the new user will be returned
266      * @throws CmsException if operation was not succesfull
267      */

268     public CmsUser addWebUser(
269         CmsRequestContext context,
270         String JavaDoc name,
271         String JavaDoc password,
272         String JavaDoc group,
273         String JavaDoc additionalGroup,
274         String JavaDoc description,
275         Map JavaDoc additionalInfos) throws CmsException {
276
277         CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
278         CmsUser result = null;
279         try {
280             result = m_driverManager.addWebUser(
281                 dbc,
282                 name,
283                 password,
284                 group,
285                 additionalGroup,
286                 description,
287                 additionalInfos);
288         } catch (Exception JavaDoc e) {
289             dbc.report(null, Messages.get().container(Messages.ERR_ADD_USER_WEB_1, name), e);
290         } finally {
291             dbc.clear();
292         }
293         return result;
294     }
295
296     /**
297      * Creates a backup of the current project.<p>
298      *
299      * @param context the current request context
300      * @param tagId the version of the backup
301      * @param publishDate the date of publishing
302      *
303      * @throws CmsException if operation was not succesful
304      */

305     public void backupProject(CmsRequestContext context, int tagId, long publishDate) throws CmsException {
306
307         CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
308         try {
309             m_driverManager.backupProject(dbc, tagId, publishDate);
310         } catch (Exception JavaDoc e) {
311             dbc.report(null, Messages.get().container(
312                 Messages.ERR_BACKUP_PROJECT_4,
313                 new Object JavaDoc[] {
314                     new Integer JavaDoc(tagId),
315                     dbc.currentProject().getName(),
316                     new Integer JavaDoc(dbc.currentProject().getId()),
317                     new Long JavaDoc(publishDate)}), e);
318         } finally {
319             dbc.clear();
320         }
321     }
322
323     /**
324      * Changes the project id of the resource to the current project, indicating that
325      * the resource was last modified in this project.<p>
326      *
327      * @param context the current request context
328      * @param resource theresource to apply this operation to
329      * @throws CmsException if something goes wrong
330      * @see org.opencms.file.types.I_CmsResourceType#changeLastModifiedProjectId(CmsObject, CmsSecurityManager, CmsResource)
331      */

332     public void changeLastModifiedProjectId(CmsRequestContext context, CmsResource resource) throws CmsException {
333
334         CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
335         try {
336             checkOfflineProject(dbc);
337             checkPermissions(dbc, resource, CmsPermissionSet.ACCESS_WRITE, true, CmsResourceFilter.ALL);
338             m_driverManager.changeLastModifiedProjectId(dbc, resource);
339         } catch (Exception JavaDoc e) {
340             dbc.report(null, Messages.get().container(
341                 Messages.ERR_CHANGE_LAST_MODIFIED_RESOURCE_IN_PROJECT_1,
342                 context.getSitePath(resource)), e);
343         } finally {
344             dbc.clear();
345         }
346
347     }
348
349     /**
350      * Changes the lock of a resource to the current user, that is "steals" the lock from another user.<p>
351      *
352      * @param context the current request context
353      * @param resource the resource to change the lock for
354      * @throws CmsException if something goes wrong
355      * @see org.opencms.file.types.I_CmsResourceType#changeLock(CmsObject, CmsSecurityManager, CmsResource)
356      */

357     public void changeLock(CmsRequestContext context, CmsResource resource) throws CmsException {
358
359         CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
360         checkOfflineProject(dbc);
361         try {
362             m_driverManager.changeLock(dbc, resource);
363         } catch (Exception JavaDoc e) {
364             dbc.report(null, Messages.get().container(
365                 Messages.ERR_CHANGE_LOCK_OF_RESOURCE_1,
366                 context.getSitePath(resource)), e);
367         } finally {
368             dbc.clear();
369         }
370     }
371
372     /**
373      * Returns a list with all sub resources of a given folder that have set the given property,
374      * matching the current property's value with the given old value and replacing it by a given new value.<p>
375      *
376      * @param context the current request context
377      * @param resource the resource on which property definition values are changed
378      * @param propertyDefinition the name of the propertydefinition to change the value
379      * @param oldValue the old value of the propertydefinition
380      * @param newValue the new value of the propertydefinition
381      * @param recursive if true, change recursively all property values on sub-resources (only for folders)
382      *
383      * @return a list with the <code>{@link CmsResource}</code>'s where the property value has been changed
384      *
385      * @throws CmsVfsException for now only when the search for the oldvalue failed.
386      * @throws CmsException if operation was not successful
387      */

388     public synchronized List changeResourcesInFolderWithProperty(
389         CmsRequestContext context,
390         CmsResource resource,
391         String JavaDoc propertyDefinition,
392         String JavaDoc oldValue,
393         String JavaDoc newValue,
394         boolean recursive) throws CmsException, CmsVfsException {
395
396         int todo = 0;
397         // check if this belongs here - should be in driver manager (?)
398

399         // collect the resources to look up
400
List resources = new ArrayList JavaDoc();
401         if (recursive) {
402             resources = readResourcesWithProperty(context, resource.getRootPath(), propertyDefinition);
403         } else {
404             resources.add(resource);
405         }
406
407         Pattern JavaDoc oldPattern;
408         try {
409             // compile regular expression pattern
410
oldPattern = Pattern.compile(oldValue);
411         } catch (PatternSyntaxException JavaDoc e) {
412             throw new CmsVfsException(Messages.get().container(
413                 Messages.ERR_CHANGE_RESOURCES_IN_FOLDER_WITH_PROP_4,
414                 new Object JavaDoc[] {propertyDefinition, oldValue, newValue, context.getSitePath(resource)}), e);
415         }
416
417         List changedResources = new ArrayList JavaDoc(resources.size());
418         // create permission set and filter to check each resource
419
CmsPermissionSet perm = CmsPermissionSet.ACCESS_WRITE;
420         CmsResourceFilter filter = CmsResourceFilter.IGNORE_EXPIRATION;
421         for (int i = 0; i < resources.size(); i++) {
422             // loop through found resources and check property values
423
CmsResource res = (CmsResource)resources.get(i);
424             // check resource state and permissions
425
try {
426                 checkPermissions(context, res, perm, true, filter);
427             } catch (Exception JavaDoc e) {
428                 // resource is deleted or not writable for current user
429
continue;
430             }
431             CmsProperty property = readPropertyObject(context, res, propertyDefinition, false);
432             String JavaDoc structureValue = property.getStructureValue();
433             String JavaDoc resourceValue = property.getResourceValue();
434             boolean changed = false;
435             if (structureValue != null && oldPattern.matcher(structureValue).matches()) {
436                 // change structure value
437
property.setStructureValue(newValue);
438                 changed = true;
439             }
440             if (resourceValue != null && oldPattern.matcher(resourceValue).matches()) {
441                 // change resource value
442
property.setResourceValue(newValue);
443                 changed = true;
444             }
445             if (changed) {
446                 // write property object if something has changed
447
writePropertyObject(context, res, property);
448                 changedResources.add(res);
449             }
450         }
451         return changedResources;
452     }
453
454     /**
455      * Changes the user type of the user.<p>
456      *
457      * @param context the current request context
458      * @param userId the id of the user to change
459      * @param userType the new usertype of the user
460      *
461      * @throws CmsException if something goes wrong
462      */

463     public void changeUserType(CmsRequestContext context, CmsUUID userId, int userType) throws CmsException {
464
465         CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
466
467         try {
468             checkRole(dbc, CmsRole.ACCOUNT_MANAGER);
469             m_driverManager.changeUserType(dbc, userId, userType);
470         } catch (Exception JavaDoc e) {
471             dbc.report(null, Messages.get().container(Messages.ERR_CHANGE_USER_TYPE_WITH_ID_1, userId.toString()), e);
472         } finally {
473             dbc.clear();
474         }
475     }
476
477     /**
478      * Changes the user type of the user.<p>
479
480      * Only the administrator can change the type.<p>
481      *
482      * @param context the current request context
483      * @param username the name of the user to change
484      * @param userType the new usertype of the user
485      * @throws CmsException if something goes wrong
486      */

487     public void changeUserType(CmsRequestContext context, String JavaDoc username, int userType) throws CmsException {
488
489         CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
490
491         try {
492             checkRole(dbc, CmsRole.ACCOUNT_MANAGER);
493             m_driverManager.changeUserType(dbc, username, userType);
494         } catch (Exception JavaDoc e) {
495             dbc.report(null, Messages.get().container(Messages.ERR_CHANGE_USER_TYPE_WITH_NAME_1, username), e);
496         } finally {
497             dbc.clear();
498         }
499     }
500
501     /**
502      * Checks if the current user has management access to the given project.<p>
503      *
504      * @param dbc the current database context
505      * @param project the project to check
506      *
507      * @throws CmsRoleViolationException if the user does not have the required role permissions
508      */

509     public void checkManagerOfProjectRole(CmsDbContext dbc, CmsProject project) throws CmsRoleViolationException {
510
511         if (!hasManagerOfProjectRole(dbc, project)) {
512             throw new CmsRoleViolationException(org.opencms.security.Messages.get().container(
513                 org.opencms.security.Messages.ERR_NOT_MANAGER_OF_PROJECT_2,
514                 dbc.currentUser().getName(),
515                 dbc.currentProject().getName()));
516         }
517     }
518
519     /**
520      * Checks if the project in the given database context is not the "Online" project,
521      * and throws an Exception if this is the case.<p>
522      *
523      * This is used to ensure a user is in an "Offline" project
524      * before write access to VFS resources is granted.<p>
525      *
526      * @param dbc the current OpenCms users database context
527      *
528      * @throws CmsVfsException if the project in the given database context is the "Online" project
529      */

530     public void checkOfflineProject(CmsDbContext dbc) throws CmsVfsException {
531
532         if (dbc.currentProject().isOnlineProject()) {
533             throw new CmsVfsException(org.opencms.file.Messages.get().container(
534                 org.opencms.file.Messages.ERR_NOT_ALLOWED_IN_ONLINE_PROJECT_0));
535         }
536     }
537
538     /**
539      * Performs a blocking permission check on a resource.<p>
540      *
541      * If the required permissions are not satisfied by the permissions the user has on the resource,
542      * an exception is thrown.<p>
543      *
544      * @param context the current request context
545      * @param resource the resource on which permissions are required
546      * @param requiredPermissions the set of permissions required to access the resource
547      * @param checkLock if true, the lock status of the resource is also checked
548      * @param filter the filter for the resource
549      *
550      * @throws CmsException in case of any i/o error
551      * @throws CmsSecurityException if the required permissions are not satisfied
552      *
553      * @see #checkPermissions(CmsRequestContext, CmsResource, CmsPermissionSet, int)
554      */

555     public void checkPermissions(
556         CmsRequestContext context,
557         CmsResource resource,
558         CmsPermissionSet requiredPermissions,
559         boolean checkLock,
560         CmsResourceFilter filter) throws CmsException, CmsSecurityException {
561
562         CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
563         try {
564             // check the access permissions
565
checkPermissions(dbc, resource, requiredPermissions, checkLock, filter);
566         } finally {
567             dbc.clear();
568         }
569     }
570
571     /**
572      * Checks if the current user has the permissions to publish the given publish list
573      * (which contains the information about the resources / project to publish).<p>
574      *
575      * @param dbc the current OpenCms users database context
576      * @param publishList the publish list to check (contains the information about the resources / project to publish)
577      *
578      * @throws CmsException if the user does not have the required permissions becasue of project lock state
579      * @throws CmsMultiException if issues occur like a direct publish is attempted on a resource
580      * whose parent folder is new or deleted in the offline project,
581      * or if the current user has no management access to the current project
582      */

583     public void checkPublishPermissions(CmsDbContext dbc, CmsPublishList publishList)
584     throws CmsException, CmsMultiException {
585
586         // is the current project an "offline" project?
587
checkOfflineProject(dbc);
588
589         // check if the current project is unlocked
590
if (dbc.currentProject().getFlags() != CmsProject.PROJECT_STATE_UNLOCKED) {
591             CmsMessageContainer errMsg = org.opencms.security.Messages.get().container(
592                 org.opencms.security.Messages.ERR_RESOURCE_LOCKED_1,
593                 dbc.currentProject().getName());
594             throw new CmsLockException(errMsg);
595         }
596
597         // check if this is a "direct publish" attempt
598
if (!publishList.isDirectPublish()) {
599             // check if the user is a manager of the current project, in this case he has publish permissions
600
checkManagerOfProjectRole(dbc, dbc.getRequestContext().currentProject());
601         } else {
602             // direct publish, create exception containers
603
CmsMultiException resourceIssues = new CmsMultiException();
604             CmsMultiException permissionIssues = new CmsMultiException();
605             // iterate all resources in the direct publish list
606
Iterator JavaDoc it = publishList.getDirectPublishResources().iterator();
607             List parentFolders = new ArrayList JavaDoc();
608             while (it.hasNext()) {
609                 CmsResource res = (CmsResource)it.next();
610                 // the parent folder must not be new or deleted
611
String JavaDoc parentFolder = CmsResource.getParentFolder(res.getRootPath());
612                 if ((parentFolder != null) && !parentFolders.contains(parentFolder)) {
613                     // check each parent folder only once
614
CmsResource parent = readResource(dbc, parentFolder, CmsResourceFilter.ALL);
615                     if (parent.getState() == CmsResource.STATE_DELETED) {
616                         // parent folder is deleted - direct publish not allowed
617
resourceIssues.addException(new CmsVfsException(Messages.get().container(
618                             Messages.ERR_DIRECT_PUBLISH_PARENT_DELETED_2,
619                             dbc.getRequestContext().removeSiteRoot(res.getRootPath()),
620                             parentFolder)));
621                     }
622                     if (parent.getState() == CmsResource.STATE_NEW) {
623                         // parent folder is new - direct publish not allowed
624
resourceIssues.addException(new CmsVfsException(Messages.get().container(
625                             Messages.ERR_DIRECT_PUBLISH_PARENT_NEW_2,
626                             dbc.removeSiteRoot(res.getRootPath()),
627                             parentFolder)));
628                     }
629                     // add checked parent folder to prevent duplicate checks
630
parentFolders.add(parentFolder);
631                 }
632                 // check if the user has the explicit permission to direct publish the selected resource
633
if (PERM_ALLOWED != hasPermissions(
634                     dbc.getRequestContext(),
635                     res,
636                     CmsPermissionSet.ACCESS_DIRECT_PUBLISH,
637                     true,
638                     CmsResourceFilter.ALL)) {
639
640                     // the user has no "direct publish" permissions on the resource
641
permissionIssues.addException(new CmsSecurityException(Messages.get().container(
642                         Messages.ERR_DIRECT_PUBLISH_NO_PERMISSIONS_1,
643                         dbc.removeSiteRoot(res.getRootPath()))));
644                 }
645             }
646
647             if (permissionIssues.hasExceptions()) {
648                 // there have been permission issues
649
if (hasManagerOfProjectRole(dbc, dbc.getRequestContext().currentProject())) {
650                     // if user is a manager of the project, permission issues are void because he can publish anyway
651
permissionIssues = new CmsMultiException();
652                 }
653             }
654             if (resourceIssues.hasExceptions() || permissionIssues.hasExceptions()) {
655                 // there are issues, permission check has failed
656
resourceIssues.addExceptions(permissionIssues.getExceptions());
657                 throw resourceIssues;
658             }
659         }
660         // no issues have been found , permissions are granted
661
}
662
663     /**
664      * Checks if the current user has the permissions to publish the given publish list
665      * (which contains the information about the resources / project to publish).<p>
666      *
667      * @param context the current request context
668      * @param publishList the publish list to check (contains the information about the resources / project to publish)
669      *
670      * @throws CmsException if the user does not have the required permissions becasue of project lock state
671      * @throws CmsMultiException if issues occur like a direct publish is attempted on a resource
672      * whose parent folder is new or deleted in the offline project,
673      * or if the current user has no management access to the current project
674      */

675     public void checkPublishPermissions(CmsRequestContext context, CmsPublishList publishList)
676     throws CmsException, CmsMultiException {
677
678         CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
679         try {
680             // check the access permissions
681
checkPublishPermissions(dbc, publishList);
682         } finally {
683             dbc.clear();
684         }
685     }
686
687     /**
688      * Checks if the user of the current database context
689      * has permissions to impersonate the given role.<p>
690      *
691      * @param dbc the current OpenCms users database context
692      * @param role the role to check
693      *
694      * @throws CmsRoleViolationException if the user does not have the required role permissions
695      */

696     public void checkRole(CmsDbContext dbc, CmsRole role) throws CmsRoleViolationException {
697
698         if (!hasRole(dbc, role)) {
699             throw role.createRoleViolationException(dbc.getRequestContext());
700         }
701     }
702
703     /**
704      * Checks if the user of the current database context
705      * has permissions to impersonate the given role.<p>
706      *
707      * @param context the current request context
708      * @param role the role to check
709      *
710      * @throws CmsRoleViolationException if the user does not have the required role permissions
711      */

712     public void checkRole(CmsRequestContext context, CmsRole role) throws CmsRoleViolationException {
713
714         CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
715         try {
716             checkRole(dbc, role);
717         } finally {
718             dbc.clear();
719         }
720     }
721
722     /**
723      * Changes the resource flags of a resource.<p>
724      *
725      * The resource flags are used to indicate various "special" conditions
726      * for a resource. Most notably, the "internal only" setting which signals
727      * that a resource can not be directly requested with it's URL.<p>
728      *
729      * @param context the current request context
730      * @param resource the resource to change the flags for
731      * @param flags the new resource flags for this resource
732      * @throws CmsException if something goes wrong
733      * @throws CmsSecurityException if the user has insufficient permission for the given resource (({@link CmsPermissionSet#ACCESS_WRITE} required).
734      * @see org.opencms.file.types.I_CmsResourceType#chflags(CmsObject, CmsSecurityManager, CmsResource, int)
735      */

736     public void chflags(CmsRequestContext context, CmsResource resource, int flags)
737     throws CmsException, CmsSecurityException {
738
739         CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
740         try {
741             checkOfflineProject(dbc);
742             checkPermissions(dbc, resource, CmsPermissionSet.ACCESS_WRITE, true, CmsResourceFilter.ALL);
743             m_driverManager.chflags(dbc, resource, flags);
744         } catch (Exception JavaDoc e) {
745             dbc.report(null, Messages.get().container(
746                 Messages.ERR_CHANGE_RESOURCE_FLAGS_1,
747                 context.getSitePath(resource)), e);
748         } finally {
749             dbc.clear();
750         }
751     }
752
753     /**
754      * Changes the resource type of a resource.<p>
755      *
756      * OpenCms handles resources according to the resource type,
757      * not the file suffix. This is e.g. why a JSP in OpenCms can have the
758      * suffix ".html" instead of ".jsp" only. Changing the resource type
759      * makes sense e.g. if you want to make a plain text file a JSP resource,
760      * or a binary file an image, etc.<p>
761      *
762      * @param context the current request context
763      * @param resource the resource to change the type for
764      * @param type the new resource type for this resource
765      *
766      * @throws CmsException if something goes wrong
767      * @throws CmsSecurityException if the user has insufficient permission for the given resource (({@link CmsPermissionSet#ACCESS_WRITE} required)).
768      *
769      * @see org.opencms.file.types.I_CmsResourceType#chtype(CmsObject, CmsSecurityManager, CmsResource, int)
770      * @see CmsObject#chtype(String, int)
771      */

772     public void chtype(CmsRequestContext context, CmsResource resource, int type)
773     throws CmsException, CmsSecurityException {
774
775         CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
776         try {
777             checkOfflineProject(dbc);
778             checkPermissions(dbc, resource, CmsPermissionSet.ACCESS_WRITE, true, CmsResourceFilter.ALL);
779             m_driverManager.chtype(dbc, resource, type);
780         } catch (Exception JavaDoc e) {
781             dbc.report(null, Messages.get().container(
782                 Messages.ERR_CHANGE_RESOURCE_TYPE_1,
783                 context.getSitePath(resource)), e);
784         } finally {
785             dbc.clear();
786         }
787     }
788
789     /**
790      * Copies the access control entries of a given resource to a destination resorce.<p>
791      *
792      * Already existing access control entries of the destination resource are removed.<p>
793      *
794      * @param context the current request context
795      * @param source the resource to copy the access control entries from
796      * @param destination the resource to which the access control entries are copied
797      *
798      * @throws CmsException if something goes wrong
799      * @throws CmsSecurityException if the user has insufficient permission for the given resource ({@link CmsPermissionSet#ACCESS_CONTROL} required).
800      */

801     public void copyAccessControlEntries(CmsRequestContext context, CmsResource source, CmsResource destination)
802     throws CmsException, CmsSecurityException {
803
804         CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
805         try {
806             checkOfflineProject(dbc);
807             checkPermissions(dbc, source, CmsPermissionSet.ACCESS_READ, true, CmsResourceFilter.ALL);
808             checkPermissions(dbc, destination, CmsPermissionSet.ACCESS_CONTROL, true, CmsResourceFilter.ALL);
809             m_driverManager.copyAccessControlEntries(dbc, source, destination, true);
810         } catch (Exception JavaDoc e) {
811             CmsRequestContext rc = context;
812             dbc.report(null, Messages.get().container(
813                 Messages.ERR_COPY_ACE_2,
814                 rc.removeSiteRoot(source.getRootPath()),
815                 rc.removeSiteRoot(destination.getRootPath())), e);
816         } finally {
817             dbc.clear();
818         }
819     }
820
821     /**
822      * Copies a resource.<p>
823      *
824      * You must ensure that the destination path is an absolute, valid and
825      * existing VFS path. Relative paths from the source are currently not supported.<p>
826      *
827      * The copied resource will always be locked to the current user
828      * after the copy operation.<p>
829      *
830      * In case the target resource already exists, it is overwritten with the
831      * source resource.<p>
832      *
833      * The <code>siblingMode</code> parameter controls how to handle siblings
834      * during the copy operation.<br>
835      * Possible values for this parameter are: <br>
836      * <ul>
837      * <li><code>{@link org.opencms.file.CmsResource#COPY_AS_NEW}</code></li>
838      * <li><code>{@link org.opencms.file.CmsResource#COPY_AS_SIBLING}</code></li>
839      * <li><code>{@link org.opencms.file.CmsResource#COPY_PRESERVE_SIBLING}</code></li>
840      * </ul><p>
841      *
842      * @param context the current request context
843      * @param source the resource to copy
844      * @param destination the name of the copy destination with complete path
845      * @param siblingMode indicates how to handle siblings during copy
846      *
847      * @throws CmsException if something goes wrong
848      * @throws CmsSecurityException if resource could not be copied
849      *
850      * @see CmsObject#copyResource(String, String, int)
851      * @see org.opencms.file.types.I_CmsResourceType#copyResource(CmsObject, CmsSecurityManager, CmsResource, String, int)
852      */

853     public void copyResource(CmsRequestContext context, CmsResource source, String JavaDoc destination, int siblingMode)
854     throws CmsException, CmsSecurityException {
855
856         CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
857         CmsRequestContext rc = context;
858         try {
859             checkOfflineProject(dbc);
860             checkPermissions(dbc, source, CmsPermissionSet.ACCESS_READ, true, CmsResourceFilter.ALL);
861             // target permissions will be checked later
862
m_driverManager.copyResource(dbc, source, destination, siblingMode);
863         } catch (Exception JavaDoc e) {
864             dbc.report(null, Messages.get().container(
865                 Messages.ERR_COPY_RESOURCE_2,
866                 rc.removeSiteRoot(source.getRootPath()),
867                 rc.removeSiteRoot(destination)), e);
868         } finally {
869             dbc.clear();
870         }
871     }
872
873     /**
874      * Copies a resource to the current project of the user.<p>
875      *
876      * @param context the current request context
877      * @param resource the resource to apply this operation to
878      * @throws CmsException if something goes wrong
879      * @throws CmsRoleViolationException if the current user does not have management access to the project.
880      * @see org.opencms.file.types.I_CmsResourceType#copyResourceToProject(CmsObject, CmsSecurityManager, CmsResource)
881      */

882     public void copyResourceToProject(CmsRequestContext context, CmsResource resource)
883     throws CmsException, CmsRoleViolationException {
884
885         CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
886         try {
887             checkOfflineProject(dbc);
888             checkManagerOfProjectRole(dbc, context.currentProject());
889
890             if (dbc.currentProject().getFlags() != CmsProject.PROJECT_STATE_UNLOCKED) {
891                 throw new CmsLockException(org.opencms.lock.Messages.get().container(
892                     org.opencms.lock.Messages.ERR_RESOURCE_LOCKED_1,
893                     dbc.currentProject().getName()));
894             }
895
896             m_driverManager.copyResourceToProject(dbc, resource);
897         } catch (Exception JavaDoc e) {
898             dbc.report(null, Messages.get().container(
899                 Messages.ERR_COPY_RESOURCE_TO_PROJECT_2,
900                 context.getSitePath(resource),
901                 context.currentProject().getName()), e);
902         } finally {
903             dbc.clear();
904         }
905     }
906
907     /**
908      * Counts the locked resources in this project.<p>
909      *
910      * @param context the current request context
911      * @param id the id of the project
912      *
913      * @return the amount of locked resources in this project
914      *
915      * @throws CmsException if something goes wrong
916      * @throws CmsRoleViolationException if the current user does not have management access to the project.
917      */

918     public int countLockedResources(CmsRequestContext context, int id) throws CmsException, CmsRoleViolationException {
919
920         CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
921         CmsProject project = null;
922         int result = 0;
923         try {
924             project = m_driverManager.readProject(dbc, id);
925             checkManagerOfProjectRole(dbc, project);
926             result = m_driverManager.countLockedResources(project);
927         } catch (Exception JavaDoc e) {
928             dbc.report(null, Messages.get().container(
929                 Messages.ERR_COUNT_LOCKED_RESOURCES_PROJECT_2,
930                 (project == null) ? "<failed to read>" : project.getName(),
931                 new Integer JavaDoc(id)), e);
932         } finally {
933             dbc.clear();
934         }
935         return result;
936     }
937
938     /**
939      * Counts the locked resources in a given folder.<p>
940      *
941      * @param context the current request context
942      * @param foldername the folder to search in
943      *
944      * @return the amount of locked resources in this project
945      *
946      * @throws CmsException if something goes wrong
947      */

948     public int countLockedResources(CmsRequestContext context, String JavaDoc foldername) throws CmsException {
949
950         CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
951         // perform a test for read permissions on the folder
952
readResource(dbc, foldername, CmsResourceFilter.ALL);
953         int result = 0;
954         try {
955             result = m_driverManager.countLockedResources(dbc, foldername);
956         } catch (Exception JavaDoc e) {
957             dbc.report(null, Messages.get().container(Messages.ERR_COUNT_LOCKED_RESOURCES_FOLDER_1, foldername), e);
958         } finally {
959             dbc.clear();
960         }
961         return result;
962     }
963
964     /**
965      * Creates a new user group.<p>
966      *
967      * @param context the current request context
968      * @param name the name of the new group
969      * @param description the description for the new group
970      * @param flags the flags for the new group
971      * @param parent the name of the parent group (or <code>null</code>)
972      *
973      * @return a <code>{@link CmsGroup}</code> object representing the newly created group
974      *
975      * @throws CmsException if operation was not successful.
976      * @throws CmsRoleViolationException if the role {@link CmsRole#ACCOUNT_MANAGER} is not owned by the current user.
977      *
978      */

979     public CmsGroup createGroup(CmsRequestContext context, String JavaDoc name, String JavaDoc description, int flags, String JavaDoc parent)
980     throws CmsException, CmsRoleViolationException {
981
982         CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
983
984         CmsGroup result = null;
985         try {
986             checkRole(dbc, CmsRole.ACCOUNT_MANAGER);
987             result = m_driverManager.createGroup(dbc, new CmsUUID(), name, description, flags, parent);
988         } catch (Exception JavaDoc e) {
989             dbc.report(null, Messages.get().container(Messages.ERR_CREATE_GROUP_1, name), e);
990         } finally {
991             dbc.clear();
992         }
993         return result;
994     }
995
996     /**
997      * Creates a project.<p>
998      *
999      * @param context the current request context
1000     * @param name the name of the project to create
1001     * @param description the description of the project
1002     * @param groupname the project user group to be set
1003     * @param managergroupname the project manager group to be set
1004     * @param projecttype the type of the project
1005     *
1006     * @return the created project
1007     *
1008     * @throws CmsException if something goes wrong
1009     * @throws CmsRoleViolationException if the current user does not own the role {@link CmsRole#PROJECT_MANAGER}.
1010     */

1011    public CmsProject createProject(
1012        CmsRequestContext context,
1013        String JavaDoc name,
1014        String JavaDoc description,
1015        String JavaDoc groupname,
1016        String JavaDoc managergroupname,
1017        int projecttype) throws CmsException, CmsRoleViolationException {
1018
1019        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
1020
1021        CmsProject result = null;
1022        try {
1023            checkRole(dbc, CmsRole.PROJECT_MANAGER);
1024            result = m_driverManager.createProject(dbc, name, description, groupname, managergroupname, projecttype);
1025        } catch (Exception JavaDoc e) {
1026
1027            dbc.report(null, Messages.get().container(Messages.ERR_CREATE_PROJECT_1, name), e);
1028        } finally {
1029            dbc.clear();
1030        }
1031        return result;
1032    }
1033
1034    /**
1035     * Creates a property definition.<p>
1036     *
1037     * Property definitions are valid for all resource types.<p>
1038     *
1039     * @param context the current request context
1040     * @param name the name of the property definition to create
1041     *
1042     * @return the created property definition
1043     *
1044     * @throws CmsException if something goes wrong
1045     * @throws CmsSecurityException if the current project is online.
1046     * @throws CmsRoleViolationException if the current user does not own the role {@link CmsRole#PROPERTY_MANAGER}.
1047     */

1048    public CmsPropertyDefinition createPropertyDefinition(CmsRequestContext context, String JavaDoc name)
1049    throws CmsException, CmsSecurityException, CmsRoleViolationException {
1050
1051        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
1052        CmsPropertyDefinition result = null;
1053
1054        try {
1055            checkOfflineProject(dbc);
1056            checkRole(dbc, CmsRole.PROPERTY_MANAGER);
1057            result = m_driverManager.createPropertyDefinition(dbc, name);
1058        } catch (Exception JavaDoc e) {
1059            dbc.report(null, Messages.get().container(Messages.ERR_CREATE_PROPDEF_1, name), e);
1060        } finally {
1061            dbc.clear();
1062        }
1063        return result;
1064    }
1065
1066    /**
1067     * Creates a new resource of the given resource type with the provided content and properties.<p>
1068     *
1069     * If the provided content is null and the resource is not a folder, the content will be set to an empty byte array.<p>
1070     *
1071     * @param context the current request context
1072     * @param resourcename the name of the resource to create (full path)
1073     * @param type the type of the resource to create
1074     * @param content the content for the new resource
1075     * @param properties the properties for the new resource
1076     * @return the created resource
1077     * @throws CmsException if something goes wrong
1078     *
1079     * @see org.opencms.file.types.I_CmsResourceType#createResource(CmsObject, CmsSecurityManager, String, byte[], List)
1080     */

1081    public CmsResource createResource(
1082        CmsRequestContext context,
1083        String JavaDoc resourcename,
1084        int type,
1085        byte[] content,
1086        List properties) throws CmsException {
1087
1088        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
1089        CmsResource newResource = null;
1090        try {
1091            checkOfflineProject(dbc);
1092            newResource = m_driverManager.createResource(dbc, resourcename, type, content, properties);
1093        } catch (Exception JavaDoc e) {
1094            dbc.report(null, Messages.get().container(Messages.ERR_CREATE_RESOURCE_1, resourcename), e);
1095        } finally {
1096            dbc.clear();
1097        }
1098        return newResource;
1099    }
1100
1101    /**
1102     * Creates a new sibling of the source resource.<p>
1103     *
1104     * @param context the current request context
1105     * @param source the resource to create a sibling for
1106     * @param destination the name of the sibling to create with complete path
1107     * @param properties the individual properties for the new sibling
1108     * @throws CmsException if something goes wrong
1109     * @see org.opencms.file.types.I_CmsResourceType#createSibling(CmsObject, CmsSecurityManager, CmsResource, String, List)
1110     */

1111    public void createSibling(CmsRequestContext context, CmsResource source, String JavaDoc destination, List properties)
1112    throws CmsException {
1113
1114        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
1115        try {
1116            checkOfflineProject(dbc);
1117            m_driverManager.createSibling(dbc, source, destination, properties);
1118        } catch (Exception JavaDoc e) {
1119            dbc.report(null, Messages.get().container(
1120                Messages.ERR_CREATE_SIBLING_1,
1121                context.removeSiteRoot(source.getRootPath())), e);
1122        } finally {
1123            dbc.clear();
1124        }
1125    }
1126
1127    /**
1128     * Creates a new task.<p>
1129     *
1130     * @param context the current request context
1131     * @param currentUser the current user
1132     * @param projectid the current project id
1133     * @param agentName user who will edit the task
1134     * @param roleName usergroup for the task
1135     * @param taskName name of the task
1136     * @param taskType type of the task
1137     * @param taskComment description of the task
1138     * @param timeout time when the task must finished
1139     * @param priority Id for the priority
1140     *
1141     * @return a new task object
1142     *
1143     * @throws CmsException if something goes wrong
1144     */

1145    public CmsTask createTask(
1146        CmsRequestContext context,
1147        CmsUser currentUser,
1148        int projectid,
1149        String JavaDoc agentName,
1150        String JavaDoc roleName,
1151        String JavaDoc taskName,
1152        String JavaDoc taskComment,
1153        int taskType,
1154        long timeout,
1155        int priority) throws CmsException {
1156
1157        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
1158        CmsTask result = null;
1159        try {
1160            result = m_driverManager.createTask(
1161                dbc,
1162                currentUser,
1163                projectid,
1164                agentName,
1165                roleName,
1166                taskName,
1167                taskComment,
1168                taskType,
1169                timeout,
1170                priority);
1171        } catch (Exception JavaDoc e) {
1172            dbc.report(null, Messages.get().container(Messages.ERR_CREATE_TASK_1, taskName), e);
1173        } finally {
1174            dbc.clear();
1175        }
1176        return result;
1177    }
1178
1179    /**
1180     * Creates a new task.<p>
1181     *
1182     * This is just a more limited version of the
1183     * <code>{@link #createTask(CmsRequestContext, CmsUser, int, String, String, String, String, int, long, int)}</code>
1184     * method, where: <br>
1185     * <ul>
1186     * <il>the project id is the current project id.</il>
1187     * <il>the task type is the standard task type <b>1</b>.</il>
1188     * <il>with no comments</il>
1189     * </ul><p>
1190     *
1191     * @param context the current request context
1192     * @param agentName the user who will edit the task
1193     * @param roleName a usergroup for the task
1194     * @param taskname the name of the task
1195     * @param timeout the time when the task must finished
1196     * @param priority the id for the priority of the task
1197     *
1198     * @return the created task
1199     *
1200     * @throws CmsException if something goes wrong
1201     */

1202    public CmsTask createTask(
1203        CmsRequestContext context,
1204        String JavaDoc agentName,
1205        String JavaDoc roleName,
1206        String JavaDoc taskname,
1207        long timeout,
1208        int priority) throws CmsException {
1209
1210        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
1211        CmsTask result = null;
1212        try {
1213            result = m_driverManager.createTask(dbc, agentName, roleName, taskname, timeout, priority);
1214        } catch (Exception JavaDoc e) {
1215            dbc.report(null, Messages.get().container(Messages.ERR_CREATE_TASK_1, taskname), e);
1216        } finally {
1217            dbc.clear();
1218        }
1219        return result;
1220    }
1221
1222    /**
1223     * Creates the project for the temporary workplace files.<p>
1224     *
1225     * @param context the current request context
1226     *
1227     * @return the created project for the temporary workplace files
1228     *
1229     * @throws CmsException if something goes wrong
1230     */

1231    public CmsProject createTempfileProject(CmsRequestContext context) throws CmsException {
1232
1233        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
1234
1235        CmsProject result = null;
1236        try {
1237            checkRole(dbc, CmsRole.PROJECT_MANAGER);
1238            result = m_driverManager.createTempfileProject(dbc);
1239        } catch (Exception JavaDoc e) {
1240            dbc.report(null, Messages.get().container(Messages.ERR_CREATE_TEMPFILE_PROJECT_0), e);
1241        } finally {
1242            dbc.clear();
1243        }
1244        return result;
1245    }
1246
1247    /**
1248     * Creates a new user.<p>
1249     *
1250     * @param context the current request context
1251     * @param name the name for the new user
1252     * @param password the password for the new user
1253     * @param description the description for the new user
1254     * @param additionalInfos the additional infos for the user
1255     *
1256     * @return the created user
1257     *
1258     * @see CmsObject#createUser(String, String, String, Map)
1259     *
1260     * @throws CmsException if something goes wrong
1261     * @throws CmsRoleViolationException if the current user does not own the rule {@link CmsRole#ACCOUNT_MANAGER}
1262     */

1263    public CmsUser createUser(
1264        CmsRequestContext context,
1265        String JavaDoc name,
1266        String JavaDoc password,
1267        String JavaDoc description,
1268        Map JavaDoc additionalInfos) throws CmsException, CmsRoleViolationException {
1269
1270        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
1271
1272        CmsUser result = null;
1273        try {
1274            checkRole(dbc, CmsRole.ACCOUNT_MANAGER);
1275            result = m_driverManager.createUser(dbc, name, password, description, additionalInfos);
1276        } catch (Exception JavaDoc e) {
1277            dbc.report(null, Messages.get().container(Messages.ERR_CREATE_USER_1, name), e);
1278        } finally {
1279            dbc.clear();
1280        }
1281        return result;
1282    }
1283
1284    /**
1285     * Deletes all entries in the published resource table.<p>
1286     *
1287     * @param context the current request context
1288     * @param linkType the type of resource deleted (0= non-paramter, 1=parameter)
1289     *
1290     * @throws CmsException if something goes wrong
1291     */

1292    public void deleteAllStaticExportPublishedResources(CmsRequestContext context, int linkType) throws CmsException {
1293
1294        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
1295        try {
1296            m_driverManager.deleteAllStaticExportPublishedResources(dbc, linkType);
1297        } catch (Exception JavaDoc e) {
1298            dbc.report(null, Messages.get().container(Messages.ERR_DELETE_STATEXP_PUBLISHED_RESOURCES_0), e);
1299        } finally {
1300            dbc.clear();
1301        }
1302    }
1303
1304    /**
1305     * Deletes the versions from the backup tables that are older then the given timestamp
1306     * and/or number of remaining versions.<p>
1307     *
1308     * The number of verions always wins, i.e. if the given timestamp would delete more versions
1309     * than given in the versions parameter, the timestamp will be ignored. <p>
1310     *
1311     * Deletion will delete file header, content and properties. <p>
1312     *
1313     * @param context the current request context
1314     * @param timestamp timestamp which defines the date after which backup resources must be deleted
1315     * @param versions the number of versions per file which should kept in the system
1316     * @param report the report for output logging
1317     *
1318     * @throws CmsException if operation was not succesful
1319     * @throws CmsRoleViolationException if the current user does not own the rule {@link CmsRole#HISTORY_MANAGER}
1320     */

1321    public void deleteBackups(CmsRequestContext context, long timestamp, int versions, I_CmsReport report)
1322    throws CmsException, CmsRoleViolationException {
1323
1324        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
1325        try {
1326            checkRole(dbc, CmsRole.HISTORY_MANAGER);
1327            m_driverManager.deleteBackups(dbc, timestamp, versions, report);
1328        } catch (Exception JavaDoc e) {
1329            dbc.report(null, Messages.get().container(
1330                Messages.ERR_DELETE_BACKUPS_2,
1331                new Date JavaDoc(timestamp),
1332                new Integer JavaDoc(versions)), e);
1333        } finally {
1334            dbc.clear();
1335        }
1336    }
1337
1338    /**
1339     * Deletes a group, where all permissions, users and childs of the group
1340     * are transfered to a replacement group.<p>
1341     *
1342     * @param context the current request context
1343     * @param groupId the id of the group to be deleted
1344     * @param replacementId the id of the group to be transfered, can be <code>null</code>
1345     *
1346     * @throws CmsException if operation was not succesful
1347     * @throws CmsSecurityException if the group is a default group.
1348     * @throws CmsRoleViolationException if the current user does not own the rule {@link CmsRole#ACCOUNT_MANAGER}
1349     */

1350    public void deleteGroup(CmsRequestContext context, CmsUUID groupId, CmsUUID replacementId)
1351    throws CmsException, CmsRoleViolationException, CmsSecurityException {
1352
1353        CmsGroup group = readGroup(context, groupId);
1354        if (OpenCms.getDefaultUsers().isDefaultGroup(group.getName())) {
1355            throw new CmsSecurityException(Messages.get().container(
1356                Messages.ERR_CONSTRAINT_DELETE_GROUP_DEFAULT_1,
1357                group.getName()));
1358        }
1359        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
1360        try {
1361            // catch own exception as special cause for general "Error deleting group".
1362
checkRole(dbc, CmsRole.ACCOUNT_MANAGER);
1363            // this is needed because
1364
// I_CmsUserDriver#removeAccessControlEntriesForPrincipal(CmsDbContext, CmsProject, CmsProject, CmsUUID)
1365
// expects an offline project, if not data will become inconsistent
1366
checkOfflineProject(dbc);
1367            m_driverManager.deleteGroup(dbc, group, replacementId);
1368        } catch (Exception JavaDoc e) {
1369            dbc.report(null, Messages.get().container(Messages.ERR_DELETE_GROUP_1, group.getName()), e);
1370        } finally {
1371            dbc.clear();
1372        }
1373    }
1374
1375    /**
1376     * Delete a user group.<p>
1377     *
1378     * Only groups that contain no subgroups can be deleted.<p>
1379     *
1380     * @param context the current request context
1381     * @param name the name of the group that is to be deleted
1382     *
1383     * @throws CmsException if operation was not succesful
1384     * @throws CmsSecurityException if the group is a default group.
1385     * @throws CmsRoleViolationException if the current user does not own the rule {@link CmsRole#ACCOUNT_MANAGER}
1386     *
1387     */

1388    public void deleteGroup(CmsRequestContext context, String JavaDoc name)
1389    throws CmsException, CmsRoleViolationException, CmsSecurityException {
1390
1391        if (OpenCms.getDefaultUsers().isDefaultGroup(name)) {
1392            throw new CmsSecurityException(Messages.get().container(
1393                Messages.ERR_CONSTRAINT_DELETE_GROUP_DEFAULT_1,
1394                name));
1395        }
1396        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
1397        try {
1398            // catch own exception as special cause for general "Error deleting group".
1399
checkRole(dbc, CmsRole.ACCOUNT_MANAGER);
1400            // this is needed because
1401
// I_CmsUserDriver#removeAccessControlEntriesForPrincipal(CmsDbContext, CmsProject, CmsProject, CmsUUID)
1402
// expects an offline project, if not data will become inconsistent
1403
checkOfflineProject(dbc);
1404            m_driverManager.deleteGroup(dbc, name);
1405        } catch (Exception JavaDoc e) {
1406            dbc.report(null, Messages.get().container(Messages.ERR_DELETE_GROUP_1, name), e);
1407        } finally {
1408            dbc.clear();
1409        }
1410    }
1411
1412    /**
1413     * Deletes a project.<p>
1414     *
1415     * All modified resources currently inside this project will be reset to their online state.<p>
1416     *
1417     * @param context the current request context
1418     * @param projectId the ID of the project to be deleted
1419     *
1420     * @throws CmsException if something goes wrong
1421     * @throws CmsRoleViolationException if the current user does not own management access to the project
1422     */

1423    public void deleteProject(CmsRequestContext context, int projectId) throws CmsException, CmsRoleViolationException {
1424
1425        if (projectId == CmsProject.ONLINE_PROJECT_ID) {
1426            // online project must not be deleted
1427
throw new CmsVfsException(org.opencms.file.Messages.get().container(
1428                org.opencms.file.Messages.ERR_NOT_ALLOWED_IN_ONLINE_PROJECT_0));
1429        }
1430
1431        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
1432        CmsProject deleteProject = null;
1433        try {
1434            // read the project that should be deleted
1435
deleteProject = m_driverManager.readProject(dbc, projectId);
1436            checkManagerOfProjectRole(dbc, deleteProject);
1437            m_driverManager.deleteProject(dbc, deleteProject);
1438        } catch (Exception JavaDoc e) {
1439            String JavaDoc projectName = deleteProject == null ? String.valueOf(projectId) : deleteProject.getName();
1440            dbc.report(null, Messages.get().container(Messages.ERR_DELETE_PROJECT_1, projectName), e);
1441        } finally {
1442            dbc.clear();
1443        }
1444    }
1445
1446    /**
1447     * Deletes a property definition.<p>
1448     *
1449     * @param context the current request context
1450     * @param name the name of the property definition to delete
1451     *
1452     * @throws CmsException if something goes wrong
1453     * @throws CmsSecurityException if the project to delete is the "Online" project
1454     * @throws CmsRoleViolationException if the current user does not own the role {@link CmsRole#PROPERTY_MANAGER}
1455     */

1456    public void deletePropertyDefinition(CmsRequestContext context, String JavaDoc name)
1457    throws CmsException, CmsSecurityException, CmsRoleViolationException {
1458
1459        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
1460        try {
1461            checkOfflineProject(dbc);
1462            checkRole(dbc, CmsRole.PROPERTY_MANAGER);
1463            m_driverManager.deletePropertyDefinition(dbc, name);
1464        } catch (Exception JavaDoc e) {
1465            dbc.report(null, Messages.get().container(Messages.ERR_DELETE_PROPERTY_1, name), e);
1466        } finally {
1467            dbc.clear();
1468        }
1469    }
1470
1471    /**
1472     * Deletes a resource given its name.<p>
1473     *
1474     * The <code>siblingMode</code> parameter controls how to handle siblings
1475     * during the delete operation.<br>
1476     * Possible values for this parameter are: <br>
1477     * <ul>
1478     * <li><code>{@link org.opencms.file.CmsResource#DELETE_REMOVE_SIBLINGS}</code></li>
1479     * <li><code>{@link org.opencms.file.CmsResource#DELETE_PRESERVE_SIBLINGS}</code></li>
1480     * </ul><p>
1481     *
1482     * @param context the current request context
1483     * @param resource the name of the resource to delete (full path)
1484     * @param siblingMode indicates how to handle siblings of the deleted resource
1485     * @throws CmsException if something goes wrong
1486     * @throws CmsSecurityException if the user does not have {@link CmsPermissionSet#ACCESS_WRITE} on the given resource.
1487     * @see org.opencms.file.types.I_CmsResourceType#deleteResource(CmsObject, CmsSecurityManager, CmsResource, int)
1488     */

1489    public void deleteResource(CmsRequestContext context, CmsResource resource, int siblingMode)
1490    throws CmsException, CmsSecurityException {
1491
1492        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
1493        try {
1494            checkOfflineProject(dbc);
1495            checkPermissions(dbc, resource, CmsPermissionSet.ACCESS_WRITE, true, CmsResourceFilter.ALL);
1496            m_driverManager.deleteResource(dbc, resource, siblingMode);
1497        } catch (Exception JavaDoc e) {
1498            dbc.report(null, Messages.get().container(Messages.ERR_DELETE_RESOURCE_1, context.getSitePath(resource)), e);
1499        } finally {
1500            dbc.clear();
1501        }
1502    }
1503
1504    /**
1505     * Deletes an entry in the published resource table.<p>
1506     *
1507     * @param context the current request context
1508     * @param resourceName The name of the resource to be deleted in the static export
1509     * @param linkType the type of resource deleted (0= non-paramter, 1=parameter)
1510     * @param linkParameter the parameters ofthe resource
1511     *
1512     * @throws CmsException if something goes wrong
1513     */

1514    public void deleteStaticExportPublishedResource(
1515        CmsRequestContext context,
1516        String JavaDoc resourceName,
1517        int linkType,
1518        String JavaDoc linkParameter) throws CmsException {
1519
1520        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
1521        try {
1522            m_driverManager.deleteStaticExportPublishedResource(dbc, resourceName, linkType, linkParameter);
1523        } catch (Exception JavaDoc e) {
1524            dbc.report(
1525                null,
1526                Messages.get().container(Messages.ERR_DELETE_STATEXP_PUBLISHES_RESOURCE_1, resourceName),
1527                e);
1528        } finally {
1529            dbc.clear();
1530        }
1531    }
1532
1533    /**
1534     * Deletes a user.<p>
1535     *
1536     * @param context the current request context
1537     * @param userId the Id of the user to be deleted
1538     *
1539     * @throws CmsException if something goes wrong
1540     */

1541    public void deleteUser(CmsRequestContext context, CmsUUID userId) throws CmsException {
1542
1543        CmsUser user = readUser(context, userId);
1544        deleteUser(context, user, null);
1545    }
1546
1547    /**
1548     * Deletes a user, where all permissions and resources attributes of the user
1549     * were transfered to a replacement user.<p>
1550     *
1551     * @param context the current request context
1552     * @param userId the id of the user to be deleted
1553     * @param replacementId the id of the user to be transfered
1554     *
1555     * @throws CmsException if operation was not successful
1556     */

1557    public void deleteUser(CmsRequestContext context, CmsUUID userId, CmsUUID replacementId) throws CmsException {
1558
1559        CmsUser user = readUser(context, userId);
1560        CmsUser replacementUser = null;
1561        if (replacementId != null && !replacementId.isNullUUID()) {
1562            replacementUser = readUser(context, replacementId);
1563        }
1564        deleteUser(context, user, replacementUser);
1565    }
1566
1567    /**
1568     * Deletes a user.<p>
1569     *
1570     * @param context the current request context
1571     * @param username the name of the user to be deleted
1572     *
1573     * @throws CmsException if something goes wrong
1574     */

1575    public void deleteUser(CmsRequestContext context, String JavaDoc username) throws CmsException {
1576
1577        CmsUser user = readUser(context, username, CmsUser.USER_TYPE_SYSTEMUSER);
1578        deleteUser(context, user, null);
1579    }
1580
1581    /**
1582     * Deletes a web user.<p>
1583     *
1584     * @param context the current request context
1585     * @param userId the Id of the web user to be deleted
1586     *
1587     * @throws CmsException if something goes wrong
1588     */

1589    public void deleteWebUser(CmsRequestContext context, CmsUUID userId) throws CmsException {
1590
1591        CmsUser user = readUser(context, userId);
1592        deleteUser(context, user, null);
1593    }
1594
1595    /**
1596     * Destroys this security manager.<p>
1597     *
1598     * @throws Throwable if something goes wrong
1599     */

1600    public synchronized void destroy() throws Throwable JavaDoc {
1601
1602        finalize();
1603        if (CmsLog.INIT.isInfoEnabled()) {
1604            CmsLog.INIT.info(Messages.get().getBundle().key(
1605                Messages.INIT_SECURITY_MANAGER_SHUTDOWN_1,
1606                this.getClass().getName()));
1607        }
1608    }
1609
1610    /**
1611     * Ends a task.<p>
1612     *
1613     * @param context the current request context
1614     * @param taskid the ID of the task to end
1615     *
1616     * @throws CmsException if something goes wrong
1617     */

1618    public void endTask(CmsRequestContext context, int taskid) throws CmsException {
1619
1620        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
1621        try {
1622            m_driverManager.endTask(dbc, taskid);
1623        } catch (Exception JavaDoc e) {
1624            dbc.report(null, Messages.get().container(Messages.ERR_END_TASK_1, new Integer JavaDoc(taskid)), e);
1625        } finally {
1626            dbc.clear();
1627        }
1628    }
1629
1630    /**
1631     * Checks the availability of a resource in the VFS,
1632     * using the <code>{@link CmsResourceFilter#DEFAULT}</code> filter.<p>
1633     *
1634     * A resource may be of type <code>{@link CmsFile}</code> or
1635     * <code>{@link CmsFolder}</code>.<p>
1636     *
1637     * The specified filter controls what kind of resources should be "found"
1638     * during the read operation. This will depend on the application. For example,
1639     * using <code>{@link CmsResourceFilter#DEFAULT}</code> will only return currently
1640     * "valid" resources, while using <code>{@link CmsResourceFilter#IGNORE_EXPIRATION}</code>
1641     * will ignore the date release / date expired information of the resource.<p>
1642     *
1643     * This method also takes into account the user permissions, so if
1644     * the given resource exists, but the current user has not the required
1645     * permissions, then this method will return <code>false</code>.<p>
1646     *
1647     * @param context the current request context
1648     * @param resourcePath the name of the resource to read (full path)
1649     * @param filter the resource filter to use while reading
1650     *
1651     * @return <code>true</code> if the resource is available
1652     *
1653     * @see CmsObject#existsResource(String, CmsResourceFilter)
1654     * @see CmsObject#existsResource(String)
1655     */

1656    public boolean existsResource(CmsRequestContext context, String JavaDoc resourcePath, CmsResourceFilter filter) {
1657
1658        boolean result = false;
1659        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
1660        try {
1661            readResource(dbc, resourcePath, filter);
1662            result = true;
1663        } catch (Exception JavaDoc e) {
1664            result = false;
1665        } finally {
1666            dbc.clear();
1667        }
1668        return result;
1669    }
1670
1671    /**
1672     * Fills the given publish list with the the VFS resources that actually get published.<p>
1673     *
1674     * Please refer to the source code of this method for the rules on how to decide whether a
1675     * new/changed/deleted <code>{@link CmsResource}</code> object can be published or not.<p>
1676     *
1677     * @param context the current request context
1678     * @param publishList must be initialized with basic publish information (Project or direct publish operation)
1679     *
1680     * @return the given publish list filled with all new/changed/deleted files from the current (offline) project
1681     * that will be published actually
1682     *
1683     * @throws CmsException if something goes wrong
1684     *
1685     * @see org.opencms.db.CmsPublishList
1686     */

1687    public CmsPublishList fillPublishList(CmsRequestContext context, CmsPublishList publishList) throws CmsException {
1688
1689        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
1690        CmsPublishList result = null;
1691        try {
1692            result = m_driverManager.fillPublishList(dbc, publishList);
1693        } catch (Exception JavaDoc e) {
1694            if (publishList.isDirectPublish()) {
1695                dbc.report(null, Messages.get().container(
1696                    Messages.ERR_GET_PUBLISH_LIST_DIRECT_1,
1697                    CmsFileUtil.formatResourceNames(context, publishList.getDirectPublishResources())), e);
1698            } else {
1699                dbc.report(null, Messages.get().container(
1700                    Messages.ERR_GET_PUBLISH_LIST_PROJECT_1,
1701                    context.currentProject().getName()), e);
1702            }
1703        } finally {
1704            dbc.clear();
1705        }
1706        return result;
1707    }
1708
1709    /**
1710     * Forwards a task to a new user.<p>
1711     *
1712     * @param context the current request context
1713     * @param taskid the Id of the task to forward
1714     * @param newRoleName the new group name for the task
1715     * @param newUserName the new user who gets the task. if it is empty, a new agent will automatic selected
1716     *
1717     * @throws CmsException if something goes wrong
1718     */

1719    public void forwardTask(CmsRequestContext context, int taskid, String JavaDoc newRoleName, String JavaDoc newUserName)
1720    throws CmsException {
1721
1722        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
1723        try {
1724            m_driverManager.forwardTask(dbc, taskid, newRoleName, newUserName);
1725        } catch (Exception JavaDoc e) {
1726            dbc.report(null, Messages.get().container(
1727                Messages.ERR_FORWARD_TASK_3,
1728                new Integer JavaDoc(taskid),
1729                newUserName,
1730                newRoleName), e);
1731        } finally {
1732            dbc.clear();
1733        }
1734    }
1735
1736    /**
1737     * Returns the list of access control entries of a resource given its name.<p>
1738     *
1739     * @param context the current request context
1740     * @param resource the resource to read the access control entries for
1741     * @param getInherited true if the result should include all access control entries inherited by parent folders
1742     *
1743     * @return a list of <code>{@link CmsAccessControlEntry}</code> objects defining all permissions for the given resource
1744     *
1745     * @throws CmsException if something goes wrong
1746     */

1747    public List getAccessControlEntries(CmsRequestContext context, CmsResource resource, boolean getInherited)
1748    throws CmsException {
1749
1750        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
1751        List result = null;
1752        try {
1753            result = m_driverManager.getAccessControlEntries(dbc, resource, getInherited);
1754        } catch (Exception JavaDoc e) {
1755            dbc.report(null, Messages.get().container(Messages.ERR_GET_ACL_ENTRIES_1, context.getSitePath(resource)), e);
1756        } finally {
1757            dbc.clear();
1758        }
1759        return result;
1760    }
1761
1762    /**
1763     * Returns the access control list (summarized access control entries) of a given resource.<p>
1764     *
1765     * If <code>inheritedOnly</code> is set, only inherited access control entries are returned.<p>
1766     *
1767     * @param context the current request context
1768     * @param resource the resource
1769     * @param inheritedOnly skip non-inherited entries if set
1770     *
1771     * @return the access control list of the resource
1772     *
1773     * @throws CmsException if something goes wrong
1774     */

1775    public CmsAccessControlList getAccessControlList(
1776        CmsRequestContext context,
1777        CmsResource resource,
1778        boolean inheritedOnly) throws CmsException {
1779
1780        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
1781        CmsAccessControlList result = null;
1782        try {
1783            result = m_driverManager.getAccessControlList(dbc, resource, inheritedOnly);
1784        } catch (Exception JavaDoc e) {
1785            dbc.report(null, Messages.get().container(Messages.ERR_GET_ACL_ENTRIES_1, context.getSitePath(resource)), e);
1786
1787        } finally {
1788            dbc.clear();
1789        }
1790        return result;
1791    }
1792
1793    /**
1794     * Returns all projects which are owned by the current user or which are
1795     * accessible for the group of the user.<p>
1796     *
1797     * @param context the current request context
1798     *
1799     * @return a list of objects of type <code>{@link CmsProject}</code>
1800     *
1801     * @throws CmsException if something goes wrong
1802     */

1803    public List getAllAccessibleProjects(CmsRequestContext context) throws CmsException {
1804
1805        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
1806        List result = null;
1807        try {
1808            result = m_driverManager.getAllAccessibleProjects(dbc);
1809        } catch (Exception JavaDoc e) {
1810            dbc.report(null, Messages.get().container(
1811                Messages.ERR_GET_ALL_ACCESSIBLE_PROJECTS_1,
1812                dbc.currentUser().getName()), e);
1813        } finally {
1814            dbc.clear();
1815        }
1816        return result;
1817    }
1818
1819    /**
1820     * Returns a list with all projects from history.<p>
1821     *
1822     * @param context the current request context
1823     *
1824     * @return list of <code>{@link CmsBackupProject}</code> objects
1825     * with all projects from history.
1826     *
1827     * @throws CmsException if operation was not succesful
1828     */

1829    public List getAllBackupProjects(CmsRequestContext context) throws CmsException {
1830
1831        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
1832        List result = null;
1833        try {
1834            result = m_driverManager.getAllBackupProjects(dbc);
1835        } catch (Exception JavaDoc e) {
1836            dbc.report(null, Messages.get().container(
1837                Messages.ERR_GET_ALL_ACCESSIBLE_PROJECTS_1,
1838                dbc.currentUser().getName()), e);
1839        } finally {
1840            dbc.clear();
1841        }
1842        return result;
1843    }
1844
1845    /**
1846     * Returns all projects which are owned by the current user or which are manageable
1847     * for the group of the user.<p>
1848     *
1849     * @param context the current request context
1850     *
1851     * @return a list of objects of type <code>{@link CmsProject}</code>
1852     *
1853     * @throws CmsException if operation was not succesful
1854     */

1855    public List getAllManageableProjects(CmsRequestContext context) throws CmsException {
1856
1857        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
1858        List result = null;
1859        try {
1860            result = m_driverManager.getAllManageableProjects(dbc);
1861        } catch (Exception JavaDoc e) {
1862            dbc.report(null, Messages.get().container(
1863                Messages.ERR_GET_ALL_MANAGEABLE_PROJECTS_1,
1864                dbc.currentUser().getName()), e);
1865        } finally {
1866            dbc.clear();
1867        }
1868        return result;
1869    }
1870
1871    /**
1872     * Returns the next version id for the published backup resources.<p>
1873     *
1874     * @param context the current request context
1875     *
1876     * @return the new version id
1877     */

1878    public int getBackupTagId(CmsRequestContext context) {
1879
1880        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
1881        int result = 0;
1882        try {
1883            result = m_driverManager.getBackupTagId(dbc);
1884        } finally {
1885            dbc.clear();
1886        }
1887        return result;
1888    }
1889
1890    /**
1891     * Returns all child groups of a group.<p>
1892     *
1893     * @param context the current request context
1894     * @param groupname the name of the group
1895     *
1896     * @return a list of all child <code>{@link CmsGroup}</code> objects or <code>null</code>
1897     *
1898     * @throws CmsException if operation was not succesful
1899     */

1900    public List getChild(CmsRequestContext context, String JavaDoc groupname) throws CmsException {
1901
1902        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
1903        List result = null;
1904        try {
1905            checkRole(dbc, CmsRole.SYSTEM_USER);
1906            result = m_driverManager.getChild(dbc, groupname);
1907        } catch (Exception JavaDoc e) {
1908            dbc.report(null, Messages.get().container(Messages.ERR_GET_CHILD_GROUPS_1, groupname), e);
1909        } finally {
1910            dbc.clear();
1911        }
1912        return result;
1913    }
1914
1915    /**
1916     * Returns all child groups of a group.<p>
1917     *
1918     * This method also returns all sub-child groups of the current group.<p>
1919     *
1920     * @param context the current request context
1921     * @param groupname the name of the group
1922     *
1923     * @return a list of all child <code>{@link CmsGroup}</code> objects or <code>null</code>
1924     *
1925     * @throws CmsException if operation was not succesful
1926     */

1927    public List getChilds(CmsRequestContext context, String JavaDoc groupname) throws CmsException {
1928
1929        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
1930        List result = null;
1931        try {
1932            checkRole(dbc, CmsRole.SYSTEM_USER);
1933            result = m_driverManager.getChilds(dbc, groupname);
1934        } catch (Exception JavaDoc e) {
1935            dbc.report(null, Messages.get().container(Messages.ERR_GET_CHILD_GROUPS_TRANSITIVE_1, groupname), e);
1936        } finally {
1937            dbc.clear();
1938        }
1939        return result;
1940    }
1941
1942    /**
1943     * Gets the configurations of the OpenCms properties file.<p>
1944     *
1945     * @return the configurations of the properties file
1946     */

1947    public Map JavaDoc getConfigurations() {
1948
1949        return m_driverManager.getConfigurations();
1950    }
1951
1952    /**
1953     * Returns the list of groups to which the user directly belongs to.<p>
1954     *
1955     * @param context the current request context
1956     * @param username The name of the user
1957     *
1958     * @return a list of <code>{@link CmsGroup}</code> objects
1959     *
1960     * @throws CmsException if operation was not succesful
1961     */

1962    public List getDirectGroupsOfUser(CmsRequestContext context, String JavaDoc username) throws CmsException {
1963
1964        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
1965        List result = null;
1966        try {
1967            result = m_driverManager.getDirectGroupsOfUser(dbc, username);
1968        } catch (Exception JavaDoc e) {
1969            dbc.report(null, Messages.get().container(Messages.ERR_GET_DIRECT_GROUP_OF_USER_1, username), e);
1970        } finally {
1971            dbc.clear();
1972        }
1973        return result;
1974    }
1975
1976    /**
1977     * Returns all available groups.<p>
1978     *
1979     * @param context the current request context
1980     *
1981     * @return a list of all available <code>{@link CmsGroup}</code> objects
1982     *
1983     * @throws CmsException if operation was not succesful
1984     */

1985    public List getGroups(CmsRequestContext context) throws CmsException {
1986
1987        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
1988        List result = null;
1989        try {
1990            checkRole(dbc, CmsRole.SYSTEM_USER);
1991            result = m_driverManager.getGroups(dbc);
1992        } catch (Exception JavaDoc e) {
1993            dbc.report(null, Messages.get().container(Messages.ERR_GET_GROUPS_0), e);
1994        } finally {
1995            dbc.clear();
1996        }
1997        return result;
1998    }
1999
2000    /**
2001     * Returns the groups of a user.<p>
2002     *
2003     * @param context the current request context
2004     * @param username the name of the user
2005     *
2006     * @return a list of <code>{@link CmsGroup}</code> objects
2007     *
2008     * @throws CmsException if operation was not succesful
2009     */

2010    public List getGroupsOfUser(CmsRequestContext context, String JavaDoc username) throws CmsException {
2011
2012        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
2013        List result = null;
2014        try {
2015            result = m_driverManager.getGroupsOfUser(dbc, username);
2016        } catch (Exception JavaDoc e) {
2017            dbc.report(null, Messages.get().container(Messages.ERR_GET_GROUPS_OF_USER_1, username), e);
2018        } finally {
2019            dbc.clear();
2020        }
2021        return result;
2022    }
2023
2024    /**
2025     * Returns the groups of a Cms user filtered by the specified IP address.<p>
2026     *
2027     * @param context the current request context
2028     * @param username the name of the user
2029     * @param remoteAddress the IP address to filter the groups in the result list
2030     *
2031     * @return a list of <code>{@link CmsGroup}</code> objects filtered by the specified IP address
2032     *
2033     * @throws CmsException if operation was not succesful
2034     */

2035    public List getGroupsOfUser(CmsRequestContext context, String JavaDoc username, String JavaDoc remoteAddress) throws CmsException {
2036
2037        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
2038        List result = null;
2039        try {
2040            result = m_driverManager.getGroupsOfUser(dbc, username, remoteAddress);
2041        } catch (Exception JavaDoc e) {
2042            dbc.report(null, Messages.get().container(Messages.ERR_GET_GROUPS_OF_USER_2, username, remoteAddress), e);
2043        } finally {
2044            dbc.clear();
2045        }
2046        return result;
2047    }
2048
2049    /**
2050     * Returns the lock state of a resource.<p>
2051     *
2052     * @param context the current request context
2053     * @param resource the resource to return the lock state for
2054     * @return the lock state of the resource
2055     * @throws CmsException if something goes wrong
2056     */

2057    public CmsLock getLock(CmsRequestContext context, CmsResource resource) throws CmsException {
2058
2059        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
2060        CmsLock result = null;
2061        try {
2062            result = m_driverManager.getLock(dbc, resource);
2063        } catch (Exception JavaDoc e) {
2064            dbc.report(null, Messages.get().container(Messages.ERR_GET_LOCK_1, context.getSitePath(resource)), e);
2065        } finally {
2066            dbc.clear();
2067        }
2068        return result;
2069    }
2070
2071    /**
2072     * Returns the parent group of a group.<p>
2073     *
2074     * @param context the current request context
2075     * @param groupname the name of the group
2076     *
2077     * @return group the parent group or <code>null</code>
2078     *
2079     * @throws CmsException if operation was not succesful
2080     */

2081    public CmsGroup getParent(CmsRequestContext context, String JavaDoc groupname) throws CmsException {
2082
2083        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
2084        CmsGroup result = null;
2085        try {
2086            result = m_driverManager.getParent(dbc, groupname);
2087        } catch (Exception JavaDoc e) {
2088            dbc.report(null, Messages.get().container(Messages.ERR_GET_PARENT_GROUP_1, groupname), e);
2089        } finally {
2090            dbc.clear();
2091        }
2092        return result;
2093    }
2094
2095    /**
2096     * Returns the set of permissions of the current user for a given resource.<p>
2097     *
2098     * @param context the current request context
2099     * @param resource the resource
2100     * @param user the user
2101     *
2102     * @return bitset with allowed permissions
2103     *
2104     * @throws CmsException if something goes wrong
2105     */

2106    public CmsPermissionSetCustom getPermissions(CmsRequestContext context, CmsResource resource, CmsUser user)
2107    throws CmsException {
2108
2109        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
2110        CmsPermissionSetCustom result = null;
2111        try {
2112            result = m_driverManager.getPermissions(dbc, resource, user);
2113        } catch (Exception JavaDoc e) {
2114            dbc.report(null, Messages.get().container(
2115                Messages.ERR_GET_PERMISSIONS_2,
2116                user.getName(),
2117                context.getSitePath(resource)), e);
2118        } finally {
2119            dbc.clear();
2120        }
2121        return result;
2122    }
2123
2124    /**
2125     * Returns all resources associated to a given principal via an ACE with the given permissions.<p>
2126     *
2127     * If the <code>includeAttr</code> flag is set it returns also all resources associated to
2128     * a given principal through some of following attributes.<p>
2129     *
2130     * <ul>
2131     * <li>User Created</li>
2132     * <li>User Last Modified</li>
2133     * </ul><p>
2134     *
2135     * @param context the current request context
2136     * @param principalId the id of the principal
2137     * @param permissions a set of permissions to match, can be <code>null</code> for all ACEs
2138     * @param includeAttr a flag to include resources associated by attributes
2139     *
2140     * @return a list of <code>{@link CmsResource}</code> objects
2141     *
2142     * @throws CmsException if something goes wrong
2143     */

2144    public List getResourcesForPrincipal(
2145        CmsRequestContext context,
2146        CmsUUID principalId,
2147        CmsPermissionSet permissions,
2148        boolean includeAttr) throws CmsException {
2149
2150        List dependencies;
2151        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
2152        try {
2153            dependencies = m_driverManager.getResourcesForPrincipal(
2154                dbc,
2155                dbc.currentProject(),
2156                principalId,
2157                permissions,
2158                includeAttr);
2159        } catch (Exception JavaDoc e) {
2160            dbc.report(null, Messages.get().container(Messages.ERR_READ_RESOURCES_FOR_PRINCIPAL_LOG_1, principalId), e);
2161            dependencies = new ArrayList JavaDoc();
2162        } finally {
2163            dbc.clear();
2164        }
2165        return dependencies;
2166    }
2167
2168    /**
2169     * Returns an instance of the common sql manager.<p>
2170     *
2171     * @return an instance of the common sql manager
2172     */

2173    public CmsSqlManager getSqlManager() {
2174
2175        return m_driverManager.getSqlManager();
2176    }
2177
2178    /**
2179     * Returns the value of the given parameter for the given task.<p>
2180     *
2181     * @param context the current request context
2182     * @param taskId the Id of the task
2183     * @param parName name of the parameter
2184     *
2185     * @return task parameter value
2186     *
2187     * @throws CmsException if something goes wrong
2188     */

2189    public String JavaDoc getTaskPar(CmsRequestContext context, int taskId, String JavaDoc parName) throws CmsException {
2190
2191        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
2192        String JavaDoc result = null;
2193        try {
2194            result = m_driverManager.getTaskPar(dbc, taskId, parName);
2195        } catch (Exception JavaDoc e) {
2196            dbc.report(null, Messages.get().container(Messages.ERR_GET_TASK_PARAM_2, parName, new Integer JavaDoc(taskId)), e);
2197        } finally {
2198            dbc.clear();
2199        }
2200        return result;
2201    }
2202
2203    /**
2204     * Get the template task id for a given taskname.<p>
2205     *
2206     * @param context the current request context
2207     * @param taskName name of the task
2208     *
2209     * @return id from the task template
2210     *
2211     * @throws CmsException if something goes wrong
2212     */

2213    public int getTaskType(CmsRequestContext context, String JavaDoc taskName) throws CmsException {
2214
2215        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
2216        int result = 0;
2217        try {
2218            result = m_driverManager.getTaskType(dbc, taskName);
2219        } catch (Exception JavaDoc e) {
2220            dbc.report(null, Messages.get().container(Messages.ERR_GET_TASK_TYPE_1, taskName), e);
2221        } finally {
2222            dbc.clear();
2223        }
2224        return result;
2225    }
2226
2227    /**
2228     * Returns all available users.<p>
2229     *
2230     * @param context the current request context
2231     *
2232     * @return a list of all available <code>{@link CmsUser}</code> objects
2233     *
2234     * @throws CmsException if operation was not succesful
2235     */

2236    public List getUsers(CmsRequestContext context) throws CmsException {
2237
2238        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
2239        List result = null;
2240        try {
2241            checkRole(dbc, CmsRole.SYSTEM_USER);
2242            result = m_driverManager.getUsers(dbc);
2243        } catch (Exception JavaDoc e) {
2244            dbc.report(null, Messages.get().container(Messages.ERR_GET_USERS_0), e);
2245        } finally {
2246            dbc.clear();
2247        }
2248        return result;
2249    }
2250
2251    /**
2252     * Returns all users from a given type.<p>
2253     *
2254     * @param context the current request context
2255     * @param type the type of the users
2256     *
2257     * @return a list of all <code>{@link CmsUser}</code> objects of the given type
2258     *
2259     * @throws CmsException if operation was not succesful
2260     */

2261    public List getUsers(CmsRequestContext context, int type) throws CmsException {
2262
2263        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
2264        List result = null;
2265        try {
2266            if (type != CmsUser.USER_TYPE_WEBUSER) {
2267                checkRole(dbc, CmsRole.SYSTEM_USER);
2268            }
2269            result = m_driverManager.getUsers(dbc, type);
2270        } catch (Exception JavaDoc e) {
2271            dbc.report(null, Messages.get().container(Messages.ERR_GET_USERS_OF_TYPE_1, new Integer JavaDoc(type)), e);
2272        } finally {
2273            dbc.clear();
2274        }
2275        return result;
2276    }
2277
2278    /**
2279     * Returns a list of users in a group.<p>
2280     *
2281     * @param context the current request context
2282     * @param groupname the name of the group to list users from
2283     *
2284     * @return all <code>{@link CmsUser}</code> objects in the group
2285     *
2286     * @throws CmsException if operation was not succesful
2287     */

2288    public List getUsersOfGroup(CmsRequestContext context, String JavaDoc groupname) throws CmsException {
2289
2290        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
2291        List result = null;
2292        try {
2293            checkRole(dbc, CmsRole.SYSTEM_USER);
2294            result = m_driverManager.getUsersOfGroup(dbc, groupname);
2295        } catch (Exception JavaDoc e) {
2296            dbc.report(null, Messages.get().container(Messages.ERR_GET_USERS_OF_GROUP_1, groupname), e);
2297        } finally {
2298            dbc.clear();
2299        }
2300        return result;
2301    }
2302
2303    /**
2304     * Checks if the current user has management access to the given project.<p>
2305     *
2306     * @param dbc the current database context
2307     * @param project the project to check
2308     *
2309     * @return <code>true</code>, if the user has management access to the project
2310     */

2311    public boolean hasManagerOfProjectRole(CmsDbContext dbc, CmsProject project) {
2312
2313        if (project.isOnlineProject()) {
2314            // no user is the project manager of the "Online" project
2315
return false;
2316        }
2317
2318        if (dbc.currentUser().getId().equals(project.getOwnerId())) {
2319            // user is the owner of the current project
2320
return true;
2321        }
2322
2323        if (hasRole(dbc, CmsRole.PROJECT_MANAGER)) {
2324            // user is admin
2325
return true;
2326        }
2327
2328        // get all groups of the user
2329
List groups;
2330        try {
2331            groups = m_driverManager.getGroupsOfUser(dbc, dbc.currentUser().getName());
2332        } catch (CmsException e) {
2333            // any exception: result is false
2334
return false;
2335        }
2336
2337        for (int i = 0; i < groups.size(); i++) {
2338            // check if the user is a member in the current projects manager group
2339
if (((CmsGroup)groups.get(i)).getId().equals(project.getManagerGroupId())) {
2340                // this group is manager of the project
2341
return true;
2342            }
2343        }
2344
2345        // the user is not manager of the current project
2346
return false;
2347    }
2348
2349    /**
2350     * Performs a non-blocking permission check on a resource.<p>
2351     *
2352     * This test will not throw an exception in case the required permissions are not
2353     * available for the requested operation. Instead, it will return one of the
2354     * following values:<ul>
2355     * <li><code>{@link #PERM_ALLOWED}</code></li>
2356     * <li><code>{@link #PERM_FILTERED}</code></li>
2357     * <li><code>{@link #PERM_DENIED}</code></li></ul><p>
2358     *
2359     * @param context the current request context
2360     * @param resource the resource on which permissions are required
2361     * @param requiredPermissions the set of permissions required for the operation
2362     * @param checkLock if true, a lock for the current user is required for
2363     * all write operations, if false it's ok to write as long as the resource
2364     * is not locked by another user
2365     * @param filter the resource filter to use
2366     *
2367     * @return <code>{@link #PERM_ALLOWED}</code> if the user has sufficient permissions on the resource
2368     * for the requested operation
2369     *
2370     * @throws CmsException in case of i/o errors (NOT because of insufficient permissions)
2371     *
2372     * @see #hasPermissions(CmsDbContext, CmsResource, CmsPermissionSet, boolean, CmsResourceFilter)
2373     */

2374    public int hasPermissions(
2375        CmsRequestContext context,
2376        CmsResource resource,
2377        CmsPermissionSet requiredPermissions,
2378        boolean checkLock,
2379        CmsResourceFilter filter) throws CmsException {
2380
2381        int result = 0;
2382        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
2383        try {
2384            result = hasPermissions(dbc, resource, requiredPermissions, checkLock, filter);
2385        } finally {
2386            dbc.clear();
2387        }
2388        return result;
2389    }
2390
2391    /**
2392     * Checks if the user of the current database context is a member of the given role.<p>
2393     *
2394     * @param dbc the current OpenCms users database context
2395     * @param role the role to check
2396     *
2397     * @return <code>true</code> if the user of the current database context is at a member of at last
2398     * one of the roles in the given role set
2399     */

2400    public boolean hasRole(CmsDbContext dbc, CmsRole role) {
2401
2402        return hasRole(dbc, dbc.currentUser(), role);
2403    }
2404
2405    /**
2406     * Checks if the given user is a member of the given role.<p>
2407     *
2408     * @param dbc the current OpenCms users database context
2409     * @param user the user to check the role for
2410     * @param role the role to check
2411     *
2412     * @return <code>true</code> if the user of the current database context is at a member of at last
2413     * one of the roles in the given role set
2414     */

2415    public boolean hasRole(CmsDbContext dbc, CmsUser user, CmsRole role) {
2416
2417        // read all groups of the current user
2418
List groups;
2419        try {
2420            groups = m_driverManager.getGroupsOfUser(dbc, user.getName(), dbc.getRequestContext().getRemoteAddress());
2421        } catch (CmsException e) {
2422            // any exception: return false
2423
return false;
2424        }
2425
2426        return role.hasRole(groups);
2427    }
2428
2429    /**
2430     * Checks if the user of the given request context
2431     * is a member of at last one of the roles in the given role set.<p>
2432     *
2433     * @param context the current request context
2434     * @param role the role to check
2435     *
2436     * @return <code>true</code> if the user of given request context is at a member of at last
2437     * one of the roles in the given role set
2438     */

2439    public boolean hasRole(CmsRequestContext context, CmsRole role) {
2440
2441        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
2442        boolean result;
2443        try {
2444            result = hasRole(dbc, role);
2445        } finally {
2446            dbc.clear();
2447        }
2448        return result;
2449    }
2450
2451    /**
2452     * Writes a list of access control entries as new access control entries of a given resource.<p>
2453     *
2454     * Already existing access control entries of this resource are removed before.<p>
2455     *
2456     * Access is granted, if:<p>
2457     * <ul>
2458     * <li>the current user has control permission on the resource</li>
2459     * </ul><p>
2460     *
2461     * @param context the current request context
2462     * @param resource the resource
2463     * @param acEntries a list of <code>{@link CmsAccessControlEntry}</code> objects
2464     *
2465     * @throws CmsException if something goes wrong
2466     * @throws CmsSecurityException if the required permissions are not satisfied
2467     */

2468    public void importAccessControlEntries(CmsRequestContext context, CmsResource resource, List acEntries)
2469    throws CmsException, CmsSecurityException {
2470
2471        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
2472        try {
2473            checkOfflineProject(dbc);
2474            checkPermissions(dbc, resource, CmsPermissionSet.ACCESS_CONTROL, true, CmsResourceFilter.ALL);
2475            m_driverManager.importAccessControlEntries(dbc, resource, acEntries);
2476        } catch (Exception JavaDoc e) {
2477            dbc.report(
2478                null,
2479                Messages.get().container(Messages.ERR_IMPORT_ACL_ENTRIES_1, context.getSitePath(resource)),
2480                e);
2481        } finally {
2482            dbc.clear();
2483        }
2484    }
2485
2486    /**
2487     * Creates a new resource with the provided content and properties.<p>
2488     *
2489     * The <code>content</code> parameter may be null if the resource id already exists.
2490     * If so, the created resource will be made a sibling of the existing resource,
2491     * the existing content will remain unchanged.
2492     * This is used during file import for import of siblings as the
2493     * <code>manifest.xml</code> only contains one binary copy per file.
2494     * If the resource id exists but the <code>content</code> is not null,
2495     * the created resource will be made a sibling of the existing resource,
2496     * and both will share the new content.<p>
2497     *
2498     * Note: the id used to identify the content record (pk of the record) is generated
2499     * on each call of this method (with valid content) !
2500     *
2501     * @param context the current request context
2502     * @param resourcePath the name of the resource to create (full path)
2503     * @param resource the new resource to create
2504     * @param content the content for the new resource
2505     * @param properties the properties for the new resource
2506     * @param importCase if true, signals that this operation is done while importing resource, causing different lock behaviour and potential "lost and found" usage
2507     * @return the created resource
2508     * @throws CmsException if something goes wrong
2509     */

2510    public CmsResource importResource(
2511        CmsRequestContext context,
2512        String JavaDoc resourcePath,
2513        CmsResource resource,
2514        byte[] content,
2515        List properties,
2516        boolean importCase) throws CmsException {
2517
2518        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
2519        CmsResource newResource = null;
2520        try {
2521            checkOfflineProject(dbc);
2522            newResource = m_driverManager.createResource(dbc, resourcePath, resource, content, properties, importCase);
2523        } catch (Exception JavaDoc e) {
2524            dbc.report(null, Messages.get().container(
2525                Messages.ERR_IMPORT_RESOURCE_2,
2526                context.getSitePath(resource),
2527                resourcePath), e);
2528        } finally {
2529            dbc.clear();
2530        }
2531        return newResource;
2532    }
2533
2534    /**
2535     * Creates a new user by import.<p>
2536     *
2537     * @param context the current request context
2538     * @param id the id of the user
2539     * @param name the new name for the user
2540     * @param password the new password for the user
2541     * @param description the description for the user
2542     * @param firstname the firstname of the user
2543     * @param lastname the lastname of the user
2544     * @param email the email of the user
2545     * @param address the address of the user
2546     * @param flags the flags for a user (for example <code>{@link I_CmsPrincipal#FLAG_ENABLED}</code>)
2547     * @param type the type of the user
2548     * @param additionalInfos the additional user infos
2549     *
2550     * @return the imported user
2551     *
2552     * @throws CmsException if something goes wrong
2553     * @throws CmsRoleViolationException if the role {@link CmsRole#ACCOUNT_MANAGER} is not owned by the current user.
2554     */

2555    public CmsUser importUser(
2556        CmsRequestContext context,
2557        String JavaDoc id,
2558        String JavaDoc name,
2559        String JavaDoc password,
2560        String JavaDoc description,
2561        String JavaDoc firstname,
2562        String JavaDoc lastname,
2563        String JavaDoc email,
2564        String JavaDoc address,
2565        int flags,
2566        int type,
2567        Map JavaDoc additionalInfos) throws CmsException, CmsRoleViolationException {
2568
2569        CmsUser newUser = null;
2570
2571        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
2572
2573        try {
2574            checkRole(dbc, CmsRole.ACCOUNT_MANAGER);
2575            newUser = m_driverManager.importUser(
2576                dbc,
2577                id,
2578                name,
2579                password,
2580                description,
2581                firstname,
2582                lastname,
2583                email,
2584                address,
2585                flags,
2586                type,
2587                additionalInfos);
2588
2589        } catch (Exception JavaDoc e) {
2590            dbc.report(null, Messages.get().container(
2591                Messages.ERR_IMPORT_USER_9,
2592                new Object JavaDoc[] {
2593                    id,
2594                    name,
2595                    description,
2596                    firstname,
2597                    lastname,
2598                    email,
2599                    address,
2600                    new Integer JavaDoc(flags),
2601                    new Integer JavaDoc(type),
2602                    additionalInfos}), e);
2603        } finally {
2604            dbc.clear();
2605        }
2606
2607        return newUser;
2608    }
2609
2610    /**
2611     * Initializes this security manager with a given runtime info factory.<p>
2612     *
2613     * @param configurationManager the configurationManager
2614     * @param dbContextFactory the initialized OpenCms runtime info factory
2615     *
2616     * @throws CmsInitException if the initialization fails
2617     */

2618    public void init(CmsConfigurationManager configurationManager, I_CmsDbContextFactory dbContextFactory)
2619    throws CmsInitException {
2620
2621        if (dbContextFactory == null) {
2622            throw new CmsInitException(org.opencms.main.Messages.get().container(
2623                org.opencms.main.Messages.ERR_CRITICAL_NO_DB_CONTEXT_0));
2624        }
2625
2626        m_dbContextFactory = dbContextFactory;
2627
2628        CmsSystemConfiguration systemConfiguation = (CmsSystemConfiguration)configurationManager.getConfiguration(CmsSystemConfiguration.class);
2629        CmsCacheSettings settings = systemConfiguation.getCacheSettings();
2630
2631        String JavaDoc className = settings.getCacheKeyGenerator();
2632        try {
2633            // initialize the key generator
2634
m_keyGenerator = (I_CmsCacheKey)Class.forName(className).newInstance();
2635        } catch (Exception JavaDoc e) {
2636            throw new CmsInitException(org.opencms.main.Messages.get().container(
2637                org.opencms.main.Messages.ERR_CRITICAL_CLASS_CREATION_1,
2638                className));
2639        }
2640
2641        LRUMap lruMap = new LRUMap(settings.getPermissionCacheSize());
2642        m_permissionCache = Collections.synchronizedMap(lruMap);
2643        if (OpenCms.getMemoryMonitor().enabled()) {
2644            OpenCms.getMemoryMonitor().register(this.getClass().getName() + ".m_permissionCache", lruMap);
2645        }
2646
2647        m_driverManager = CmsDriverManager.newInstance(configurationManager, this, dbContextFactory);
2648
2649        if (CmsLog.INIT.isInfoEnabled()) {
2650            CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_SECURITY_MANAGER_INIT_0));
2651        }
2652    }
2653
2654    /**
2655     * Checks if the specified resource is inside the current project.<p>
2656     *
2657     * The project "view" is determined by a set of path prefixes.
2658     * If the resource starts with any one of this prefixes, it is considered to
2659     * be "inside" the project.<p>
2660     *
2661     * @param context the current request context
2662     * @param resourcename the specified resource name (full path)
2663     *
2664     * @return <code>true</code>, if the specified resource is inside the current project
2665     */

2666    public boolean isInsideCurrentProject(CmsRequestContext context, String JavaDoc resourcename) {
2667
2668        boolean result = false;
2669        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
2670        try {
2671            result = m_driverManager.isInsideCurrentProject(dbc, resourcename);
2672        } finally {
2673            dbc.clear();
2674        }
2675        return result;
2676    }
2677
2678    /**
2679     * Checks if the current user has management access to the current project.<p>
2680     *
2681     * @param context the current request context
2682     *
2683     * @return <code>true</code>, if the user has management access to the current project
2684     */

2685    public boolean isManagerOfProject(CmsRequestContext context) {
2686
2687        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
2688        return hasManagerOfProjectRole(dbc, context.currentProject());
2689    }
2690
2691    /**
2692     * Locks a resource.<p>
2693     *
2694     * The <code>mode</code> parameter controls what kind of lock is used.<br>
2695     * Possible values for this parameter are: <br>
2696     * <ul>
2697     * <li><code>{@link org.opencms.lock.CmsLock#COMMON}</code></li>
2698     * <li><code>{@link org.opencms.lock.CmsLock#TEMPORARY}</code></li>
2699     * </ul><p>
2700     *
2701     * @param context the current request context
2702     * @param resource the resource to lock
2703     * @param mode flag indicating the mode for the lock
2704     *
2705     * @throws CmsException if something goes wrong
2706     *
2707     * @see CmsObject#lockResource(String, int)
2708     * @see org.opencms.file.types.I_CmsResourceType#lockResource(CmsObject, CmsSecurityManager, CmsResource, int)
2709     */

2710    public void lockResource(CmsRequestContext context, CmsResource resource, int mode) throws CmsException {
2711
2712        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
2713        try {
2714            checkOfflineProject(dbc);
2715            checkPermissions(dbc, resource, CmsPermissionSet.ACCESS_WRITE, false, CmsResourceFilter.ALL);
2716            m_driverManager.lockResource(dbc, resource, mode);
2717        } catch (Exception JavaDoc e) {
2718            dbc.report(null, Messages.get().container(
2719                Messages.ERR_LOCK_RESOURCE_2,
2720                context.getSitePath(resource),
2721                (mode == CmsLock.COMMON) ? "CmsLock.C_MODE_COMMON" : "CmsLock.C_MODE_TEMP"), e);
2722        } finally {
2723            dbc.clear();
2724        }
2725    }
2726
2727    /**
2728     * Attempts to authenticate a user into OpenCms with the given password.<p>
2729     *
2730     * @param context the current request context
2731     * @param username the name of the user to be logged in
2732     * @param password the password of the user
2733     * @param remoteAddress the ip address of the request
2734     * @param userType the user type to log in (System user or Web user)
2735     *
2736     * @return the logged in user
2737     *
2738     * @throws CmsException if the login was not succesful
2739     */

2740    public CmsUser loginUser(
2741        CmsRequestContext context,
2742        String JavaDoc username,
2743        String JavaDoc password,
2744        String JavaDoc remoteAddress,
2745        int userType) throws CmsException {
2746
2747        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
2748        CmsUser result = null;
2749        try {
2750            result = m_driverManager.loginUser(dbc, username, password, remoteAddress, userType);
2751        } finally {
2752            dbc.clear();
2753        }
2754        return result;
2755    }
2756
2757    /**
2758     * Lookup and read the user or group with the given UUID.<p>
2759     *
2760     * @param context the current request context
2761     * @param principalId the UUID of the principal to lookup
2762     *
2763     * @return the principal (group or user) if found, otherwise <code>null</code>
2764     */

2765    public I_CmsPrincipal lookupPrincipal(CmsRequestContext context, CmsUUID principalId) {
2766
2767        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
2768        I_CmsPrincipal result = null;
2769        try {
2770            result = m_driverManager.lookupPrincipal(dbc, principalId);
2771        } finally {
2772            dbc.clear();
2773        }
2774        return result;
2775    }
2776
2777    /**
2778     * Lookup and read the user or group with the given name.<p>
2779     *
2780     * @param context the current request context
2781     * @param principalName the name of the principal to lookup
2782     *
2783     * @return the principal (group or user) if found, otherwise <code>null</code>
2784     */

2785    public I_CmsPrincipal lookupPrincipal(CmsRequestContext context, String JavaDoc principalName) {
2786
2787        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
2788        I_CmsPrincipal result = null;
2789        try {
2790            result = m_driverManager.lookupPrincipal(dbc, principalName);
2791        } finally {
2792            dbc.clear();
2793        }
2794        return result;
2795    }
2796
2797    /**
2798     * Moves a resource to the "lost and found" folder.<p>
2799     *
2800     * The method can also be used to check get the name of a resource
2801     * in the "lost and found" folder only without actually moving the
2802     * the resource. To do this, the <code>returnNameOnly</code> flag
2803     * must be set to <code>true</code>.<p>
2804     *
2805     * In general, it is the same name as the given resource has, the only exception is
2806     * if a resource in the "lost and found" folder with the same name already exists.
2807     * In such case, a counter is added to the resource name.<p>
2808     *
2809     * @param context the current request context
2810     * @param resourcename the name of the resource to apply this operation to
2811     * @param returnNameOnly if <code>true</code>, only the name of the resource in the "lost and found"
2812     * folder is returned, the move operation is not really performed
2813     *
2814     * @return the name of the resource inside the "lost and found" folder
2815     *
2816     * @throws CmsException if something goes wrong
2817     *
2818     * @see CmsObject#moveToLostAndFound(String)
2819     * @see CmsObject#getLostAndFoundName(String)
2820     */

2821    public String JavaDoc moveToLostAndFound(CmsRequestContext context, String JavaDoc resourcename, boolean returnNameOnly)
2822    throws CmsException {
2823
2824        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
2825        String JavaDoc result = null;
2826        try {
2827            result = m_driverManager.moveToLostAndFound(dbc, resourcename, returnNameOnly);
2828        } catch (Exception JavaDoc e) {
2829            dbc.report(null, Messages.get().container(Messages.ERR_MOVE_TO_LOST_AND_FOUND_1, resourcename), e);
2830        } finally {
2831            dbc.clear();
2832        }
2833        return result;
2834    }
2835
2836    /**
2837     * Publishes the resources of a specified publish list.<p>
2838     *
2839     * @param cms the current request context
2840     * @param publishList a publish list
2841     * @param report an instance of <code>{@link I_CmsReport}</code> to print messages
2842     *
2843     * @return the publish history id of the published project
2844     *
2845     * @throws CmsException if something goes wrong
2846     *
2847     * @see #fillPublishList(CmsRequestContext, CmsPublishList)
2848     */

2849    public CmsUUID publishProject(CmsObject cms, CmsPublishList publishList, I_CmsReport report) throws CmsException {
2850
2851        CmsRequestContext context = cms.getRequestContext();
2852        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
2853        try {
2854            // check if the current user has the required publish permissions
2855
checkPublishPermissions(dbc, publishList);
2856            m_driverManager.publishProject(cms, dbc, publishList, report);
2857        } finally {
2858            dbc.clear();
2859        }
2860        return publishList.getPublishHistoryId();
2861    }
2862
2863    /**
2864     * Reactivates a task.<p>
2865     *
2866     * Setting its state to <code>{@link org.opencms.workflow.CmsTaskService#TASK_STATE_STARTED}</code> and
2867     * the percentage to <b>zero</b>.<p>
2868     *
2869     * @param context the current request context
2870     * @param taskId the id of the task to reactivate
2871     *
2872     * @throws CmsException if something goes wrong
2873     */

2874    public void reactivateTask(CmsRequestContext context, int taskId) throws CmsException {
2875
2876        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
2877        try {
2878            m_driverManager.reactivateTask(dbc, taskId);
2879        } catch (Exception JavaDoc e) {
2880            dbc.report(null, Messages.get().container(Messages.ERR_REACTIVATE_TASK_1, new Integer JavaDoc(taskId)), e);
2881        } finally {
2882            dbc.clear();
2883        }
2884    }
2885
2886    /**
2887     * Reads the agent of a task.<p>
2888     *
2889     * @param context the current request context
2890     * @param task the task to read the agent from
2891     *
2892     * @return the owner of a task
2893     *
2894     * @throws CmsException if something goes wrong
2895     */

2896    public CmsUser readAgent(CmsRequestContext context, CmsTask task) throws CmsException {
2897
2898        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
2899        CmsUser result = null;
2900        try {
2901            result = m_driverManager.readAgent(dbc, task);
2902        } catch (Exception JavaDoc e) {
2903            dbc.report(null, Messages.get().container(
2904                Messages.ERR_READ_TASK_OWNER_2,
2905                task.getName(),
2906                new Integer JavaDoc(task.getId())), e);
2907        } finally {
2908            dbc.clear();
2909        }
2910        return result;
2911    }
2912
2913    /**
2914     * Reads all file headers of a file.<br>
2915     *
2916     * This method returns a list with the history of all file headers, i.e.
2917     * the file headers of a file, independent of the project they were attached to.<br>
2918     *
2919     * The reading excludes the file content.<p>
2920     *
2921     * @param context the current request context
2922     * @param resource the resource to be read
2923     *
2924     * @return a list of file headers, as <code>{@link CmsBackupResource}</code> objects, read from the Cms
2925     *
2926     * @throws CmsException if something goes wrong
2927     */

2928    public List readAllBackupFileHeaders(CmsRequestContext context, CmsResource resource) throws CmsException {
2929
2930        List result = null;
2931        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
2932        try {
2933            result = m_driverManager.readAllBackupFileHeaders(dbc, resource);
2934        } catch (Exception JavaDoc e) {
2935            dbc.report(null, Messages.get().container(
2936                Messages.ERR_READ_ALL_BKP_FILE_HEADERS_1,
2937                context.getSitePath(resource)), e);
2938        } finally {
2939            dbc.clear();
2940        }
2941        return result;
2942    }
2943
2944    /**
2945     * Reads all propertydefinitions for the given mapping type.<p>
2946     *
2947     * @param context the current request context
2948     *
2949     * @return a list with the <code>{@link CmsPropertyDefinition}</code> objects (may be empty)
2950     *
2951     * @throws CmsException if something goes wrong
2952     */

2953    public List readAllPropertyDefinitions(CmsRequestContext context) throws CmsException {
2954
2955        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
2956        List result = null;
2957        try {
2958            result = m_driverManager.readAllPropertyDefinitions(dbc);
2959        } catch (Exception JavaDoc e) {
2960            dbc.report(null, Messages.get().container(Messages.ERR_READ_ALL_PROPDEF_0), e);
2961        } finally {
2962            dbc.clear();
2963        }
2964        return result;
2965    }
2966
2967    /**
2968     * Returns the first ancestor folder matching the filter criteria.<p>
2969     *
2970     * If no folder matching the filter criteria is found, null is returned.<p>
2971     *
2972     * @param context the context of the current request
2973     * @param resource the resource to start
2974     * @param filter the resource filter to match while reading the ancestors
2975     *
2976     * @return the first ancestor folder matching the filter criteria or null if no folder was found
2977     *
2978     * @throws CmsException if something goes wrong
2979     */

2980    public CmsFolder readAncestor(CmsRequestContext context, CmsResource resource, CmsResourceFilter filter)
2981    throws CmsException {
2982
2983        // get the full folder path of the resource to start from
2984
String JavaDoc path = CmsResource.getFolderPath(resource.getRootPath());
2985        do {
2986            // check if the current folder matches the given filter
2987
if (existsResource(context, path, filter)) {
2988                // folder matches, return it
2989
return readFolder(context, path, filter);
2990            } else {
2991                // folder does not match filter criteria, go up one folder
2992
path = CmsResource.getParentFolder(path);
2993            }
2994
2995            if (CmsStringUtil.isEmpty(path) || !path.startsWith(context.getSiteRoot())) {
2996                // site root or root folder reached and no matching folder found
2997
return null;
2998            }
2999        } while (true);
3000    }
3001
3002    /**
3003     * Returns a file from the history.<br>
3004     *
3005     * The reading includes the file content.<p>
3006     *
3007     * @param context the current request context
3008     * @param tagId the id of the tag of the file
3009     * @param resource the resource to be read
3010     *
3011     * @return the file read
3012     *
3013     * @throws CmsException if operation was not succesful
3014     */

3015    public CmsBackupResource readBackupFile(CmsRequestContext context, int tagId, CmsResource resource)
3016    throws CmsException {
3017
3018        CmsBackupResource result = null;
3019        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
3020        try {
3021            result = m_driverManager.readBackupFile(dbc, tagId, resource);
3022        } catch (Exception JavaDoc e) {
3023            dbc.report(null, Messages.get().container(
3024                Messages.ERR_READ_BKP_FILE_2,
3025                context.getSitePath(resource),
3026                new Integer JavaDoc(tagId)), e);
3027        } finally {
3028            dbc.clear();
3029        }
3030        return result;
3031    }
3032
3033    /**
3034     * Returns a backup project.<p>
3035     *
3036     * @param context the current request context
3037     * @param tagId the tagId of the project
3038     *
3039     * @return the requested backup project
3040     *
3041     * @throws CmsException if something goes wrong
3042     */

3043    public CmsBackupProject readBackupProject(CmsRequestContext context, int tagId) throws CmsException {
3044
3045        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
3046        CmsBackupProject result = null;
3047        try {
3048            result = m_driverManager.readBackupProject(dbc, tagId);
3049        } catch (Exception JavaDoc e) {
3050            dbc.report(null, Messages.get().container(
3051                Messages.ERR_READ_BKP_PROJECT_2,
3052                new Integer JavaDoc(tagId),
3053                dbc.currentProject().getName()), e);
3054        } finally {
3055            dbc.clear();
3056        }
3057        return result;
3058    }
3059
3060    /**
3061     * Reads the list of <code>{@link CmsProperty}</code> objects that belong the the given backup resource.<p>
3062     *
3063     * @param context the current request context
3064     * @param resource the backup resource to read the properties from
3065     *
3066     * @return the list of <code>{@link CmsProperty}</code> objects that belong the the given backup resource
3067     *
3068     * @throws CmsException if something goes wrong
3069     */

3070    public List readBackupPropertyObjects(CmsRequestContext context, CmsBackupResource resource) throws CmsException {
3071
3072        List result = null;
3073        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
3074        try {
3075            result = m_driverManager.readBackupPropertyObjects(dbc, resource);
3076        } catch (Exception JavaDoc e) {
3077            dbc.report(null, Messages.get().container(
3078                Messages.ERR_READ_PROPS_FOR_RESOURCE_1,
3079                context.getSitePath(resource)), e);
3080        } finally {
3081            dbc.clear();
3082        }
3083        return result;
3084    }
3085
3086    /**
3087     * Returns the child resources of a resource, that is the resources
3088     * contained in a folder.<p>
3089     *
3090     * With the parameters <code>getFolders</code> and <code>getFiles</code>
3091     * you can control what type of resources you want in the result list:
3092     * files, folders, or both.<p>
3093     *
3094     * This method is mainly used by the workplace explorer.<p>
3095     *
3096     * @param context the current request context
3097     * @param resource the resource to return the child resources for
3098     * @param filter the resource filter to use
3099     * @param getFolders if true the child folders are included in the result
3100     * @param getFiles if true the child files are included in the result
3101     *
3102     * @return a list of all child resources
3103     *
3104     * @throws CmsException if something goes wrong
3105     * @throws CmsSecurityException if the user has insufficient permission for the given resource (read is required).
3106     *
3107     */

3108    public List readChildResources(
3109        CmsRequestContext context,
3110        CmsResource resource,
3111        CmsResourceFilter filter,
3112        boolean getFolders,
3113        boolean getFiles) throws CmsException, CmsSecurityException {
3114
3115        List result = null;
3116        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
3117        try {
3118            // check the access permissions
3119
checkPermissions(dbc, resource, CmsPermissionSet.ACCESS_READ, true, CmsResourceFilter.ALL);
3120            result = m_driverManager.readChildResources(dbc, resource, filter, getFolders, getFiles);
3121        } catch (Exception JavaDoc e) {
3122            dbc.report(null, Messages.get().container(
3123                Messages.ERR_READ_CHILD_RESOURCES_1,
3124                context.getSitePath(resource)), e);
3125        } finally {
3126            dbc.clear();
3127        }
3128        return result;
3129    }
3130
3131    /**
3132     * Reads a file resource (including it's binary content) from the VFS,
3133     * using the specified resource filter.<p>
3134     *
3135     * In case you do not need the file content,
3136     * use <code>{@link #readResource(CmsRequestContext, String, CmsResourceFilter)}</code> instead.<p>
3137     *
3138     * The specified filter controls what kind of resources should be "found"
3139     * during the read operation. This will depend on the application. For example,
3140     * using <code>{@link CmsResourceFilter#DEFAULT}</code> will only return currently
3141     * "valid" resources, while using <code>{@link CmsResourceFilter#IGNORE_EXPIRATION}</code>
3142     * will ignore the date release / date expired information of the resource.<p>
3143     *
3144     * @param context the current request context
3145     * @param resource the resource to be read
3146     * @param filter the filter object
3147     *
3148     * @return the file read from the VFS
3149     *
3150     * @throws CmsException if something goes wrong
3151     */

3152    public CmsFile readFile(CmsRequestContext context, CmsResource resource, CmsResourceFilter filter)
3153    throws CmsException {
3154
3155        CmsFile result = null;
3156        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
3157        try {
3158            result = m_driverManager.readFile(dbc, resource, filter);
3159        } catch (Exception JavaDoc e) {
3160            dbc.report(
3161                null,
3162                Messages.get().container(Messages.ERR_READ_FILE_2, context.getSitePath(resource), filter),
3163                e);
3164        } finally {
3165            dbc.clear();
3166        }
3167        return result;
3168    }
3169
3170    /**
3171     * Reads a folder resource from the VFS,
3172     * using the specified resource filter.<p>
3173     *
3174     * The specified filter controls what kind of resources should be "found"
3175     * during the read operation. This will depend on the application. For example,
3176     * using <code>{@link CmsResourceFilter#DEFAULT}</code> will only return currently
3177     * "valid" resources, while using <code>{@link CmsResourceFilter#IGNORE_EXPIRATION}</code>
3178     * will ignore the date release / date expired information of the resource.<p>
3179     *
3180     * @param context the current request context
3181     * @param resourcename the name of the folder to read (full path)
3182     * @param filter the resource filter to use while reading
3183     *
3184     * @return the folder that was read
3185     *
3186     * @throws CmsException if something goes wrong
3187     */

3188    public CmsFolder readFolder(CmsRequestContext context, String JavaDoc resourcename, CmsResourceFilter filter)
3189    throws CmsException {
3190
3191        CmsFolder result = null;
3192        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
3193        try {
3194            result = readFolder(dbc, resourcename, filter);
3195        } catch (Exception JavaDoc e) {
3196            dbc.report(null, Messages.get().container(Messages.ERR_READ_FOLDER_2, resourcename, filter), e);
3197        } finally {
3198            dbc.clear();
3199        }
3200        return result;
3201    }
3202
3203    /**
3204     * Reads all given tasks from a user for a project.<p>
3205     *
3206     * The <code>tasktype</code> parameter will filter the tasks.
3207     * The possible values for this parameter are:<br>
3208     * <ul>
3209     * <il><code>{@link org.opencms.workflow.CmsTaskService#TASKS_ALL}</code>: Reads all tasks</il>
3210     * <il><code>{@link org.opencms.workflow.CmsTaskService#TASKS_OPEN}</code>: Reads all open tasks</il>
3211     * <il><code>{@link org.opencms.workflow.CmsTaskService#TASKS_DONE}</code>: Reads all finished tasks</il>
3212     * <il><code>{@link org.opencms.workflow.CmsTaskService#TASKS_NEW}</code>: Reads all new tasks</il>
3213     * </ul>
3214     *
3215     * @param context the current request context
3216     * @param projectId the id of the project in which the tasks are defined
3217     * @param ownerName the owner of the task
3218     * @param taskType the type of task you want to read
3219     * @param orderBy specifies how to order the tasks
3220     * @param sort sorting of the tasks
3221     *
3222     * @return a list of given <code>{@link CmsTask}</code> objects for a user for a project
3223     *
3224     * @throws CmsException if operation was not successful
3225     */

3226    public List readGivenTasks(
3227        CmsRequestContext context,
3228        int projectId,
3229        String JavaDoc ownerName,
3230        int taskType,
3231        String JavaDoc orderBy,
3232        String JavaDoc sort) throws CmsException {
3233
3234        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
3235        List result = null;
3236        try {
3237            result = m_driverManager.readGivenTasks(dbc, projectId, ownerName, taskType, orderBy, sort);
3238        } catch (Exception JavaDoc e) {
3239            dbc.report(null, Messages.get().container(
3240                org.opencms.workflow.Messages.toTaskTypeString(taskType, context),
3241                new Integer JavaDoc(projectId),
3242                ownerName), e);
3243        } finally {
3244            dbc.clear();
3245        }
3246        return result;
3247    }
3248
3249    /**
3250     * Reads the group of a project.<p>
3251     *
3252     * @param context the current request context
3253     * @param project the project to read from
3254     *
3255     * @return the group of a resource
3256     */

3257    public CmsGroup readGroup(CmsRequestContext context, CmsProject project) {
3258
3259        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
3260        CmsGroup result = null;
3261        try {
3262            result = m_driverManager.readGroup(dbc, project);
3263        } finally {
3264            dbc.clear();
3265        }
3266        return result;
3267    }
3268
3269    /**
3270     * Reads the group (role) of a task from the OpenCms.<p>
3271     *
3272     * @param context the current request context
3273     * @param task the task to read from
3274     *
3275     * @return the group of a resource
3276     *
3277     * @throws CmsException if operation was not succesful
3278     */

3279    public CmsGroup readGroup(CmsRequestContext context, CmsTask task) throws CmsException {
3280
3281        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
3282        CmsGroup result = null;
3283        try {
3284            result = m_driverManager.readGroup(dbc, task);
3285        } catch (Exception JavaDoc e) {
3286            dbc.report(null, Messages.get().container(Messages.ERR_READ_GROUP_TASK_1, task.getName()), e);
3287        } finally {
3288            dbc.clear();
3289        }
3290        return result;
3291    }
3292
3293    /**
3294     * Reads a group based on its id.<p>
3295     *
3296     * @param context the current request context
3297     * @param groupId the id of the group that is to be read
3298     *
3299     * @return the requested group
3300     *
3301     * @throws CmsException if operation was not succesful
3302     */

3303    public CmsGroup readGroup(CmsRequestContext context, CmsUUID groupId) throws CmsException {
3304
3305        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
3306        CmsGroup result = null;
3307        try {
3308            result = m_driverManager.readGroup(dbc, groupId);
3309        } catch (Exception JavaDoc e) {
3310            dbc.report(null, Messages.get().container(Messages.ERR_READ_GROUP_FOR_ID_1, groupId.toString()), e);
3311        } finally {
3312            dbc.clear();
3313        }
3314        return result;
3315    }
3316
3317    /**
3318     * Reads a group based on its name.<p>
3319     *
3320     * @param context the current request context
3321     * @param groupname the name of the group that is to be read
3322     *
3323     * @return the requested group
3324     *
3325     * @throws CmsException if operation was not succesful
3326     */

3327    public CmsGroup readGroup(CmsRequestContext context, String JavaDoc groupname) throws CmsException {
3328
3329        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
3330        CmsGroup result = null;
3331        try {
3332            result = m_driverManager.readGroup(dbc, groupname);
3333        } catch (Exception JavaDoc e) {
3334            dbc.report(null, Messages.get().container(Messages.ERR_READ_GROUP_FOR_NAME_1, groupname), e);
3335        } finally {
3336            dbc.clear();
3337        }
3338        return result;
3339    }
3340
3341    /**
3342     * Reads the manager group of a project.<p>
3343     *
3344     * @param context the current request context
3345     * @param project the project to read from
3346     *
3347     * @return the group of a resource
3348     */

3349    public CmsGroup readManagerGroup(CmsRequestContext context, CmsProject project) {
3350
3351        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
3352        CmsGroup result = null;
3353        try {
3354            result = m_driverManager.readManagerGroup(dbc, project);
3355        } finally {
3356            dbc.clear();
3357        }
3358        return result;
3359    }
3360
3361    /**
3362     * Reads the original agent of a task.<p>
3363     *
3364     * @param context the current request context
3365     * @param task the task to read the original agent from
3366     *
3367     * @return the owner of a task
3368     *
3369     * @throws CmsException if something goes wrong
3370     */

3371    public CmsUser readOriginalAgent(CmsRequestContext context, CmsTask task) throws CmsException {
3372
3373        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
3374        CmsUser result = null;
3375        try {
3376            result = m_driverManager.readOriginalAgent(dbc, task);
3377        } catch (Exception JavaDoc e) {
3378            dbc.report(null, Messages.get().container(
3379                Messages.ERR_READ_ORIGINAL_TASK_OWNER_2,
3380                task.getName(),
3381                new Integer JavaDoc(task.getId())), e);
3382        } finally {
3383            dbc.clear();
3384        }
3385        return result;
3386    }
3387
3388    /**
3389     * Reads the owner of a project from the OpenCms.<p>
3390     *
3391     * @param context the current request context
3392     * @param project the project to get the owner from
3393     *
3394     * @return the owner of a resource
3395     *
3396     * @throws CmsException if something goes wrong
3397     */

3398    public CmsUser readOwner(CmsRequestContext context, CmsProject project) throws CmsException {
3399
3400        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
3401        CmsUser result = null;
3402        try {
3403            result = m_driverManager.readOwner(dbc, project);
3404        } catch (Exception JavaDoc e) {
3405            dbc.report(null, Messages.get().container(
3406                Messages.ERR_READ_OWNER_FOR_PROJECT_2,
3407                project.getName(),
3408                new Integer JavaDoc(project.getId())), e);
3409        } finally {
3410            dbc.clear();
3411        }
3412        return result;
3413    }
3414
3415    /**
3416     * Reads the owner (initiator) of a task.<p>
3417     *
3418     * @param context the current request context
3419     * @param task the task to read the owner from
3420     *
3421     * @return the owner of a task
3422     *
3423     * @throws CmsException if something goes wrong
3424     */

3425    public CmsUser readOwner(CmsRequestContext context, CmsTask task) throws CmsException {
3426
3427        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
3428        CmsUser result = null;
3429        try {
3430            result = m_driverManager.readOwner(dbc, task);
3431        } catch (Exception JavaDoc e) {
3432            dbc.report(null, Messages.get().container(
3433                Messages.ERR_READ_OWNER_FOR_TASK_2,
3434                task.getName(),
3435                new Integer JavaDoc(task.getId())), e);
3436        } finally {
3437            dbc.clear();
3438        }
3439        return result;
3440    }
3441
3442    /**
3443     * Reads the owner of a tasklog.<p>
3444     *
3445     * @param context the current request context
3446     * @param log the tasklog
3447     *
3448     * @return the owner of a resource
3449     *
3450     * @throws CmsException if something goes wrong
3451     */

3452    public CmsUser readOwner(CmsRequestContext context, CmsTaskLog log) throws CmsException {
3453
3454        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
3455        CmsUser result = null;
3456        try {
3457            result = m_driverManager.readOwner(dbc, log);
3458        } catch (Exception JavaDoc e) {
3459            dbc.report(
3460                null,
3461                Messages.get().container(Messages.ERR_READ_OWNER_FOR_TASKLOG_1, new Integer JavaDoc(log.getId())),
3462                e);
3463        } finally {
3464            dbc.clear();
3465        }
3466        return result;
3467    }
3468
3469    /**
3470     * Builds a list of resources for a given path.<p>
3471     *
3472     * @param context the current request context
3473     * @param projectId the project to lookup the resource
3474     * @param path the requested path
3475     * @param filter a filter object (only "includeDeleted" information is used!)
3476     *
3477     * @return list of <code>{@link CmsResource}</code>s
3478     *
3479     * @throws CmsException if something goes wrong
3480     */

3481    public List readPath(CmsRequestContext context, int projectId, String JavaDoc path, CmsResourceFilter filter)
3482    throws CmsException {
3483
3484        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
3485        List result = null;
3486        try {
3487            result = m_driverManager.readPath(dbc, projectId, path, filter);
3488        } catch (Exception JavaDoc e) {
3489            dbc.report(null, Messages.get().container(Messages.ERR_READ_PATH_2, new Integer JavaDoc(projectId), path), e);
3490        } finally {
3491            dbc.clear();
3492        }
3493        return result;
3494    }
3495
3496    /**
3497     * Reads a project of a given task.<p>
3498     *
3499     * @param context the current request context
3500     * @param task the task to read the project of
3501     *
3502     * @return the project of the task
3503     *
3504     * @throws CmsException if something goes wrong
3505     */

3506    public CmsProject readProject(CmsRequestContext context, CmsTask task) throws CmsException {
3507
3508        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
3509        CmsProject result = null;
3510        try {
3511            result = m_driverManager.readProject(dbc, task);
3512        } catch (Exception JavaDoc e) {
3513            dbc.report(null, Messages.get().container(
3514                Messages.ERR_READ_PROJECT_FOR_TASK_2,
3515                task.getName(),
3516                new Integer JavaDoc(task.getId())), e);
3517        } finally {
3518            dbc.clear();
3519        }
3520        return result;
3521    }
3522
3523    /**
3524     * Reads a project given the projects id.<p>
3525     *
3526     * @param id the id of the project
3527     *
3528     * @return the project read
3529     *
3530     * @throws CmsException if something goes wrong
3531     */

3532    public CmsProject readProject(int id) throws CmsException {
3533
3534        CmsDbContext dbc = m_dbContextFactory.getDbContext();
3535        CmsProject result = null;
3536        try {
3537            result = m_driverManager.readProject(dbc, id);
3538        } catch (Exception JavaDoc e) {
3539            dbc.report(null, Messages.get().container(Messages.ERR_READ_PROJECT_FOR_ID_1, new Integer JavaDoc(id)), e);
3540        } finally {
3541            dbc.clear();
3542        }
3543        return result;
3544    }
3545
3546    /**
3547     * Reads a project.<p>
3548     *
3549     * Important: Since a project name can be used multiple times, this is NOT the most efficient
3550     * way to read the project. This is only a convenience for front end developing.
3551     * Reading a project by name will return the first project with that name.
3552     * All core classes must use the id version {@link #readProject(int)} to ensure the right project is read.<p>
3553     *
3554     * @param name the name of the project
3555     *
3556     * @return the project read
3557     *
3558     * @throws CmsException if something goes wrong
3559     */

3560    public CmsProject readProject(String JavaDoc name) throws CmsException {
3561
3562        CmsDbContext dbc = m_dbContextFactory.getDbContext();
3563        CmsProject result = null;
3564        try {
3565            result = m_driverManager.readProject(dbc, name);
3566        } catch (Exception JavaDoc e) {
3567            dbc.report(null, Messages.get().container(Messages.ERR_READ_PROJECT_FOR_NAME_1, name), e);
3568        } finally {
3569            dbc.clear();
3570        }
3571        return result;
3572    }
3573
3574    /**
3575     * Reads all task log entries for a project.
3576     *
3577     * @param context the current request context
3578     * @param projectId the id of the project for which the tasklog will be read
3579     *
3580     * @return a list of <code>{@link CmsTaskLog}</code> objects
3581     *
3582     * @throws CmsException if something goes wrong
3583     */

3584    public List readProjectLogs(CmsRequestContext context, int projectId) throws CmsException {
3585
3586        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
3587        List result = null;
3588        try {
3589            result = m_driverManager.readProjectLogs(dbc, projectId);
3590        } catch (Exception JavaDoc e) {
3591            dbc.report(
3592                null,
3593                Messages.get().container(Messages.ERR_READ_TASKLOGS_FOR_PROJECT_1, new Integer JavaDoc(projectId)),
3594                e);
3595        } finally {
3596            dbc.clear();
3597        }
3598        return result;
3599    }
3600
3601    /**
3602     * Returns the list of all resource names that define the "view" of the given project.<p>
3603     *
3604     * @param context the current request context
3605     * @param project the project to get the project resources for
3606     *
3607     * @return the list of all resources, as <code>{@link String}</code> objects
3608     * that define the "view" of the given project.
3609     *
3610     * @throws CmsException if something goes wrong
3611     */

3612    public List readProjectResources(CmsRequestContext context, CmsProject project) throws CmsException {
3613
3614        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
3615        List result = null;
3616        try {
3617            result = m_driverManager.readProjectResources(dbc, project);
3618        } catch (Exception JavaDoc e) {
3619            dbc.report(null, Messages.get().container(
3620                Messages.ERR_READ_PROJECT_RESOURCES_2,
3621                project.getName(),
3622                new Integer JavaDoc(project.getId())), e);
3623        } finally {
3624            dbc.clear();
3625        }
3626        return result;
3627    }
3628
3629    /**
3630     * Reads all resources of a project that match a given state from the VFS.<p>
3631     *
3632     * Possible values for the <code>state</code> parameter are:<br>
3633     * <ul>
3634     * <li><code>{@link CmsResource#STATE_CHANGED}</code>: Read all "changed" resources in the project</li>
3635     * <li><code>{@link CmsResource#STATE_NEW}</code>: Read all "new" resources in the project</li>
3636     * <li><code>{@link CmsResource#STATE_DELETED}</code>: Read all "deleted" resources in the project</li>
3637     * <li><code>{@link CmsResource#STATE_KEEP}</code>: Read all resources either "changed", "new" or "deleted" in the project</li>
3638     * </ul><p>
3639     *
3640     * @param context the current request context
3641     * @param projectId the id of the project to read the file resources for
3642     * @param state the resource state to match
3643     *
3644     * @return a list of <code>{@link CmsResource}</code> objects matching the filter criteria
3645     *
3646     * @throws CmsException if something goes wrong
3647     *
3648     * @see CmsObject#readProjectView(int, int)
3649     */

3650    public List readProjectView(CmsRequestContext context, int projectId, int state) throws CmsException {
3651
3652        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
3653        List result = null;
3654        try {
3655            result = m_driverManager.readProjectView(dbc, projectId, state);
3656        } catch (Exception JavaDoc e) {
3657            dbc.report(null, Messages.get().container(
3658                Messages.ERR_READ_PROJECT_VIEW_2,
3659                new Integer JavaDoc(projectId),
3660                org.opencms.workflow.Messages.toTaskTypeString(state, context)), e);
3661        } finally {
3662            dbc.clear();
3663        }
3664        return result;
3665    }
3666
3667    /**
3668     * Reads a property definition.<p>
3669     *
3670     * If no property definition with the given name is found,
3671     * <code>null</code> is returned.<p>
3672     *
3673     * @param context the current request context
3674     * @param name the name of the property definition to read
3675     *
3676     * @return the property definition that was read,
3677     * or <code>null</code> if there is no property definition with the given name.
3678     *
3679     * @throws CmsException if something goes wrong
3680     */

3681    public CmsPropertyDefinition readPropertyDefinition(CmsRequestContext context, String JavaDoc name) throws CmsException {
3682
3683        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
3684        CmsPropertyDefinition result = null;
3685        try {
3686            result = m_driverManager.readPropertyDefinition(dbc, name);
3687        } catch (Exception JavaDoc e) {
3688            dbc.report(null, Messages.get().container(Messages.ERR_READ_PROPDEF_1, name), e);
3689        } finally {
3690            dbc.clear();
3691        }
3692        return result;
3693    }
3694
3695    /**
3696     * Reads a property object from a resource specified by a property name.<p>
3697     *
3698     * Returns <code>{@link CmsProperty#getNullProperty()}</code> if the property is not found.<p>
3699     *
3700     * @param context the context of the current request
3701     * @param resource the resource where the property is mapped to
3702     * @param key the property key name
3703     * @param search if <code>true</code>, the property is searched on all parent folders of the resource.
3704     * if it's not found attached directly to the resource.
3705     *
3706     * @return the required property, or <code>{@link CmsProperty#getNullProperty()}</code> if the property was not found
3707     *
3708     * @throws CmsException if something goes wrong
3709     */

3710    public CmsProperty readPropertyObject(CmsRequestContext context, CmsResource resource, String JavaDoc key, boolean search)
3711    throws CmsException {
3712
3713        CmsProperty result = null;
3714        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
3715        try {
3716            result = m_driverManager.readPropertyObject(dbc, resource, key, search);
3717        } catch (Exception JavaDoc e) {
3718            dbc.report(null, Messages.get().container(
3719                Messages.ERR_READ_PROP_FOR_RESOURCE_2,
3720                key,
3721                context.getSitePath(resource)), e);
3722        } finally {
3723            dbc.clear();
3724        }
3725        return result;
3726    }
3727
3728    /**
3729     * Reads all property objects from a resource.<p>
3730     *
3731     * Returns an empty list if no properties are found.<p>
3732     *
3733     * If the <code>search</code> parameter is <code>true</code>, the properties of all
3734     * parent folders of the resource are also read. The results are merged with the
3735     * properties directly attached to the resource. While merging, a property
3736     * on a parent folder that has already been found will be ignored.
3737     * So e.g. if a resource has a property "Title" attached, and it's parent folder
3738     * has the same property attached but with a differrent value, the result list will
3739     * contain only the property with the value from the resource, not form the parent folder(s).<p>
3740     *
3741     * @param context the context of the current request
3742     * @param resource the resource where the property is mapped to
3743     * @param search <code>true</code>, if the properties should be searched on all parent folders if not found on the resource
3744     *
3745     * @return a list of <code>{@link CmsProperty}</code> objects
3746     *
3747     * @throws CmsException if something goes wrong
3748     */

3749    public List readPropertyObjects(CmsRequestContext context, CmsResource resource, boolean search)
3750    throws CmsException {
3751
3752        List result = null;
3753        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
3754        try {
3755            result = m_driverManager.readPropertyObjects(dbc, resource, search);
3756        } catch (Exception JavaDoc e) {
3757            dbc.report(null, Messages.get().container(
3758                Messages.ERR_READ_PROPS_FOR_RESOURCE_1,
3759                context.getSitePath(resource)), e);
3760        } finally {
3761            dbc.clear();
3762        }
3763        return result;
3764    }
3765
3766    /**
3767     * Reads the resources that were published in a publish task for a given publish history ID.<p>
3768     *
3769     * @param context the current request context
3770     * @param publishHistoryId unique int ID to identify each publish task in the publish history
3771     *
3772     * @return a list of <code>{@link org.opencms.db.CmsPublishedResource}</code> objects
3773     *
3774     * @throws CmsException if something goes wrong
3775     */

3776    public List readPublishedResources(CmsRequestContext context, CmsUUID publishHistoryId) throws CmsException {
3777
3778        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
3779        List result = null;
3780        try {
3781            result = m_driverManager.readPublishedResources(dbc, publishHistoryId);
3782        } catch (Exception JavaDoc e) {
3783            dbc.report(null, Messages.get().container(
3784                Messages.ERR_READ_PUBLISHED_RESOURCES_FOR_ID_1,
3785                publishHistoryId.toString()), e);
3786        } finally {
3787            dbc.clear();
3788        }
3789        return result;
3790    }
3791
3792    /**
3793     * Reads a resource from the VFS,
3794     * using the specified resource filter.<p>
3795     *
3796     * A resource may be of type <code>{@link CmsFile}</code> or
3797     * <code>{@link CmsFolder}</code>. In case of
3798     * a file, the resource will not contain the binary file content. Since reading
3799     * the binary content is a cost-expensive database operation, it's recommended
3800     * to work with resources if possible, and only read the file content when absolutly
3801     * required. To "upgrade" a resource to a file,
3802     * use <code>{@link CmsFile#upgrade(CmsResource, CmsObject)}</code>.<p>
3803     *
3804     * The specified filter controls what kind of resources should be "found"
3805     * during the read operation. This will depend on the application. For example,
3806     * using <code>{@link CmsResourceFilter#DEFAULT}</code> will only return currently
3807     * "valid" resources, while using <code>{@link CmsResourceFilter#IGNORE_EXPIRATION}</code>
3808     * will ignore the date release / date expired information of the resource.<p>
3809     *
3810     * @param context the current request context
3811     * @param resourcePath the name of the resource to read (full path)
3812     * @param filter the resource filter to use while reading
3813     *
3814     * @return the resource that was read
3815     *
3816     * @throws CmsException if the resource could not be read for any reason
3817     *
3818     * @see CmsObject#readResource(String, CmsResourceFilter)
3819     * @see CmsObject#readResource(String)
3820     * @see CmsFile#upgrade(CmsResource, CmsObject)
3821     */

3822    public CmsResource readResource(CmsRequestContext context, String JavaDoc resourcePath, CmsResourceFilter filter)
3823    throws CmsException {
3824
3825        CmsResource result = null;
3826        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
3827        try {
3828            result = readResource(dbc, resourcePath, filter);
3829        } catch (Exception JavaDoc e) {
3830            dbc.report(
3831                null,
3832                Messages.get().container(Messages.ERR_READ_RESOURCE_1, dbc.removeSiteRoot(resourcePath)),
3833                e);
3834        } finally {
3835            dbc.clear();
3836        }
3837        return result;
3838    }
3839
3840    /**
3841     * Reads all resources below the given path matching the filter criteria,
3842     * including the full tree below the path only in case the <code>readTree</code>
3843     * parameter is <code>true</code>.<p>
3844     *
3845     * @param context the current request context
3846     * @param parent the parent path to read the resources from
3847     * @param filter the filter
3848     * @param readTree <code>true</code> to read all subresources
3849     *
3850     * @return a list of <code>{@link CmsResource}</code> objects matching the filter criteria
3851     *
3852     * @throws CmsSecurityException if the user has insufficient permission for the given resource (read is required).
3853     * @throws CmsException if something goes wrong
3854     *
3855     */

3856    public List readResources(CmsRequestContext context, CmsResource parent, CmsResourceFilter filter, boolean readTree)
3857    throws CmsException, CmsSecurityException {
3858
3859        List result = null;
3860        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
3861        try {
3862            // check the access permissions
3863
checkPermissions(dbc, parent, CmsPermissionSet.ACCESS_READ, true, CmsResourceFilter.ALL);
3864            result = m_driverManager.readResources(dbc, parent, filter, readTree);
3865        } catch (Exception JavaDoc e) {
3866            dbc.report(null, Messages.get().container(
3867                Messages.ERR_READ_RESOURCES_1,
3868                context.removeSiteRoot(parent.getRootPath())), e);
3869        } finally {
3870            dbc.clear();
3871        }
3872        return result;
3873    }
3874
3875    /**
3876     * Reads all resources that have a value set for the specified property (definition) in the given path.<p>
3877     *
3878     * Both individual and shared properties of a resource are checked.<p>
3879     *
3880     * @param context the current request context
3881     * @param path the folder to get the resources with the property from
3882     * @param propertyDefinition the name of the property (definition) to check for
3883     *
3884     * @return a list of all <code>{@link CmsResource}</code> objects
3885     * that have a value set for the specified property.
3886     *
3887     * @throws CmsException if something goes wrong
3888     */

3889    public List readResourcesWithProperty(CmsRequestContext context, String JavaDoc path, String JavaDoc propertyDefinition)
3890    throws CmsException {
3891
3892        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
3893        List result = null;
3894        try {
3895            result = m_driverManager.readResourcesWithProperty(dbc, path, propertyDefinition);
3896        } catch (Exception JavaDoc e) {
3897            dbc.report(null, Messages.get().container(
3898                Messages.ERR_READ_RESOURCES_FOR_PROP_SET_2,
3899                path,
3900                propertyDefinition), e);
3901        } finally {
3902            dbc.clear();
3903        }
3904        return result;
3905    }
3906
3907    /**
3908     * Reads all resources that have a value (containing the specified value) set
3909     * for the specified property (definition) in the given path.<p>
3910     *
3911     * Both individual and shared properties of a resource are checked.<p>
3912     *
3913     * @param context the current request context
3914     * @param path the folder to get the resources with the property from
3915     * @param propertyDefinition the name of the property (definition) to check for
3916     * @param value the string to search in the value of the property
3917     *
3918     * @return a list of all <code>{@link CmsResource}</code> objects
3919     * that have a value set for the specified property.
3920     *
3921     * @throws CmsException if something goes wrong
3922     */

3923    public List readResourcesWithProperty(
3924        CmsRequestContext context,
3925        String JavaDoc path,
3926        String JavaDoc propertyDefinition,
3927        String JavaDoc value) throws CmsException {
3928
3929        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
3930        List result = null;
3931        try {
3932            result = m_driverManager.readResourcesWithProperty(dbc, path, propertyDefinition, value);
3933        } catch (Exception JavaDoc e) {
3934            dbc.report(null, Messages.get().container(
3935                Messages.ERR_READ_RESOURCES_FOR_PROP_VALUE_3,
3936                path,
3937                propertyDefinition,
3938                value), e);
3939        } finally {
3940            dbc.clear();
3941        }
3942        return result;
3943    }
3944
3945    /**
3946     * Returns a set of users that are responsible for a specific resource.<p>
3947     *
3948     * @param context the current request context
3949     * @param resource the resource to get the responsible users from
3950     *
3951     * @return the set of users that are responsible for a specific resource
3952     *
3953     * @throws CmsException if something goes wrong
3954     */

3955    public Set readResponsiblePrincipals(CmsRequestContext context, CmsResource resource) throws CmsException {
3956
3957        Set result = null;
3958        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
3959        try {
3960            result = m_driverManager.readResponsiblePrincipals(dbc, resource);
3961        } catch (Exception JavaDoc e) {
3962            dbc.report(null, Messages.get().container(Messages.ERR_READ_RESPONSIBLE_USERS_1, resource.getRootPath()), e);
3963        } finally {
3964            dbc.clear();
3965        }
3966        return result;
3967    }
3968
3969    /**
3970     * Returns a set of users that are responsible for a specific resource.<p>
3971     *
3972     * @param context the current request context
3973     * @param resource the resource to get the responsible users from
3974     *
3975     * @return the set of users that are responsible for a specific resource
3976     *
3977     * @throws CmsException if something goes wrong
3978     */

3979    public Set readResponsibleUsers(CmsRequestContext context, CmsResource resource) throws CmsException {
3980
3981        Set result = null;
3982        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
3983        try {
3984            result = m_driverManager.readResponsibleUsers(dbc, resource);
3985        } catch (Exception JavaDoc e) {
3986            dbc.report(null, Messages.get().container(Messages.ERR_READ_RESPONSIBLE_USERS_1, resource.getRootPath()), e);
3987        } finally {
3988            dbc.clear();
3989        }
3990        return result;
3991    }
3992
3993    /**
3994     * Returns a List of all siblings of the specified resource,
3995     * the specified resource being always part of the result set.<p>
3996     *
3997     * @param context the request context
3998     * @param resource the specified resource
3999     * @param filter a filter object
4000     *
4001     * @return a list of <code>{@link CmsResource}</code>s that
4002     * are siblings to the specified resource,
4003     * including the specified resource itself.
4004     *
4005     * @throws CmsException if something goes wrong
4006     */

4007    public List readSiblings(CmsRequestContext context, CmsResource resource, CmsResourceFilter filter)
4008    throws CmsException {
4009
4010        List result = null;
4011        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
4012        try {
4013            result = m_driverManager.readSiblings(dbc, resource, filter);
4014        } catch (Exception JavaDoc e) {
4015            dbc.report(null, Messages.get().container(Messages.ERR_READ_SIBLINGS_1, context.getSitePath(resource)), e);
4016        } finally {
4017            dbc.clear();
4018        }
4019        return result;
4020    }
4021
4022    /**
4023     * Returns the parameters of a resource in the table of all published template resources.<p>
4024     *
4025     * @param context the current request context
4026     * @param rfsName the rfs name of the resource
4027     *
4028     * @return the paramter string of the requested resource
4029     *
4030     * @throws CmsException if something goes wrong
4031     */

4032    public String JavaDoc readStaticExportPublishedResourceParameters(CmsRequestContext context, String JavaDoc rfsName)
4033    throws CmsException {
4034
4035        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
4036        String JavaDoc result = null;
4037        try {
4038            result = m_driverManager.readStaticExportPublishedResourceParameters(dbc, rfsName);
4039        } catch (Exception JavaDoc e) {
4040            dbc.report(
4041                null,
4042                Messages.get().container(Messages.ERR_READ_STATEXP_PUBLISHED_RESOURCE_PARAMS_1, rfsName),
4043                e);
4044        } finally {
4045            dbc.clear();
4046        }
4047        return result;
4048    }
4049
4050    /**
4051     * Returns a list of all template resources which must be processed during a static export.<p>
4052     *
4053     * @param context the current request context
4054     * @param parameterResources flag for reading resources with parameters (1) or without (0)
4055     * @param timestamp for reading the data from the db
4056     *
4057     * @return a list of template resources as <code>{@link String}</code> objects
4058     *
4059     * @throws CmsException if something goes wrong
4060     */

4061    public List readStaticExportResources(CmsRequestContext context, int parameterResources, long timestamp)
4062    throws CmsException {
4063
4064        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
4065        List result = null;
4066        try {
4067            result = m_driverManager.readStaticExportResources(dbc, parameterResources, timestamp);
4068        } catch (Exception JavaDoc e) {
4069            dbc.report(null, Messages.get().container(Messages.ERR_READ_STATEXP_RESOURCES_1, new Date JavaDoc(timestamp)), e);
4070        } finally {
4071            dbc.clear();
4072        }
4073        return result;
4074    }
4075
4076    /**
4077     * Reads the task with the given id.<p>
4078     *
4079     * @param context the current request context
4080     * @param id the id for the task to read
4081     *
4082     * @return the task with the given id
4083     *
4084     * @throws CmsException if something goes wrong
4085     */

4086    public CmsTask readTask(CmsRequestContext context, int id) throws CmsException {
4087
4088        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
4089        CmsTask result = null;
4090        try {
4091            result = m_driverManager.readTask(dbc, id);
4092        } catch (Exception JavaDoc e) {
4093            dbc.report(null, Messages.get().container(Messages.ERR_READ_TASK_FOR_ID_1, new Integer JavaDoc(id)), e);
4094        } finally {
4095            dbc.clear();
4096        }
4097        return result;
4098    }
4099
4100    /**
4101     * Reads log entries for a task.<p>
4102     *
4103     * @param context the current request context
4104     * @param taskid the task for the tasklog to read
4105     *
4106     * @return a list of <code>{@link CmsTaskLog}</code> objects
4107     *
4108     * @throws CmsException if something goes wrong
4109     */

4110    public List readTaskLogs(CmsRequestContext context, int taskid) throws CmsException {
4111
4112        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
4113        List result = null;
4114        try {
4115            result = m_driverManager.readTaskLogs(dbc, taskid);
4116        } catch (Exception JavaDoc e) {
4117            dbc.report(null, Messages.get().container(Messages.ERR_READ_TASKLOGS_FOR_ID_1, new Integer JavaDoc(taskid)), e);
4118        } finally {
4119            dbc.clear();
4120        }
4121        return result;
4122    }
4123
4124    /**
4125     * Reads all tasks for a project.<p>
4126     *
4127     * The <code>tasktype</code> parameter will filter the tasks.
4128     * The possible values are:<br>
4129     * <ul>
4130     * <il><code>{@link org.opencms.workflow.CmsTaskService#TASKS_ALL}</code>: Reads all tasks</il>
4131     * <il><code>{@link org.opencms.workflow.CmsTaskService#TASKS_OPEN}</code>: Reads all open tasks</il>
4132     * <il><code>{@link org.opencms.workflow.CmsTaskService#TASKS_DONE}</code>: Reads all finished tasks</il>
4133     * <il><code>{@link org.opencms.workflow.CmsTaskService#TASKS_NEW}</code>: Reads all new tasks</il>
4134     * </ul><p>
4135     *
4136     * @param context the current request context
4137     * @param projectId the id of the project in which the tasks are defined. Can be null to select all tasks
4138     * @param tasktype the type of task you want to read
4139     * @param orderBy specifies how to order the tasks
4140     * @param sort sort order: C_SORT_ASC, C_SORT_DESC, or null
4141     *
4142     * @return a list of <code>{@link CmsTask}</code> objects for the project
4143     *
4144     * @throws CmsException if operation was not successful
4145     */

4146    public List readTasksForProject(CmsRequestContext context, int projectId, int tasktype, String JavaDoc orderBy, String JavaDoc sort)
4147    throws CmsException {
4148
4149        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
4150        List result = null;
4151        try {
4152            result = m_driverManager.readTasksForProject(dbc, projectId, tasktype, orderBy, sort);
4153        } catch (Exception JavaDoc e) {
4154            dbc.report(null, Messages.get().container(
4155                Messages.ERR_READ_TASK_FOR_PROJECT_AND_TYPE_2,
4156                new Integer JavaDoc(projectId),
4157                org.opencms.workflow.Messages.toTaskTypeString(tasktype, context)), e);
4158        } finally {
4159            dbc.clear();
4160        }
4161        return result;
4162    }
4163
4164    /**
4165     * Reads all tasks for a role in a project.<p>
4166     *
4167     * The <code>tasktype</code> parameter will filter the tasks.
4168     * The possible values for this parameter are:<br>
4169     * <ul>
4170     * <il><code>{@link org.opencms.workflow.CmsTaskService#TASKS_ALL}</code>: Reads all tasks</il>
4171     * <il><code>{@link org.opencms.workflow.CmsTaskService#TASKS_OPEN}</code>: Reads all open tasks</il>
4172     * <il><code>{@link org.opencms.workflow.CmsTaskService#TASKS_DONE}</code>: Reads all finished tasks</il>
4173     * <il><code>{@link org.opencms.workflow.CmsTaskService#TASKS_NEW}</code>: Reads all new tasks</il>
4174     * </ul><p>
4175     *
4176     * @param context the current request context
4177     * @param projectId the id of the Project in which the tasks are defined
4178     * @param roleName the role who has to process the task
4179     * @param tasktype the type of task you want to read
4180     * @param orderBy specifies how to order the tasks
4181     * @param sort sort order C_SORT_ASC, C_SORT_DESC, or null
4182     *
4183     * @return list of <code>{@link CmsTask}</code> objects for the role
4184     *
4185     * @throws CmsException if operation was not successful
4186     */

4187    public List readTasksForRole(
4188        CmsRequestContext context,
4189        int projectId,
4190        String JavaDoc roleName,
4191        int tasktype,
4192        String JavaDoc orderBy,
4193        String JavaDoc sort) throws CmsException {
4194
4195        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
4196        List result = null;
4197        try {
4198            result = m_driverManager.readTasksForRole(dbc, projectId, roleName, tasktype, orderBy, sort);
4199        } catch (Exception JavaDoc e) {
4200            dbc.report(null, Messages.get().container(
4201                Messages.ERR_READ_TASK_FOR_PROJECT_AND_ROLE_AND_TYPE_3,
4202                new Integer JavaDoc(projectId),
4203                roleName,
4204                org.opencms.workflow.Messages.toTaskTypeString(tasktype, context)), e);
4205        } finally {
4206            dbc.clear();
4207        }
4208        return result;
4209    }
4210
4211    /**
4212     * Reads all tasks for a user in a project.<p>
4213     *
4214     * The <code>tasktype</code> parameter will filter the tasks.
4215     * The possible values for this parameter are:<br>
4216     * <ul>
4217     * <il><code>{@link org.opencms.workflow.CmsTaskService#TASKS_ALL}</code>: Reads all tasks</il>
4218     * <il><code>{@link org.opencms.workflow.CmsTaskService#TASKS_OPEN}</code>: Reads all open tasks</il>
4219     * <il><code>{@link org.opencms.workflow.CmsTaskService#TASKS_DONE}</code>: Reads all finished tasks</il>
4220     * <il><code>{@link org.opencms.workflow.CmsTaskService#TASKS_NEW}</code>: Reads all new tasks</il>
4221     * </ul>
4222     *
4223     * @param context the current request context
4224     * @param projectId the id of the Project in which the tasks are defined
4225     * @param userName the user who has to process the task
4226     * @param taskType the type of task you want to read
4227     * @param orderBy specifies how to order the tasks
4228     * @param sort sort order C_SORT_ASC, C_SORT_DESC, or null
4229     *
4230     * @return a list of <code>{@link CmsTask}</code> objects for the user
4231     *
4232     * @throws CmsException if operation was not successful
4233     */

4234    public List readTasksForUser(
4235        CmsRequestContext context,
4236        int projectId,
4237        String JavaDoc userName,
4238        int taskType,
4239        String JavaDoc orderBy,
4240        String JavaDoc sort) throws CmsException {
4241
4242        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
4243        List result = null;
4244        try {
4245            result = m_driverManager.readTasksForUser(dbc, projectId, userName, taskType, orderBy, sort);
4246        } catch (Exception JavaDoc e) {
4247            dbc.report(null, Messages.get().container(
4248                Messages.ERR_READ_TASK_FOR_PROJECT_AND_USER_AND_TYPE_3,
4249                new Integer JavaDoc(projectId),
4250                userName,
4251                org.opencms.workflow.Messages.toTaskTypeString(taskType, context)), e);
4252        } finally {
4253            dbc.clear();
4254        }
4255        return result;
4256    }
4257
4258    /**
4259     * Returns a user object based on the id of a user.<p>
4260     *
4261     * @param context the current request context
4262     * @param id the id of the user to read
4263     *
4264     * @return the user read
4265     *
4266     * @throws CmsException if something goes wrong
4267     */

4268    public CmsUser readUser(CmsRequestContext context, CmsUUID id) throws CmsException {
4269
4270        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
4271        CmsUser result = null;
4272        try {
4273            result = m_driverManager.readUser(dbc, id);
4274        } catch (Exception JavaDoc e) {
4275            dbc.report(null, Messages.get().container(Messages.ERR_READ_USER_FOR_ID_1, id.toString()), e);
4276        } finally {
4277            dbc.clear();
4278        }
4279        return result;
4280    }
4281
4282    /**
4283     * Returns a user object.<p>
4284     *
4285     * @param context the current request context
4286     * @param username the name of the user that is to be read
4287     * @param type the type of the user
4288     *
4289     * @return user read
4290     *
4291     * @throws CmsException if operation was not succesful
4292     */

4293    public CmsUser readUser(CmsRequestContext context, String JavaDoc username, int type) throws CmsException {
4294
4295        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
4296        CmsUser result = null;
4297        try {
4298            result = m_driverManager.readUser(dbc, username, type);
4299        } catch (Exception JavaDoc e) {
4300            dbc.report(null, Messages.get().container(Messages.ERR_READ_USER_FOR_NAME_1, username), e);
4301        } finally {
4302            dbc.clear();
4303        }
4304        return result;
4305    }
4306
4307    /**
4308     * Returns a user object if the password for the user is correct.<p>
4309     *
4310     * If the user/pwd pair is not valid a <code>{@link CmsException}</code> is thrown.<p>
4311     *
4312     * @param context the current request context
4313     * @param username the username of the user that is to be read
4314     * @param password the password of the user that is to be read
4315     *
4316     * @return user read
4317     *
4318     * @throws CmsException if operation was not succesful
4319     */

4320    public CmsUser readUser(CmsRequestContext context, String JavaDoc username, String JavaDoc password) throws CmsException {
4321
4322        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
4323        CmsUser result = null;
4324        try {
4325            result = m_driverManager.readUser(dbc, username, password);
4326        } catch (Exception JavaDoc e) {
4327            dbc.report(null, Messages.get().container(Messages.ERR_READ_USER_FOR_NAME_1, username), e);
4328        } finally {
4329            dbc.clear();
4330        }
4331        return result;
4332    }
4333
4334    /**
4335     * Returns a user object.<p>
4336     *
4337     * @param username the name of the user that is to be read
4338     *
4339     * @return user read form the cms
4340     *
4341     * @throws CmsException if operation was not succesful
4342     */

4343    public CmsUser readUser(String JavaDoc username) throws CmsException {
4344
4345        CmsDbContext dbc = m_dbContextFactory.getDbContext();
4346        CmsUser result = null;
4347        try {
4348            result = m_driverManager.readUser(dbc, username);
4349        } catch (Exception JavaDoc e) {
4350            dbc.report(null, Messages.get().container(Messages.ERR_READ_USER_FOR_NAME_1, username), e);
4351        } finally {
4352            dbc.clear();
4353        }
4354        return result;
4355    }
4356
4357    /**
4358     * Read a web user from the database.<p>
4359     *
4360     * @param context the current request context
4361     * @param username the web user to read
4362     *
4363     * @return the read web user
4364     *
4365     * @throws CmsException if the user could not be read.
4366     */

4367    public CmsUser readWebUser(CmsRequestContext context, String JavaDoc username) throws CmsException {
4368
4369        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
4370        CmsUser result = null;
4371        try {
4372            result = m_driverManager.readWebUser(dbc, username);
4373        } catch (Exception JavaDoc e) {
4374            dbc.report(null, Messages.get().container(Messages.ERR_READ_USER_WEB_1, username), e);
4375        } finally {
4376            dbc.clear();
4377        }
4378        return result;
4379    }
4380
4381    /**
4382     * Returns a user object if the password for the user is correct.<p>
4383     *
4384     * If the user/pwd pair is not valid a <code>{@link CmsException}</code> is thrown.<p>
4385     *
4386     * @param context the current request context
4387     * @param username the username of the user that is to be read
4388     * @param password the password of the user that is to be read
4389     *
4390     * @return the webuser read
4391     *
4392     * @throws CmsException if operation was not succesful
4393     */

4394    public CmsUser readWebUser(CmsRequestContext context, String JavaDoc username, String JavaDoc password) throws CmsException {
4395
4396        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
4397        CmsUser result = null;
4398        try {
4399            result = m_driverManager.readWebUser(dbc, username, password);
4400        } catch (Exception JavaDoc e) {
4401            dbc.report(null, Messages.get().container(Messages.ERR_READ_USER_WEB_1, username), e);
4402        } finally {
4403            dbc.clear();
4404        }
4405        return result;
4406    }
4407
4408    /**
4409     * Removes an access control entry for a given resource and principal.<p>
4410     *
4411     * @param context the current request context
4412     * @param resource the resource
4413     * @param principal the id of the principal to remove the the access control entry for
4414     *
4415     * @throws CmsException if something goes wrong
4416     * @throws CmsSecurityException if the user has insufficient permission for the given resource (conrol of access control is required).
4417     *
4418     */

4419    public void removeAccessControlEntry(CmsRequestContext context, CmsResource resource, CmsUUID principal)
4420    throws CmsException, CmsSecurityException {
4421
4422        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
4423        try {
4424            checkOfflineProject(dbc);
4425            checkPermissions(dbc, resource, CmsPermissionSet.ACCESS_CONTROL, true, CmsResourceFilter.ALL);
4426            m_driverManager.removeAccessControlEntry(dbc, resource, principal);
4427        } catch (Exception JavaDoc e) {
4428            dbc.report(null, Messages.get().container(
4429                Messages.ERR_REMOVE_ACL_ENTRY_2,
4430                context.getSitePath(resource),
4431                principal.toString()), e);
4432        } finally {
4433            dbc.clear();
4434        }
4435    }
4436
4437    /**
4438     * Removes a resource from the current project of the user.<p>
4439     *
4440     * @param context the current request context
4441     * @param resource the resource to apply this operation to
4442     * @throws CmsException if something goes wrong
4443     * @throws CmsRoleViolationException if the current user does not have management access to the project.
4444     * @see org.opencms.file.types.I_CmsResourceType#copyResourceToProject(CmsObject, CmsSecurityManager, CmsResource)
4445     */

4446    public void removeResourceFromProject(CmsRequestContext context, CmsResource resource)
4447    throws CmsException, CmsRoleViolationException {
4448
4449        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
4450        try {
4451            checkOfflineProject(dbc);
4452            checkManagerOfProjectRole(dbc, context.currentProject());
4453
4454            if (dbc.currentProject().getFlags() != CmsProject.PROJECT_STATE_UNLOCKED) {
4455                throw new CmsLockException(org.opencms.lock.Messages.get().container(
4456                    org.opencms.lock.Messages.ERR_RESOURCE_LOCKED_1,
4457                    dbc.currentProject().getName()));
4458            }
4459
4460            m_driverManager.removeResourceFromProject(dbc, resource);
4461        } catch (Exception JavaDoc e) {
4462            dbc.report(null, Messages.get().container(
4463                Messages.ERR_COPY_RESOURCE_TO_PROJECT_2,
4464                context.getSitePath(resource),
4465                context.currentProject().getName()), e);
4466        } finally {
4467            dbc.clear();
4468        }
4469    }
4470
4471    /**
4472     * Removes a user from a group.<p>
4473     *
4474     * @param context the current request context
4475     * @param username the name of the user that is to be removed from the group
4476     * @param groupname the name of the group
4477     *
4478     * @throws CmsException if operation was not succesful
4479     * @throws CmsRoleViolationException if the current user does not own the rule {@link CmsRole#ACCOUNT_MANAGER}
4480     *
4481     */

4482    public void removeUserFromGroup(CmsRequestContext context, String JavaDoc username, String JavaDoc groupname)
4483    throws CmsException, CmsRoleViolationException {
4484
4485        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
4486        try {
4487            checkRole(dbc, CmsRole.ACCOUNT_MANAGER);
4488            m_driverManager.removeUserFromGroup(dbc, username, groupname);
4489        } catch (Exception JavaDoc e) {
4490            dbc.report(null, Messages.get().container(Messages.ERR_REMOVE_USER_FROM_GROUP_2, username, groupname), e);
4491        } finally {
4492            dbc.clear();
4493        }
4494    }
4495
4496    /**
4497     * Replaces the content, type and properties of a resource.<p>
4498     *
4499     * @param context the current request context
4500     * @param resource the name of the resource to apply this operation to
4501     * @param type the new type of the resource
4502     * @param content the new content of the resource
4503     * @param properties the new properties of the resource
4504     *
4505     * @throws CmsException if something goes wrong
4506     * @throws CmsSecurityException if the user has insufficient permission for the given resource (write access permission is required).
4507     *
4508     * @see CmsObject#replaceResource(String, int, byte[], List)
4509     * @see org.opencms.file.types.I_CmsResourceType#replaceResource(CmsObject, CmsSecurityManager, CmsResource, int, byte[], List)
4510     */

4511    public void replaceResource(
4512        CmsRequestContext context,
4513        CmsResource resource,
4514        int type,
4515        byte[] content,
4516        List properties) throws CmsException, CmsSecurityException {
4517
4518        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
4519        try {
4520            checkOfflineProject(dbc);
4521            checkPermissions(dbc, resource, CmsPermissionSet.ACCESS_WRITE, true, CmsResourceFilter.ALL);
4522            m_driverManager.replaceResource(dbc, resource, type, content, properties);
4523        } catch (Exception JavaDoc e) {
4524            dbc.report(
4525                null,
4526                Messages.get().container(Messages.ERR_REPLACE_RESOURCE_1, context.getSitePath(resource)),
4527                e);
4528        } finally {
4529            dbc.clear();
4530        }
4531    }
4532
4533    /**
4534     * Resets the password for a specified user.<p>
4535     *
4536     * @param context the current request context
4537     * @param username the name of the user
4538     * @param oldPassword the old password
4539     * @param newPassword the new password
4540     *
4541     * @throws CmsException if the user data could not be read from the database
4542     * @throws CmsSecurityException if the specified username and old password could not be verified
4543     */

4544    public void resetPassword(CmsRequestContext context, String JavaDoc username, String JavaDoc oldPassword, String JavaDoc newPassword)
4545    throws CmsException, CmsSecurityException {
4546
4547        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
4548        try {
4549            m_driverManager.resetPassword(dbc, username, oldPassword, newPassword);
4550        } catch (Exception JavaDoc e) {
4551            dbc.report(null, Messages.get().container(Messages.ERR_RESET_PASSWORD_1, username), e);
4552        } finally {
4553            dbc.clear();
4554        }
4555    }
4556
4557    /**
4558     * Restores a file in the current project with a version from the backup archive.<p>
4559     *
4560     * @param context the current request context
4561     * @param resource the resource to restore from the archive
4562     * @param tag the tag (version) id to resource form the archive
4563     *
4564     * @throws CmsException if something goes wrong
4565     *
4566     * @see CmsObject#restoreResourceBackup(String, int)
4567     * @see org.opencms.file.types.I_CmsResourceType#restoreResourceBackup(CmsObject, CmsSecurityManager, CmsResource, int)
4568     * @throws CmsSecurityException if the user has insufficient permission for the given resource (write access permission is required).
4569     */

4570    public void restoreResource(CmsRequestContext context, CmsResource resource, int tag)
4571    throws CmsException, CmsSecurityException {
4572
4573        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
4574        try {
4575            checkOfflineProject(dbc);
4576            checkPermissions(dbc, resource, CmsPermissionSet.ACCESS_WRITE, true, CmsResourceFilter.ALL);
4577            m_driverManager.restoreResource(dbc, resource, tag);
4578        } catch (Exception JavaDoc e) {
4579            dbc.report(null, Messages.get().container(
4580                Messages.ERR_RESTORE_RESOURCE_2,
4581                context.getSitePath(resource),
4582                new Integer JavaDoc(tag)), e);
4583        } finally {
4584            dbc.clear();
4585        }
4586    }
4587
4588    /**
4589     * Changes the "expire" date of a resource.<p>
4590     *
4591     * @param context the current request context
4592     * @param resource the resource to touch
4593     * @param dateExpired the new expire date of the changed resource
4594     *
4595     * @throws CmsException if something goes wrong
4596     * @throws CmsSecurityException if the user has insufficient permission for the given resource (write access permission is required).
4597     *
4598     * @see CmsObject#setDateExpired(String, long, boolean)
4599     * @see org.opencms.file.types.I_CmsResourceType#setDateExpired(CmsObject, CmsSecurityManager, CmsResource, long, boolean)
4600     */

4601    public void setDateExpired(CmsRequestContext context, CmsResource resource, long dateExpired)
4602    throws CmsException, CmsSecurityException {
4603
4604        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
4605        try {
4606            checkOfflineProject(dbc);
4607            checkPermissions(dbc, resource, CmsPermissionSet.ACCESS_WRITE, true, CmsResourceFilter.IGNORE_EXPIRATION);
4608            m_driverManager.setDateExpired(dbc, resource, dateExpired);
4609        } catch (Exception JavaDoc e) {
4610            dbc.report(null, Messages.get().container(
4611                Messages.ERR_SET_DATE_EXPIRED_2,
4612                new Object JavaDoc[] {new Date JavaDoc(dateExpired), context.getSitePath(resource)}), e);
4613        } finally {
4614            dbc.clear();
4615        }
4616    }
4617
4618    /**
4619     * Changes the "last modified" timestamp of a resource.<p>
4620     *
4621     * @param context the current request context
4622     * @param resource the resource to touch
4623     * @param dateLastModified timestamp the new timestamp of the changed resource
4624     *
4625     * @throws CmsException if something goes wrong
4626     * @throws CmsSecurityException if the user has insufficient permission for the given resource (write access permission is required).
4627     *
4628     * @see CmsObject#setDateLastModified(String, long, boolean)
4629     * @see org.opencms.file.types.I_CmsResourceType#setDateLastModified(CmsObject, CmsSecurityManager, CmsResource, long, boolean)
4630     */

4631    public void setDateLastModified(CmsRequestContext context, CmsResource resource, long dateLastModified)
4632    throws CmsException, CmsSecurityException {
4633
4634        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
4635        try {
4636            checkOfflineProject(dbc);
4637            checkPermissions(dbc, resource, CmsPermissionSet.ACCESS_WRITE, true, CmsResourceFilter.IGNORE_EXPIRATION);
4638            m_driverManager.setDateLastModified(dbc, resource, dateLastModified);
4639        } catch (Exception JavaDoc e) {
4640            dbc.report(null, Messages.get().container(
4641                Messages.ERR_SET_DATE_LAST_MODIFIED_2,
4642                new Object JavaDoc[] {new Date JavaDoc(dateLastModified), context.getSitePath(resource)}), e);
4643        } finally {
4644            dbc.clear();
4645        }
4646    }
4647
4648    /**
4649     * Changes the "release" date of a resource.<p>
4650     *
4651     * @param context the current request context
4652     * @param resource the resource to touch
4653     * @param dateReleased the new release date of the changed resource
4654     *
4655     * @throws CmsException if something goes wrong
4656     * @throws CmsSecurityException if the user has insufficient permission for the given resource (write access permission is required).
4657     *
4658     * @see CmsObject#setDateReleased(String, long, boolean)
4659     * @see org.opencms.file.types.I_CmsResourceType#setDateReleased(CmsObject, CmsSecurityManager, CmsResource, long, boolean)
4660     */

4661    public void setDateReleased(CmsRequestContext context, CmsResource resource, long dateReleased)
4662    throws CmsException, CmsSecurityException {
4663
4664        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
4665        try {
4666            checkOfflineProject(dbc);
4667            checkPermissions(dbc, resource, CmsPermissionSet.ACCESS_WRITE, true, CmsResourceFilter.IGNORE_EXPIRATION);
4668            m_driverManager.setDateReleased(dbc, resource, dateReleased);
4669        } catch (Exception JavaDoc e) {
4670            dbc.report(null, Messages.get().container(
4671                Messages.ERR_SET_DATE_RELEASED_2,
4672                new Object JavaDoc[] {new Date JavaDoc(dateReleased), context.getSitePath(resource)}), e);
4673        } finally {
4674            dbc.clear();
4675        }
4676    }
4677
4678    /**
4679     * Set a new name for a task.<p>
4680     *
4681     * @param context the current request context
4682     * @param taskId the Id of the task to set the percentage
4683     * @param name the new name value
4684     *
4685     * @throws CmsException if something goes wrong
4686     */

4687    public void setName(CmsRequestContext context, int taskId, String JavaDoc name) throws CmsException {
4688
4689        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
4690        try {
4691            m_driverManager.setName(dbc, taskId, name);
4692        } catch (Exception JavaDoc e) {
4693            dbc.report(null, Messages.get().container(Messages.ERR_SET_TASK_NAME_2, name, new Integer JavaDoc(taskId)), e);
4694        } finally {
4695            dbc.clear();
4696        }
4697    }
4698
4699    /**
4700     * Sets a new parent-group for an already existing group.<p>
4701     *
4702     * @param context the current request context
4703     * @param groupName the name of the group that should be written
4704     * @param parentGroupName the name of the parent group to set,
4705     * or <code>null</code> if the parent
4706     * group should be deleted.
4707     *
4708     * @throws CmsException if operation was not succesful
4709     * @throws CmsRoleViolationException if the current user does not own the rule {@link CmsRole#ACCOUNT_MANAGER}
4710     *
4711     */

4712    public void setParentGroup(CmsRequestContext context, String JavaDoc groupName, String JavaDoc parentGroupName)
4713    throws CmsException, CmsRoleViolationException {
4714
4715        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
4716
4717        try {
4718            checkRole(dbc, CmsRole.ACCOUNT_MANAGER);
4719            m_driverManager.setParentGroup(dbc, groupName, parentGroupName);
4720        } catch (Exception JavaDoc e) {
4721            dbc.report(null, Messages.get().container(Messages.ERR_SET_PARENT_GROUP_2, parentGroupName, groupName), e);
4722        } finally {
4723            dbc.clear();
4724        }
4725    }
4726
4727    /**
4728     * Sets the password for a user.<p>
4729     *
4730     * @param context the current request context
4731     * @param username the name of the user
4732     * @param newPassword the new password
4733     *
4734     * @throws CmsException if operation was not succesfull
4735     * @throws CmsRoleViolationException if the current user does not own the rule {@link CmsRole#ACCOUNT_MANAGER}
4736     */

4737    public void setPassword(CmsRequestContext context, String JavaDoc username, String JavaDoc newPassword)
4738    throws CmsException, CmsRoleViolationException {
4739
4740        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
4741        try {
4742            checkRole(dbc, CmsRole.ACCOUNT_MANAGER);
4743            m_driverManager.setPassword(dbc, username, newPassword);
4744        } catch (Exception JavaDoc e) {
4745            dbc.report(null, Messages.get().container(Messages.ERR_SET_PASSWORD_1, username), e);
4746        } finally {
4747            dbc.clear();
4748        }
4749    }
4750
4751    /**
4752     * Set priority of a task.<p>
4753     *
4754     * @param context the current request context
4755     * @param taskId the Id of the task to set the percentage
4756     * @param priority the priority value
4757     *
4758     * @throws CmsException if something goes wrong
4759     */

4760    public void setPriority(CmsRequestContext context, int taskId, int priority) throws CmsException {
4761
4762        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
4763        try {
4764            m_driverManager.setPriority(dbc, taskId, priority);
4765        } catch (Exception JavaDoc e) {
4766            dbc.report(null, Messages.get().container(
4767                Messages.ERR_SET_TASK_PRIORITY_2,
4768                new Integer JavaDoc(taskId),
4769                new Integer JavaDoc(priority)), e);
4770        } finally {
4771            dbc.clear();
4772        }
4773    }
4774
4775    /**
4776     * Set a Parameter for a task.<p>
4777     *
4778     * @param context the current request context
4779     * @param taskId the Id of the task
4780     * @param parName name of the parameter
4781     * @param parValue value if the parameter
4782     *
4783     * @throws CmsException if something goes wrong
4784     */

4785    public void setTaskPar(CmsRequestContext context, int taskId, String JavaDoc parName, String JavaDoc parValue) throws CmsException {
4786
4787        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
4788        try {
4789            m_driverManager.setTaskPar(dbc, taskId, parName, parValue);
4790        } catch (Exception JavaDoc e) {
4791            dbc.report(null, Messages.get().container(
4792                Messages.ERR_SET_TASK_PARAM_3,
4793                parName,
4794                parValue,
4795                new Integer JavaDoc(taskId)), e);
4796        } finally {
4797            dbc.clear();
4798        }
4799    }
4800
4801    /**
4802     * Set timeout of a task.<p>
4803     *
4804     * @param context the current request context
4805     * @param taskId the Id of the task to set the percentage
4806     * @param timeout new timeout value
4807     *
4808     * @throws CmsException if something goes wrong
4809     */

4810    public void setTimeout(CmsRequestContext context, int taskId, long timeout) throws CmsException {
4811
4812        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
4813        try {
4814            m_driverManager.setTimeout(dbc, taskId, timeout);
4815        } catch (Exception JavaDoc e) {
4816            dbc.report(null, Messages.get().container(
4817                Messages.ERR_SET_TASK_TIMEOUT_2,
4818                new Date JavaDoc(timeout),
4819                new Integer JavaDoc(taskId)), e);
4820        } finally {
4821            dbc.clear();
4822        }
4823    }
4824
4825    /**
4826     * Undos all changes in the resource by restoring the version from the
4827     * online project to the current offline project.<p>
4828     *
4829     * @param context the current request context
4830     * @param resource the name of the resource to apply this operation to
4831     *
4832     * @throws CmsException if something goes wrong
4833     * @throws CmsSecurityException if the user has insufficient permission for the given resource (write access permission is required).
4834     *
4835     * @see CmsObject#undoChanges(String, boolean)
4836     * @see org.opencms.file.types.I_CmsResourceType#undoChanges(CmsObject, CmsSecurityManager, CmsResource, boolean)
4837     */

4838    public void undoChanges(CmsRequestContext context, CmsResource resource) throws CmsException, CmsSecurityException {
4839
4840        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
4841        try {
4842            checkOfflineProject(dbc);
4843            checkPermissions(dbc, resource, CmsPermissionSet.ACCESS_WRITE, true, CmsResourceFilter.ALL);
4844            m_driverManager.undoChanges(dbc, resource);
4845        } catch (Exception JavaDoc e) {
4846            dbc.report(null, Messages.get().container(
4847                Messages.ERR_UNDO_CHANGES_FOR_RESOURCE_1,
4848                context.getSitePath(resource)), e);
4849        } finally {
4850            dbc.clear();
4851        }
4852    }
4853
4854    /**
4855     * Unlocks all resources in this project.<p>
4856     *
4857     * @param context the current request context
4858     * @param projectId the id of the project to be published
4859     *
4860     * @throws CmsException if something goes wrong
4861     * @throws CmsRoleViolationException if the current user does not own the rule {@link CmsRole#PROJECT_MANAGER} for the current project.
4862     */

4863    public void unlockProject(CmsRequestContext context, int projectId) throws CmsException, CmsRoleViolationException {
4864
4865        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
4866        CmsProject project = m_driverManager.readProject(dbc, projectId);
4867
4868        try {
4869            checkManagerOfProjectRole(dbc, project);
4870            m_driverManager.unlockProject(project);
4871        } catch (Exception JavaDoc e) {
4872            dbc.report(null, Messages.get().container(
4873                Messages.ERR_UNLOCK_PROJECT_2,
4874                new Integer JavaDoc(projectId),
4875                dbc.currentUser().getName()), e);
4876        } finally {
4877            dbc.clear();
4878        }
4879    }
4880
4881    /**
4882     * Unlocks a resource.<p>
4883     *
4884     * @param context the current request context
4885     * @param resource the resource to unlock
4886     *
4887     * @throws CmsException if something goes wrong
4888     * @throws CmsSecurityException if the user has insufficient permission for the given resource (write access permission is required).
4889     *
4890     * @see CmsObject#unlockResource(String)
4891     * @see org.opencms.file.types.I_CmsResourceType#unlockResource(CmsObject, CmsSecurityManager, CmsResource)
4892     */

4893    public void unlockResource(CmsRequestContext context, CmsResource resource)
4894    throws CmsException, CmsSecurityException {
4895
4896        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
4897        try {
4898            checkOfflineProject(dbc);
4899            checkPermissions(dbc, resource, CmsPermissionSet.ACCESS_WRITE, true, CmsResourceFilter.ALL);
4900            m_driverManager.unlockResource(dbc, resource);
4901        } catch (Exception JavaDoc e) {
4902            dbc.report(null, Messages.get().container(
4903                Messages.ERR_UNLOCK_RESOURCE_2,
4904                context.getSitePath(resource),
4905                dbc.currentUser().getName()), e);
4906        } finally {
4907            dbc.clear();
4908        }
4909    }
4910
4911    /**
4912     * Tests if a user is member of the given group.<p>
4913     *
4914     * @param context the current request context
4915     * @param username the name of the user to check
4916     * @param groupname the name of the group to check
4917     *
4918     * @return <code>true</code>, if the user is in the group; or <code>false</code> otherwise
4919     *
4920     * @throws CmsException if operation was not succesful
4921     */

4922    public boolean userInGroup(CmsRequestContext context, String JavaDoc username, String JavaDoc groupname) throws CmsException {
4923
4924        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
4925        boolean result = false;
4926        try {
4927            result = m_driverManager.userInGroup(dbc, username, groupname);
4928        } catch (Exception JavaDoc e) {
4929            dbc.report(null, Messages.get().container(Messages.ERR_USER_IN_GROUP_2, username, groupname), e);
4930        } finally {
4931            dbc.clear();
4932        }
4933        return result;
4934    }
4935
4936    /**
4937     * Validates the HTML links in the unpublished files of the specified
4938     * publish list, if a file resource type implements the interface
4939     * <code>{@link org.opencms.validation.I_CmsXmlDocumentLinkValidatable}</code>.<p>
4940     *
4941     * @param cms the current user's Cms object
4942     * @param publishList an OpenCms publish list
4943     * @param report a report to write the messages to
4944     *
4945     * @return a map with lists of invalid links (<code>String</code> objects) keyed by resource names
4946     *
4947     * @throws Exception if something goes wrong
4948     *
4949     * @see #fillPublishList(CmsRequestContext, CmsPublishList)
4950     */

4951    public Map JavaDoc validateHtmlLinks(CmsObject cms, CmsPublishList publishList, I_CmsReport report) throws Exception JavaDoc {
4952
4953        return m_driverManager.validateHtmlLinks(cms, publishList, report);
4954    }
4955
4956    /**
4957     * This method checks if a new password follows the rules for
4958     * new passwords, which are defined by a Class implementing the
4959     * <code>{@link org.opencms.security.I_CmsPasswordHandler}</code>
4960     * interface and configured in the opencms.properties file.<p>
4961     *
4962     * If this method throws no exception the password is valid.<p>
4963     *
4964     * @param password the new password that has to be checked
4965     *
4966     * @throws CmsSecurityException if the password is not valid
4967     */

4968    public void validatePassword(String JavaDoc password) throws CmsSecurityException {
4969
4970        m_driverManager.validatePassword(password);
4971    }
4972
4973    /**
4974     * Writes an access control entries to a given resource.<p>
4975     *
4976     * @param context the current request context
4977     * @param resource the resource
4978     * @param ace the entry to write
4979     *
4980     * @throws CmsSecurityException if the user has insufficient permission for the given resource ({@link CmsPermissionSet#ACCESS_CONTROL} required).
4981     * @throws CmsException if something goes wrong
4982     */

4983    public void writeAccessControlEntry(CmsRequestContext context, CmsResource resource, CmsAccessControlEntry ace)
4984    throws CmsException, CmsSecurityException {
4985
4986        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
4987        try {
4988            checkOfflineProject(dbc);
4989            checkPermissions(dbc, resource, CmsPermissionSet.ACCESS_CONTROL, true, CmsResourceFilter.ALL);
4990            m_driverManager.writeAccessControlEntry(dbc, resource, ace);
4991        } catch (Exception JavaDoc e) {
4992            dbc.report(null, Messages.get().container(Messages.ERR_WRITE_ACL_ENTRY_1, context.getSitePath(resource)), e);
4993        } finally {
4994            dbc.clear();
4995        }
4996    }
4997
4998    /**
4999     * Writes a resource to the OpenCms VFS, including it's content.<p>
5000     *
5001     * Applies only to resources of type <code>{@link CmsFile}</code>
5002     * i.e. resources that have a binary content attached.<p>
5003     *
5004     * Certain resource types might apply content validation or transformation rules
5005     * before the resource is actually written to the VFS. The returned result
5006     * might therefore be a modified version from the provided original.<p>
5007     *
5008     * @param context the current request context
5009     * @param resource the resource to apply this operation to
5010     *
5011     * @return the written resource (may have been modified)
5012     *
5013     * @throws CmsSecurityException if the user has insufficient permission for the given resource ({@link CmsPermissionSet#ACCESS_WRITE} required).
5014     * @throws CmsException if something goes wrong
5015     *
5016     * @see CmsObject#writeFile(CmsFile)
5017     * @see org.opencms.file.types.I_CmsResourceType#writeFile(CmsObject, CmsSecurityManager, CmsFile)
5018     */

5019    public CmsFile writeFile(CmsRequestContext context, CmsFile resource) throws CmsException, CmsSecurityException {
5020
5021        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
5022        CmsFile result = null;
5023        try {
5024            checkOfflineProject(dbc);
5025            checkPermissions(dbc, resource, CmsPermissionSet.ACCESS_WRITE, true, CmsResourceFilter.ALL);
5026            result = m_driverManager.writeFile(dbc, resource);
5027        } catch (Exception JavaDoc e) {
5028            dbc.report(null, Messages.get().container(Messages.ERR_WRITE_FILE_1, context.getSitePath(resource)), e);
5029        } finally {
5030            dbc.clear();
5031        }
5032        return result;
5033    }
5034
5035    /**
5036     * Writes an already existing group.<p>
5037     *
5038     * The group id has to be a valid OpenCms group id.<br>
5039     *
5040     * The group with the given id will be completely overriden
5041     * by the given data.<p>
5042     *
5043     * @param context the current request context
5044     * @param group the group that should be written
5045     *
5046     * @throws CmsRoleViolationException if the current user does not own the role {@link CmsRole#ACCOUNT_MANAGER} for the current project.
5047     * @throws CmsException if operation was not succesfull
5048     */

5049    public void writeGroup(CmsRequestContext context, CmsGroup group) throws CmsException, CmsRoleViolationException {
5050
5051        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
5052        try {
5053            checkRole(dbc, CmsRole.ACCOUNT_MANAGER);
5054            m_driverManager.writeGroup(dbc, group);
5055        } catch (Exception JavaDoc e) {
5056            dbc.report(null, Messages.get().container(Messages.ERR_WRITE_GROUP_1, group.getName()), e);
5057        } finally {
5058            dbc.clear();
5059        }
5060    }
5061
5062    /**
5063     * Writes an already existing project.<p>
5064     *
5065     * The project id has to be a valid OpenCms project id.<br>
5066     *
5067     * The project with the given id will be completely overriden
5068     * by the given data.<p>
5069     *
5070     * @param project the project that should be written
5071     * @param context the current request context
5072     *
5073     * @throws CmsRoleViolationException if the current user does not own the role {@link CmsRole#PROJECT_MANAGER} for the current project.
5074     * @throws CmsException if operation was not successful
5075     */

5076    public void writeProject(CmsRequestContext context, CmsProject project)
5077    throws CmsRoleViolationException, CmsException {
5078
5079        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
5080        try {
5081            checkRole(dbc, CmsRole.PROJECT_MANAGER);
5082            m_driverManager.writeProject(dbc, project);
5083        } catch (Exception JavaDoc e) {
5084            dbc.report(null, Messages.get().container(Messages.ERR_WRITE_PROJECT_1, project.getName()), e);
5085        } finally {
5086            dbc.clear();
5087        }
5088    }
5089
5090    /**
5091     * Writes a property for a specified resource.<p>
5092     *
5093     * @param context the current request context
5094     * @param resource the resource to write the property for
5095     * @param property the property to write
5096     *
5097     * @throws CmsException if something goes wrong
5098     * @throws CmsSecurityException if the user has insufficient permission for the given resource ({@link CmsPermissionSet#ACCESS_WRITE} required).
5099     *
5100     * @see CmsObject#writePropertyObject(String, CmsProperty)
5101     * @see org.opencms.file.types.I_CmsResourceType#writePropertyObject(CmsObject, CmsSecurityManager, CmsResource, CmsProperty)
5102     */

5103    public void writePropertyObject(CmsRequestContext context, CmsResource resource, CmsProperty property)
5104    throws CmsException, CmsSecurityException {
5105
5106        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
5107        try {
5108            checkOfflineProject(dbc);
5109            checkPermissions(dbc, resource, CmsPermissionSet.ACCESS_WRITE, true, CmsResourceFilter.IGNORE_EXPIRATION);
5110            m_driverManager.writePropertyObject(dbc, resource, property);
5111        } catch (Exception JavaDoc e) {
5112            dbc.report(null, Messages.get().container(
5113                Messages.ERR_WRITE_PROP_2,
5114                property.getName(),
5115                context.getSitePath(resource)), e);
5116        } finally {
5117            dbc.clear();
5118        }
5119    }
5120
5121    /**
5122     * Writes a list of properties for a specified resource.<p>
5123     *
5124     * Code calling this method has to ensure that the no properties
5125     * <code>a, b</code> are contained in the specified list so that <code>a.equals(b)</code>,
5126     * otherwise an exception is thrown.<p>
5127     *
5128     * @param context the current request context
5129     * @param resource the resource to write the properties for
5130     * @param properties the list of properties to write
5131     *
5132     * @throws CmsException if something goes wrong
5133     * @throws CmsSecurityException if the user has insufficient permission for the given resource ({@link CmsPermissionSet#ACCESS_WRITE} required).
5134     *
5135     * @see CmsObject#writePropertyObjects(String, List)
5136     * @see org.opencms.file.types.I_CmsResourceType#writePropertyObjects(CmsObject, CmsSecurityManager, CmsResource, List)
5137     */

5138    public void writePropertyObjects(CmsRequestContext context, CmsResource resource, List properties)
5139    throws CmsException, CmsSecurityException {
5140
5141        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
5142        try {
5143            checkOfflineProject(dbc);
5144            checkPermissions(dbc, resource, CmsPermissionSet.ACCESS_WRITE, true, CmsResourceFilter.IGNORE_EXPIRATION);
5145
5146            // write the properties
5147
m_driverManager.writePropertyObjects(dbc, resource, properties);
5148
5149            // update the resource state
5150
resource.setUserLastModified(context.currentUser().getId());
5151            m_driverManager.getVfsDriver().writeResource(
5152                dbc,
5153                context.currentProject(),
5154                resource,
5155                CmsDriverManager.UPDATE_RESOURCE_STATE);
5156
5157        } catch (Exception JavaDoc e) {
5158            dbc.report(null, Messages.get().container(Messages.ERR_WRITE_PROPS_1, context.getSitePath(resource)), e);
5159        } finally {
5160            dbc.clear();
5161        }
5162    }
5163
5164    /**
5165     * Writes a resource to the OpenCms VFS.<p>
5166     *
5167     * @param context the current request context
5168     * @param resource the resource to write
5169     *
5170     * @throws CmsSecurityException if the user has insufficient permission for the given resource ({@link CmsPermissionSet#ACCESS_WRITE} required).
5171     * @throws CmsException if something goes wrong
5172     */

5173    public void writeResource(CmsRequestContext context, CmsResource resource)
5174    throws CmsException, CmsSecurityException {
5175
5176        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
5177        try {
5178            checkOfflineProject(dbc);
5179            checkPermissions(dbc, resource, CmsPermissionSet.ACCESS_WRITE, true, CmsResourceFilter.ALL);
5180            m_driverManager.writeResource(dbc, resource);
5181        } catch (Exception JavaDoc e) {
5182            dbc.report(null, Messages.get().container(Messages.ERR_WRITE_RESOURCE_1, context.getSitePath(resource)), e);
5183        } finally {
5184            dbc.clear();
5185        }
5186    }
5187
5188    /**
5189     * Inserts an entry in the published resource table.<p>
5190     *
5191     * This is done during static export.<p>
5192     *
5193     * @param context the current request context
5194     * @param resourceName The name of the resource to be added to the static export
5195     * @param linkType the type of resource exported (0= non-paramter, 1=parameter)
5196     * @param linkParameter the parameters added to the resource
5197     * @param timestamp a timestamp for writing the data into the db
5198     *
5199     * @throws CmsException if something goes wrong
5200     */

5201    public void writeStaticExportPublishedResource(
5202        CmsRequestContext context,
5203        String JavaDoc resourceName,
5204        int linkType,
5205        String JavaDoc linkParameter,
5206        long timestamp) throws CmsException {
5207
5208        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
5209        try {
5210            m_driverManager.writeStaticExportPublishedResource(dbc, resourceName, linkType, linkParameter, timestamp);
5211        } catch (Exception JavaDoc e) {
5212            dbc.report(null, Messages.get().container(
5213                Messages.ERR_WRITE_STATEXP_PUBLISHED_RESOURCES_3,
5214                resourceName,
5215                linkParameter,
5216                new Date JavaDoc(timestamp)), e);
5217        } finally {
5218            dbc.clear();
5219        }
5220    }
5221
5222    /**
5223     * Writes a new user tasklog for a task.<p>
5224     *
5225     * @param context the current request context
5226     * @param taskid the Id of the task
5227     * @param comment description for the log
5228     *
5229     * @throws CmsException if something goes wrong
5230     */

5231    public void writeTaskLog(CmsRequestContext context, int taskid, String JavaDoc comment) throws CmsException {
5232
5233        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
5234        try {
5235            m_driverManager.writeTaskLog(dbc, taskid, comment);
5236        } catch (Exception JavaDoc e) {
5237            dbc.report(null, Messages.get().container(Messages.ERR_WRITE_TASK_LOG_1, new Integer JavaDoc(taskid)), e);
5238        } finally {
5239            dbc.clear();
5240        }
5241    }
5242
5243    /**
5244     * Writes a new user tasklog for a task.<p>
5245     *
5246     * @param context the current request context
5247     * @param taskId the Id of the task
5248     * @param comment description for the log
5249     * @param type type of the tasklog. User tasktypes must be greater than 100
5250     *
5251     * @throws CmsException something goes wrong
5252     */

5253    public void writeTaskLog(CmsRequestContext context, int taskId, String JavaDoc comment, int type) throws CmsException {
5254
5255        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
5256        try {
5257            m_driverManager.writeTaskLog(dbc, taskId, comment, type);
5258        } catch (Exception JavaDoc e) {
5259            dbc.report(null, Messages.get().container(Messages.ERR_WRITE_TASK_LOG_1, new Integer JavaDoc(taskId)), e);
5260        } finally {
5261            dbc.clear();
5262        }
5263    }
5264
5265    /**
5266     * Updates the user information. <p>
5267     *
5268     * The user id has to be a valid OpenCms user id.<br>
5269     *
5270     * The user with the given id will be completely overriden
5271     * by the given data.<p>
5272     *
5273     * @param context the current request context
5274     * @param user the user to be updated
5275     *
5276     * @throws CmsRoleViolationException if the current user does not own the rule {@link CmsRole#ACCOUNT_MANAGER} for the current project.
5277     * @throws CmsException if operation was not succesful
5278     */

5279    public void writeUser(CmsRequestContext context, CmsUser user) throws CmsException, CmsRoleViolationException {
5280
5281        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
5282        try {
5283            if (!context.currentUser().equals(user)) {
5284                // a user is allowed to write his own data (e.g. for "change preferences")
5285
checkRole(dbc, CmsRole.ACCOUNT_MANAGER);
5286            }
5287            m_driverManager.writeUser(dbc, user);
5288        } catch (Exception JavaDoc e) {
5289            dbc.report(null, Messages.get().container(Messages.ERR_WRITE_USER_1, user.getName()), e);
5290        } finally {
5291            dbc.clear();
5292        }
5293    }
5294
5295    /**
5296     * Updates the user information of a web user.<br>
5297     *
5298     * Only a web user can be updated this way.<p>
5299     *
5300     * The user id has to be a valid OpenCms user id.<br>
5301     *
5302     * The user with the given id will be completely overriden
5303     * by the given data.<p>
5304     *
5305     * @param context the current request context
5306     * @param user the user to be updated
5307     *
5308     * @throws CmsException if operation was not succesful
5309     */

5310    public void writeWebUser(CmsRequestContext context, CmsUser user) throws CmsException {
5311
5312        if (!user.isWebUser()) {
5313            throw new CmsSecurityException(Messages.get().container(Messages.ERR_WRITE_WEB_USER_CONSTRAINT_0));
5314        }
5315        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
5316        try {
5317            m_driverManager.writeWebUser(dbc, user);
5318        } catch (Exception JavaDoc e) {
5319            dbc.report(null, Messages.get().container(Messages.ERR_WRITE_WEB_USER_1, user.getName()), e);
5320        } finally {
5321            dbc.clear();
5322        }
5323    }
5324
5325    /**
5326     * Performs a blocking permission check on a resource.<p>
5327     *
5328     * If the required permissions are not satisfied by the permissions the user has on the resource,
5329     * an exception is thrown.<p>
5330     *
5331     * @param dbc the current database context
5332     * @param resource the resource on which permissions are required
5333     * @param requiredPermissions the set of permissions required to access the resource
5334     * @param checkLock if true, the lock status of the resource is also checked
5335     * @param filter the filter for the resource
5336     *
5337     * @throws CmsException in case of any i/o error
5338     * @throws CmsSecurityException if the required permissions are not satisfied
5339     *
5340     * @see #hasPermissions(CmsRequestContext, CmsResource, CmsPermissionSet, boolean, CmsResourceFilter)
5341     */

5342    protected void checkPermissions(
5343        CmsDbContext dbc,
5344        CmsResource resource,
5345        CmsPermissionSet requiredPermissions,
5346        boolean checkLock,
5347        CmsResourceFilter filter) throws CmsException, CmsSecurityException {
5348
5349        // get the permissions
5350
int permissions = hasPermissions(dbc, resource, requiredPermissions, checkLock, filter);
5351        if (permissions != 0) {
5352            checkPermissions(dbc.getRequestContext(), resource, requiredPermissions, permissions);
5353        }
5354    }
5355
5356    /**
5357     * Applies the permission check result of a previous call
5358     * to {@link #hasPermissions(CmsRequestContext, CmsResource, CmsPermissionSet, boolean, CmsResourceFilter)}.<p>
5359     *
5360     * @param context the current request context
5361     * @param resource the resource on which permissions are required
5362     * @param requiredPermissions the set of permissions required to access the resource
5363     * @param permissions the permissions to check
5364     *
5365     * @throws CmsSecurityException if the required permissions are not satisfied
5366     * @throws CmsLockException if the lock status is not as required
5367     * @throws CmsVfsResourceNotFoundException if the required resource has been filtered
5368     */

5369    protected void checkPermissions(
5370        CmsRequestContext context,
5371        CmsResource resource,
5372        CmsPermissionSet requiredPermissions,
5373        int permissions) throws CmsSecurityException, CmsLockException, CmsVfsResourceNotFoundException {
5374
5375        switch (permissions) {
5376            case PERM_FILTERED:
5377                throw new CmsVfsResourceNotFoundException(Messages.get().container(
5378                    Messages.ERR_PERM_FILTERED_1,
5379                    context.getSitePath(resource)));
5380
5381            case PERM_DENIED:
5382                throw new CmsPermissionViolationException(Messages.get().container(
5383                    Messages.ERR_PERM_DENIED_2,
5384                    context.getSitePath(resource),
5385                    requiredPermissions.getPermissionString()));
5386
5387            case PERM_NOTLOCKED:
5388                throw new CmsLockException(Messages.get().container(
5389                    Messages.ERR_PERM_NOTLOCKED_2,
5390                    context.getSitePath(resource),
5391                    context.currentUser().getName()));
5392
5393            case PERM_ALLOWED:
5394            default:
5395                return;
5396        }
5397    }
5398
5399    /**
5400     * Clears the permission cache.<p>
5401     */

5402    protected void clearPermissionCache() {
5403
5404        m_permissionCache.clear();
5405    }
5406
5407    /**
5408     * @see java.lang.Object#finalize()
5409     */

5410    protected void finalize() throws Throwable JavaDoc {
5411
5412        try {
5413            if (m_driverManager != null) {
5414                m_driverManager.destroy();
5415            }
5416        } catch (Throwable JavaDoc t) {
5417            if (LOG.isErrorEnabled()) {
5418                LOG.error(Messages.get().getBundle().key(Messages.LOG_ERR_DRIVER_MANAGER_CLOSE_0), t);
5419            }
5420        }
5421
5422        m_driverManager = null;
5423        m_dbContextFactory = null;
5424
5425        super.finalize();
5426
5427    }
5428
5429    /**
5430     * Performs a non-blocking permission check on a resource.<p>
5431     *
5432     * This test will not throw an exception in case the required permissions are not
5433     * available for the requested operation. Instead, it will return one of the
5434     * following values:<ul>
5435     * <li><code>{@link #PERM_ALLOWED}</code></li>
5436     * <li><code>{@link #PERM_FILTERED}</code></li>
5437     * <li><code>{@link #PERM_DENIED}</code></li></ul><p>
5438     *
5439     * @param dbc the current database context
5440     * @param resource the resource on which permissions are required
5441     * @param requiredPermissions the set of permissions required for the operation
5442     * @param checkLock if true, a lock for the current user is required for
5443     * all write operations, if false it's ok to write as long as the resource
5444     * is not locked by another user
5445     * @param filter the resource filter to use
5446     *
5447     * @return <code>PERM_ALLOWED</code> if the user has sufficient permissions on the resource
5448     * for the requested operation
5449     *
5450     * @throws CmsException in case of i/o errors (NOT because of insufficient permissions)
5451     */

5452    protected int hasPermissions(
5453        CmsDbContext dbc,
5454        CmsResource resource,
5455        CmsPermissionSet requiredPermissions,
5456        boolean checkLock,
5457        CmsResourceFilter filter) throws CmsException {
5458
5459        // check if the resource is valid according to the current filter
5460
// if not, throw a CmsResourceNotFoundException
5461
if (!filter.isValid(dbc.getRequestContext(), resource)) {
5462            return PERM_FILTERED;
5463        }
5464
5465        // checking the filter is less cost intensive then checking the cache,
5466
// this is why basic filter results are not cached
5467
String JavaDoc cacheKey = m_keyGenerator.getCacheKeyForUserPermissions(
5468            filter.requireVisible() && checkLock ? "11" : (!filter.requireVisible() && checkLock ? "01"
5469            : (filter.requireVisible() && !checkLock ? "10" : "00")),
5470            dbc,
5471            resource,
5472            requiredPermissions);
5473        Integer JavaDoc cacheResult = (Integer JavaDoc)m_permissionCache.get(cacheKey);
5474        if (cacheResult != null) {
5475            return cacheResult.intValue();
5476        }
5477
5478        int denied = 0;
5479
5480        // if this is the onlineproject, write is rejected
5481
if (dbc.currentProject().isOnlineProject()) {
5482            denied |= CmsPermissionSet.PERMISSION_WRITE;
5483        }
5484
5485        // check if the current user is admin
5486
boolean canIgnorePermissions = hasRole(dbc, CmsRole.VFS_MANAGER);
5487
5488        // check lock status
5489
boolean writeRequired = requiredPermissions.requiresWritePermission()
5490            || requiredPermissions.requiresControlPermission();
5491
5492        // if the resource type is jsp
5493
// write is only allowed for administrators
5494
if (writeRequired && !canIgnorePermissions && (resource.getTypeId() == CmsResourceTypeJsp.getStaticTypeId())) {
5495            if (!hasRole(dbc, CmsRole.DEVELOPER)) {
5496                denied |= CmsPermissionSet.PERMISSION_WRITE;
5497                denied |= CmsPermissionSet.PERMISSION_CONTROL;
5498            }
5499        }
5500
5501        if (writeRequired && checkLock) {
5502            // check lock state only if required
5503
CmsLock lock = m_driverManager.getLock(dbc, resource);
5504            // if the resource is not locked by the current user, write and control
5505
// access must cause a permission error that must not be cached
5506
if (lock.isNullLock() || !dbc.currentUser().getId().equals(lock.getUserId())) {
5507                return PERM_NOTLOCKED;
5508            }
5509        }
5510
5511        CmsPermissionSetCustom permissions;
5512        if (canIgnorePermissions) {
5513            // if the current user is administrator, anything is allowed
5514
permissions = new CmsPermissionSetCustom(~0);
5515        } else {
5516            // otherwise, get the permissions from the access control list
5517
permissions = m_driverManager.getPermissions(dbc, resource, dbc.currentUser());
5518        }
5519
5520        // revoke the denied permissions
5521
permissions.denyPermissions(denied);
5522
5523        if ((permissions.getPermissions() & CmsPermissionSet.PERMISSION_VIEW) == 0) {
5524            // resource "invisible" flag is set for this user
5525
if (filter.requireVisible()) {
5526                // filter requires visible permission - extend required permission set
5527
requiredPermissions = new CmsPermissionSet(requiredPermissions.getAllowedPermissions()
5528                    | CmsPermissionSet.PERMISSION_VIEW, requiredPermissions.getDeniedPermissions());
5529            } else {
5530                // view permissions can be ignored by filter
5531
permissions.setPermissions(
5532                    // modify permissions so that view is allowed
5533
permissions.getAllowedPermissions() | CmsPermissionSet.PERMISSION_VIEW,
5534                    permissions.getDeniedPermissions() & ~CmsPermissionSet.PERMISSION_VIEW);
5535            }
5536        }
5537
5538        Integer JavaDoc result;
5539        if ((requiredPermissions.getPermissions() & (permissions.getPermissions())) == requiredPermissions.getPermissions()) {
5540            result = PERM_ALLOWED_INTEGER;
5541        } else {
5542            result = PERM_DENIED_INTEGER;
5543        }
5544        m_permissionCache.put(cacheKey, result);
5545
5546        if ((result != PERM_ALLOWED_INTEGER) && LOG.isDebugEnabled()) {
5547            LOG.debug(Messages.get().getBundle().key(
5548                Messages.LOG_NO_PERMISSION_RESOURCE_USER_4,
5549                new Object JavaDoc[] {
5550                    dbc.getRequestContext().removeSiteRoot(resource.getRootPath()),
5551                    dbc.currentUser().getName(),
5552                    requiredPermissions.getPermissionString(),
5553                    permissions.getPermissionString()}));
5554        }
5555
5556        return result.intValue();
5557    }
5558
5559    /**
5560     * Reads a folder from the VFS, using the specified resource filter.<p>
5561     *
5562     * @param dbc the current database context
5563     * @param resourcename the name of the folder to read (full path)
5564     * @param filter the resource filter to use while reading
5565     *
5566     * @return the folder that was read
5567     *
5568     * @throws CmsException if something goes wrong
5569     */

5570    protected CmsFolder readFolder(CmsDbContext dbc, String JavaDoc resourcename, CmsResourceFilter filter) throws CmsException {
5571
5572        CmsResource resource = readResource(dbc, resourcename, filter);
5573        return m_driverManager.convertResourceToFolder(resource);
5574    }
5575
5576    /**
5577     * Reads a resource from the OpenCms VFS, using the specified resource filter.<p>
5578     *
5579     * @param dbc the current database context
5580     * @param resourcePath the name of the resource to read (full path)
5581     * @param filter the resource filter to use while reading
5582     *
5583     * @return the resource that was read
5584     *
5585     * @throws CmsException if something goes wrong
5586     *
5587     * @see CmsObject#readResource(String, CmsResourceFilter)
5588     * @see CmsObject#readResource(String)
5589     * @see CmsFile#upgrade(CmsResource, CmsObject)
5590     */

5591    protected CmsResource readResource(CmsDbContext dbc, String JavaDoc resourcePath, CmsResourceFilter filter)
5592    throws CmsException {
5593
5594        // read the resource from the VFS
5595
CmsResource resource = m_driverManager.readResource(dbc, resourcePath, filter);
5596
5597        // check if the user has read access to the resource
5598
checkPermissions(dbc, resource, CmsPermissionSet.ACCESS_READ, true, filter);
5599
5600        // access was granted - return the resource
5601
return resource;
5602    }
5603
5604    /**
5605     * Deletes a user, where all permissions and resources attributes of the user
5606     * were transfered to a replacement user, if given.<p>
5607     *
5608     * @param context the current request context
5609     * @param user the user to be deleted
5610     * @param replacement the user to be transfered, can be <code>null</code>
5611     *
5612     * @throws CmsRoleViolationException if the current user does not own the rule {@link CmsRole#ACCOUNT_MANAGER}
5613     * @throws CmsSecurityException in case the user is a default user
5614     * @throws CmsException if something goes wrong
5615     */

5616    private void deleteUser(CmsRequestContext context, CmsUser user, CmsUser replacement)
5617    throws CmsException, CmsSecurityException, CmsRoleViolationException {
5618
5619        if (OpenCms.getDefaultUsers().isDefaultUser(user.getName())) {
5620            throw new CmsSecurityException(org.opencms.security.Messages.get().container(
5621                org.opencms.security.Messages.ERR_CANT_DELETE_DEFAULT_USER_1,
5622                user.getName()));
5623        }
5624        if (context.currentUser().equals(user)) {
5625            throw new CmsSecurityException(Messages.get().container(Messages.ERR_USER_CANT_DELETE_ITSELF_USER_0));
5626        }
5627        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
5628        try {
5629            checkRole(dbc, CmsRole.ACCOUNT_MANAGER);
5630            // this is needed because
5631
// I_CmsUserDriver#removeAccessControlEntriesForPrincipal(CmsDbContext, CmsProject, CmsProject, CmsUUID)
5632
// expects an offline project, if not data will become inconsistent
5633
checkOfflineProject(dbc);
5634            if (replacement == null) {
5635                m_driverManager.deleteUser(dbc, context.currentProject(), user.getName(), null);
5636            } else {
5637                m_driverManager.deleteUser(dbc, context.currentProject(), user.getName(), replacement.getName());
5638            }
5639        } catch (Exception JavaDoc e) {
5640            dbc.report(null, Messages.get().container(Messages.ERR_DELETE_USER_1, user.getName()), e);
5641        } finally {
5642            dbc.clear();
5643        }
5644    }
5645}
Popular Tags