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.CmsResourceState; 031import org.opencms.db.CmsSecurityManager; 032import org.opencms.loader.CmsLoaderException; 033import org.opencms.main.CmsIllegalArgumentException; 034import org.opencms.main.CmsLog; 035import org.opencms.main.OpenCms; 036import org.opencms.util.CmsUUID; 037 038import org.apache.commons.logging.Log; 039 040/** 041 * A folder resource in the OpenCms VFS.<p> 042 * 043 * A folder resource is a CmsResource object that can contain sub-resources.<p> 044 * 045 * @since 6.0.0 046 */ 047public class CmsFolder extends CmsResource { 048 049 /** The log object for this class. */ 050 private static final Log LOG = CmsLog.getLog(CmsSecurityManager.class); 051 /** Serial version UID required for safe serialization. */ 052 private static final long serialVersionUID = 5527163725725725452L; 053 054 /** 055 * Constructor, creates a new CmsFolder Object from the given CmsResource.<p> 056 * 057 * @param resource the base resource object to create a folder from 058 */ 059 public CmsFolder(CmsResource resource) { 060 061 this( 062 resource.getStructureId(), 063 resource.getResourceId(), 064 resource.getRootPath(), 065 resource.getTypeId(), 066 resource.getFlags(), 067 resource.getProjectLastModified(), 068 resource.getState(), 069 resource.getDateCreated(), 070 resource.getUserCreated(), 071 resource.getDateLastModified(), 072 resource.getUserLastModified(), 073 resource.getDateReleased(), 074 resource.getDateExpired(), 075 resource.getVersion()); 076 } 077 078 /** 079 * Constructor, creates a new CmsFolder object.<p> 080 * 081 * @param structureId the id of this resources structure record 082 * @param resourceId the id of this resources resource record 083 * @param path the filename of this resouce 084 * @param type the type of this resource 085 * @param flags the flags of this resource 086 * @param projectId the project id this resource was last modified in 087 * @param state the state of this resource 088 * @param dateCreated the creation date of this resource 089 * @param userCreated the id of the user who created this resource 090 * @param dateLastModified the date of the last modification of this resource 091 * @param userLastModified the id of the user who did the last modification of this resource * @param size the size of the file content of this resource 092 * @param dateReleased the release date of this resource 093 * @param dateExpired the expiration date of this resource 094 * @param version the version number of this resource 095 */ 096 public CmsFolder( 097 CmsUUID structureId, 098 CmsUUID resourceId, 099 String path, 100 int type, 101 int flags, 102 CmsUUID projectId, 103 CmsResourceState state, 104 long dateCreated, 105 CmsUUID userCreated, 106 long dateLastModified, 107 CmsUUID userLastModified, 108 long dateReleased, 109 long dateExpired, 110 int version) { 111 112 super( 113 structureId, 114 resourceId, 115 path, 116 type, 117 true, 118 flags, 119 projectId, 120 state, 121 dateCreated, 122 userCreated, 123 dateLastModified, 124 userLastModified, 125 dateReleased, 126 dateExpired, 127 1, 128 -1, 129 -1, 130 version); 131 } 132 133 /** 134 * Returns <code>true</code> if the given resource size describes a folder type.<p> 135 * 136 * This is <code>true</code> in case <code>size < 0</code>.<p> 137 * 138 * @param size the resource size to check 139 * 140 * @return true if the given resource size describes a folder type or false if it is no folder 141 */ 142 public static final boolean isFolderSize(long size) { 143 144 return (size < 0); 145 } 146 147 /** 148 * Returns <code>true</code> if the given resource type id describes a folder type.<p> 149 * 150 * @param typeId the resource type id to check 151 * 152 * @return true if the given resource type id describes a folder type or false if it is no folder or an unknown type. 153 */ 154 public static final boolean isFolderType(int typeId) { 155 156 try { 157 return OpenCms.getResourceManager().getResourceType(typeId).isFolder(); 158 } catch (CmsLoaderException e) { 159 if (LOG.isWarnEnabled()) { 160 LOG.warn(Messages.get().getBundle().key(Messages.ERR_UNKNOWN_RESOURCE_TYPE_1, Integer.valueOf(typeId)), e); 161 } 162 } 163 return false; 164 } 165 166 /** 167 * Returns <code>true</code> if the given resource type name describes a folder type.<p> 168 * 169 * @param typeName the resource type name to check 170 * 171 * @return true if the given resource type name describes a folder type 172 */ 173 public static final boolean isFolderType(String typeName) { 174 175 try { 176 return OpenCms.getResourceManager().getResourceType(typeName).isFolder(); 177 } catch (CmsLoaderException e) { 178 throw new CmsIllegalArgumentException( 179 Messages.get().container(Messages.ERR_UNKNOWN_RESOURCE_TYPE_1, typeName), 180 e); 181 } 182 } 183 184 /** 185 * Returns a clone of this Objects instance.<p> 186 * 187 * @return a clone of this instance 188 */ 189 @Override 190 public Object clone() { 191 192 CmsResource clone = new CmsFolder( 193 getStructureId(), 194 getResourceId(), 195 getRootPath(), 196 getTypeId(), 197 getFlags(), 198 getProjectLastModified(), 199 getState(), 200 getDateCreated(), 201 getUserCreated(), 202 getDateLastModified(), 203 getUserLastModified(), 204 getDateReleased(), 205 getDateExpired(), 206 getVersion()); 207 208 if (isTouched()) { 209 clone.setDateLastModified(getDateLastModified()); 210 } 211 212 return clone; 213 } 214 215 /** 216 * A folder does always have the content date <code>-1</code>.<p> 217 * 218 * @see org.opencms.file.CmsResource#getDateContent() 219 */ 220 @Override 221 public long getDateContent() { 222 223 return -1; 224 } 225 226 /** 227 * A folder does always have length <code>-1</code>.<p> 228 * 229 * @see org.opencms.file.CmsResource#getLength() 230 */ 231 @Override 232 public int getLength() { 233 234 return -1; 235 } 236 237 /** 238 * Since this is a folder, not a file, <code>false</code> is always returned.<p> 239 * 240 * @see org.opencms.file.CmsResource#isFile() 241 */ 242 @Override 243 public boolean isFile() { 244 245 return false; 246 } 247 248 /** 249 * Since this is a folder, <code>true</code> is always returned.<p> 250 * 251 * @see org.opencms.file.CmsResource#isFolder() 252 */ 253 @Override 254 public boolean isFolder() { 255 256 return true; 257 } 258 259 /** 260 * @see org.opencms.file.CmsResource#isTemporaryFile() 261 */ 262 @Override 263 public boolean isTemporaryFile() { 264 265 return false; 266 } 267}