001: /*
002: * File : $Source: /usr/local/cvs/opencms/src/org/opencms/db/CmsCacheKey.java,v $
003: * Date : $Date: 2008-02-27 12:05:42 $
004: * Version: $Revision: 1.18 $
005: *
006: * This library is part of OpenCms -
007: * the Open Source Content Management System
008: *
009: * Copyright (c) 2002 - 2008 Alkacon Software GmbH (http://www.alkacon.com)
010: *
011: * This library is free software; you can redistribute it and/or
012: * modify it under the terms of the GNU Lesser General Public
013: * License as published by the Free Software Foundation; either
014: * version 2.1 of the License, or (at your option) any later version.
015: *
016: * This library is distributed in the hope that it will be useful,
017: * but WITHOUT ANY WARRANTY; without even the implied warranty of
018: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019: * Lesser General Public License for more details.
020: *
021: * For further information about Alkacon Software GmbH, please see the
022: * company website: http://www.alkacon.com
023: *
024: * For further information about OpenCms, please see the
025: * project website: http://www.opencms.org
026: *
027: * You should have received a copy of the GNU Lesser General Public
028: * License along with this library; if not, write to the Free Software
029: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
030: */
031:
032: package org.opencms.db;
033:
034: import org.opencms.file.CmsGroup;
035: import org.opencms.file.CmsResource;
036: import org.opencms.file.CmsUser;
037: import org.opencms.security.CmsPermissionSet;
038:
039: /**
040: * Generates the cache keys for the user and permission caches.<p>
041: *
042: * @author Carsten Weinholz
043: *
044: * @version $Revision: 1.18 $
045: *
046: * @since 6.0.0
047: */
048: public class CmsCacheKey implements I_CmsCacheKey {
049:
050: /** Cache key for a list of sub-resources (files and folders) of a folder. */
051: public static final String CACHE_KEY_SUBALL = "_all_";
052:
053: /** Cache key for a list of sub-files of a folder. */
054: public static final String CACHE_KEY_SUBFILES = "_files_";
055:
056: /** Cache key for a list of sub-folders of a folder. */
057: public static final String CACHE_KEY_SUBFOLDERS = "_folders_";
058:
059: /**
060: * Constructor to create a new instance of CmsCacheKey.<p>
061: */
062: public CmsCacheKey() {
063:
064: // empty
065: }
066:
067: /**
068: * @see org.opencms.db.I_CmsCacheKey#getCacheKeyForGroupUsers(java.lang.String, org.opencms.db.CmsDbContext, org.opencms.file.CmsGroup)
069: */
070: public String getCacheKeyForGroupUsers(String prefix,
071: CmsDbContext context, CmsGroup group) {
072:
073: StringBuffer cacheBuffer = new StringBuffer(64);
074: cacheBuffer.append(prefix);
075: cacheBuffer.append('_');
076: cacheBuffer.append(group.getName());
077: return cacheBuffer.toString();
078: }
079:
080: /**
081: * @see org.opencms.db.I_CmsCacheKey#getCacheKeyForUserGroups(java.lang.String, org.opencms.db.CmsDbContext, org.opencms.file.CmsUser)
082: */
083: public String getCacheKeyForUserGroups(String prefix,
084: CmsDbContext context, CmsUser user) {
085:
086: StringBuffer cacheBuffer = new StringBuffer(64);
087: cacheBuffer.append(prefix);
088: cacheBuffer.append('_');
089: cacheBuffer.append(user.getName());
090: return cacheBuffer.toString();
091: }
092:
093: /**
094: * @see org.opencms.db.I_CmsCacheKey#getCacheKeyForUserPermissions(java.lang.String, org.opencms.db.CmsDbContext, org.opencms.file.CmsResource, org.opencms.security.CmsPermissionSet)
095: */
096: public String getCacheKeyForUserPermissions(String prefix,
097: CmsDbContext context, CmsResource resource,
098: CmsPermissionSet requiredPermissions) {
099:
100: StringBuffer cacheBuffer = new StringBuffer(64);
101: cacheBuffer.append(prefix);
102: cacheBuffer.append('_');
103: cacheBuffer.append(context.currentUser().getName());
104: cacheBuffer
105: .append(context.currentProject().isOnlineProject() ? "_0_"
106: : "_1_");
107: cacheBuffer.append(requiredPermissions.getPermissionString());
108: cacheBuffer.append('_');
109: cacheBuffer.append(resource.getStructureId().toString());
110: return cacheBuffer.toString();
111: }
112: }
|