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.db; 029 030import org.opencms.file.CmsGroup; 031import org.opencms.file.CmsResource; 032import org.opencms.file.CmsUser; 033import org.opencms.security.CmsPermissionSet; 034 035/** 036 * Generates the cache keys for the user and permission caches.<p> 037 * 038 * @since 6.0.0 039 */ 040public class CmsCacheKey implements I_CmsCacheKey { 041 042 /** Cache key for a list of sub-resources (files and folders) of a folder. */ 043 public static final String CACHE_KEY_SUBALL = "_all_"; 044 045 /** Cache key for a list of sub-files of a folder. */ 046 public static final String CACHE_KEY_SUBFILES = "_files_"; 047 048 /** Cache key for a list of sub-folders of a folder. */ 049 public static final String CACHE_KEY_SUBFOLDERS = "_folders_"; 050 051 /** 052 * Constructor to create a new instance of CmsCacheKey.<p> 053 */ 054 public CmsCacheKey() { 055 056 // empty 057 } 058 059 /** 060 * @see org.opencms.db.I_CmsCacheKey#getCacheKeyForGroupUsers(java.lang.String, org.opencms.db.CmsDbContext, org.opencms.file.CmsGroup) 061 */ 062 public String getCacheKeyForGroupUsers(String prefix, CmsDbContext context, CmsGroup group) { 063 064 if (!context.getProjectId().isNullUUID()) { 065 return ""; 066 } 067 StringBuffer cacheBuffer = new StringBuffer(64); 068 cacheBuffer.append(prefix); 069 cacheBuffer.append('_'); 070 cacheBuffer.append(group.getName()); 071 return cacheBuffer.toString(); 072 } 073 074 /** 075 * @see org.opencms.db.I_CmsCacheKey#getCacheKeyForUserGroups(java.lang.String, org.opencms.db.CmsDbContext, org.opencms.file.CmsUser) 076 */ 077 public String getCacheKeyForUserGroups(String prefix, CmsDbContext context, CmsUser user) { 078 079 if (!context.getProjectId().isNullUUID()) { 080 return ""; 081 } 082 StringBuffer cacheBuffer = new StringBuffer(64); 083 cacheBuffer.append(prefix); 084 cacheBuffer.append('_'); 085 cacheBuffer.append(user.getName()); 086 return cacheBuffer.toString(); 087 } 088 089 /** 090 * @see org.opencms.db.I_CmsCacheKey#getCacheKeyForUserPermissions(java.lang.String, org.opencms.db.CmsDbContext, org.opencms.file.CmsResource, org.opencms.security.CmsPermissionSet) 091 */ 092 public String getCacheKeyForUserPermissions( 093 String prefix, 094 CmsDbContext context, 095 CmsResource resource, 096 CmsPermissionSet requiredPermissions) { 097 098 if (!context.getProjectId().isNullUUID()) { 099 return ""; 100 } 101 StringBuffer cacheBuffer = new StringBuffer(64); 102 cacheBuffer.append(prefix); 103 cacheBuffer.append('_'); 104 cacheBuffer.append(context.currentUser().getName()); 105 cacheBuffer.append(context.currentProject().isOnlineProject() ? "_0_" : "_1_"); 106 cacheBuffer.append(requiredPermissions.getPermissionString()); 107 cacheBuffer.append('_'); 108 cacheBuffer.append(resource.getStructureId().toString()); 109 return cacheBuffer.toString(); 110 } 111}