1 31 32 package org.opencms.file; 33 34 import org.opencms.main.CmsException; 35 import org.opencms.util.CmsUUID; 36 37 import java.io.Serializable ; 38 39 53 public class CmsFile extends CmsResource implements Cloneable , Serializable , Comparable { 54 55 56 private static final long serialVersionUID = -5201022482708455620L; 57 58 59 private CmsUUID m_contentId; 60 61 62 private byte[] m_fileContent; 63 64 70 public CmsFile(CmsResource resource) { 71 72 this( 73 resource.getStructureId(), 74 resource.getResourceId(), 75 CmsUUID.getNullUUID(), 76 resource.getRootPath(), 77 resource.getTypeId(), 78 resource.getFlags(), 79 resource.getProjectLastModified(), 80 resource.getState(), 81 resource.getDateCreated(), 82 resource.getUserCreated(), 83 resource.getDateLastModified(), 84 resource.getUserLastModified(), 85 resource.getDateReleased(), 86 resource.getDateExpired(), 87 resource.getSiblingCount(), 88 0, 89 new byte[0]); 90 91 if (resource instanceof CmsFile) { 92 m_fileContent = ((CmsFile)resource).getContents(); 94 m_contentId = ((CmsFile)resource).getContentId(); 95 if (m_fileContent == null) { 96 m_fileContent = new byte[0]; 97 m_contentId = CmsUUID.getNullUUID(); 98 } 99 } 100 } 101 102 122 public CmsFile( 123 CmsUUID structureId, 124 CmsUUID resourceId, 125 CmsUUID contentId, 126 String path, 127 int type, 128 int flags, 129 int projectId, 130 int state, 131 long dateCreated, 132 CmsUUID userCreated, 133 long dateLastModified, 134 CmsUUID userLastModified, 135 long dateReleased, 136 long dateExpired, 137 int linkCount, 138 int length, 139 byte[] content) { 140 141 super( 143 structureId, 144 resourceId, 145 path, 146 type, 147 false, 148 flags, 149 projectId, 150 state, 151 dateCreated, 152 userCreated, 153 dateLastModified, 154 userLastModified, 155 dateReleased, 156 dateExpired, 157 linkCount, 158 length); 159 160 m_contentId = contentId; 162 m_fileContent = content; 163 } 164 165 178 public static CmsFile upgrade(CmsResource resource, CmsObject cms) throws CmsException { 179 180 if (resource instanceof CmsFile) { 182 CmsFile file = (CmsFile)resource; 184 if ((file.getContents() != null) && (file.getContents().length > 0)) { 185 return file; 187 } 188 } else if (resource instanceof CmsBackupResource) { 189 CmsFile file = (CmsFile)resource; 191 if ((file.getContents() != null) && (file.getContents().length > 0)) { 192 return file; 194 } else { 195 CmsBackupResource backupResource = (CmsBackupResource)resource; 197 backupResource = cms.readBackupFile(backupResource.getRootPath(), backupResource.getVersionId()); 198 return backupResource; 199 } 200 } 201 202 String filename = cms.getSitePath(resource); 204 return cms.readFile(filename, CmsResourceFilter.IGNORE_EXPIRATION); 206 } 207 208 213 public Object clone() { 214 215 byte[] newContent = new byte[this.getContents().length]; 216 System.arraycopy(getContents(), 0, newContent, 0, getContents().length); 217 218 CmsFile clone = new CmsFile( 219 getStructureId(), 220 getResourceId(), 221 getContentId(), 222 getRootPath(), 223 getTypeId(), 224 getFlags(), 225 getProjectLastModified(), 226 getState(), 227 getDateCreated(), 228 getUserCreated(), 229 getDateLastModified(), 230 getUserLastModified(), 231 getDateReleased(), 232 getDateExpired(), 233 getSiblingCount(), 234 getLength(), 235 newContent); 236 237 if (isTouched()) { 238 clone.setDateLastModified(getDateLastModified()); 239 } 240 241 return clone; 242 } 243 244 249 public CmsUUID getContentId() { 250 251 return m_contentId; 252 } 253 254 259 public byte[] getContents() { 260 261 return m_fileContent; 262 } 263 264 267 public int getLength() { 268 269 return m_length; 270 } 271 272 275 public boolean isFile() { 276 277 return true; 278 } 279 280 283 public boolean isFolder() { 284 285 return false; 286 } 287 288 293 public void setContents(byte[] value) { 294 295 m_fileContent = value; 296 if (m_fileContent.length > 0) { 297 m_length = m_fileContent.length; 298 } else { 299 m_length = 0; 300 } 301 } 302 } | Popular Tags |