001/*
002 * This library is part of OpenCms -
003 * the Open Source Content Management System
004 *
005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com)
006 *
007 * This library is free software; you can redistribute it and/or
008 * modify it under the terms of the GNU Lesser General Public
009 * License as published by the Free Software Foundation; either
010 * version 2.1 of the License, or (at your option) any later version.
011 *
012 * This library is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015 * Lesser General Public License for more details.
016 *
017 * For further information about Alkacon Software GmbH & Co. KG, please see the
018 * company website: http://www.alkacon.com
019 *
020 * For further information about OpenCms, please see the
021 * project website: http://www.opencms.org
022 *
023 * You should have received a copy of the GNU Lesser General Public
024 * License along with this library; if not, write to the Free Software
025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
026 */
027
028package org.opencms.file;
029
030import org.opencms.db.CmsDbEntryNotFoundException;
031import org.opencms.db.CmsPublishedResource;
032import org.opencms.db.CmsResourceState;
033import org.opencms.db.CmsSecurityManager;
034import org.opencms.db.log.CmsLogEntry;
035import org.opencms.db.log.CmsLogFilter;
036import org.opencms.db.urlname.CmsUrlNameMappingEntry;
037import org.opencms.db.urlname.CmsUrlNameMappingFilter;
038import org.opencms.file.CmsResource.CmsResourceDeleteMode;
039import org.opencms.file.history.CmsHistoryPrincipal;
040import org.opencms.file.history.CmsHistoryProject;
041import org.opencms.file.history.I_CmsHistoryResource;
042import org.opencms.file.types.I_CmsResourceType;
043import org.opencms.i18n.CmsLocaleGroupService;
044import org.opencms.lock.CmsLock;
045import org.opencms.lock.CmsLockFilter;
046import org.opencms.lock.CmsLockType;
047import org.opencms.main.CmsException;
048import org.opencms.main.CmsIllegalArgumentException;
049import org.opencms.main.I_CmsEventListener;
050import org.opencms.main.OpenCms;
051import org.opencms.relations.CmsRelation;
052import org.opencms.relations.CmsRelationFilter;
053import org.opencms.relations.CmsRelationType;
054import org.opencms.report.I_CmsReport;
055import org.opencms.security.CmsAccessControlEntry;
056import org.opencms.security.CmsAccessControlList;
057import org.opencms.security.CmsOrganizationalUnit;
058import org.opencms.security.CmsPermissionSet;
059import org.opencms.security.CmsPrincipal;
060import org.opencms.security.CmsRole;
061import org.opencms.security.CmsRoleViolationException;
062import org.opencms.security.CmsSecurityException;
063import org.opencms.security.I_CmsPermissionHandler;
064import org.opencms.security.I_CmsPrincipal;
065import org.opencms.util.CmsPair;
066import org.opencms.util.CmsStringUtil;
067import org.opencms.util.CmsUUID;
068import org.opencms.xml.content.CmsNumberSuffixNameSequence;
069
070import java.util.ArrayList;
071import java.util.Collections;
072import java.util.Iterator;
073import java.util.List;
074import java.util.Locale;
075import java.util.Map;
076import java.util.Set;
077
078/**
079 * This pivotal class provides all authorized access to the OpenCms VFS resources.<p>
080 *
081 * It encapsulates user identification and permissions.
082 * Think of it as an initialized "shell" to access the OpenCms VFS.
083 * Every call to a method here will be checked for user permissions
084 * according to the <code>{@link org.opencms.file.CmsRequestContext}</code> this CmsObject instance was created with.<p>
085 *
086 * From a JSP page running in OpenCms, use <code>{@link org.opencms.jsp.CmsJspBean#getCmsObject()}</code> to gain
087 * access to the current users CmsObject. Usually this is done with a <code>{@link org.opencms.jsp.CmsJspActionElement}</code>.<p>
088 *
089 * To generate a new instance of this class in your application, use
090 * <code>{@link org.opencms.main.OpenCms#initCmsObject(String)}</code>. The argument String should be
091 * the name of the guest user, usually "Guest" and more formally obtained by <code>{@link org.opencms.db.CmsDefaultUsers#getUserGuest()}</code>.
092 * This will give you an initialized context with guest user permissions.
093 * Then use <code>{@link CmsObject#loginUser(String, String)}</code> to log in the user you want.
094 * Obviously you need the password for the new user.
095 * You should never try to create an instance of this class using the constructor,
096 * this is reserved for internal operation only.<p>
097 *
098 * @since 6.0.0
099 */
100public final class CmsObject {
101
102    /** The request context. */
103    protected CmsRequestContext m_context;
104
105    /** The security manager to access the cms. */
106    protected CmsSecurityManager m_securityManager;
107
108    /**
109     * Connects an OpenCms user context to a running database.<p>
110     *
111     * <b>Please note:</b> This constructor is internal to OpenCms and not for public use.
112     * If you want to create a new instance of a <code>{@link CmsObject}</code> in your application,
113     * use <code>{@link org.opencms.main.OpenCms#initCmsObject(String)}</code>.<p>
114     *
115     * @param securityManager the security manager
116     * @param context the request context that contains the user authentication
117     */
118    public CmsObject(CmsSecurityManager securityManager, CmsRequestContext context) {
119
120        init(securityManager, context);
121    }
122
123    /**
124     * Adds a new relation to the given resource.<p>
125     *
126     * @param resource the source resource
127     * @param target the target resource
128     * @param type the type of the relation
129     *
130     * @throws CmsException if something goes wrong
131     */
132    public void addRelationToResource(CmsResource resource, CmsResource target, String type) throws CmsException {
133
134        createRelation(resource, target, type, false);
135    }
136
137    /**
138     * Adds a new relation to the given resource.<p>
139     *
140     * @param resourceName the name of the source resource
141     * @param targetPath the path of the target resource
142     * @param type the type of the relation
143     *
144     * @throws CmsException if something goes wrong
145     */
146    public void addRelationToResource(String resourceName, String targetPath, String type) throws CmsException {
147
148        createRelation(resourceName, targetPath, type, false);
149    }
150
151    /**
152     * Convenience method to add the site root from the current user's
153     * request context to the given resource name.<p>
154     *
155     * @param resourcename the resource name
156     *
157     * @return the resource name with the site root added
158     *
159     * @see CmsRequestContext#addSiteRoot(String)
160     */
161    public String addSiteRoot(String resourcename) {
162
163        return m_context.addSiteRoot(resourcename);
164    }
165
166    /**
167     * Adds a user to a group.<p>
168     *
169     * @param username the name of the user that is to be added to the group
170     * @param groupname the name of the group
171     *
172     * @throws CmsException if something goes wrong
173     */
174    public void addUserToGroup(String username, String groupname) throws CmsException {
175
176        m_securityManager.addUserToGroup(m_context, username, groupname, false);
177    }
178
179    /**
180     * This method works just like {@link CmsObject#adjustLinks(String, String)}, but you can specify multiple source
181     * files, and the target folder is interpreted as the folder into which the source files have been copied.<p>
182     *
183     * @param sourceFiles the list of source files
184     * @param targetParentFolder the folder into which the source files have been copied
185     *
186     * @throws CmsException if something goes wrong
187     */
188    public void adjustLinks(List<String> sourceFiles, String targetParentFolder) throws CmsException {
189
190        CmsObject cms = OpenCms.initCmsObject(this);
191        cms.getRequestContext().setSiteRoot("");
192        List<String> rootSourceFiles = new ArrayList<String>();
193        for (String sourceFile : sourceFiles) {
194            rootSourceFiles.add(addSiteRoot(sourceFile));
195        }
196        String rootTargetParentFolder = addSiteRoot(targetParentFolder);
197
198        CmsLinkRewriter rewriter = new CmsLinkRewriter(cms, rootSourceFiles, rootTargetParentFolder);
199        rewriter.rewriteLinks();
200    }
201
202    /**
203     * This method works just like {@link CmsObject#adjustLinks(String, String)}, but instead of specifying
204     * a single source and target folder, you can specify multiple sources and the corresponding targets in
205     * a map of strings.
206     *
207     * @param sourceTargetMap a map with the source files as keys and the corresponding targets as values
208     * @param targetParentFolder the folder into which the source files have been copied
209     *
210     * @throws CmsException if something goes wrong
211     */
212    public void adjustLinks(Map<String, String> sourceTargetMap, String targetParentFolder) throws CmsException {
213
214        CmsObject cms = OpenCms.initCmsObject(this);
215        cms.getRequestContext().setSiteRoot("");
216        List<CmsPair<String, String>> sourcesAndTargets = new ArrayList<CmsPair<String, String>>();
217        for (Map.Entry<String, String> entry : sourceTargetMap.entrySet()) {
218            String rootSource = addSiteRoot(entry.getKey());
219            String rootTarget = addSiteRoot(entry.getValue());
220            sourcesAndTargets.add(CmsPair.create(rootSource, rootTarget));
221        }
222        String rootTargetParentFolder = addSiteRoot(targetParentFolder);
223        CmsLinkRewriter rewriter = new CmsLinkRewriter(cms, rootTargetParentFolder, sourcesAndTargets);
224        rewriter.rewriteLinks();
225    }
226
227    /**
228     * Adjusts all links in the target folder that point to the source folder
229     * so that they are kept "relative" in the target folder where possible.
230     *
231     * If a link is found from the target folder to the source folder,
232     * then the target folder is checked if a target of the same name
233     * is found also "relative" inside the target Folder, and if so,
234     * the link is changed to that "relative" target. This is mainly used to keep
235     * relative links inside a copied folder structure intact.
236     *
237     * Example: Image we have folder /folderA/ that contains files
238     * /folderA/x1 and /folderA/y1. x1 has a link to y1 and y1 to x1.
239     * Now someone copies /folderA/ to /folderB/. So we end up with
240     * /folderB/x2 and /folderB/y2. Because of the link mechanism in OpenCms,
241     * x2 will have a link to y1 and y2 to x1. By using this method,
242     * the links from x2 to y1 will be replaced by a link x2 to y2,
243     * and y2 to x1 with y2 to x2.
244     *
245     * Link replacement works for links in XML files as well as relation only
246     * type links.
247     *
248     * @param sourceFolder the source folder
249     * @param targetFolder the target folder
250     *
251     * @throws CmsException if something goes wrong
252     */
253    public void adjustLinks(String sourceFolder, String targetFolder) throws CmsException {
254
255        String rootSourceFolder = addSiteRoot(sourceFolder);
256        String rootTargetFolder = addSiteRoot(targetFolder);
257        String siteRoot = getRequestContext().getSiteRoot();
258        getRequestContext().setSiteRoot("");
259        try {
260            CmsLinkRewriter linkRewriter = new CmsLinkRewriter(this, rootSourceFolder, rootTargetFolder);
261            linkRewriter.rewriteLinks();
262        } finally {
263            getRequestContext().setSiteRoot(siteRoot);
264        }
265    }
266
267    /**
268     * Changes the access control for a given resource and a given principal(user/group).<p>
269     *
270     * @param resourceName name of the resource
271     * @param principalType the type of the principal (currently group or user):
272     *      <ul>
273     *          <li><code>{@link I_CmsPrincipal#PRINCIPAL_USER}</code></li>
274     *          <li><code>{@link I_CmsPrincipal#PRINCIPAL_GROUP}</code></li>
275     *      </ul>
276     * @param principalName name of the principal
277     * @param allowedPermissions bit set of allowed permissions
278     * @param deniedPermissions bit set of denied permissions
279     * @param flags additional flags of the access control entry
280     *
281     * @throws CmsException if something goes wrong
282     */
283    public void chacc(
284        String resourceName,
285        String principalType,
286        String principalName,
287        int allowedPermissions,
288        int deniedPermissions,
289        int flags)
290    throws CmsException {
291
292        CmsResource res = readResource(resourceName, CmsResourceFilter.ALL);
293
294        CmsAccessControlEntry acEntry = null;
295        try {
296            I_CmsPrincipal principal = CmsPrincipal.readPrincipal(this, principalType, principalName);
297            acEntry = new CmsAccessControlEntry(
298                res.getResourceId(),
299                principal.getId(),
300                allowedPermissions,
301                deniedPermissions,
302                flags);
303            acEntry.setFlagsForPrincipal(principal);
304        } catch (CmsDbEntryNotFoundException e) {
305            // check for special ids
306            if (principalName.equalsIgnoreCase(CmsAccessControlEntry.PRINCIPAL_ALL_OTHERS_NAME)) {
307                acEntry = new CmsAccessControlEntry(
308                    res.getResourceId(),
309                    CmsAccessControlEntry.PRINCIPAL_ALL_OTHERS_ID,
310                    allowedPermissions,
311                    deniedPermissions,
312                    flags);
313                acEntry.setFlags(CmsAccessControlEntry.ACCESS_FLAGS_ALLOTHERS);
314            } else if (principalName.equalsIgnoreCase(CmsAccessControlEntry.PRINCIPAL_OVERWRITE_ALL_NAME)) {
315                acEntry = new CmsAccessControlEntry(
316                    res.getResourceId(),
317                    CmsAccessControlEntry.PRINCIPAL_OVERWRITE_ALL_ID,
318                    allowedPermissions,
319                    deniedPermissions,
320                    flags);
321                acEntry.setFlags(CmsAccessControlEntry.ACCESS_FLAGS_OVERWRITE_ALL);
322            } else if (principalType.equalsIgnoreCase(CmsRole.PRINCIPAL_ROLE)) {
323                // only vfs managers can set role based permissions
324                m_securityManager.checkRoleForResource(m_context, CmsRole.VFS_MANAGER, res);
325                // check for role
326                CmsRole role = CmsRole.valueOfRoleName(principalName);
327                // role based permissions can only be set in the system folder
328                if (role == null) {
329                    throw e;
330                }
331                acEntry = new CmsAccessControlEntry(
332                    res.getResourceId(),
333                    role.getId(),
334                    allowedPermissions,
335                    deniedPermissions,
336                    flags);
337                acEntry.setFlags(CmsAccessControlEntry.ACCESS_FLAGS_ROLE);
338            } else {
339                throw e;
340            }
341        }
342
343        m_securityManager.writeAccessControlEntry(m_context, res, acEntry);
344    }
345
346    /**
347     * Changes the access control for a given resource and a given principal(user/group).<p>
348     *
349     * @param resourceName name of the resource
350     * @param principalType the type of the principal (group or user):
351     *      <ul>
352     *          <li><code>{@link I_CmsPrincipal#PRINCIPAL_USER}</code></li>
353     *          <li><code>{@link I_CmsPrincipal#PRINCIPAL_GROUP}</code></li>
354     *      </ul>
355     * @param principalName name of the principal
356     * @param permissionString the permissions in the format ((+|-)(r|w|v|c|i|o))*
357     *
358     * @throws CmsException if something goes wrong
359     */
360    public void chacc(String resourceName, String principalType, String principalName, String permissionString)
361    throws CmsException {
362
363        CmsResource res = readResource(resourceName, CmsResourceFilter.ALL);
364
365        CmsAccessControlEntry acEntry = null;
366        try {
367            I_CmsPrincipal principal = CmsPrincipal.readPrincipal(this, principalType, principalName);
368            acEntry = new CmsAccessControlEntry(res.getResourceId(), principal.getId(), permissionString);
369            acEntry.setFlagsForPrincipal(principal);
370        } catch (CmsDbEntryNotFoundException e) {
371            // check for special ids
372            if (principalName.equalsIgnoreCase(CmsAccessControlEntry.PRINCIPAL_ALL_OTHERS_NAME)) {
373                acEntry = new CmsAccessControlEntry(
374                    res.getResourceId(),
375                    CmsAccessControlEntry.PRINCIPAL_ALL_OTHERS_ID,
376                    permissionString);
377                acEntry.setFlags(CmsAccessControlEntry.ACCESS_FLAGS_ALLOTHERS);
378            } else if (principalName.equalsIgnoreCase(CmsAccessControlEntry.PRINCIPAL_OVERWRITE_ALL_NAME)) {
379                acEntry = new CmsAccessControlEntry(
380                    res.getResourceId(),
381                    CmsAccessControlEntry.PRINCIPAL_OVERWRITE_ALL_ID,
382                    permissionString);
383                acEntry.setFlags(CmsAccessControlEntry.ACCESS_FLAGS_OVERWRITE_ALL);
384            } else if (principalType.equalsIgnoreCase(CmsRole.PRINCIPAL_ROLE)) {
385                // only vfs managers can set role based permissions
386                m_securityManager.checkRoleForResource(m_context, CmsRole.VFS_MANAGER, res);
387                // check for role
388                CmsRole role = CmsRole.valueOfRoleName(principalName);
389                // role based permissions can only be set in the system folder
390                if (role == null) {
391                    throw e;
392                }
393                acEntry = new CmsAccessControlEntry(res.getResourceId(), role.getId(), permissionString);
394                acEntry.setFlags(CmsAccessControlEntry.ACCESS_FLAGS_ROLE);
395            } else {
396                throw e;
397            }
398        }
399
400        m_securityManager.writeAccessControlEntry(m_context, res, acEntry);
401    }
402
403    /**
404     * Changes the lock of a resource to the current user,
405     * that is "steals" the lock from another user.<p>
406     *
407     * This is the "steal lock" operation.<p>
408     *
409     * @param resource the resource to change the lock
410     *
411     * @throws CmsException if something goes wrong
412     */
413    public void changeLock(CmsResource resource) throws CmsException {
414
415        getResourceType(resource).changeLock(this, m_securityManager, resource);
416    }
417
418    /**
419     * Changes the lock of a resource to the current user,
420     * that is "steals" the lock from another user.<p>
421     *
422     * This is the "steal lock" operation.<p>
423     *
424     * @param resourcename the name of the resource to change the lock with complete path
425     *
426     * @throws CmsException if something goes wrong
427     */
428    public void changeLock(String resourcename) throws CmsException {
429
430        CmsResource resource = readResource(resourcename, CmsResourceFilter.ALL);
431        changeLock(resource);
432    }
433
434    /**
435     * Returns a list with all sub resources of a given folder that have set the given property,
436     * matching the current property's value with the given old value and replacing it by a given new value.<p>
437     *
438     * @param resourcename the name of the resource to change the property value
439     * @param property the name of the property to change the value
440     * @param oldValue the old value of the property, can be a regular expression
441     * @param newValue the new value of the property
442     * @param recursive if true, change recursively all property values on sub-resources (only for folders)
443     *
444     * @return a list with the <code>{@link CmsResource}</code>'s where the property value has been changed
445     *
446     * @throws CmsException if operation was not successful
447     */
448    public List<CmsResource> changeResourcesInFolderWithProperty(
449        String resourcename,
450        String property,
451        String oldValue,
452        String newValue,
453        boolean recursive)
454    throws CmsException {
455
456        CmsResource resource = readResource(resourcename, CmsResourceFilter.IGNORE_EXPIRATION);
457        return m_securityManager.changeResourcesInFolderWithProperty(
458            m_context,
459            resource,
460            property,
461            oldValue,
462            newValue,
463            recursive);
464    }
465
466    /**
467     * Changes the resource flags of a resource.<p>
468     *
469     * The resource flags are used to indicate various "special" conditions
470     * for a resource. Most notably, the "internal only" setting which signals
471     * that a resource can not be directly requested with it's URL.<p>
472     *
473     * @param resourcename the name of the resource to change the flags for (full current site relative path)
474     * @param flags the new flags for this resource
475     *
476     * @throws CmsException if something goes wrong
477     */
478    public void chflags(String resourcename, int flags) throws CmsException {
479
480        CmsResource resource = readResource(resourcename, CmsResourceFilter.IGNORE_EXPIRATION);
481        getResourceType(resource).chflags(this, m_securityManager, resource, flags);
482    }
483
484    /**
485     * Changes the resource type of a resource.<p>
486     *
487     * OpenCms handles resources according to the resource type,
488     * not the file suffix. This is e.g. why a JSP in OpenCms can have the
489     * suffix ".html" instead of ".jsp" only. Changing the resource type
490     * makes sense e.g. if you want to make a plain text file a JSP resource,
491     * or a binary file an image, etc.<p>
492     *
493     * @param resourcename the name of the resource to change the type for (full current site relative path)
494     * @param type the new resource type for this resource
495     *
496     * @throws CmsException if something goes wrong
497     */
498    public void chtype(String resourcename, I_CmsResourceType type) throws CmsException {
499
500        CmsResource resource = readResource(resourcename, CmsResourceFilter.IGNORE_EXPIRATION);
501        getResourceType(resource).chtype(this, m_securityManager, resource, type);
502    }
503
504    /**
505     * Changes the resource type of a resource.<p>
506     *
507     * OpenCms handles resources according to the resource type,
508     * not the file suffix. This is e.g. why a JSP in OpenCms can have the
509     * suffix ".html" instead of ".jsp" only. Changing the resource type
510     * makes sense e.g. if you want to make a plain text file a JSP resource,
511     * or a binary file an image, etc.<p>
512     *
513     * @param resourcename the name of the resource to change the type for (full current site relative path)
514     * @param type the new resource type for this resource
515     *
516     * @throws CmsException if something goes wrong
517     *
518     * @deprecated
519     * Use {@link #chtype(String, I_CmsResourceType)} instead.
520     * Resource types should always be referenced either by its type class (preferred) or by type name.
521     * Use of int based resource type references will be discontinued in a future OpenCms release.
522     */
523    @Deprecated
524    public void chtype(String resourcename, int type) throws CmsException {
525
526        chtype(resourcename, getResourceType(type));
527    }
528
529    /**
530     * Copies a resource.<p>
531     *
532     * The copied resource will always be locked to the current user
533     * after the copy operation.<p>
534     *
535     * Siblings will be treated according to the
536     * <code>{@link org.opencms.file.CmsResource#COPY_PRESERVE_SIBLING}</code> mode.<p>
537     *
538     * @param source the name of the resource to copy (full current site relative path)
539     * @param destination the name of the copy destination (full current site relative path)
540     *
541     * @throws CmsException if something goes wrong
542     * @throws CmsIllegalArgumentException if the <code>destination</code> argument is null or of length 0
543     *
544     * @see #copyResource(String, String, CmsResource.CmsResourceCopyMode)
545     */
546    public void copyResource(String source, String destination) throws CmsException, CmsIllegalArgumentException {
547
548        copyResource(source, destination, CmsResource.COPY_PRESERVE_SIBLING);
549    }
550
551    /**
552     * Copies a resource.<p>
553     *
554     * The copied resource will always be locked to the current user
555     * after the copy operation.<p>
556     *
557     * The <code>siblingMode</code> parameter controls how to handle siblings
558     * during the copy operation.<br>
559     * Possible values for this parameter are: <br>
560     * <ul>
561     * <li><code>{@link CmsResource#COPY_AS_NEW}</code></li>
562     * <li><code>{@link CmsResource#COPY_AS_SIBLING}</code></li>
563     * <li><code>{@link CmsResource#COPY_PRESERVE_SIBLING}</code></li>
564     * </ul><p>
565     *
566     * @param source the name of the resource to copy (full current site relative path)
567     * @param destination the name of the copy destination (full current site relative path)
568     * @param siblingMode indicates how to handle siblings during copy
569     *
570     * @throws CmsException if something goes wrong
571     * @throws CmsIllegalArgumentException if the <code>destination</code> argument is null or of length 0
572     */
573    public void copyResource(String source, String destination, CmsResource.CmsResourceCopyMode siblingMode)
574    throws CmsException, CmsIllegalArgumentException {
575
576        CmsResource resource = readResource(source, CmsResourceFilter.IGNORE_EXPIRATION);
577        getResourceType(resource).copyResource(this, m_securityManager, resource, destination, siblingMode);
578    }
579
580    /**
581     * Copies a resource to the current project of the user.<p>
582     *
583     * This is used to extend the current users project with the
584     * specified resource, in case that the resource is not yet part of the project.
585     * The resource is not really copied like in a regular copy operation,
586     * it is in fact only "enabled" in the current users project.<p>
587     *
588     * @param resource the resource to copy to the current project
589     *
590     * @throws CmsException if something goes wrong
591     */
592    public void copyResourceToProject(CmsResource resource) throws CmsException {
593
594        getResourceType(resource).copyResourceToProject(this, m_securityManager, resource);
595    }
596
597    /**
598     * Copies a resource to the current project of the user.<p>
599     *
600     * This is used to extend the current users project with the
601     * specified resource, in case that the resource is not yet part of the project.
602     * The resource is not really copied like in a regular copy operation,
603     * it is in fact only "enabled" in the current users project.<p>
604     *
605     * @param resourcename the name of the resource to copy to the current project (full current site relative path)
606     *
607     * @throws CmsException if something goes wrong
608     */
609    public void copyResourceToProject(String resourcename) throws CmsException {
610
611        CmsResource resource = readResource(resourcename, CmsResourceFilter.ALL);
612        copyResourceToProject(resource);
613    }
614
615    /**
616     * Counts the locked resources in a project.<p>
617     *
618     * @param id the id of the project
619     *
620     * @return the number of locked resources in this project
621     *
622     * @throws CmsException if operation was not successful
623     */
624    public int countLockedResources(CmsUUID id) throws CmsException {
625
626        return m_securityManager.countLockedResources(m_context, id);
627    }
628
629    /**
630     * Copies access control entries of a given resource to another resource.<p>
631     *
632     * Already existing access control entries of the destination resource are removed.<p>
633     *
634     * @param sourceName the name of the resource of which the access control entries are copied
635     * @param destName the name of the resource to which the access control entries are applied
636     *
637     * @throws CmsException if something goes wrong
638     */
639    public void cpacc(String sourceName, String destName) throws CmsException {
640
641        CmsResource source = readResource(sourceName);
642        CmsResource dest = readResource(destName);
643        m_securityManager.copyAccessControlEntries(m_context, source, dest);
644    }
645
646    /**
647     * Creates a new user group.<p>
648     *
649     * @param groupFqn the name of the new group
650     * @param description the description of the new group
651     * @param flags the flags for the new group
652     * @param parent the parent group (or <code>null</code>)
653     *
654     * @return a <code>{@link CmsGroup}</code> object representing the newly created group
655     *
656     * @throws CmsException if operation was not successful
657     */
658    public CmsGroup createGroup(String groupFqn, String description, int flags, String parent) throws CmsException {
659
660        return m_securityManager.createGroup(m_context, groupFqn, description, flags, parent);
661    }
662
663    /**
664     * Creates a new project.<p>
665     *
666     * @param name the name of the project to create
667     * @param description the description for the new project
668     * @param groupname the name of the project user group
669     * @param managergroupname the name of the project manager group
670     *
671     * @return the created project
672     *
673     * @throws CmsException if something goes wrong
674     */
675    public CmsProject createProject(String name, String description, String groupname, String managergroupname)
676    throws CmsException {
677
678        return m_securityManager.createProject(
679            m_context,
680            name,
681            description,
682            groupname,
683            managergroupname,
684            CmsProject.PROJECT_TYPE_NORMAL);
685    }
686
687    /**
688     * Creates a new project.<p>
689     *
690     * @param name the name of the project to create
691     * @param description the description for the new project
692     * @param groupname the name of the project user group
693     * @param managergroupname the name of the project manager group
694     * @param projecttype the type of the project (normal or temporary)
695     *
696     * @return the created project
697     *
698     * @throws CmsException if operation was not successful
699     */
700    public CmsProject createProject(
701        String name,
702        String description,
703        String groupname,
704        String managergroupname,
705        CmsProject.CmsProjectType projecttype)
706    throws CmsException {
707
708        return m_securityManager.createProject(m_context, name, description, groupname, managergroupname, projecttype);
709    }
710
711    /**
712     * Creates a property definition.<p>
713     *
714     * Property definitions are valid for all resource types.<p>
715     *
716     * @param name the name of the property definition to create
717     *
718     * @return the created property definition
719     *
720     * @throws CmsException if something goes wrong
721     */
722    public CmsPropertyDefinition createPropertyDefinition(String name) throws CmsException {
723
724        return (m_securityManager.createPropertyDefinition(m_context, name));
725    }
726
727    /**
728     * Creates a resource with the given properties and content.
729     * Will throw an exception, if a resource with the given name already exists.<p>
730     *
731     * @param sitePath the site path for the resource
732     * @param resource the resource object to be imported
733     * @param content the content of the resource
734     * @param properties the properties of the resource
735     *
736     * @return the imported resource
737     *
738     * @throws CmsException if something goes wrong
739     */
740    public CmsResource createResource(
741        String sitePath,
742        CmsResource resource,
743        byte[] content,
744        List<CmsProperty> properties)
745    throws CmsException {
746
747        resource.setUserLastModified(getRequestContext().getCurrentUser().getId());
748        resource.setDateLastModified(System.currentTimeMillis());
749        // ensure resource record is updated
750        resource.setState(CmsResource.STATE_NEW);
751        return m_securityManager.createResource(
752            m_context,
753            m_context.addSiteRoot(sitePath),
754            resource,
755            content,
756            properties);
757    }
758
759    /**
760     * Creates a new resource of the given resource type with
761     * empty content and no properties.<p>
762     *
763     * @param resourcename the name of the resource to create (full current site relative path)
764     * @param type the type of the resource to create
765     *
766     * @return the created resource
767     *
768     * @throws CmsException if something goes wrong
769     * @throws CmsIllegalArgumentException if the given <code>resourcename</code> is null or of length 0
770     *
771     * @see #createResource(String, int, byte[], List)
772     */
773    public CmsResource createResource(String resourcename, I_CmsResourceType type)
774    throws CmsException, CmsIllegalArgumentException {
775
776        return createResource(resourcename, type, new byte[0], new ArrayList<CmsProperty>(0));
777    }
778
779    /**
780     * Creates a new resource of the given resource type
781     * with the provided content and properties.<p>
782     *
783     * @param resourcename the name of the resource to create (full current site relative path)
784     * @param type the type of the resource to create
785     * @param content the contents for the new resource
786     * @param properties the properties for the new resource
787     *
788     * @return the created resource
789     *
790     * @throws CmsException if something goes wrong
791     * @throws CmsIllegalArgumentException if the <code>resourcename</code> argument is null or of length 0
792     */
793    public CmsResource createResource(
794        String resourcename,
795        I_CmsResourceType type,
796        byte[] content,
797        List<CmsProperty> properties)
798    throws CmsException, CmsIllegalArgumentException {
799
800        return type.createResource(this, m_securityManager, resourcename, content, properties);
801    }
802
803    /**
804     * Creates a new resource of the given resource type with
805     * empty content and no properties.<p>
806     *
807     * @param resourcename the name of the resource to create (full current site relative path)
808     * @param type the type of the resource to create
809     *
810     * @return the created resource
811     *
812     * @throws CmsException if something goes wrong
813     * @throws CmsIllegalArgumentException if the given <code>resourcename</code> is null or of length 0
814     *
815     * @see #createResource(String, int, byte[], List)
816     *
817     * @deprecated
818     * Use {@link #createResource(String, I_CmsResourceType)} instead.
819     * Resource types should always be referenced either by its type class (preferred) or by type name.
820     * Use of int based resource type references will be discontinued in a future OpenCms release.
821     */
822    @Deprecated
823    public CmsResource createResource(String resourcename, int type) throws CmsException, CmsIllegalArgumentException {
824
825        return createResource(resourcename, getResourceType(type), new byte[0], new ArrayList<CmsProperty>(0));
826    }
827
828    /**
829     * Creates a new resource of the given resource type
830     * with the provided content and properties.<p>
831     *
832     * @param resourcename the name of the resource to create (full current site relative path)
833     * @param type the type of the resource to create
834     * @param content the contents for the new resource
835     * @param properties the properties for the new resource
836     *
837     * @return the created resource
838     *
839     * @throws CmsException if something goes wrong
840     * @throws CmsIllegalArgumentException if the <code>resourcename</code> argument is null or of length 0
841     *
842     * @deprecated
843     * Use {@link #createResource(String, I_CmsResourceType, byte[], List)} instead.
844     * Resource types should always be referenced either by its type class (preferred) or by type name.
845     * Use of int based resource type references will be discontinued in a future OpenCms release.
846     */
847    @Deprecated
848    public CmsResource createResource(String resourcename, int type, byte[] content, List<CmsProperty> properties)
849    throws CmsException, CmsIllegalArgumentException {
850
851        return createResource(resourcename, getResourceType(type), content, properties);
852    }
853
854    /**
855     * Creates a new sibling of the source resource.<p>
856     *
857     * @param source the name of the resource to create a sibling for with complete path
858     * @param destination the name of the sibling to create with complete path
859     * @param properties the individual properties for the new sibling
860     *
861     * @return the new created sibling
862     *
863     * @throws CmsException if something goes wrong
864     */
865    public CmsResource createSibling(String source, String destination, List<CmsProperty> properties)
866    throws CmsException {
867
868        CmsResource resource = readResource(source, CmsResourceFilter.IGNORE_EXPIRATION);
869        return getResourceType(resource).createSibling(this, m_securityManager, resource, destination, properties);
870    }
871
872    /**
873     * Creates the project for the temporary workplace files.<p>
874     *
875     * @return the created project for the temporary workplace files
876     *
877     * @throws CmsException if something goes wrong
878     */
879    public CmsProject createTempfileProject() throws CmsException {
880
881        return m_securityManager.createTempfileProject(m_context);
882    }
883
884    /**
885     * Creates a new user.<p>
886     *
887     * @param userFqn the name for the new user
888     * @param password the password for the new user
889     * @param description the description for the new user
890     * @param additionalInfos the additional infos for the user
891     *
892     * @return the created user
893     *
894     * @throws CmsException if something goes wrong
895     */
896    public CmsUser createUser(String userFqn, String password, String description, Map<String, Object> additionalInfos)
897    throws CmsException {
898
899        return m_securityManager.createUser(m_context, userFqn, password, description, additionalInfos);
900    }
901
902    /**
903     * Deletes all published resource entries.<p>
904     *
905     * @param linkType the type of resource deleted (0= non-parameter, 1=parameter)
906     *
907     * @throws CmsException if something goes wrong
908     */
909    public void deleteAllStaticExportPublishedResources(int linkType) throws CmsException {
910
911        m_securityManager.deleteAllStaticExportPublishedResources(m_context, linkType);
912    }
913
914    /**
915     * Deletes a group, where all permissions, users and children of the group
916     * are transfered to a replacement group.<p>
917     *
918     * @param groupId the id of the group to be deleted
919     * @param replacementId the id of the group to be transfered, can be <code>null</code>
920     *
921     * @throws CmsException if operation was not successful
922     */
923    public void deleteGroup(CmsUUID groupId, CmsUUID replacementId) throws CmsException {
924
925        m_securityManager.deleteGroup(m_context, groupId, replacementId);
926    }
927
928    /**
929     * Deletes a user group.<p>
930     *
931     * Only groups that contain no subgroups can be deleted.<p>
932     *
933     * @param group the name of the group
934     *
935     * @throws CmsException if operation was not successful
936     */
937    public void deleteGroup(String group) throws CmsException {
938
939        m_securityManager.deleteGroup(m_context, group);
940    }
941
942    /**
943     * Deletes the versions from the history tables, keeping the given number of versions per resource.<p>
944     *
945     * @param versionsToKeep number of versions to keep, is ignored if negative
946     * @param versionsDeleted number of versions to keep for deleted resources, is ignored if negative
947     * @param timeDeleted deleted resources older than this will also be deleted, is ignored if negative
948     * @param report the report for output logging
949     *
950     * @throws CmsException if operation was not successful
951     */
952    public void deleteHistoricalVersions(int versionsToKeep, int versionsDeleted, long timeDeleted, I_CmsReport report)
953    throws CmsException {
954
955        m_securityManager.deleteHistoricalVersions(m_context, versionsToKeep, versionsDeleted, timeDeleted, report);
956    }
957
958    /**
959     * Deletes the log entries matching the given filter.<p>
960     *
961     * @param filter the filter to use for deleting the log entries
962     *
963     * @throws CmsException if something goes wrong
964     *
965     * @see CmsSecurityManager#deleteLogEntries(CmsRequestContext, CmsLogFilter)
966     * @see #getLogEntries(CmsLogFilter)
967     */
968    public void deleteLogEntries(CmsLogFilter filter) throws CmsException {
969
970        m_securityManager.deleteLogEntries(m_context, filter);
971    }
972
973    /**
974     * Deletes a project.<p>
975     *
976     * All resources inside the project have to be be reset to their online state.<p>
977     *
978     * @param id the id of the project to delete
979     *
980     * @throws CmsException if operation was not successful
981     */
982    public void deleteProject(CmsUUID id) throws CmsException {
983
984        m_securityManager.deleteProject(m_context, id);
985    }
986
987    /**
988     * Deletes a property definition.<p>
989     *
990     * @param name the name of the property definition to delete
991     *
992     * @throws CmsException if something goes wrong
993     */
994    public void deletePropertyDefinition(String name) throws CmsException {
995
996        m_securityManager.deletePropertyDefinition(m_context, name);
997    }
998
999    /**
1000     * Deletes the relations to a given resource.<p>
1001     *
1002     * @param resource the resource to delete the relations from
1003     * @param filter the filter to use for deleting the relations
1004     *
1005     * @throws CmsException if something goes wrong
1006     */
1007    public void deleteRelationsFromResource(CmsResource resource, CmsRelationFilter filter) throws CmsException {
1008
1009        m_securityManager.deleteRelationsForResource(m_context, resource, filter);
1010    }
1011
1012    /**
1013     * Deletes the relations to a given resource.<p>
1014     *
1015     * @param resourceName the resource to delete the relations from
1016     * @param filter the filter to use for deleting the relations
1017     *
1018     * @throws CmsException if something goes wrong
1019     */
1020    public void deleteRelationsFromResource(String resourceName, CmsRelationFilter filter) throws CmsException {
1021
1022        CmsResource resource = readResource(resourceName, CmsResourceFilter.ALL);
1023        m_securityManager.deleteRelationsForResource(m_context, resource, filter);
1024    }
1025
1026    /**
1027     * Deletes a resource.<p>
1028     *
1029     * The <code>siblingMode</code> parameter controls how to handle siblings
1030     * during the delete operation.<br>
1031     * Possible values for this parameter are: <br>
1032     * <ul>
1033     * <li><code>{@link CmsResource#DELETE_REMOVE_SIBLINGS}</code></li>
1034     * <li><code>{@link CmsResource#DELETE_PRESERVE_SIBLINGS}</code></li>
1035     * </ul><p>
1036     *
1037     * @param res the resource to delete
1038     * @param deletePreserveSiblings indicates how to handle siblings of the deleted resource
1039     *
1040     * @throws CmsException if something goes wrong
1041     */
1042    public void deleteResource(CmsResource res, CmsResourceDeleteMode deletePreserveSiblings) throws CmsException {
1043
1044        getResourceType(res).deleteResource(this, m_securityManager, res, deletePreserveSiblings);
1045    }
1046
1047    /**
1048     * Deletes a resource given its name.<p>
1049     *
1050     * The <code>siblingMode</code> parameter controls how to handle siblings
1051     * during the delete operation.<br>
1052     * Possible values for this parameter are: <br>
1053     * <ul>
1054     * <li><code>{@link CmsResource#DELETE_REMOVE_SIBLINGS}</code></li>
1055     * <li><code>{@link CmsResource#DELETE_PRESERVE_SIBLINGS}</code></li>
1056     * </ul><p>
1057     *
1058     * @param resourcename the name of the resource to delete (full current site relative path)
1059     * @param siblingMode indicates how to handle siblings of the deleted resource
1060     *
1061     * @throws CmsException if something goes wrong
1062     */
1063    public void deleteResource(String resourcename, CmsResource.CmsResourceDeleteMode siblingMode) throws CmsException {
1064
1065        // throw the exception if resource name is an empty string
1066        if (CmsStringUtil.isEmptyOrWhitespaceOnly(resourcename)) {
1067            throw new CmsVfsResourceNotFoundException(
1068                Messages.get().container(Messages.ERR_DELETE_RESOURCE_1, resourcename));
1069        }
1070
1071        CmsResource resource = readResource(resourcename, CmsResourceFilter.IGNORE_EXPIRATION);
1072        getResourceType(resource).deleteResource(this, m_securityManager, resource, siblingMode);
1073    }
1074
1075    /**
1076     * Deletes a published resource entry.<p>
1077     *
1078     * @param resourceName The name of the resource to be deleted in the static export
1079     * @param linkType the type of resource deleted (0= non-parameter, 1=parameter)
1080     * @param linkParameter the parameters of the resource
1081     *
1082     * @throws CmsException if something goes wrong
1083     */
1084    public void deleteStaticExportPublishedResource(String resourceName, int linkType, String linkParameter)
1085    throws CmsException {
1086
1087        m_securityManager.deleteStaticExportPublishedResource(m_context, resourceName, linkType, linkParameter);
1088    }
1089
1090    /**
1091     * Deletes a user.<p>
1092     *
1093     * @param userId the id of the user to be deleted
1094     *
1095     * @throws CmsException if operation was not successful
1096     */
1097    public void deleteUser(CmsUUID userId) throws CmsException {
1098
1099        m_securityManager.deleteUser(m_context, userId);
1100    }
1101
1102    /**
1103     * Deletes a user, where all permissions and resources attributes of the user
1104     * were transfered to a replacement user.<p>
1105     *
1106     * @param userId the id of the user to be deleted
1107     * @param replacementId the id of the user to be transfered, can be <code>null</code>
1108     *
1109     * @throws CmsException if operation was not successful
1110     */
1111    public void deleteUser(CmsUUID userId, CmsUUID replacementId) throws CmsException {
1112
1113        m_securityManager.deleteUser(m_context, userId, replacementId);
1114    }
1115
1116    /**
1117     * Deletes a user.<p>
1118     *
1119     * @param username the name of the user to be deleted
1120     *
1121     * @throws CmsException if operation was not successful
1122     */
1123    public void deleteUser(String username) throws CmsException {
1124
1125        m_securityManager.deleteUser(m_context, username);
1126    }
1127
1128    /**
1129     * Checks the availability of a resource in the VFS,
1130     * using the <code>{@link CmsResourceFilter#DEFAULT}</code> filter.<p>
1131     *
1132     * A resource may be of type <code>{@link CmsFile}</code> or
1133     * <code>{@link CmsFolder}</code>.<p>
1134     *
1135     * This method also takes into account the user permissions, so if
1136     * the given resource exists, but the current user has not the required
1137     * permissions, then this method will return <code>false</code>.<p>
1138     *
1139     * @param structureId the structure id of the resource to check
1140     *
1141     * @return <code>true</code> if the resource is available
1142     *
1143     * @see #readResource(CmsUUID)
1144     * @see #existsResource(CmsUUID, CmsResourceFilter)
1145     */
1146    public boolean existsResource(CmsUUID structureId) {
1147
1148        return existsResource(structureId, CmsResourceFilter.DEFAULT);
1149    }
1150
1151    /**
1152     * Checks the availability of a resource in the VFS,
1153     * using the <code>{@link CmsResourceFilter#DEFAULT}</code> filter.<p>
1154     *
1155     * A resource may be of type <code>{@link CmsFile}</code> or
1156     * <code>{@link CmsFolder}</code>.<p>
1157     *
1158     * The specified filter controls what kind of resources should be "found"
1159     * during the read operation. This will depend on the application. For example,
1160     * using <code>{@link CmsResourceFilter#DEFAULT}</code> will only return currently
1161     * "valid" resources, while using <code>{@link CmsResourceFilter#IGNORE_EXPIRATION}</code>
1162     * will ignore the date release / date expired information of the resource.<p>
1163     *
1164     * This method also takes into account the user permissions, so if
1165     * the given resource exists, but the current user has not the required
1166     * permissions, then this method will return <code>false</code>.<p>
1167     *
1168     * @param structureId the structure id of the resource to check
1169     * @param filter the resource filter to use while checking
1170     *
1171     * @return <code>true</code> if the resource is available
1172     *
1173     * @see #readResource(CmsUUID)
1174     * @see #readResource(CmsUUID, CmsResourceFilter)
1175     */
1176    public boolean existsResource(CmsUUID structureId, CmsResourceFilter filter) {
1177
1178        return m_securityManager.existsResource(m_context, structureId, filter);
1179    }
1180
1181    /**
1182     * Checks the availability of a resource in the VFS,
1183     * using the <code>{@link CmsResourceFilter#DEFAULT}</code> filter.<p>
1184     *
1185     * A resource may be of type <code>{@link CmsFile}</code> or
1186     * <code>{@link CmsFolder}</code>.<p>
1187     *
1188     * This method also takes into account the user permissions, so if
1189     * the given resource exists, but the current user has not the required
1190     * permissions, then this method will return <code>false</code>.<p>
1191     *
1192     * @param resourcename the name of the resource to check (full current site relative path)
1193     *
1194     * @return <code>true</code> if the resource is available
1195     *
1196     * @see #readResource(String)
1197     * @see #existsResource(String, CmsResourceFilter)
1198     */
1199    public boolean existsResource(String resourcename) {
1200
1201        return existsResource(resourcename, CmsResourceFilter.DEFAULT);
1202    }
1203
1204    /**
1205     * Checks the availability of a resource in the VFS,
1206     * using the provided filter.<p>
1207     *
1208     * A resource may be of type <code>{@link CmsFile}</code> or
1209     * <code>{@link CmsFolder}</code>.<p>
1210     *
1211     * The specified filter controls what kind of resources should be "found"
1212     * during the read operation. This will depend on the application. For example,
1213     * using <code>{@link CmsResourceFilter#DEFAULT}</code> will only return currently
1214     * "valid" resources, while using <code>{@link CmsResourceFilter#IGNORE_EXPIRATION}</code>
1215     * will ignore the date release / date expired information of the resource.<p>
1216     *
1217     * This method also takes into account the user permissions, so if
1218     * the given resource exists, but the current user has not the required
1219     * permissions, then this method will return <code>false</code>.<p>
1220     *
1221     * @param resourcename the name of the resource to check (full current site relative path)
1222     * @param filter the resource filter to use while checking
1223     *
1224     * @return <code>true</code> if the resource is available
1225     *
1226     * @see #readResource(String)
1227     * @see #readResource(String, CmsResourceFilter)
1228     */
1229    public boolean existsResource(String resourcename, CmsResourceFilter filter) {
1230
1231        return m_securityManager.existsResource(m_context, addSiteRoot(resourcename), filter);
1232    }
1233
1234    /**
1235     * Returns the list of access control entries of a resource given its name.<p>
1236     *
1237     * @param resourceName the name of the resource
1238     *
1239     * @return a list of <code>{@link CmsAccessControlEntry}</code> objects
1240     *
1241     * @throws CmsException if something goes wrong
1242     */
1243    public List<CmsAccessControlEntry> getAccessControlEntries(String resourceName) throws CmsException {
1244
1245        return getAccessControlEntries(resourceName, true);
1246    }
1247
1248    /**
1249     * Returns the list of access control entries of a resource given its name.<p>
1250     *
1251     * @param resourceName the name of the resource
1252     * @param getInherited <code>true</code>, if inherited access control entries should be returned, too
1253     *
1254     * @return a list of <code>{@link CmsAccessControlEntry}</code> objects defining all permissions for the given resource
1255     *
1256     * @throws CmsException if something goes wrong
1257     */
1258    public List<CmsAccessControlEntry> getAccessControlEntries(String resourceName, boolean getInherited)
1259    throws CmsException {
1260
1261        CmsResource res = readResource(resourceName, CmsResourceFilter.ALL);
1262        return m_securityManager.getAccessControlEntries(m_context, res, getInherited);
1263    }
1264
1265    /**
1266     * Returns the access control list (summarized access control entries) of a given resource.<p>
1267     *
1268     * @param resourceName the name of the resource
1269     *
1270     * @return the access control list of the resource
1271     *
1272     * @throws CmsException if something goes wrong
1273     */
1274    public CmsAccessControlList getAccessControlList(String resourceName) throws CmsException {
1275
1276        return getAccessControlList(resourceName, false);
1277    }
1278
1279    /**
1280     * Returns the access control list (summarized access control entries) of a given resource.<p>
1281     *
1282     * If <code>inheritedOnly</code> is set, only inherited access control entries are returned.<p>
1283     *
1284     * @param resourceName the name of the resource
1285     * @param inheritedOnly if set, the non-inherited entries are skipped
1286     *
1287     * @return the access control list of the resource
1288     *
1289     * @throws CmsException if something goes wrong
1290     */
1291    public CmsAccessControlList getAccessControlList(String resourceName, boolean inheritedOnly) throws CmsException {
1292
1293        CmsResource res = readResource(resourceName, CmsResourceFilter.ALL);
1294        return m_securityManager.getAccessControlList(m_context, res, inheritedOnly);
1295    }
1296
1297    /**
1298     * Gets all access control entries for the current project.<p>
1299     *
1300     * @return the list of all access control entries
1301     *
1302     * @throws CmsException if something goes wrong
1303     */
1304    public List<CmsAccessControlEntry> getAllAccessControlEntries() throws CmsException {
1305
1306        return m_securityManager.getAllAccessControlEntries(m_context);
1307    }
1308
1309    /**
1310     * Returns a list with all projects from history.<p>
1311     *
1312     * @return list of <code>{@link CmsHistoryProject}</code> objects
1313     *           with all projects from history
1314     *
1315     * @throws CmsException  if operation was not successful
1316     */
1317    public List<CmsHistoryProject> getAllHistoricalProjects() throws CmsException {
1318
1319        return m_securityManager.getAllHistoricalProjects(m_context);
1320    }
1321
1322    /**
1323     * Gets all URL names for a given structure id.<p>
1324     *
1325     * @param id the structure id
1326     * @return the list of all URL names for that structure id
1327     *
1328     * @throws CmsException if something goes wrong
1329     */
1330    public List<String> getAllUrlNames(CmsUUID id) throws CmsException {
1331
1332        return m_securityManager.readAllUrlNameMappingEntries(m_context, id);
1333    }
1334
1335    /**
1336     * Returns a list of child resources to the given resource that can not be locked by the current user.<p>
1337     *
1338     * @param resource the resource
1339     *
1340     * @return a list of child resources to the given resource that can not be locked by the current user
1341     *
1342     * @throws CmsException if something goes wrong reading the resources
1343     */
1344    public List<CmsResource> getBlockingLockedResources(CmsResource resource) throws CmsException {
1345
1346        if (resource.isFolder()) {
1347            CmsLockFilter blockingFilter = CmsLockFilter.FILTER_ALL;
1348            blockingFilter = blockingFilter.filterNotLockableByUser(getRequestContext().getCurrentUser());
1349            return getLockedResources(resource, blockingFilter);
1350        }
1351        return Collections.<CmsResource> emptyList();
1352    }
1353
1354    /**
1355     * Returns a list of child resources to the given resource that can not be locked by the current user.<p>
1356     *
1357     * @param resourceName the resource site path
1358     *
1359     * @return a list of child resources to the given resource that can not be locked by the current user
1360     *
1361     * @throws CmsException if something goes wrong reading the resources
1362     */
1363    public List<CmsResource> getBlockingLockedResources(String resourceName) throws CmsException {
1364
1365        CmsResource resource = readResource(resourceName);
1366        return getBlockingLockedResources(resource);
1367    }
1368
1369    /**
1370     * Returns all child groups of a group.<p>
1371     *
1372     * @param groupname the name of the group
1373     * @param includeSubChildren if set also returns all sub-child groups of the given group
1374     *
1375     * @return a list of all child <code>{@link CmsGroup}</code> objects or <code>null</code>
1376     *
1377     * @throws CmsException if operation was not successful
1378     */
1379    public List<CmsGroup> getChildren(String groupname, boolean includeSubChildren) throws CmsException {
1380
1381        return m_securityManager.getChildren(m_context, groupname, includeSubChildren);
1382    }
1383
1384    /**
1385     * Returns the detail name of a resource.<p>
1386     *
1387     * The detail view URI of a content element consists of its detail page URI and the detail name returned by this
1388     * method.<p>
1389     *
1390     * @param res the resource for which the detail name should be retrieved
1391     * @param locale the locale for the detail name
1392     * @param defaultLocales the default locales for the detail name
1393     *
1394     * @return the detail name
1395     * @throws CmsException if something goes wrong
1396     */
1397    public String getDetailName(CmsResource res, Locale locale, List<Locale> defaultLocales) throws CmsException {
1398
1399        String urlName = readBestUrlName(res.getStructureId(), locale, defaultLocales);
1400        if (urlName == null) {
1401            urlName = res.getStructureId().toString();
1402        }
1403        return urlName;
1404    }
1405
1406    /**
1407     * Returns all file resources contained in a folder.<p>
1408     *
1409     * The result is filtered according to the rules of
1410     * the <code>{@link CmsResourceFilter#DEFAULT}</code> filter.<p>
1411     *
1412     * @param resourcename the full current site relative path of the resource to return the child resources for
1413     *
1414     * @return a list of all child files as <code>{@link CmsResource}</code> objects
1415     *
1416     * @throws CmsException if something goes wrong
1417     *
1418     * @see #getFilesInFolder(String, CmsResourceFilter)
1419     */
1420    public List<CmsResource> getFilesInFolder(String resourcename) throws CmsException {
1421
1422        return getFilesInFolder(resourcename, CmsResourceFilter.DEFAULT);
1423    }
1424
1425    /**
1426     * Returns all file resources contained in a folder.<p>
1427     *
1428     * With the <code>{@link CmsResourceFilter}</code> provided as parameter
1429     * you can control if you want to include deleted, invisible or
1430     * time-invalid resources in the result.<p>
1431     *
1432     * @param resourcename the full path of the resource to return the child resources for
1433     * @param filter the resource filter to use
1434     *
1435     * @return a list of all child file as <code>{@link CmsResource}</code> objects
1436     *
1437     * @throws CmsException if something goes wrong
1438     */
1439    public List<CmsResource> getFilesInFolder(String resourcename, CmsResourceFilter filter) throws CmsException {
1440
1441        CmsResource resource = readResource(resourcename, CmsResourceFilter.ALL);
1442        return m_securityManager.readChildResources(m_context, resource, filter, false, true);
1443    }
1444
1445    /**
1446     * Returns all the groups the given user belongs to.<p>
1447     *
1448     * @param username the name of the user
1449     * @param directGroupsOnly if set only the direct assigned groups will be returned, if not also indirect roles
1450     *
1451     * @return a list of <code>{@link CmsGroup}</code> objects
1452     *
1453     * @throws CmsException if operation was not successful
1454     */
1455    public List<CmsGroup> getGroupsOfUser(String username, boolean directGroupsOnly) throws CmsException {
1456
1457        return getGroupsOfUser(username, directGroupsOnly, true);
1458    }
1459
1460    /**
1461     * Returns all the groups the given user belongs to.<p>
1462     *
1463     * @param username the name of the user
1464     * @param directGroupsOnly if set only the direct assigned groups will be returned, if not also indirect roles
1465     * @param includeOtherOus if to include groups of other organizational units
1466     *
1467     * @return a list of <code>{@link CmsGroup}</code> objects
1468     *
1469     * @throws CmsException if operation was not successful
1470     */
1471    public List<CmsGroup> getGroupsOfUser(String username, boolean directGroupsOnly, boolean includeOtherOus)
1472    throws CmsException {
1473
1474        return getGroupsOfUser(username, directGroupsOnly, includeOtherOus, m_context.getRemoteAddress());
1475    }
1476
1477    /**
1478     * Returns the groups of a user filtered by the specified IP address.<p>
1479     *
1480     * @param username the name of the user
1481     * @param directGroupsOnly if set only the direct assigned groups will be returned, if not also indirect roles
1482     * @param remoteAddress the IP address to filter the groups in the result list
1483     * @param includeOtherOus if to include groups of other organizational units
1484     *
1485     * @return a list of <code>{@link CmsGroup}</code> objects filtered by the specified IP address
1486     *
1487     * @throws CmsException if operation was not successful
1488     */
1489    public List<CmsGroup> getGroupsOfUser(
1490        String username,
1491        boolean directGroupsOnly,
1492        boolean includeOtherOus,
1493        String remoteAddress)
1494    throws CmsException {
1495
1496        return m_securityManager.getGroupsOfUser(
1497            m_context,
1498            username,
1499            (includeOtherOus ? "" : CmsOrganizationalUnit.getParentFqn(username)),
1500            includeOtherOus,
1501            false,
1502            directGroupsOnly,
1503            remoteAddress);
1504    }
1505
1506    /**
1507     * Creates a new locale group service.<p>
1508     *
1509     * @return a locale group service instance
1510     */
1511    public CmsLocaleGroupService getLocaleGroupService() {
1512
1513        return new CmsLocaleGroupService(this);
1514    }
1515
1516    /**
1517     * Returns the edition lock state for a specified resource.<p>
1518     *
1519     * If the resource is waiting to be publish you might get a lock of type {@link CmsLockType#PUBLISH}.<p>
1520     *
1521     * @param resource the resource to return the edition lock state for
1522     *
1523     * @return the edition lock state for the specified resource
1524     *
1525     * @throws CmsException if something goes wrong
1526     */
1527    public CmsLock getLock(CmsResource resource) throws CmsException {
1528
1529        return m_securityManager.getLock(m_context, resource);
1530    }
1531
1532    /**
1533     * Returns the lock state for a specified resource name.<p>
1534     *
1535     * If the resource is waiting to be publish you might get a lock of type {@link CmsLockType#PUBLISH}.<p>
1536     *
1537     * @param resourcename the name if the resource to get the lock state for (full current site relative path)
1538     *
1539     * @return the lock state for the specified resource
1540     *
1541     * @throws CmsException if something goes wrong
1542     */
1543    public CmsLock getLock(String resourcename) throws CmsException {
1544
1545        CmsResource resource = readResource(resourcename, CmsResourceFilter.ALL);
1546        return getLock(resource);
1547    }
1548
1549    /**
1550     * Returns all locked resources within a folder or matches the lock of the given resource.<p>
1551     *
1552     * @param resource the resource to check
1553     * @param filter the lock filter
1554     *
1555     * @return a list of locked resources
1556     *
1557     * @throws CmsException if operation was not successful
1558     */
1559    public List<CmsResource> getLockedResources(CmsResource resource, CmsLockFilter filter) throws CmsException {
1560
1561        return m_securityManager.getLockedResourcesObjects(m_context, resource, filter);
1562    }
1563
1564    /**
1565     * Returns all locked resources within a folder or matches the lock of the given resource.<p>
1566     *
1567     * @param resourceName the name of the resource to check
1568     * @param filter the lock filter
1569     *
1570     * @return a list of locked resource paths (relative to current site)
1571     *
1572     * @throws CmsException if operation was not successful
1573     */
1574    public List<String> getLockedResources(String resourceName, CmsLockFilter filter) throws CmsException {
1575
1576        CmsResource resource = readResource(resourceName, CmsResourceFilter.ALL);
1577        return m_securityManager.getLockedResources(m_context, resource, filter);
1578    }
1579
1580    /**
1581     * Returns all locked resources within a folder or matches the lock of the given resource, but uses a cache for resource lookup.<p>
1582     *
1583     * @param resource the resource to check
1584     * @param filter the lock filter
1585     * @param cache the cache to use for resource lookups
1586     *
1587     * @return a list of locked resources
1588     *
1589     * @throws CmsException if operation was not successful
1590     */
1591    public List<CmsResource> getLockedResourcesWithCache(
1592        CmsResource resource,
1593        CmsLockFilter filter,
1594        Map<String, CmsResource> cache)
1595    throws CmsException {
1596
1597        return m_securityManager.getLockedResourcesObjectsWithCache(m_context, resource, filter, cache);
1598    }
1599
1600    /**
1601     * Returns all log entries matching the given filter.<p>
1602     *
1603     * @param filter the filter to match the relation
1604     *
1605     * @return a list containing all log entries matching the given filter
1606     *
1607     * @throws CmsException if something goes wrong
1608     *
1609     * @see CmsSecurityManager#getLogEntries(CmsRequestContext, CmsLogFilter)
1610     * @see #deleteLogEntries(CmsLogFilter)
1611     */
1612    public List<CmsLogEntry> getLogEntries(CmsLogFilter filter) throws CmsException {
1613
1614        return m_securityManager.getLogEntries(m_context, filter);
1615    }
1616
1617    /**
1618     * Returns the name a resource would have if it were moved to the
1619     * "lost and found" folder. <p>
1620     *
1621     * In general, it is the same name as the given resource has, the only exception is
1622     * if a resource in the "lost and found" folder with the same name already exists.
1623     * In such case, a counter is added to the resource name.<p>
1624     *
1625     * @param resourcename the name of the resource to get the "lost and found" name for (full current site relative path)
1626     *
1627     * @return the tentative name of the resource inside the "lost and found" folder
1628     *
1629     * @throws CmsException if something goes wrong
1630     *
1631     * @see #moveToLostAndFound(String)
1632     */
1633    public String getLostAndFoundName(String resourcename) throws CmsException {
1634
1635        CmsResource resource = readResource(resourcename, CmsResourceFilter.ALL);
1636        return m_securityManager.moveToLostAndFound(m_context, resource, true);
1637    }
1638
1639    /**
1640     * Returns the parent group of a group.<p>
1641     *
1642     * @param groupname the name of the group
1643     *
1644     * @return group the parent group or <code>null</code>
1645     *
1646     * @throws CmsException if operation was not successful
1647     */
1648    public CmsGroup getParent(String groupname) throws CmsException {
1649
1650        return m_securityManager.getParent(m_context, groupname);
1651    }
1652
1653    /**
1654     * Returns the set of permissions of the current user for a given resource.<p>
1655     *
1656     * @param resourceName the name of the resource
1657     *
1658     * @return the bit set of the permissions of the current user
1659     *
1660     * @throws CmsException if something goes wrong
1661     */
1662    public CmsPermissionSet getPermissions(String resourceName) throws CmsException {
1663
1664        return getPermissions(resourceName, m_context.getCurrentUser().getName());
1665    }
1666
1667    /**
1668     * Returns the set of permissions of a given user for a given resource.<p>
1669     *
1670     * @param resourceName the name of the resource
1671     * @param userName the name of the user
1672     *
1673     * @return the current permissions on this resource
1674     *
1675     * @throws CmsException if something goes wrong
1676     */
1677    public CmsPermissionSet getPermissions(String resourceName, String userName) throws CmsException {
1678
1679        // reading permissions is allowed even if the resource is marked as deleted
1680        CmsResource resource = readResource(resourceName, CmsResourceFilter.ALL);
1681        CmsUser user = readUser(userName);
1682        return m_securityManager.getPermissions(m_context, resource, user);
1683    }
1684
1685    /**
1686     * Returns all relations for the given resource matching the given filter.<p>
1687     *
1688     * You should have view/read permissions on the given resource.<p>
1689     *
1690     * You may become source and/or target paths to resource you do not have view/read permissions on.<p>
1691     *
1692     * @param resource the resource to retrieve the relations for
1693     * @param filter the filter to match the relation
1694     *
1695     * @return a List containing all {@link org.opencms.relations.CmsRelation}
1696     *          objects for the given resource matching the given filter
1697     *
1698     * @throws CmsException if something goes wrong
1699     *
1700     * @see CmsSecurityManager#getRelationsForResource(CmsRequestContext, CmsResource, CmsRelationFilter)
1701     */
1702    public List<CmsRelation> getRelationsForResource(CmsResource resource, CmsRelationFilter filter)
1703    throws CmsException {
1704
1705        return m_securityManager.getRelationsForResource(m_context, resource, filter);
1706    }
1707
1708    /**
1709     * Returns all relations for the given resource matching the given filter.<p>
1710     *
1711     * You should have view/read permissions on the given resource.<p>
1712     *
1713     * You may become source and/or target paths to resource you do not have view/read permissions on.<p>
1714     *
1715     * @param resourceName the name of the resource to retrieve the relations for
1716     * @param filter the filter to match the relation
1717     *
1718     * @return a List containing all {@link org.opencms.relations.CmsRelation}
1719     *          objects for the given resource matching the given filter
1720     *
1721     * @throws CmsException if something goes wrong
1722     *
1723     * @see CmsSecurityManager#getRelationsForResource(CmsRequestContext, CmsResource, CmsRelationFilter)
1724     */
1725    public List<CmsRelation> getRelationsForResource(String resourceName, CmsRelationFilter filter)
1726    throws CmsException {
1727
1728        return getRelationsForResource(readResource(resourceName, CmsResourceFilter.ALL), filter);
1729    }
1730
1731    /**
1732     * Returns the current users request context.<p>
1733     *
1734     * This request context is used to authenticate the user for all
1735     * OpenCms operations. It also contains the request runtime settings, e.g.
1736     * about the current site this request was made on.<p>
1737     *
1738     * @return the current users request context
1739     */
1740    public CmsRequestContext getRequestContext() {
1741
1742        return m_context;
1743    }
1744
1745    /**
1746     * Returns all resources associated to a given principal via an ACE with the given permissions.<p>
1747     *
1748     * If the <code>includeAttr</code> flag is set it returns also all resources associated to
1749     * a given principal through some of following attributes.<p>
1750     *
1751     * <ul>
1752     *    <li>User Created</li>
1753     *    <li>User Last Modified</li>
1754     * </ul><p>
1755     *
1756     * @param principalId the id of the principal
1757     * @param permissions a set of permissions to match, can be <code>null</code> for all ACEs
1758     * @param includeAttr a flag to include resources associated by attributes
1759     *
1760     * @return a set of <code>{@link CmsResource}</code> objects
1761     *
1762     * @throws CmsException if something goes wrong
1763     */
1764    public Set<CmsResource> getResourcesForPrincipal(
1765        CmsUUID principalId,
1766        CmsPermissionSet permissions,
1767        boolean includeAttr)
1768    throws CmsException {
1769
1770        return m_securityManager.getResourcesForPrincipal(getRequestContext(), principalId, permissions, includeAttr);
1771    }
1772
1773    /**
1774     * Returns all child resources of a resource, that is the resources
1775     * contained in a folder.<p>
1776     *
1777     * With the <code>{@link CmsResourceFilter}</code> provided as parameter
1778     * you can control if you want to include deleted, invisible or
1779     * time-invalid resources in the result.<p>
1780     *
1781     * This method is mainly used by the workplace explorer.<p>
1782     *
1783     * @param resourcename the full current site relative path of the resource to return the child resources for
1784     * @param filter the resource filter to use
1785     *
1786     * @return a list of all child <code>{@link CmsResource}</code>s
1787     *
1788     * @throws CmsException if something goes wrong
1789     */
1790    public List<CmsResource> getResourcesInFolder(String resourcename, CmsResourceFilter filter) throws CmsException {
1791
1792        CmsResource resource = readResource(resourcename, CmsResourceFilter.ALL);
1793        return m_securityManager.readChildResources(m_context, resource, filter, true, true);
1794    }
1795
1796    /**
1797     * Adjusts the absolute resource root path for the current site.<p>
1798     *
1799     * The full root path of a resource is always available using
1800     * <code>{@link CmsResource#getRootPath()}</code>. From this name this method cuts
1801     * of the current site root using
1802     * <code>{@link CmsRequestContext#removeSiteRoot(String)}</code>.<p>
1803     *
1804     * If the resource root path does not start with the current site root,
1805     * it is left untouched.<p>
1806     *
1807     * @param resource the resource to get the adjusted site root path for
1808     *
1809     * @return the absolute resource path adjusted for the current site
1810     *
1811     * @see CmsRequestContext#removeSiteRoot(String)
1812     * @see CmsRequestContext#getSitePath(CmsResource)
1813     * @see CmsResource#getRootPath()
1814     */
1815    public String getSitePath(CmsResource resource) {
1816
1817        return m_context.getSitePath(resource);
1818    }
1819
1820    /**
1821     * Returns all folder resources contained in a folder.<p>
1822     *
1823     * The result is filtered according to the rules of
1824     * the <code>{@link CmsResourceFilter#DEFAULT}</code> filter.<p>
1825     *
1826     * @param resourcename the full current site relative path of the resource to return the child resources for.
1827     *
1828     * @return a list of all child file as <code>{@link CmsResource}</code> objects
1829     *
1830     * @throws CmsException if something goes wrong
1831     *
1832     * @see #getSubFolders(String, CmsResourceFilter)
1833     */
1834    public List<CmsResource> getSubFolders(String resourcename) throws CmsException {
1835
1836        return getSubFolders(resourcename, CmsResourceFilter.DEFAULT);
1837    }
1838
1839    /**
1840     * Returns all folder resources contained in a folder.<p>
1841     *
1842     * With the <code>{@link CmsResourceFilter}</code> provided as parameter
1843     * you can control if you want to include deleted, invisible or
1844     * time-invalid resources in the result.<p>
1845     *
1846     * @param resourcename the full current site relative path of the resource to return the child resources for.
1847     *
1848     * @return a list of all child folder <code>{@link CmsResource}</code>s
1849     * @param filter the resource filter to use
1850     *
1851     * @throws CmsException if something goes wrong
1852     */
1853    public List<CmsResource> getSubFolders(String resourcename, CmsResourceFilter filter) throws CmsException {
1854
1855        CmsResource resource = readResource(resourcename, CmsResourceFilter.ALL);
1856        return m_securityManager.readChildResources(m_context, resource, filter, true, false);
1857    }
1858
1859    /**
1860     * Returns the newest URL names for the given structure id for each locale.<p>
1861     *
1862     * @param id the structure id
1863     * @return the list of URL names for each locale
1864     *
1865     * @throws CmsException if something goes wrong
1866     */
1867    public List<String> getUrlNamesForAllLocales(CmsUUID id) throws CmsException {
1868
1869        return m_securityManager.readUrlNamesForAllLocales(m_context, id);
1870    }
1871
1872    /**
1873     * Returns all direct users of a given group.<p>
1874     *
1875     * Users that are "indirectly" in the group are not returned in the result.<p>
1876     *
1877     * @param groupname the name of the group to get all users for
1878     *
1879     * @return all <code>{@link CmsUser}</code> objects in the group
1880     *
1881     * @throws CmsException if operation was not successful
1882     */
1883    public List<CmsUser> getUsersOfGroup(String groupname) throws CmsException {
1884
1885        return getUsersOfGroup(groupname, true);
1886    }
1887
1888    /**
1889     * Returns all direct users of a given group.<p>
1890     *
1891     * Users that are "indirectly" in the group are not returned in the result.<p>
1892     *
1893     * @param groupname the name of the group to get all users for
1894     * @param includeOtherOus if the result should include users of other ous
1895     *
1896     * @return all <code>{@link CmsUser}</code> objects in the group
1897     *
1898     * @throws CmsException if operation was not successful
1899     */
1900    public List<CmsUser> getUsersOfGroup(String groupname, boolean includeOtherOus) throws CmsException {
1901
1902        return m_securityManager.getUsersOfGroup(m_context, groupname, includeOtherOus, true, false);
1903    }
1904
1905    /**
1906     * Checks if the current user has required permissions to access a given resource.<p>
1907     *
1908     * @param resource the resource to check the permissions for
1909     * @param requiredPermissions the set of permissions to check for
1910     *
1911     * @return <code>true</code> if the required permissions are satisfied
1912     *
1913     * @throws CmsException if something goes wrong
1914     */
1915    public boolean hasPermissions(CmsResource resource, CmsPermissionSet requiredPermissions) throws CmsException {
1916
1917        return m_securityManager.hasPermissions(
1918            m_context,
1919            resource,
1920            requiredPermissions,
1921            true,
1922            CmsResourceFilter.ALL).isAllowed();
1923    }
1924
1925    /**
1926     * Checks if the current user has required permissions to access a given resource.<p>
1927     *
1928     * @param resource the resource to check the permissions for
1929     * @param requiredPermissions the set of permissions to check for
1930     * @param checkLock if <code>true</code> the lock status of the resource is checked for write operations
1931     *      and the resource needs be locked by the current user so that the test is passed,
1932     *      if <code>false</code> the lock is not checked at all
1933     * @param filter the resource filter to use
1934     *
1935     * @return <code>true</code> if the required permissions are satisfied
1936     *
1937     * @throws CmsException if something goes wrong
1938     */
1939    public boolean hasPermissions(
1940        CmsResource resource,
1941        CmsPermissionSet requiredPermissions,
1942        boolean checkLock,
1943        CmsResourceFilter filter)
1944    throws CmsException {
1945
1946        return I_CmsPermissionHandler.PERM_ALLOWED == m_securityManager.hasPermissions(
1947            m_context,
1948            resource,
1949            requiredPermissions,
1950            checkLock,
1951            filter);
1952    }
1953
1954    /**
1955     * Writes a list of access control entries as new access control entries of a given resource.<p>
1956     *
1957     * Already existing access control entries of this resource are removed before.<p>
1958     *
1959     * @param resource the resource to attach the control entries to
1960     * @param acEntries a list of <code>{@link CmsAccessControlEntry}</code> objects
1961     *
1962     * @throws CmsException if something goes wrong
1963     */
1964    public void importAccessControlEntries(CmsResource resource, List<CmsAccessControlEntry> acEntries)
1965    throws CmsException {
1966
1967        m_securityManager.importAccessControlEntries(m_context, resource, acEntries);
1968    }
1969
1970    /**
1971     * Imports a new relation to the given resource.<p>
1972     *
1973     * @param resourceName the name of the source resource
1974     * @param targetPath the path of the target resource
1975     * @param relationType the type of the relation
1976     *
1977     * @throws CmsException if something goes wrong
1978     */
1979    public void importRelation(String resourceName, String targetPath, String relationType) throws CmsException {
1980
1981        createRelation(resourceName, targetPath, relationType, true);
1982    }
1983
1984    /**
1985     * Imports a resource to the OpenCms VFS.<p>
1986     *
1987     * If a resource already exists in the VFS (i.e. has the same name and
1988     * same id) it is replaced by the imported resource.<p>
1989     *
1990     * If a resource with the same name but a different id exists,
1991     * the imported resource is (usually) moved to the "lost and found" folder.<p>
1992     *
1993     * @param resourcename the name for the resource after import (full current site relative path)
1994     * @param resource the resource object to be imported
1995     * @param content the content of the resource
1996     * @param properties the properties of the resource
1997     *
1998     * @return the imported resource
1999     *
2000     * @throws CmsException if something goes wrong
2001     *
2002     * @see CmsObject#moveToLostAndFound(String)
2003     */
2004    public CmsResource importResource(
2005        String resourcename,
2006        CmsResource resource,
2007        byte[] content,
2008        List<CmsProperty> properties)
2009    throws CmsException {
2010
2011        return getResourceType(resource).importResource(
2012            this,
2013            m_securityManager,
2014            resourcename,
2015            resource,
2016            content,
2017            properties);
2018    }
2019
2020    /**
2021     * Creates a new user by import.<p>
2022     *
2023     * @param id the id of the user
2024     * @param name the new name for the user
2025     * @param password the new password for the user
2026     * @param firstname the first name of the user
2027     * @param lastname the last name of the user
2028     * @param email the email of the user
2029     * @param flags the flags for a user (for example <code>{@link I_CmsPrincipal#FLAG_ENABLED}</code>)
2030     * @param dateCreated the creation date
2031     * @param additionalInfos the additional user infos
2032     *
2033     * @return the imported user
2034     *
2035     * @throws CmsException if something goes wrong
2036     */
2037    public CmsUser importUser(
2038        String id,
2039        String name,
2040        String password,
2041        String firstname,
2042        String lastname,
2043        String email,
2044        int flags,
2045        long dateCreated,
2046        Map<String, Object> additionalInfos)
2047    throws CmsException {
2048
2049        return m_securityManager.importUser(
2050            m_context,
2051            id,
2052            name,
2053            password,
2054            firstname,
2055            lastname,
2056            email,
2057            flags,
2058            dateCreated,
2059            additionalInfos);
2060    }
2061
2062    /**
2063     * Increments a counter and returns its old value.<p>
2064     *
2065     * @param name the name of the counter
2066     *
2067     * @return the value of the counter before incrementing
2068     *
2069     * @throws CmsException if something goes wrong
2070     */
2071    public int incrementCounter(String name) throws CmsException {
2072
2073        return m_securityManager.incrementCounter(m_context, name);
2074    }
2075
2076    /**
2077     * Checks if the specified resource is inside the current project.<p>
2078     *
2079     * The project "view" is determined by a set of path prefixes.
2080     * If the resource starts with any one of this prefixes, it is considered to
2081     * be "inside" the project.<p>
2082     *
2083     * @param resourcename the specified resource name (full current site relative path)
2084     *
2085     * @return <code>true</code>, if the specified resource is inside the current project
2086     */
2087    public boolean isInsideCurrentProject(String resourcename) {
2088
2089        return m_securityManager.isInsideCurrentProject(m_context, addSiteRoot(resourcename));
2090    }
2091
2092    /**
2093     * Checks if the current user has management access to the current project.<p>
2094     *
2095     * @return <code>true</code>, if the user has management access to the current project
2096     */
2097
2098    public boolean isManagerOfProject() {
2099
2100        return m_securityManager.isManagerOfProject(m_context);
2101    }
2102
2103    /**
2104     * Locks a resource.<p>
2105     *
2106     * This will be an exclusive, persistent lock that is removed only if the user unlocks it.<p>
2107     *
2108     * @param resource the resource to lock
2109     *
2110     * @throws CmsException if something goes wrong
2111     */
2112    public void lockResource(CmsResource resource) throws CmsException {
2113
2114        getResourceType(resource).lockResource(this, m_securityManager, resource, CmsLockType.EXCLUSIVE);
2115    }
2116
2117    /**
2118     * Locks a resource.<p>
2119     *
2120     * This will be an exclusive, persistent lock that is removed only if the user unlocks it.<p>
2121     *
2122     * @param resourcename the name of the resource to lock (full current site relative path)
2123     *
2124     * @throws CmsException if something goes wrong
2125     */
2126    public void lockResource(String resourcename) throws CmsException {
2127
2128        lockResource(resourcename, CmsLockType.EXCLUSIVE);
2129    }
2130
2131    /**
2132     * Locks a resource temporary.<p>
2133     *
2134     * This will be an exclusive, temporary lock valid only for the current users session.
2135     * Usually this should not be used directly, this method is intended for the OpenCms workplace only.<p>
2136     *
2137     * @param resource the resource to lock
2138     *
2139     * @throws CmsException if something goes wrong
2140     *
2141     * @see CmsObject#lockResource(String)
2142     */
2143    public void lockResourceTemporary(CmsResource resource) throws CmsException {
2144
2145        getResourceType(resource).lockResource(this, m_securityManager, resource, CmsLockType.TEMPORARY);
2146    }
2147
2148    /**
2149     * Locks a resource temporary.<p>
2150     *
2151     * This will be an exclusive, temporary lock valid only for the current users session.
2152     * Usually this should not be used directly, this method is intended for the OpenCms workplace only.<p>
2153     *
2154     * @param resourcename the name of the resource to lock (full current site relative path)
2155     *
2156     * @throws CmsException if something goes wrong
2157     *
2158     * @see CmsObject#lockResource(String)
2159     */
2160    public void lockResourceTemporary(String resourcename) throws CmsException {
2161
2162        lockResource(resourcename, CmsLockType.TEMPORARY);
2163    }
2164
2165    /**
2166     * Logs a user into the Cms, if the password is correct.<p>
2167     *
2168     * @param username the name of the user
2169     * @param password the password of the user
2170     *
2171     * @return the name of the logged in user
2172     *
2173     * @throws CmsException if the login was not successful
2174     */
2175    public String loginUser(String username, String password) throws CmsException {
2176
2177        return loginUser(username, password, m_context.getRemoteAddress());
2178    }
2179
2180    /**
2181     * Logs a user with a given ip address into the Cms, if the password is correct.<p>
2182     *
2183     * @param username the name of the user
2184     * @param password the password of the user
2185     * @param remoteAddress the ip address
2186     *
2187     * @return the name of the logged in user
2188     *
2189     * @throws CmsException if the login was not successful
2190     */
2191    public String loginUser(String username, String password, String remoteAddress) throws CmsException {
2192
2193        // login the user
2194        CmsUser newUser = m_securityManager.loginUser(m_context, username, password, remoteAddress);
2195        // set the project back to the "Online" project
2196        CmsProject newProject = m_securityManager.readProject(CmsProject.ONLINE_PROJECT_ID);
2197        // switch the cms context to the new user and project
2198        m_context.switchUser(newUser, newProject, newUser.getOuFqn());
2199        // init this CmsObject with the new user
2200        init(m_securityManager, m_context);
2201        // fire a login event
2202        fireEvent(I_CmsEventListener.EVENT_LOGIN_USER, newUser);
2203        // return the users login name
2204        return newUser.getName();
2205    }
2206
2207    /**
2208     * Lookups and reads the user or group with the given UUID.<p>
2209     *
2210     * @param principalId the uuid of a user or group
2211     *
2212     * @return the user or group with the given UUID
2213     */
2214    public I_CmsPrincipal lookupPrincipal(CmsUUID principalId) {
2215
2216        return m_securityManager.lookupPrincipal(m_context, principalId);
2217    }
2218
2219    /**
2220     * Lookups and reads the user or group with the given name.<p>
2221     *
2222     * @param principalName the name of the user or group
2223     *
2224     * @return the user or group with the given name
2225     */
2226    public I_CmsPrincipal lookupPrincipal(String principalName) {
2227
2228        return m_securityManager.lookupPrincipal(m_context, principalName);
2229    }
2230
2231    /**
2232     * Moves a resource to the given destination.<p>
2233     *
2234     * A move operation in OpenCms is always a copy (as sibling) followed by a delete,
2235     * this is a result of the online/offline structure of the
2236     * OpenCms VFS. This way you can see the deleted files/folders in the offline
2237     * project, and you will be unable to undelete them.<p>
2238     *
2239     * @param source the name of the resource to move (full current site relative path)
2240     * @param destination the destination resource name (full current site relative path)
2241     *
2242     * @throws CmsException if something goes wrong
2243     *
2244     * @see #renameResource(String, String)
2245     */
2246    public void moveResource(String source, String destination) throws CmsException {
2247
2248        CmsResource resource = readResource(source, CmsResourceFilter.IGNORE_EXPIRATION);
2249        getResourceType(resource).moveResource(this, m_securityManager, resource, destination);
2250    }
2251
2252    /**
2253     * Moves a resource to the "lost and found" folder.<p>
2254     *
2255     * The "lost and found" folder is a special system folder.
2256     *
2257     * This operation is used e.g. during import of resources
2258     * when a resource with the same name but a different resource ID
2259     * already exists in the VFS. In this case, the imported resource is
2260     * moved to the "lost and found" folder.<p>
2261     *
2262     * @param resourcename the name of the resource to move to "lost and found" (full current site relative path)
2263     *
2264     * @return the name of the resource inside the "lost and found" folder
2265     *
2266     * @throws CmsException if something goes wrong
2267     *
2268     * @see #getLostAndFoundName(String)
2269     */
2270    public String moveToLostAndFound(String resourcename) throws CmsException {
2271
2272        CmsResource resource = readResource(resourcename, CmsResourceFilter.ALL);
2273        return m_securityManager.moveToLostAndFound(m_context, resource, false);
2274    }
2275
2276    /**
2277     * Reads all available versions for a given resource.<p>
2278     *
2279     * @param resource the resource for which to read the versions
2280     * @return the list of historical versions of the resource
2281     *
2282     * @throws CmsException if something goes wrong
2283     */
2284    public List<I_CmsHistoryResource> readAllAvailableVersions(CmsResource resource) throws CmsException {
2285
2286        return m_securityManager.readAllAvailableVersions(m_context, resource);
2287    }
2288
2289    /**
2290     * Reads all historical versions of a resource.<br>
2291     *
2292     * The reading excludes the file content, if the resource is a file.<p>
2293     *
2294     * @param resourceName the name of the resource to be read
2295     *
2296     * @return a list of historical resources, as <code>{@link I_CmsHistoryResource}</code> objects
2297     *
2298     * @throws CmsException if operation was not successful
2299     */
2300    public List<I_CmsHistoryResource> readAllAvailableVersions(String resourceName) throws CmsException {
2301
2302        CmsResource resource = readResource(resourceName, CmsResourceFilter.ALL);
2303        return m_securityManager.readAllAvailableVersions(m_context, resource);
2304    }
2305
2306    /**
2307     * Reads all property definitions.<p>
2308     *
2309     * @return a list with the <code>{@link CmsPropertyDefinition}</code> objects (may be empty)
2310     *
2311     * @throws CmsException if something goes wrong
2312     */
2313    public List<CmsPropertyDefinition> readAllPropertyDefinitions() throws CmsException {
2314
2315        return m_securityManager.readAllPropertyDefinitions(m_context);
2316    }
2317
2318    /**
2319     * Returns the first ancestor folder matching the filter criteria.<p>
2320     *
2321     * If no folder matching the filter criteria is found, null is returned.<p>
2322     *
2323     * @param resourcename the name of the resource to start (full current site relative path)
2324     * @param filter the resource filter to match while reading the ancestors
2325     *
2326     * @return the first ancestor folder matching the filter criteria or null if no folder was found
2327     *
2328     * @throws CmsException if something goes wrong
2329     */
2330    public CmsFolder readAncestor(String resourcename, CmsResourceFilter filter) throws CmsException {
2331
2332        CmsResource resource = readResource(resourcename, CmsResourceFilter.ALL);
2333        return m_securityManager.readAncestor(m_context, resource, filter);
2334    }
2335
2336    /**
2337     * Returns the first ancestor folder matching the resource type.<p>
2338     *
2339     * If no folder with the requested resource type is found, null is returned.<p>
2340     *
2341     * @param resourcename the name of the resource to start (full current site relative path)
2342     * @param type the resource type of the folder to match
2343     *
2344     * @return the first ancestor folder matching the filter criteria or null if no folder was found
2345     *
2346     * @throws CmsException if something goes wrong
2347     */
2348    @SuppressWarnings("deprecation")
2349    public CmsFolder readAncestor(String resourcename, int type) throws CmsException {
2350
2351        return readAncestor(resourcename, CmsResourceFilter.requireType(type));
2352    }
2353
2354    /**
2355     * Reads the newest URL name which is mapped to the given structure id.<p>
2356     *
2357     * If the structure id is not mapped to any name, null will be returned.<p>
2358     *
2359     * @param id the structure id for which the newest mapped name should be returned
2360     * @param locale the locale for which the URL name should be selected if possible
2361     * @param defaultLocales the default locales which should be used if the locale is not available
2362     * @return an URL name or null
2363     * @throws CmsException if something goes wrong
2364     */
2365    public String readBestUrlName(CmsUUID id, Locale locale, List<Locale> defaultLocales) throws CmsException {
2366
2367        return m_securityManager.readBestUrlName(m_context, id, locale, defaultLocales);
2368    }
2369
2370    /**
2371     * Returns the default resource for the given folder.<p>
2372     * <ol>
2373     *   <li>the {@link CmsPropertyDefinition#PROPERTY_DEFAULT_FILE} is checked, and
2374     *   <li>if still no file could be found, the configured default files in the
2375     *       <code>opencms-vfs.xml</code> configuration are iterated until a match is
2376     *       found, and
2377     *   <li>if still no file could be found, <code>null</code> is returned
2378     * </ol>
2379     *
2380     * @param folderResource the folder
2381     * @param resourceFilter the resource filter
2382     *
2383     * @return the default file for the given folder
2384     *
2385     * @throws CmsSecurityException  if the user has no permissions to read the resulting file
2386     */
2387    public CmsResource readDefaultFile(CmsResource folderResource, CmsResourceFilter resourceFilter)
2388    throws CmsSecurityException {
2389
2390        return m_securityManager.readDefaultFile(m_context, folderResource, resourceFilter);
2391    }
2392
2393    /**
2394     * Returns the default resource for the given folder.<p>
2395     *
2396     * If the given resource name or id identifies a file, then this file is returned.<p>
2397     *
2398     * Otherwise, in case of a folder:<br>
2399     * <ol>
2400     *   <li>the {@link CmsPropertyDefinition#PROPERTY_DEFAULT_FILE} is checked, and
2401     *   <li>if still no file could be found, the configured default files in the
2402     *       <code>opencms-vfs.xml</code> configuration are iterated until a match is
2403     *       found, and
2404     *   <li>if still no file could be found, <code>null</code> is returned
2405     * </ol>
2406     *
2407     * @param resourceNameOrID the name or id of the folder to read the default file for
2408     *
2409     * @return the default file for the given folder
2410     *
2411     * @throws CmsException if something goes wrong
2412     * @throws CmsSecurityException if the user has no permissions to read the resulting file
2413     */
2414    public CmsResource readDefaultFile(String resourceNameOrID) throws CmsException, CmsSecurityException {
2415
2416        return readDefaultFile(resourceNameOrID, CmsResourceFilter.DEFAULT);
2417    }
2418
2419    /**
2420     * Returns the default resource for the given folder.<p>
2421     *
2422     * If the given resource name or id identifies a file, then this file is returned.<p>
2423     *
2424     * Otherwise, in case of a folder:<br>
2425     * <ol>
2426     *   <li>the {@link CmsPropertyDefinition#PROPERTY_DEFAULT_FILE} is checked, and
2427     *   <li>if still no file could be found, the configured default files in the
2428     *       <code>opencms-vfs.xml</code> configuration are iterated until a match is
2429     *       found, and
2430     *   <li>if still no file could be found, <code>null</code> is returned
2431     * </ol>
2432     *
2433     * @param resourceNameOrID the name or id of the folder to read the default file for#
2434     * @param filter the resource filter to use for reading the resources
2435     *
2436     * @return the default file for the given folder
2437     *
2438     * @throws CmsException if something goes wrong
2439     * @throws CmsSecurityException if the user has no permissions to read the resulting file
2440     */
2441    public CmsResource readDefaultFile(String resourceNameOrID, CmsResourceFilter filter)
2442    throws CmsException, CmsSecurityException {
2443
2444        CmsResource resource;
2445        if (CmsUUID.isValidUUID(resourceNameOrID)) {
2446            resource = readResource(new CmsUUID(resourceNameOrID), filter);
2447        } else {
2448            resource = readResource(resourceNameOrID, filter);
2449        }
2450        return m_securityManager.readDefaultFile(m_context, resource, filter);
2451    }
2452
2453    /**
2454     * Reads all deleted (historical) resources below the given path,
2455     * including the full tree below the path, if required.<p>
2456     *
2457     * The result list may include resources with the same name of
2458     * resources (with different id's).<p>
2459     *
2460     * Use in conjunction with the {@link #restoreDeletedResource(CmsUUID)}
2461     * method.<p>
2462     *
2463     * @param resourcename the parent path to read the resources from
2464     * @param readTree <code>true</code> to read all sub resources
2465     *
2466     * @return a list of <code>{@link I_CmsHistoryResource}</code> objects
2467     *
2468     * @throws CmsException if something goes wrong
2469     *
2470     * @see #readResource(CmsUUID, int)
2471     * @see #readResources(String, CmsResourceFilter, boolean)
2472     */
2473    public List<I_CmsHistoryResource> readDeletedResources(String resourcename, boolean readTree) throws CmsException {
2474
2475        CmsResource resource = readResource(resourcename, CmsResourceFilter.ALL);
2476        return m_securityManager.readDeletedResources(m_context, resource, readTree);
2477    }
2478
2479    /**
2480     * Reads a file resource (including it's binary content) from the VFS,
2481     * for the given resource (this may also be an historical version of the resource).<p>
2482     *
2483     * In case the input {@link CmsResource} object already is a {@link CmsFile} with contents
2484     * available, it is casted to a file and returned unchanged. Otherwise the file is read
2485     * from the VFS.<p>
2486     *
2487     * In case you do not need the file content,
2488     * use <code>{@link #readResource(String)}</code> or
2489     * <code>{@link #readResource(String, CmsResourceFilter)}</code> instead.<p>
2490     *
2491     * No resource filter is applied when reading the resource, since we already have
2492     * a full resource instance and assume we just want the content for that instance.
2493     * In case you need to apply a filter, use {@link #readFile(String, CmsResourceFilter)} instead.<p>
2494     *
2495     * @param resource the resource to read
2496     *
2497     * @return the file resource that was read
2498     *
2499     * @throws CmsException if the file resource could not be read for any reason
2500     *
2501     * @see #readFile(String)
2502     * @see #readFile(String, CmsResourceFilter)
2503     */
2504    public CmsFile readFile(CmsResource resource) throws CmsException {
2505
2506        // test if we already have a file
2507        if (resource instanceof CmsFile) {
2508            // resource is already a file
2509            CmsFile file = (CmsFile)resource;
2510            if ((file.getContents() != null) && (file.getContents().length > 0)) {
2511                // file has the contents already available
2512                return file;
2513            }
2514        }
2515
2516        return m_securityManager.readFile(m_context, resource);
2517    }
2518
2519    /**
2520     * Reads a file resource (including it's binary content) from the VFS,
2521     * using the <code>{@link CmsResourceFilter#DEFAULT}</code> filter.<p>
2522     *
2523     * In case you do not need the file content,
2524     * use <code>{@link #readResource(String)}</code> instead.<p>
2525     *
2526     * @param resourcename the name of the resource to read (full current site relative path)
2527     *
2528     * @return the file resource that was read
2529     *
2530     * @throws CmsException if the file resource could not be read for any reason
2531     *
2532     * @see #readFile(String, CmsResourceFilter)
2533     * @see #readFile(CmsResource)
2534     * @see #readResource(String)
2535     */
2536    public CmsFile readFile(String resourcename) throws CmsException {
2537
2538        return readFile(resourcename, CmsResourceFilter.DEFAULT);
2539    }
2540
2541    /**
2542     * Reads a file resource (including it's binary content) from the VFS,
2543     * using the specified resource filter.<p>
2544     *
2545     * In case you do not need the file content,
2546     * use <code>{@link #readResource(String, CmsResourceFilter)}</code> instead.<p>
2547     *
2548     * The specified filter controls what kind of resources should be "found"
2549     * during the read operation. This will depend on the application. For example,
2550     * using <code>{@link CmsResourceFilter#DEFAULT}</code> will only return currently
2551     * "valid" resources, while using <code>{@link CmsResourceFilter#IGNORE_EXPIRATION}</code>
2552     * will ignore the date release / date expired information of the resource.<p>
2553     *
2554     * @param resourcename the name of the resource to read (full current site relative path)
2555     * @param filter the resource filter to use while reading
2556     *
2557     * @return the file resource that was read
2558     *
2559     * @throws CmsException if the file resource could not be read for any reason
2560     *
2561     * @see #readFile(String)
2562     * @see #readFile(CmsResource)
2563     * @see #readResource(String, CmsResourceFilter)
2564     */
2565    public CmsFile readFile(String resourcename, CmsResourceFilter filter) throws CmsException {
2566
2567        CmsResource resource = readResource(resourcename, filter);
2568        return readFile(resource);
2569    }
2570
2571    /**
2572     * Reads a folder resource from the VFS,
2573     * using the <code>{@link CmsResourceFilter#DEFAULT}</code> filter.<p>
2574     *
2575     * @param resourcename the name of the folder resource to read (full current site relative path)
2576     *
2577     * @return the folder resource that was read
2578     *
2579     * @throws CmsException if the resource could not be read for any reason
2580     *
2581     * @see #readResource(String, CmsResourceFilter)
2582     * @see #readFolder(String, CmsResourceFilter)
2583     */
2584    public CmsFolder readFolder(String resourcename) throws CmsException {
2585
2586        return readFolder(resourcename, CmsResourceFilter.DEFAULT);
2587    }
2588
2589    /**
2590     * Reads a folder resource from the VFS,
2591     * using the specified resource filter.<p>
2592     *
2593     * The specified filter controls what kind of resources should be "found"
2594     * during the read operation. This will depend on the application. For example,
2595     * using <code>{@link CmsResourceFilter#DEFAULT}</code> will only return currently
2596     * "valid" resources, while using <code>{@link CmsResourceFilter#IGNORE_EXPIRATION}</code>
2597     * will ignore the date release / date expired information of the resource.<p>
2598     *
2599     * @param resourcename the name of the folder resource to read (full current site relative path)
2600     * @param filter the resource filter to use while reading
2601     *
2602     * @return the folder resource that was read
2603     *
2604     * @throws CmsException if the resource could not be read for any reason
2605     *
2606     * @see #readResource(String, CmsResourceFilter)
2607     */
2608    public CmsFolder readFolder(String resourcename, CmsResourceFilter filter) throws CmsException {
2609
2610        return m_securityManager.readFolder(m_context, addSiteRoot(resourcename), filter);
2611    }
2612
2613    /**
2614     * Reads the group of a project.<p>
2615     *
2616     * @param project the project to read the group from
2617     *
2618     * @return the group of the given project
2619     */
2620    public CmsGroup readGroup(CmsProject project) {
2621
2622        return m_securityManager.readGroup(m_context, project);
2623    }
2624
2625    /**
2626     * Reads a group based on its id.<p>
2627     *
2628     * @param groupId the id of the group to be read
2629     *
2630     * @return the group that has the provided id
2631     *
2632     * @throws CmsException if something goes wrong
2633     *
2634     * @see #readHistoryPrincipal(CmsUUID) for retrieving deleted groups
2635     */
2636    public CmsGroup readGroup(CmsUUID groupId) throws CmsException {
2637
2638        return m_securityManager.readGroup(m_context, groupId);
2639    }
2640
2641    /**
2642     * Reads a group based on its name.<p>
2643     *
2644     * @param groupName the name of the group to be read
2645     *
2646     * @return the group that has the provided name
2647     *
2648     * @throws CmsException if something goes wrong
2649     */
2650    public CmsGroup readGroup(String groupName) throws CmsException {
2651
2652        return m_securityManager.readGroup(m_context, groupName);
2653    }
2654
2655    /**
2656     * Reads a principal (an user or group) from the historical archive based on its ID.<p>
2657     *
2658     * @param principalId the id of the principal to read
2659     *
2660     * @return the historical principal entry with the given id
2661     *
2662     * @throws CmsException if something goes wrong, ie. {@link org.opencms.db.CmsDbEntryNotFoundException}
2663     *
2664     * @see #readUser(CmsUUID)
2665     * @see #readGroup(CmsUUID)
2666     */
2667    public CmsHistoryPrincipal readHistoryPrincipal(CmsUUID principalId) throws CmsException {
2668
2669        return m_securityManager.readHistoricalPrincipal(m_context, principalId);
2670    }
2671
2672    /**
2673     * Returns the latest historical project entry with the given id.<p>
2674     *
2675     * @param projectId the project id
2676     *
2677     * @return the requested historical project entry
2678     *
2679     * @throws CmsException if operation was not successful
2680     */
2681    public CmsHistoryProject readHistoryProject(CmsUUID projectId) throws CmsException {
2682
2683        return (m_securityManager.readHistoryProject(m_context, projectId));
2684    }
2685
2686    /**
2687     * Returns a historical project entry.<p>
2688     *
2689     * @param publishTag publish tag of the project
2690     *
2691     * @return the requested historical project entry
2692     *
2693     * @throws CmsException if operation was not successful
2694     */
2695    public CmsHistoryProject readHistoryProject(int publishTag) throws CmsException {
2696
2697        return (m_securityManager.readHistoryProject(m_context, publishTag));
2698    }
2699
2700    /**
2701     * Reads the list of all <code>{@link CmsProperty}</code> objects that belong to the given historical resource version.<p>
2702     *
2703     * @param resource the historical resource version to read the properties for
2704     *
2705     * @return the list of <code>{@link CmsProperty}</code> objects
2706     *
2707     * @throws CmsException if something goes wrong
2708     */
2709    public List<CmsProperty> readHistoryPropertyObjects(I_CmsHistoryResource resource) throws CmsException {
2710
2711        return m_securityManager.readHistoryPropertyObjects(m_context, resource);
2712    }
2713
2714    /**
2715     * This method retrieves the structure id which is mapped to a given URL name.<p>
2716     *
2717     * If there is no structure id mapped to the given name, null will be returned.<p>
2718     *
2719     * However if the parameter is a string which represents a valid uuid, it will be directly returned as a {@link CmsUUID} instance.<p>
2720     *
2721     * @param name the url name
2722     * @return the id which is mapped to the URL name
2723     *
2724     * @throws CmsException if something goes wrong
2725     */
2726    public CmsUUID readIdForUrlName(String name) throws CmsException {
2727
2728        if (CmsUUID.isValidUUID(name)) {
2729            return new CmsUUID(name);
2730        }
2731        return m_securityManager.readIdForUrlName(m_context, name);
2732    }
2733
2734    /**
2735     * Returns the project manager group of a project.<p>
2736     *
2737     * @param project the project
2738     *
2739     * @return the manager group of the project
2740     */
2741    public CmsGroup readManagerGroup(CmsProject project) {
2742
2743        return m_securityManager.readManagerGroup(m_context, project);
2744    }
2745
2746    /**
2747     * Reads the owner of a project.<p>
2748     *
2749     * @param project the project to read the owner from
2750     *
2751     * @return the owner of the project
2752     *
2753     * @throws CmsException if something goes wrong
2754     */
2755    public CmsUser readOwner(CmsProject project) throws CmsException {
2756
2757        return m_securityManager.readOwner(m_context, project);
2758    }
2759
2760    /**
2761     * Returns the parent folder to the given structure id.<p>
2762     *
2763     * @param structureId the child structure id
2764     *
2765     * @return the parent folder <code>{@link CmsResource}</code>
2766     *
2767     * @throws CmsException if something goes wrong
2768     */
2769    public CmsResource readParentFolder(CmsUUID structureId) throws CmsException {
2770
2771        return m_securityManager.readParentFolder(m_context, structureId);
2772    }
2773
2774    /**
2775     * Builds a list of resources for a given path.<p>
2776     *
2777     * @param path the requested path
2778     * @param filter a filter object (only "includeDeleted" information is used!)
2779     *
2780     * @return list of <code>{@link CmsResource}</code>s
2781     *
2782     * @throws CmsException if something goes wrong
2783     */
2784    public List<CmsResource> readPath(String path, CmsResourceFilter filter) throws CmsException {
2785
2786        return m_securityManager.readPath(m_context, addSiteRoot(path), filter);
2787    }
2788
2789    /**
2790     * Reads the project with the given id.<p>
2791     *
2792     * @param id the id of the project
2793     *
2794     * @return the project with the given id
2795     *
2796     * @throws CmsException if operation was not successful
2797     */
2798    public CmsProject readProject(CmsUUID id) throws CmsException {
2799
2800        return m_securityManager.readProject(id);
2801    }
2802
2803    /**
2804     * Reads the project with the given name.<p>
2805     *
2806     * @param name the name of the project
2807     *
2808     * @return the project with the given name
2809     *
2810     * @throws CmsException if operation was not successful
2811     */
2812    public CmsProject readProject(String name) throws CmsException {
2813
2814        return m_securityManager.readProject(name);
2815    }
2816
2817    /**
2818     * Returns the list of all resource names that define the "view" of the given project.<p>
2819     *
2820     * @param project the project to get the project resources for
2821     *
2822     * @return the list of all resource names (root paths), as <code>{@link String}</code>
2823     *              objects that define the "view" of the given project
2824     *
2825     * @throws CmsException if something goes wrong
2826     */
2827    public List<String> readProjectResources(CmsProject project) throws CmsException {
2828
2829        return m_securityManager.readProjectResources(m_context, project);
2830    }
2831
2832    /**
2833     * Reads all resources of a project that match a given state from the VFS.<p>
2834     *
2835     * Possible values for the <code>state</code> parameter are:<br>
2836     * <ul>
2837     * <li><code>{@link CmsResource#STATE_CHANGED}</code>: Read all "changed" resources in the project</li>
2838     * <li><code>{@link CmsResource#STATE_NEW}</code>: Read all "new" resources in the project</li>
2839     * <li><code>{@link CmsResource#STATE_DELETED}</code>: Read all "deleted" resources in the project</li>
2840     * <li><code>{@link CmsResource#STATE_KEEP}</code>: Read all resources either "changed", "new" or "deleted" in the project</li>
2841     * </ul><p>
2842     *
2843     * @param projectId the id of the project to read the file resources for
2844     * @param state the resource state to match
2845     *
2846     * @return all <code>{@link CmsResource}</code>s of a project that match a given criteria from the VFS
2847     *
2848     * @throws CmsException if something goes wrong
2849     */
2850    public List<CmsResource> readProjectView(CmsUUID projectId, CmsResourceState state) throws CmsException {
2851
2852        return m_securityManager.readProjectView(m_context, projectId, state);
2853    }
2854
2855    /**
2856     * Reads a property definition.<p>
2857     *
2858     * If no property definition with the given name is found,
2859     * <code>null</code> is returned.<p>
2860     *
2861     * @param name the name of the property definition to read
2862     *
2863     * @return the property definition that was read
2864     *
2865     * @throws CmsException a CmsDbEntryNotFoundException is thrown if the property definition does not exist
2866     */
2867    public CmsPropertyDefinition readPropertyDefinition(String name) throws CmsException {
2868
2869        return (m_securityManager.readPropertyDefinition(m_context, name));
2870    }
2871
2872    /**
2873     * Reads a property object from a resource specified by a property name.<p>
2874     *
2875     * Returns <code>{@link CmsProperty#getNullProperty()}</code> if the property is not found.<p>
2876     *
2877     * This method is more efficient then using <code>{@link CmsObject#readPropertyObject(String, String, boolean)}</code>
2878     * if you already have an instance of the resource to look up the property from.<p>
2879     *
2880     * @param resource the resource where the property is attached to
2881     * @param property the property name
2882     * @param search if true, the property is searched on all parent folders of the resource,
2883     *      if it's not found attached directly to the resource
2884     *
2885     * @return the required property, or <code>{@link CmsProperty#getNullProperty()}</code> if the property was not found
2886     *
2887     * @throws CmsException if something goes wrong
2888     */
2889    public CmsProperty readPropertyObject(CmsResource resource, String property, boolean search) throws CmsException {
2890
2891        return m_securityManager.readPropertyObject(m_context, resource, property, search);
2892    }
2893
2894    /**
2895     * Reads the locale specific version of a property object from a resource specified by a property name.<p>
2896     *
2897     * Returns <code>{@link CmsProperty#getNullProperty()}</code> if the property is not found.<p>
2898     *
2899     * This method is more efficient then using <code>{@link CmsObject#readPropertyObject(String, String, boolean)}</code>
2900     * if you already have an instance of the resource to look up the property from.<p>
2901     *
2902     * @param resource the resource where the property is attached to
2903     * @param property the property name
2904     * @param search if true, the property is searched on all parent folders of the resource,
2905     *      if it's not found attached directly to the resource
2906     * @param locale the locale for which the property should be read.
2907     *
2908     * @return the required property, or <code>{@link CmsProperty#getNullProperty()}</code> if the property was not found
2909     *
2910     * @throws CmsException if something goes wrong
2911     */
2912    public CmsProperty readPropertyObject(CmsResource resource, String property, boolean search, Locale locale)
2913    throws CmsException {
2914
2915        return m_securityManager.readPropertyObject(m_context, resource, property, search, locale);
2916    }
2917
2918    /**
2919     * Reads a property object from a resource specified by a property name.<p>
2920     *
2921     * Returns <code>{@link CmsProperty#getNullProperty()}</code> if the property is not found.<p>
2922     *
2923     * @param resourcePath the name of resource where the property is attached to
2924     * @param property the property name
2925     * @param search if true, the property is searched on all parent folders of the resource,
2926     *      if it's not found attached directly to the resource
2927     *
2928     * @return the required property, or <code>{@link CmsProperty#getNullProperty()}</code> if the property was not found
2929     *
2930     * @throws CmsException if something goes wrong
2931     */
2932    public CmsProperty readPropertyObject(String resourcePath, String property, boolean search) throws CmsException {
2933
2934        CmsResource resource = readResource(resourcePath, CmsResourceFilter.ALL);
2935        return m_securityManager.readPropertyObject(m_context, resource, property, search);
2936    }
2937
2938    /**
2939     * Reads the locale specific version of a property object from a resource specified by a property name.<p>
2940     *
2941     * Returns <code>{@link CmsProperty#getNullProperty()}</code> if the property is not found.<p>
2942     *
2943     * @param resourcePath the name of resource where the property is attached to
2944     * @param property the property name
2945     * @param search if true, the property is searched on all parent folders of the resource,
2946     *      if it's not found attached directly to the resource
2947     * @param locale the locale for which the property should be read.
2948     *
2949     * @return the required property, or <code>{@link CmsProperty#getNullProperty()}</code> if the property was not found
2950     *
2951     * @throws CmsException if something goes wrong
2952     */
2953    public CmsProperty readPropertyObject(String resourcePath, String property, boolean search, Locale locale)
2954    throws CmsException {
2955
2956        CmsResource resource = readResource(resourcePath, CmsResourceFilter.ALL);
2957        return m_securityManager.readPropertyObject(m_context, resource, property, search, locale);
2958    }
2959
2960    /**
2961     * Reads all property objects from a resource.<p>
2962     *
2963     * Returns an empty list if no properties are found.<p>
2964     *
2965     * This method is more efficient then using <code>{@link CmsObject#readPropertyObjects(String, boolean)}</code>
2966     * if you already have an instance of the resource to look up the property from.<p>
2967     *
2968     * If the <code>search</code> parameter is <code>true</code>, the properties of all
2969     * parent folders of the resource are also read. The results are merged with the
2970     * properties directly attached to the resource. While merging, a property
2971     * on a parent folder that has already been found will be ignored.
2972     * So e.g. if a resource has a property "Title" attached, and it's parent folder
2973     * has the same property attached but with a different value, the result list will
2974     * contain only the property with the value from the resource, not form the parent folder(s).<p>
2975     *
2976     * @param resource the resource where the property is mapped to
2977     * @param search if <code>true</code>, the properties of all parent folders of the resource
2978     *      are merged with the resource properties.
2979     *
2980     * @return a list of <code>{@link CmsProperty}</code> objects
2981     *
2982     * @throws CmsException if something goes wrong
2983     */
2984    public List<CmsProperty> readPropertyObjects(CmsResource resource, boolean search) throws CmsException {
2985
2986        return m_securityManager.readPropertyObjects(m_context, resource, search);
2987    }
2988
2989    /**
2990     * Reads all property objects from a resource.<p>
2991     *
2992     * Returns an empty list if no properties are found.<p>
2993     *
2994     * All properties in the result List will be in frozen (read only) state, so you can't change the values.<p>
2995     *
2996     * If the <code>search</code> parameter is <code>true</code>, the properties of all
2997     * parent folders of the resource are also read. The results are merged with the
2998     * properties directly attached to the resource. While merging, a property
2999     * on a parent folder that has already been found will be ignored.
3000     * So e.g. if a resource has a property "Title" attached, and it's parent folder
3001     * has the same property attached but with a different value, the result list will
3002     * contain only the property with the value from the resource, not form the parent folder(s).<p>
3003     *
3004     * @param resourcePath the name of resource where the property is mapped to
3005     * @param search if <code>true</code>, the properties of all parent folders of the resource
3006     *      are merged with the resource properties.
3007     *
3008     * @return a list of <code>{@link CmsProperty}</code> objects
3009     *
3010     * @throws CmsException if something goes wrong
3011     */
3012    public List<CmsProperty> readPropertyObjects(String resourcePath, boolean search) throws CmsException {
3013
3014        CmsResource resource = readResource(resourcePath, CmsResourceFilter.ALL);
3015        return m_securityManager.readPropertyObjects(m_context, resource, search);
3016    }
3017
3018    /**
3019     * Reads the resources that were published in a publish task for a given publish history ID.<p>
3020     *
3021     * @param publishHistoryId unique ID to identify each publish task in the publish history
3022     *
3023     * @return a list of <code>{@link org.opencms.db.CmsPublishedResource}</code> objects
3024     *
3025     * @throws CmsException if something goes wrong
3026     */
3027    public List<CmsPublishedResource> readPublishedResources(CmsUUID publishHistoryId) throws CmsException {
3028
3029        return m_securityManager.readPublishedResources(m_context, publishHistoryId);
3030    }
3031
3032    /**
3033     * Returns all relations matching the given filter.<p>
3034     *
3035     * @param filter the filter to match the relation
3036     *
3037     * @return all relations matching the given filter
3038     *
3039     * @throws CmsException if something goes wrong
3040     *
3041     * @see CmsSecurityManager#getRelationsForResource(CmsRequestContext, CmsResource, CmsRelationFilter)
3042     * @see #getRelationsForResource(CmsResource, CmsRelationFilter)
3043     */
3044    public List<CmsRelation> readRelations(CmsRelationFilter filter) throws CmsException {
3045
3046        return m_securityManager.getRelationsForResource(m_context, null, filter);
3047    }
3048
3049    /**
3050     * Reads a resource from the VFS,
3051     * using the <code>{@link CmsResourceFilter#DEFAULT}</code> filter.<p>
3052     *
3053     * A resource may be of type <code>{@link CmsFile}</code> or
3054     * <code>{@link CmsFolder}</code>. In case of
3055     * a file, the resource will not contain the binary file content. Since reading
3056     * the binary content is a cost-expensive database operation, it's recommended
3057     * to work with resources if possible, and only read the file content when absolutely
3058     * required. To "upgrade" a resource to a file,
3059     * use <code>{@link #readFile(CmsResource)}</code>.<p>
3060     *
3061     * @param structureID the structure ID of the resource to read
3062     *
3063     * @return the resource that was read
3064     *
3065     * @throws CmsException if the resource could not be read for any reason
3066     *
3067     * @see #readFile(String)
3068     * @see #readResource(CmsUUID, CmsResourceFilter)
3069     */
3070    public CmsResource readResource(CmsUUID structureID) throws CmsException {
3071
3072        return readResource(structureID, CmsResourceFilter.DEFAULT);
3073    }
3074
3075    /**
3076     * Reads a resource from the VFS,
3077     * using the specified resource filter.<p>
3078     *
3079     * A resource may be of type <code>{@link CmsFile}</code> or
3080     * <code>{@link CmsFolder}</code>. In case of
3081     * a file, the resource will not contain the binary file content. Since reading
3082     * the binary content is a cost-expensive database operation, it's recommended
3083     * to work with resources if possible, and only read the file content when absolutely
3084     * required. To "upgrade" a resource to a file,
3085     * use <code>{@link #readFile(CmsResource)}</code>.<p>
3086     *
3087     * The specified filter controls what kind of resources should be "found"
3088     * during the read operation. This will depend on the application. For example,
3089     * using <code>{@link CmsResourceFilter#DEFAULT}</code> will only return currently
3090     * "valid" resources, while using <code>{@link CmsResourceFilter#IGNORE_EXPIRATION}</code>
3091     * will ignore the date release / date expired information of the resource.<p>
3092     *
3093     * @param structureID the structure ID of the resource to read
3094     * @param filter the resource filter to use while reading
3095     *
3096     * @return the resource that was read
3097     *
3098     * @throws CmsException if the resource could not be read for any reason
3099     *
3100     * @see #readFile(String, CmsResourceFilter)
3101     * @see #readFolder(String, CmsResourceFilter)
3102     */
3103    public CmsResource readResource(CmsUUID structureID, CmsResourceFilter filter) throws CmsException {
3104
3105        return m_securityManager.readResource(m_context, structureID, filter);
3106    }
3107
3108    /**
3109     * Reads the historical resource with the given version for the resource given
3110     * the given structure id.<p>
3111     *
3112     * A resource may be of type <code>{@link CmsFile}</code> or
3113     * <code>{@link CmsFolder}</code>. In case of a file, the resource will not
3114     * contain the binary file content. Since reading the binary content is a
3115     * cost-expensive database operation, it's recommended to work with resources
3116     * if possible, and only read the file content when absolutely required. To
3117     * "upgrade" a resource to a file, use
3118     * <code>{@link #readFile(CmsResource)}</code>.<p>
3119     *
3120     * Please note that historical versions are just generated during publishing,
3121     * so the first version with version number 1 is generated during publishing
3122     * of a new resource (exception is a new sibling, that may also contain some
3123     * relevant versions of already published siblings) and the last version
3124     * available is the version of the current online resource.<p>
3125     *
3126     * @param structureID the structure ID of the resource to read
3127     * @param version the version number you want to retrieve
3128     *
3129     * @return the resource that was read
3130     *
3131     * @throws CmsException if the resource could not be read for any reason
3132     * @throws CmsVfsResourceNotFoundException if the version does not exists
3133     *
3134     * @see #restoreResourceVersion(CmsUUID, int)
3135     */
3136    public I_CmsHistoryResource readResource(CmsUUID structureID, int version)
3137    throws CmsException, CmsVfsResourceNotFoundException {
3138
3139        CmsResource resource = readResource(structureID, CmsResourceFilter.ALL);
3140        return m_securityManager.readResource(m_context, resource, version);
3141    }
3142
3143    /**
3144     * Reads a resource from the VFS,
3145     * using the <code>{@link CmsResourceFilter#DEFAULT}</code> filter.<p>
3146     *
3147     * A resource may be of type <code>{@link CmsFile}</code> or
3148     * <code>{@link CmsFolder}</code>. In case of
3149     * a file, the resource will not contain the binary file content. Since reading
3150     * the binary content is a cost-expensive database operation, it's recommended
3151     * to work with resources if possible, and only read the file content when absolutely
3152     * required. To "upgrade" a resource to a file,
3153     * use <code>{@link #readFile(CmsResource)}</code>.<p>
3154     *
3155     * @param resourcename the name of the resource to read (full current site relative path)
3156     *
3157     * @return the resource that was read
3158     *
3159     * @throws CmsException if the resource could not be read for any reason
3160     *
3161     * @see #readFile(String)
3162     * @see #readResource(String, CmsResourceFilter)
3163     */
3164    public CmsResource readResource(String resourcename) throws CmsException {
3165
3166        return readResource(resourcename, CmsResourceFilter.DEFAULT);
3167    }
3168
3169    /**
3170     * Reads a resource from the VFS,
3171     * using the specified resource filter.<p>
3172     *
3173     * A resource may be of type <code>{@link CmsFile}</code> or
3174     * <code>{@link CmsFolder}</code>. In case of
3175     * a file, the resource will not contain the binary file content. Since reading
3176     * the binary content is a cost-expensive database operation, it's recommended
3177     * to work with resources if possible, and only read the file content when absolutely
3178     * required. To "upgrade" a resource to a file,
3179     * use <code>{@link #readFile(CmsResource)}</code>.<p>
3180     *
3181     * The specified filter controls what kind of resources should be "found"
3182     * during the read operation. This will depend on the application. For example,
3183     * using <code>{@link CmsResourceFilter#DEFAULT}</code> will only return currently
3184     * "valid" resources, while using <code>{@link CmsResourceFilter#IGNORE_EXPIRATION}</code>
3185     * will ignore the date release / date expired information of the resource.<p>
3186     *
3187     * @param resourcename the name of the resource to read (full current site relative path)
3188     * @param filter the resource filter to use while reading
3189     *
3190     * @return the resource that was read
3191     *
3192     * @throws CmsException if the resource could not be read for any reason
3193     *
3194     * @see #readFile(String, CmsResourceFilter)
3195     * @see #readFolder(String, CmsResourceFilter)
3196     */
3197    public CmsResource readResource(String resourcename, CmsResourceFilter filter) throws CmsException {
3198
3199        return m_securityManager.readResource(m_context, addSiteRoot(resourcename), filter);
3200    }
3201
3202    /**
3203     * Reads all resources below the given resource matching the filter criteria,
3204     * including the full tree below the path only in case the <code>readTree</code>
3205     * parameter is <code>true</code>.<p>
3206     *
3207     * @param resource the parent resource
3208     * @param filter the filter
3209     * @param readTree <code>true</code> to read all sub resources
3210     *
3211     * @return a list of <code>{@link CmsResource}</code> objects matching the filter criteria
3212     *
3213     * @throws CmsException if something goes wrong
3214     */
3215    public List<CmsResource> readResources(CmsResource resource, CmsResourceFilter filter, boolean readTree)
3216    throws CmsException {
3217
3218        return m_securityManager.readResources(m_context, resource, filter, readTree);
3219    }
3220
3221    /**
3222     * Reads all resources below the given path matching the filter criteria,
3223     * including the full tree below the path.<p>
3224     *
3225     * @param resourcename the parent path to read the resources from
3226     * @param filter the filter
3227     *
3228     * @return a list of <code>{@link CmsResource}</code> objects matching the filter criteria
3229     *
3230     * @throws CmsException if something goes wrong
3231     *
3232     * @see #readResources(String, CmsResourceFilter, boolean)
3233     */
3234    public List<CmsResource> readResources(String resourcename, CmsResourceFilter filter) throws CmsException {
3235
3236        return readResources(resourcename, filter, true);
3237    }
3238
3239    /**
3240     * Reads all resources below the given path matching the filter criteria,
3241     * including the full tree below the path only in case the <code>readTree</code>
3242     * parameter is <code>true</code>.<p>
3243     *
3244     * @param resourcename the parent path to read the resources from
3245     * @param filter the filter
3246     * @param readTree <code>true</code> to read all sub resources
3247     *
3248     * @return a list of <code>{@link CmsResource}</code> objects matching the filter criteria
3249     *
3250     * @throws CmsException if something goes wrong
3251     */
3252    public List<CmsResource> readResources(String resourcename, CmsResourceFilter filter, boolean readTree)
3253    throws CmsException {
3254
3255        CmsResource resource = readResource(resourcename, CmsResourceFilter.ALL);
3256        return m_securityManager.readResources(m_context, resource, filter, readTree);
3257    }
3258
3259    /**
3260     * Reads all resources that have a value set for the specified property.<p>
3261     *
3262     * Both individual and shared properties of a resource are checked.<p>
3263     *
3264     * Will use the {@link CmsResourceFilter#ALL} resource filter.<p>
3265     *
3266     * @param propertyDefinition the name of the property to check for
3267     *
3268     * @return a list of all <code>{@link CmsResource}</code> objects
3269     *          that have a value set for the specified property.
3270     *
3271     * @throws CmsException if something goes wrong
3272     */
3273    public List<CmsResource> readResourcesWithProperty(String propertyDefinition) throws CmsException {
3274
3275        return readResourcesWithProperty("/", propertyDefinition);
3276    }
3277
3278    /**
3279     * Reads all resources that have a value set for the specified property in the given path.<p>
3280     *
3281     * Both individual and shared properties of a resource are checked.<p>
3282     *
3283     * Will use the {@link CmsResourceFilter#ALL} resource filter.<p>
3284     *
3285     * @param path the folder to get the resources with the property from
3286     * @param propertyDefinition the name of the property to check for
3287     *
3288     * @return all <code>{@link CmsResource}</code> objects
3289     *          that have a value set for the specified property in the given path.
3290     *
3291     * @throws CmsException if something goes wrong
3292     */
3293    public List<CmsResource> readResourcesWithProperty(String path, String propertyDefinition) throws CmsException {
3294
3295        return readResourcesWithProperty(path, propertyDefinition, null);
3296    }
3297
3298    /**
3299     * Reads all resources that have a value (containing the specified value) set
3300     * for the specified property in the given path.<p>
3301     *
3302     * Both individual and shared properties of a resource are checked.<p>
3303     *
3304     * If the <code>value</code> parameter is <code>null</code>, all resources having the
3305     * given property set are returned.<p>
3306     *
3307     * Will use the {@link CmsResourceFilter#ALL} resource filter.<p>
3308     *
3309     * @param path the folder to get the resources with the property from
3310     * @param propertyDefinition the name of the property to check for
3311     * @param value the string to search in the value of the property
3312     *
3313     * @return all <code>{@link CmsResource}</code> objects
3314     *          that have a value set for the specified property in the given path.
3315     *
3316     * @throws CmsException if something goes wrong
3317     */
3318    public List<CmsResource> readResourcesWithProperty(String path, String propertyDefinition, String value)
3319    throws CmsException {
3320
3321        CmsResource resource = readResource(path, CmsResourceFilter.IGNORE_EXPIRATION);
3322        return m_securityManager.readResourcesWithProperty(
3323            m_context,
3324            resource,
3325            propertyDefinition,
3326            value,
3327            CmsResourceFilter.ALL);
3328    }
3329
3330    /**
3331     * Reads all resources that have a value (containing the specified value) set
3332     * for the specified property in the given path.<p>
3333     *
3334     * Both individual and shared properties of a resource are checked.<p>
3335     *
3336     * If the <code>value</code> parameter is <code>null</code>, all resources having the
3337     * given property set are returned.<p>
3338     *
3339     * Will use the given resource filter.<p>
3340     *
3341     * @param path the folder to get the resources with the property from
3342     * @param propertyDefinition the name of the property to check for
3343     * @param value the string to search in the value of the property
3344     * @param filter the resource filter to apply to the result set
3345     *
3346     * @return all <code>{@link CmsResource}</code> objects
3347     *          that have a value set for the specified property in the given path.
3348     *
3349     * @throws CmsException if something goes wrong
3350     */
3351    public List<CmsResource> readResourcesWithProperty(
3352        String path,
3353        String propertyDefinition,
3354        String value,
3355        CmsResourceFilter filter)
3356    throws CmsException {
3357
3358        CmsResource resource = readResource(path, CmsResourceFilter.IGNORE_EXPIRATION);
3359        return m_securityManager.readResourcesWithProperty(m_context, resource, propertyDefinition, value, filter);
3360    }
3361
3362    /**
3363     * Returns a set of principals that are responsible for a specific resource.<p>
3364     *
3365     * @param resource the resource to get the responsible principals from
3366     *
3367     * @return the set of principals that are responsible for a specific resource
3368     *
3369     * @throws CmsException if something goes wrong
3370     */
3371    public Set<I_CmsPrincipal> readResponsiblePrincipals(CmsResource resource) throws CmsException {
3372
3373        return m_securityManager.readResponsiblePrincipals(m_context, resource);
3374    }
3375
3376    /**
3377     * Returns a set of users that are responsible for a specific resource.<p>
3378     *
3379     * @param resource the resource to get the responsible users from
3380     *
3381     * @return the set of users that are responsible for a specific resource
3382     *
3383     * @throws CmsException if something goes wrong
3384     */
3385    public Set<CmsUser> readResponsibleUsers(CmsResource resource) throws CmsException {
3386
3387        return m_securityManager.readResponsibleUsers(m_context, resource);
3388    }
3389
3390    /**
3391     * Returns a list of all siblings of the specified resource,
3392     * the specified resource being always part of the result set.<p>
3393     *
3394     * @param resource the resource
3395     * @param filter a resource filter
3396     *
3397     * @return a list of <code>{@link CmsResource}</code>s that
3398     *          are siblings to the specified resource,
3399     *          including the specified resource itself.
3400     *
3401     * @throws CmsException if something goes wrong
3402     */
3403    public List<CmsResource> readSiblings(CmsResource resource, CmsResourceFilter filter) throws CmsException {
3404
3405        return m_securityManager.readSiblings(m_context, resource, filter);
3406    }
3407
3408    /**
3409     * Returns a list of all siblings of the specified resource,
3410     * the specified resource being always part of the result set.<p>
3411     *
3412     * @param resourcename the name of the specified resource
3413     * @param filter a resource filter
3414     *
3415     * @return a list of <code>{@link CmsResource}</code>s that
3416     *          are siblings to the specified resource,
3417     *          including the specified resource itself.
3418     *
3419     * @throws CmsException if something goes wrong
3420     */
3421    public List<CmsResource> readSiblings(String resourcename, CmsResourceFilter filter) throws CmsException {
3422
3423        CmsResource resource = readResource(resourcename, filter);
3424        return readSiblings(resource, filter);
3425    }
3426
3427    /**
3428     * Reads all resources with the given resource id.<p>
3429     *
3430     * @param resourceId the resource id for which we want the siblings
3431     * @param filter the resource filter used to read the resources
3432     * @return the siblings which share the given resource id
3433     *
3434     * @throws CmsException if something goes wrong
3435     */
3436    public List<CmsResource> readSiblingsForResourceId(CmsUUID resourceId, CmsResourceFilter filter)
3437    throws CmsException {
3438
3439        CmsResource pseudoResource = new CmsResource(
3440            null,
3441            resourceId,
3442            null,
3443            0,
3444            false,
3445            0,
3446            null,
3447            null,
3448            0,
3449            null,
3450            0,
3451            null,
3452            0,
3453            0,
3454            0,
3455            0,
3456            0,
3457            0);
3458        return readSiblings(pseudoResource, filter);
3459    }
3460
3461    /**
3462     * Returns the parameters of a resource in the list of all published template resources.<p>
3463     *
3464     * @param rfsName the rfs name of the resource
3465     *
3466     * @return the parameter string of the requested resource
3467     *
3468     * @throws CmsException if something goes wrong
3469     */
3470    public String readStaticExportPublishedResourceParameters(String rfsName) throws CmsException {
3471
3472        return m_securityManager.readStaticExportPublishedResourceParameters(m_context, rfsName);
3473    }
3474
3475    /**
3476     * Returns a list of all template resources which must be processed during a static export.<p>
3477     *
3478     * @param parameterResources flag for reading resources with parameters (1) or without (0)
3479     *
3480     * @param timestamp a time stamp for reading the data from the db
3481     *
3482     * @return a list of template resources as <code>{@link String}</code> objects
3483     *
3484     * @throws CmsException if something goes wrong
3485     */
3486    public List<String> readStaticExportResources(int parameterResources, long timestamp) throws CmsException {
3487
3488        return m_securityManager.readStaticExportResources(m_context, parameterResources, timestamp);
3489    }
3490
3491    /**
3492     * Reads the URL name mappings matching a given filter.<p>
3493     *
3494     * @param filter the filter to match
3495     * @return the URL name mappings matching the filter
3496     *
3497     * @throws CmsException if something goes wrong
3498     */
3499    public List<CmsUrlNameMappingEntry> readUrlNameMappings(CmsUrlNameMappingFilter filter) throws CmsException {
3500
3501        return m_securityManager.readUrlNameMappings(m_context, filter);
3502    }
3503
3504    /**
3505     * Reads the URL names for all locales.<p>
3506     *
3507     * @param structureId the id of resource for which the URL names should be read
3508     * @return returns the URL names for the resource
3509     *
3510     * @throws CmsException if something goes wrong
3511     */
3512    public List<String> readUrlNamesForAllLocales(CmsUUID structureId) throws CmsException {
3513
3514        List<String> detailNames = m_securityManager.readUrlNamesForAllLocales(m_context, structureId);
3515        if (detailNames.isEmpty()) {
3516            List<String> result = new ArrayList<String>();
3517            result.add(structureId.toString());
3518            return result;
3519        }
3520        return detailNames;
3521    }
3522
3523    /**
3524     * Reads a user based on its id.<p>
3525     *
3526     * @param userId the id of the user to be read
3527     *
3528     * @return the user with the given id
3529     *
3530     * @throws CmsException if something goes wrong
3531     *
3532     * @see #readHistoryPrincipal(CmsUUID) for retrieving data of deleted users
3533     */
3534    public CmsUser readUser(CmsUUID userId) throws CmsException {
3535
3536        return m_securityManager.readUser(m_context, userId);
3537    }
3538
3539    /**
3540     * Reads a user based on its name.<p>
3541     *
3542     * @param username the name of the user to be read
3543     *
3544     * @return the user with the given name
3545     *
3546     * @throws CmsException if something goes wrong
3547     */
3548    public CmsUser readUser(String username) throws CmsException {
3549
3550        return m_securityManager.readUser(m_context, username);
3551    }
3552
3553    /**
3554     * Returns a user, if the password is correct.<p>
3555     *
3556     * If the user/pwd pair is not valid a <code>{@link CmsException}</code> is thrown.<p>
3557     *
3558     * @param username the name of the user to be returned
3559     * @param password the password of the user to be returned
3560     *
3561     * @return the validated user
3562     *
3563     * @throws CmsException if operation was not successful
3564     */
3565    public CmsUser readUser(String username, String password) throws CmsException {
3566
3567        return m_securityManager.readUser(m_context, username, password);
3568    }
3569
3570    /**
3571     * Removes a resource from the current project of the user.<p>
3572     *
3573     * This is used to reduce the current users project with the
3574     * specified resource, in case that the resource is already part of the project.
3575     * The resource is not really removed like in a regular copy operation,
3576     * it is in fact only "disabled" in the current users project.<p>
3577     *
3578     * @param resourcename the name of the resource to remove to the current project (full current site relative path)
3579     *
3580     * @throws CmsException if something goes wrong
3581     */
3582    public void removeResourceFromProject(String resourcename) throws CmsException {
3583
3584        // TODO: this should be also possible if the resource has been deleted
3585        CmsResource resource = readResource(resourcename, CmsResourceFilter.ALL);
3586        getResourceType(resource).removeResourceFromProject(this, m_securityManager, resource);
3587    }
3588
3589    /**
3590     * Removes a user from a group.<p>
3591     *
3592     * @param username the name of the user that is to be removed from the group
3593     * @param groupname the name of the group
3594     *
3595     * @throws CmsException if operation was not successful
3596     */
3597    public void removeUserFromGroup(String username, String groupname) throws CmsException {
3598
3599        m_securityManager.removeUserFromGroup(m_context, username, groupname, false);
3600    }
3601
3602    /**
3603     * Renames a resource to the given destination name,
3604     * this is identical to a <code>move</code> operation.<p>
3605     *
3606     * @param source the name of the resource to rename (full current site relative path)
3607     * @param destination the new resource name (full path)
3608     *
3609     * @throws CmsException if something goes wrong
3610     *
3611     * @see #moveResource(String, String)
3612     */
3613    public void renameResource(String source, String destination) throws CmsException {
3614
3615        moveResource(source, destination);
3616    }
3617
3618    /**
3619     * Replaces the content, type and properties of a resource.<p>
3620     *
3621     * @param resourcename the name of the resource to replace (full current site relative path)
3622     * @param type the new type of the resource
3623     * @param content the new content of the resource
3624     * @param properties the new properties of the resource
3625     *
3626     * @throws CmsException if something goes wrong
3627     */
3628    public void replaceResource(
3629        String resourcename,
3630        I_CmsResourceType type,
3631        byte[] content,
3632        List<CmsProperty> properties)
3633    throws CmsException {
3634
3635        CmsResource resource = readResource(resourcename, CmsResourceFilter.IGNORE_EXPIRATION);
3636        getResourceType(resource).replaceResource(this, m_securityManager, resource, type, content, properties);
3637    }
3638
3639    /**
3640     * Replaces the content, type and properties of a resource.<p>
3641     *
3642     * @param resourcename the name of the resource to replace (full current site relative path)
3643     * @param type the new type of the resource
3644     * @param content the new content of the resource
3645     * @param properties the new properties of the resource
3646     *
3647     * @throws CmsException if something goes wrong
3648     *
3649     * @deprecated
3650     * Use {@link #replaceResource(String, I_CmsResourceType, byte[], List)} instead.
3651     * Resource types should always be referenced either by its type class (preferred) or by type name.
3652     * Use of int based resource type references will be discontinued in a future OpenCms release.
3653     */
3654    @Deprecated
3655    public void replaceResource(String resourcename, int type, byte[] content, List<CmsProperty> properties)
3656    throws CmsException {
3657
3658        replaceResource(resourcename, getResourceType(type), content, properties);
3659    }
3660
3661    /**
3662     * Restores a deleted resource identified by its structure id from the historical archive.<p>
3663     *
3664     * These ids can be obtained from the {@link #readDeletedResources(String, boolean)} method.<p>
3665     *
3666     * @param structureId the structure id of the resource to restore
3667     *
3668     * @throws CmsException if something goes wrong
3669     */
3670    public void restoreDeletedResource(CmsUUID structureId) throws CmsException {
3671
3672        m_securityManager.restoreDeletedResource(m_context, structureId);
3673    }
3674
3675    /**
3676     * Restores a resource in the current project with a version from the historical archive.<p>
3677     *
3678     * @param structureId the structure id of the resource to restore from the archive
3679     * @param version the desired version of the resource to be restored
3680     *
3681     * @throws CmsException if something goes wrong
3682     *
3683     * @see #readResource(CmsUUID, int)
3684     */
3685    public void restoreResourceVersion(CmsUUID structureId, int version) throws CmsException {
3686
3687        CmsResource resource = readResource(structureId, CmsResourceFilter.IGNORE_EXPIRATION);
3688        getResourceType(resource).restoreResource(this, m_securityManager, resource, version);
3689    }
3690
3691    /**
3692     * Removes an access control entry of a given principal from a given resource.<p>
3693     *
3694     * @param resourceName name of the resource
3695     * @param principalType the type of the principal (currently group or user)
3696     * @param principalName the name of the principal
3697     *
3698     * @throws CmsException if something goes wrong
3699     */
3700    public void rmacc(String resourceName, String principalType, String principalName) throws CmsException {
3701
3702        CmsResource res = readResource(resourceName, CmsResourceFilter.ALL);
3703
3704        if (CmsUUID.isValidUUID(principalName)) {
3705            // principal name is in fact a UUID, probably the user was already deleted
3706            m_securityManager.removeAccessControlEntry(m_context, res, new CmsUUID(principalName));
3707        } else if (CmsAccessControlEntry.PRINCIPAL_ALL_OTHERS_NAME.equals(principalName)) {
3708            m_securityManager.removeAccessControlEntry(m_context, res, CmsAccessControlEntry.PRINCIPAL_ALL_OTHERS_ID);
3709        } else if (CmsAccessControlEntry.PRINCIPAL_OVERWRITE_ALL_NAME.equals(principalName)) {
3710            m_securityManager.removeAccessControlEntry(
3711                m_context,
3712                res,
3713                CmsAccessControlEntry.PRINCIPAL_OVERWRITE_ALL_ID);
3714        } else {
3715            try {
3716                // principal name not a UUID, assume this is a normal group or user name
3717                I_CmsPrincipal principal = CmsPrincipal.readPrincipal(this, principalType, principalName);
3718                m_securityManager.removeAccessControlEntry(m_context, res, principal.getId());
3719            } catch (CmsDbEntryNotFoundException e) {
3720                // role case
3721                CmsRole role = CmsRole.valueOfRoleName(principalName);
3722                if (role == null) {
3723                    throw e;
3724                }
3725                m_securityManager.removeAccessControlEntry(m_context, res, role.getId());
3726            }
3727        }
3728    }
3729
3730    /**
3731     * Changes the "expire" date of a resource.<p>
3732     *
3733     * @param resource the resource to change
3734     * @param dateExpired the new expire date of the changed resource
3735     * @param recursive if this operation is to be applied recursively to all resources in a folder
3736     *
3737     * @throws CmsException if something goes wrong
3738     */
3739    public void setDateExpired(CmsResource resource, long dateExpired, boolean recursive) throws CmsException {
3740
3741        getResourceType(resource).setDateExpired(this, m_securityManager, resource, dateExpired, recursive);
3742    }
3743
3744    /**
3745     * Changes the "expire" date of a resource.<p>
3746     *
3747     * @param resourcename the name of the resource to change (full current site relative path)
3748     * @param dateExpired the new expire date of the changed resource
3749     * @param recursive if this operation is to be applied recursively to all resources in a folder
3750     *
3751     * @throws CmsException if something goes wrong
3752     */
3753    public void setDateExpired(String resourcename, long dateExpired, boolean recursive) throws CmsException {
3754
3755        CmsResource resource = readResource(resourcename, CmsResourceFilter.IGNORE_EXPIRATION);
3756        setDateExpired(resource, dateExpired, recursive);
3757    }
3758
3759    /**
3760     * Changes the "last modified" time stamp of a resource.<p>
3761     *
3762     * @param resourcename the name of the resource to change (full current site relative path)
3763     * @param dateLastModified time stamp the new time stamp of the changed resource
3764     * @param recursive if this operation is to be applied recursively to all resources in a folder
3765     *
3766     * @throws CmsException if something goes wrong
3767     */
3768    public void setDateLastModified(String resourcename, long dateLastModified, boolean recursive) throws CmsException {
3769
3770        CmsResource resource = readResource(resourcename, CmsResourceFilter.IGNORE_EXPIRATION);
3771        getResourceType(resource).setDateLastModified(this, m_securityManager, resource, dateLastModified, recursive);
3772    }
3773
3774    /**
3775     * Changes the "release" date of a resource.<p>
3776     *
3777     * @param resource the resource to change
3778     * @param dateReleased the new release date of the changed resource
3779     * @param recursive if this operation is to be applied recursively to all resources in a folder
3780     *
3781     * @throws CmsException if something goes wrong
3782     */
3783    public void setDateReleased(CmsResource resource, long dateReleased, boolean recursive) throws CmsException {
3784
3785        getResourceType(resource).setDateReleased(this, m_securityManager, resource, dateReleased, recursive);
3786    }
3787
3788    /**
3789     * Changes the "release" date of a resource.<p>
3790     *
3791     * @param resourcename the name of the resource to change (full current site relative path)
3792     * @param dateReleased the new release date of the changed resource
3793     * @param recursive if this operation is to be applied recursively to all resources in a folder
3794     *
3795     * @throws CmsException if something goes wrong
3796     */
3797    public void setDateReleased(String resourcename, long dateReleased, boolean recursive) throws CmsException {
3798
3799        CmsResource resource = readResource(resourcename, CmsResourceFilter.IGNORE_EXPIRATION);
3800        setDateReleased(resource, dateReleased, recursive);
3801    }
3802
3803    /**
3804     * Sets a new parent-group for an already existing group.<p>
3805     *
3806     * @param groupName the name of the group that should be updated
3807     * @param parentGroupName the name of the parent group to set,
3808     *                      or <code>null</code> if the parent
3809     *                      group should be deleted.
3810     *
3811     * @throws CmsException  if operation was not successful
3812     */
3813    public void setParentGroup(String groupName, String parentGroupName) throws CmsException {
3814
3815        m_securityManager.setParentGroup(m_context, groupName, parentGroupName);
3816    }
3817
3818    /**
3819     * Sets the password for a user.<p>
3820     *
3821     * @param username the name of the user
3822     * @param newPassword the new password
3823     *
3824     * @throws CmsException if operation was not successful
3825     */
3826    public void setPassword(String username, String newPassword) throws CmsException {
3827
3828        m_securityManager.setPassword(m_context, username, newPassword);
3829    }
3830
3831    /**
3832     * Sets the password for a specified user.<p>
3833     *
3834     * @param username the name of the user
3835     * @param oldPassword the old password
3836     * @param newPassword the new password
3837     *
3838     * @throws CmsException if the user data could not be read from the database
3839     */
3840    public void setPassword(String username, String oldPassword, String newPassword) throws CmsException {
3841
3842        m_securityManager.resetPassword(m_context, username, oldPassword, newPassword);
3843    }
3844
3845    /**
3846     * Undeletes a resource.<p>
3847     *
3848     * Only resources that have already been published once can be undeleted,
3849     * if a "new" resource is deleted it can not be undeleted.<p>
3850     *
3851     * @param resourcename the name of the resource to undelete
3852     * @param recursive if this operation is to be applied recursively to all resources in a folder
3853     *
3854     * @throws CmsException if something goes wrong
3855     *
3856     * @see CmsObject#undoChanges(String, CmsResource.CmsResourceUndoMode)
3857     */
3858    public void undeleteResource(String resourcename, boolean recursive) throws CmsException {
3859
3860        CmsResource resource = readResource(resourcename, CmsResourceFilter.ALL);
3861        getResourceType(resource).undelete(this, m_securityManager, resource, recursive);
3862    }
3863
3864    /**
3865     * Undoes all changes to a resource by restoring the version from the
3866     * online project to the current offline project.<p>
3867     *
3868     * @param resourcename the name of the resource to undo the changes for
3869     * @param mode the undo mode, one of the <code>{@link CmsResource.CmsResourceUndoMode}#UNDO_XXX</code> constants
3870     *
3871     * @throws CmsException if something goes wrong
3872     *
3873     * @see CmsResource#UNDO_CONTENT
3874     * @see CmsResource#UNDO_CONTENT_RECURSIVE
3875     * @see CmsResource#UNDO_MOVE_CONTENT
3876     * @see CmsResource#UNDO_MOVE_CONTENT_RECURSIVE
3877     */
3878    public void undoChanges(String resourcename, CmsResource.CmsResourceUndoMode mode) throws CmsException {
3879
3880        CmsResource resource = readResource(resourcename, CmsResourceFilter.ALL);
3881        getResourceType(resource).undoChanges(this, m_securityManager, resource, mode);
3882    }
3883
3884    /**
3885     * Unlocks all resources of a project.
3886     *
3887     * @param id the id of the project to be unlocked
3888     *
3889     * @throws CmsException if operation was not successful
3890     */
3891    public void unlockProject(CmsUUID id) throws CmsException {
3892
3893        m_securityManager.unlockProject(m_context, id);
3894    }
3895
3896    /**
3897     * Unlocks a resource.<p>
3898     *
3899     * @param resource the resource to unlock
3900     *
3901     * @throws CmsException if something goes wrong
3902     */
3903    public void unlockResource(CmsResource resource) throws CmsException {
3904
3905        getResourceType(resource).unlockResource(this, m_securityManager, resource);
3906    }
3907
3908    /**
3909     * Unlocks a resource.<p>
3910     *
3911     * @param resourcename the name of the resource to unlock (full current site relative path)
3912     *
3913     * @throws CmsException if something goes wrong
3914     */
3915    public void unlockResource(String resourcename) throws CmsException {
3916
3917        CmsResource resource = readResource(resourcename, CmsResourceFilter.ALL);
3918        getResourceType(resource).unlockResource(this, m_securityManager, resource);
3919    }
3920
3921    /**
3922     * Updates the last login date on the given user to the current time.<p>
3923     *
3924     * @param user the user to be updated
3925     *
3926     * @throws CmsRoleViolationException if the current user does not own the rule {@link CmsRole#ACCOUNT_MANAGER} for the current project
3927     * @throws CmsException if operation was not successful
3928     */
3929    public void updateLastLoginDate(CmsUser user) throws CmsRoleViolationException, CmsException {
3930
3931        m_securityManager.updateLastLoginDate(m_context, user);
3932    }
3933
3934    /**
3935     * Tests if a user is member of the given group.<p>
3936     *
3937     * @param username the name of the user to test
3938     * @param groupname the name of the group to test
3939     *
3940     * @return <code>true</code>, if the user is in the group; or <code>false</code> otherwise
3941     *
3942     * @throws CmsException if operation was not successful
3943     */
3944    public boolean userInGroup(String username, String groupname) throws CmsException {
3945
3946        return (m_securityManager.userInGroup(m_context, username, groupname));
3947    }
3948
3949    /**
3950     * This method checks if a new password follows the rules for
3951     * new passwords, which are defined by a Class implementing the
3952     * <code>{@link org.opencms.security.I_CmsPasswordHandler}</code>
3953     * interface and configured in the opencms.properties file.<p>
3954     *
3955     * If this method throws no exception the password is valid.<p>
3956     *
3957     * @param password the new password that has to be checked
3958     *
3959     * @throws CmsSecurityException if the password is not valid
3960     */
3961    public void validatePassword(String password) throws CmsSecurityException {
3962
3963        m_securityManager.validatePassword(password);
3964    }
3965
3966    /**
3967     * Writes a resource to the OpenCms VFS, including it's content.<p>
3968     *
3969     * Applies only to resources of type <code>{@link CmsFile}</code>
3970     * i.e. resources that have a binary content attached.<p>
3971     *
3972     * Certain resource types might apply content validation or transformation rules
3973     * before the resource is actually written to the VFS. The returned result
3974     * might therefore be a modified version from the provided original.<p>
3975     *
3976     * @param resource the resource to write
3977     *
3978     * @return the written resource (may have been modified)
3979     *
3980     * @throws CmsException if something goes wrong
3981     */
3982    public CmsFile writeFile(CmsFile resource) throws CmsException {
3983
3984        return getResourceType(resource).writeFile(this, m_securityManager, resource);
3985    }
3986
3987    /**
3988     * Writes an already existing group.<p>
3989     *
3990     * The group has to be a valid OpenCms group.<br>
3991     *
3992     * The group will be completely overridden by the given data.<p>
3993     *
3994     * @param group the group that should be written
3995     *
3996     * @throws CmsException if operation was not successful
3997     */
3998    public void writeGroup(CmsGroup group) throws CmsException {
3999
4000        m_securityManager.writeGroup(m_context, group);
4001    }
4002
4003    /**
4004     * Creates a historical entry of the current project.<p>
4005     *
4006     * @param publishTag the correlative publish tag
4007     * @param publishDate the date of publishing
4008
4009     * @throws CmsException if operation was not successful
4010     */
4011    public void writeHistoryProject(int publishTag, long publishDate) throws CmsException {
4012
4013        m_securityManager.writeHistoryProject(m_context, publishTag, publishDate);
4014    }
4015
4016    /**
4017     * Writes an already existing project.<p>
4018     *
4019     * The project id has to be a valid OpenCms project id.<br>
4020     *
4021     * The project with the given id will be completely overridden
4022     * by the given data.<p>
4023     *
4024     * @param project the project that should be written
4025     *
4026     * @throws CmsException if operation was not successful
4027     */
4028    public void writeProject(CmsProject project) throws CmsException {
4029
4030        m_securityManager.writeProject(m_context, project);
4031    }
4032
4033    /**
4034     * Writes the 'projectlastmodified' field of a resource record.<p>
4035     *
4036     * @param resource the resource which should be modified
4037     * @param project the project whose id should be written into the resource record
4038     *
4039     * @throws CmsException if something goes wrong
4040     */
4041    public void writeProjectLastModified(CmsResource resource, CmsProject project) throws CmsException {
4042
4043        m_securityManager.writeResourceProjectLastModified(getRequestContext(), resource, project);
4044    }
4045
4046    /**
4047     * Writes a property for a specified resource.<p>
4048     *
4049     * @param resourcename the name of resource with complete path
4050     * @param property the property to write
4051     *
4052     * @throws CmsException if something goes wrong
4053     */
4054    public void writePropertyObject(String resourcename, CmsProperty property) throws CmsException {
4055
4056        CmsResource resource = readResource(resourcename, CmsResourceFilter.IGNORE_EXPIRATION);
4057        getResourceType(resource).writePropertyObject(this, m_securityManager, resource, property);
4058    }
4059
4060    /**
4061     * Writes a list of properties for a specified resource.<p>
4062     *
4063     * Code calling this method has to ensure that the no properties
4064     * <code>a, b</code> are contained in the specified list so that <code>a.equals(b)</code>,
4065     * otherwise an exception is thrown.<p>
4066     *
4067     * @param res the resource
4068     * @param properties the list of properties to write
4069     *
4070     * @throws CmsException if something goes wrong
4071     */
4072    public void writePropertyObjects(CmsResource res, List<CmsProperty> properties) throws CmsException {
4073
4074        getResourceType(res).writePropertyObjects(this, m_securityManager, res, properties);
4075    }
4076
4077    /**
4078     * Writes a list of properties for a specified resource.<p>
4079     *
4080     * Code calling this method has to ensure that the no properties
4081     * <code>a, b</code> are contained in the specified list so that <code>a.equals(b)</code>,
4082     * otherwise an exception is thrown.<p>
4083     *
4084     * @param resourcename the name of resource with complete path
4085     * @param properties the list of properties to write
4086     *
4087     * @throws CmsException if something goes wrong
4088     */
4089    public void writePropertyObjects(String resourcename, List<CmsProperty> properties) throws CmsException {
4090
4091        CmsResource resource = readResource(resourcename, CmsResourceFilter.IGNORE_EXPIRATION);
4092        getResourceType(resource).writePropertyObjects(this, m_securityManager, resource, properties);
4093    }
4094
4095    /**
4096     * Writes a resource.<p>
4097     *
4098     * @param resource the file to write
4099     *
4100     * @throws CmsException if resource type is set to folder, or
4101     *                      if the user has not the rights to write the file header.
4102     */
4103    public void writeResource(CmsResource resource) throws CmsException {
4104
4105        m_securityManager.writeResource(m_context, resource);
4106    }
4107
4108    /**
4109     * Writes a published resource entry.<p>
4110     *
4111     * This is done during static export.<p>
4112     *
4113     * @param resourceName The name of the resource to be added to the static export
4114     * @param linkType the type of resource exported (0= non-parameter, 1=parameter)
4115     * @param linkParameter the parameters added to the resource
4116     * @param timestamp a time stamp for writing the data into the db
4117     *
4118     * @throws CmsException if something goes wrong
4119     */
4120    public void writeStaticExportPublishedResource(
4121        String resourceName,
4122        int linkType,
4123        String linkParameter,
4124        long timestamp)
4125    throws CmsException {
4126
4127        m_securityManager.writeStaticExportPublishedResource(
4128            m_context,
4129            resourceName,
4130            linkType,
4131            linkParameter,
4132            timestamp);
4133    }
4134
4135    /**
4136     * Writes a new URL name mapping for a given resource.<p>
4137     *
4138     * The first name from the given name sequence which is not already mapped to another resource will be used
4139     * for the URL name mapping.<p>
4140     *
4141     * @param nameSeq an iterator for generating names for the mapping
4142     * @param structureId the structure id to which the name should be mapped
4143     * @param locale the locale of the mapping
4144     * @param replaceOnPublish if the mapping should replace previous mappings when published
4145     *
4146     * @return the name which was actually mapped to the structure id
4147     *
4148     * @throws CmsException if something goes wrong
4149     */
4150    public String writeUrlNameMapping(
4151        Iterator<String> nameSeq,
4152        CmsUUID structureId,
4153        String locale,
4154        boolean replaceOnPublish)
4155    throws CmsException {
4156
4157        return m_securityManager.writeUrlNameMapping(m_context, nameSeq, structureId, locale, replaceOnPublish);
4158    }
4159
4160    /**
4161     * Writes a new URL name mapping for a given resource.<p>
4162     *
4163     * This method uses {@link CmsNumberSuffixNameSequence} to generate a sequence of name candidates
4164     * from the given base name.<p>
4165     *
4166     * @param name the base name for the mapping
4167     * @param structureId the structure id to which the name should be mapped
4168     * @param locale the locale of the mapping
4169     * @param replaceOnPublish mappings for which this is set will replace older mappings on publish
4170     *
4171     * @return the URL name that was actually used for the mapping
4172     *
4173     * @throws CmsException if something goes wrong
4174     */
4175    public String writeUrlNameMapping(String name, CmsUUID structureId, String locale, boolean replaceOnPublish)
4176    throws CmsException {
4177
4178        return writeUrlNameMapping(new CmsNumberSuffixNameSequence(name), structureId, locale, replaceOnPublish);
4179    }
4180
4181    /**
4182     * Updates the user information. <p>
4183     *
4184     * The user id has to be a valid OpenCms user id.<br>
4185     *
4186     * The user with the given id will be completely overriden
4187     * by the given data.<p>
4188     *
4189     * @param user the user to be written
4190     *
4191     * @throws CmsException if operation was not successful
4192     */
4193    public void writeUser(CmsUser user) throws CmsException {
4194
4195        m_securityManager.writeUser(m_context, user);
4196    }
4197
4198    /**
4199     * Adds a new relation to the given resource.<p>
4200     *
4201     * @param resource the source resource
4202     * @param target the target resource
4203     * @param relationType the type of the relation
4204     * @param importCase if importing relations
4205     *
4206     * @throws CmsException if something goes wrong
4207     */
4208    private void createRelation(CmsResource resource, CmsResource target, String relationType, boolean importCase)
4209    throws CmsException {
4210
4211        CmsRelationType type = CmsRelationType.valueOf(relationType);
4212        m_securityManager.addRelationToResource(m_context, resource, target, type, importCase);
4213    }
4214
4215    /**
4216     * Adds a new relation to the given resource.<p>
4217     *
4218     * @param resourceName the name of the source resource
4219     * @param targetPath the path of the target resource
4220     * @param relationType the type of the relation
4221     * @param importCase if importing relations
4222     *
4223     * @throws CmsException if something goes wrong
4224     */
4225    private void createRelation(String resourceName, String targetPath, String relationType, boolean importCase)
4226    throws CmsException {
4227
4228        CmsResource resource = readResource(resourceName, CmsResourceFilter.IGNORE_EXPIRATION);
4229        CmsResource target = readResource(targetPath, CmsResourceFilter.IGNORE_EXPIRATION);
4230        createRelation(resource, target, relationType, importCase);
4231    }
4232
4233    /**
4234     * Notify all event listeners that a particular event has occurred.<p>
4235     *
4236     * The event will be given to all registered <code>{@link I_CmsEventListener}</code>s.<p>
4237     *
4238     * @param type the type of the event
4239     * @param data a data object that contains data used by the event listeners
4240     *
4241     * @see OpenCms#addCmsEventListener(I_CmsEventListener)
4242     * @see OpenCms#addCmsEventListener(I_CmsEventListener, int[])
4243     */
4244    private void fireEvent(int type, Object data) {
4245
4246        OpenCms.fireCmsEvent(type, Collections.singletonMap("data", data));
4247    }
4248
4249    /**
4250     * Convenience method to get the initialized resource type instance for the given resource,
4251     * with a fall back to special "unknown" resource types in case the resource type is not configured.<p>
4252     *
4253     * @param resource the resource to get the type for
4254     *
4255     * @return the initialized resource type instance for the given resource
4256     *
4257     * @see org.opencms.loader.CmsResourceManager#getResourceType(int)
4258     */
4259    private I_CmsResourceType getResourceType(CmsResource resource) {
4260
4261        return OpenCms.getResourceManager().getResourceType(resource);
4262    }
4263
4264    /**
4265     * Convenience method to return the initialized resource type
4266     * instance for the given id.<p>
4267     *
4268     * @param resourceType the id of the resource type to get
4269     *
4270     * @return the initialized resource type instance for the given id
4271     *
4272     * @throws CmsException if something goes wrong
4273     *
4274     * @see org.opencms.loader.CmsResourceManager#getResourceType(int)
4275     */
4276    private I_CmsResourceType getResourceType(int resourceType) throws CmsException {
4277
4278        return OpenCms.getResourceManager().getResourceType(resourceType);
4279    }
4280
4281    /**
4282     * Initializes this <code>{@link CmsObject}</code> with the provided user context and database connection.<p>
4283     *
4284     * @param securityManager the security manager
4285     * @param context the request context that contains the user authentication
4286     */
4287    private void init(CmsSecurityManager securityManager, CmsRequestContext context) {
4288
4289        m_securityManager = securityManager;
4290        m_context = context;
4291    }
4292
4293    /**
4294     * Locks a resource.<p>
4295     *
4296     * The <code>type</code> parameter controls what kind of lock is used.<br>
4297     * Possible values for this parameter are: <br>
4298     * <ul>
4299     * <li><code>{@link org.opencms.lock.CmsLockType#EXCLUSIVE}</code></li>
4300     * <li><code>{@link org.opencms.lock.CmsLockType#TEMPORARY}</code></li>
4301     * </ul><p>
4302     *
4303     * @param resourcename the name of the resource to lock (full current site relative path)
4304     * @param type type of the lock
4305     *
4306     * @throws CmsException if something goes wrong
4307     */
4308    private void lockResource(String resourcename, CmsLockType type) throws CmsException {
4309
4310        // throw the exception if resource name is an empty string
4311        if (CmsStringUtil.isEmptyOrWhitespaceOnly(resourcename)) {
4312            throw new CmsVfsResourceNotFoundException(
4313                Messages.get().container(Messages.ERR_LOCK_RESOURCE_1, resourcename));
4314        }
4315        CmsResource resource = readResource(resourcename, CmsResourceFilter.ALL);
4316        getResourceType(resource).lockResource(this, m_securityManager, resource, type);
4317    }
4318
4319}