1 20 package org.jahia.data.files; 21 22 import java.text.DateFormat ; 23 import java.util.Date ; 24 25 import org.jahia.registries.ServicesRegistry; 26 import org.jahia.services.usermanager.JahiaUser; 27 import java.io.Serializable ; 28 29 30 37 public class JahiaFile implements Serializable , Cloneable { 38 39 public static final int STATE_ACTIVE = 1; 40 public static final int STATE_BACKUP = 0; 41 42 43 private int m_FileID = -1; 44 45 private int m_FilemanagerID = -1; 46 47 private int m_FolderID = -1; 48 49 private String m_UploadUser = ""; 50 51 private int m_PageID = -1; 52 53 private int m_IsPublic = 1; 54 55 private String m_RealName = ""; 56 57 private String m_StorageName = ""; 58 59 private long m_LastModifDate; 60 61 private long m_Size = 0; 62 63 private String m_Type =""; 64 65 private String m_Title = ""; 66 67 private String m_Descr =""; 68 69 private String m_DownloadUrl ="#"; 70 71 private String m_Version = "0"; 72 73 private int m_State = STATE_ACTIVE; 74 75 76 80 protected JahiaFile(){ 81 } 82 83 99 public JahiaFile( int filemanagerID, 100 int folderID, 101 String uploadUser, 102 String realName, 103 String storageName, 104 long lastModifDate, 105 long size, 106 String type, 107 String title, 108 String descr, 109 String version, 110 int state ) 111 { 112 m_FilemanagerID = filemanagerID; 113 m_FolderID = folderID; 114 m_UploadUser = uploadUser; 115 m_RealName = realName; 116 m_StorageName = storageName; 117 m_LastModifDate = lastModifDate; 118 m_Size = size; 119 m_Type = type; 120 m_Title = title; 121 m_Descr = descr; 122 m_Version = version; 123 m_State = state; 124 } 125 126 public int getFileID(){ 127 return m_FileID; 128 } 129 130 public void setFileID(int id){ 131 m_FileID = id; 132 } 133 134 public int getFilemanagerID(){ 135 return m_FilemanagerID; 136 } 137 138 public void setFilemanagerID(int id){ 139 m_FilemanagerID = id; 140 } 141 142 public int getFolderID(){ 143 return m_FolderID; 144 } 145 146 public void setFolderID(int id){ 147 m_FolderID = id; 148 } 149 150 public String getUploadUser(){ 151 return m_UploadUser; 152 } 153 154 public void setUploadUser(String name){ 155 m_UploadUser = name; 156 } 157 158 public int getPageID(){ 159 return m_PageID; 160 } 161 162 public void setPageID(int id){ 163 m_PageID = id; 164 } 165 166 public int getPublic(){ 167 return m_IsPublic; 168 } 169 170 public void setPublic(int val){ 171 m_IsPublic = val; 172 } 173 174 public String getRealName(){ 175 return m_RealName; 176 } 177 178 public void setRealName(String realName){ 179 m_RealName = realName; 180 } 181 182 public String getStorageName(){ 183 return m_StorageName; 184 } 185 186 public void setStorageName(String storageName){ 187 m_StorageName = storageName; 188 } 189 190 public long getLastModifDate(){ 191 return m_LastModifDate; 192 } 193 194 public void setLastModifDate(long lastModifDate){ 195 m_LastModifDate = lastModifDate; 196 } 197 198 public long getSize(){ 199 return m_Size; 200 } 201 202 public void setSize(long size){ 203 m_Size = size; 204 } 205 206 public String getType(){ 207 return m_Type; 208 } 209 210 public void setType(String type){ 211 m_Type = type; 212 } 213 214 public String getTitle(){ 215 return m_Title; 216 } 217 218 public void setTitle(String title){ 219 m_Title = title; 220 } 221 222 public String getDescr(){ 223 return m_Descr; 224 } 225 226 public void setDescr(String descr){ 227 m_Descr = descr; 228 } 229 230 public String getVersion(){ 231 return this.m_Version; 232 } 233 234 public void setVersion(String version){ 235 this.m_Version = version; 236 } 237 238 public int getState(){ 239 return this.m_State; 240 } 241 242 public void setState(int state){ 243 this.m_State = state; 244 } 245 246 public String getDownloadUrl(){ 247 return m_DownloadUrl; 248 } 249 250 public void setDownloadUrl(String dUrl){ 251 m_DownloadUrl = dUrl; 252 } 253 254 255 257 public String getFormatedLastModifDate(){ 258 259 String fmtDate = ""; 260 Date tmpDate = new Date (); 261 tmpDate.setTime(m_LastModifDate); 262 263 DateFormat dateFmt = DateFormat.getDateInstance(); 264 265 fmtDate = DateFormat.getDateInstance().format(tmpDate); 266 267 return fmtDate; 268 } 269 270 public String getFormatedSize(){ 271 272 return String.valueOf(m_Size >> 10) + " Kb"; 273 } 274 275 276 public boolean isImage(){ 277 278 return m_Type.startsWith("image"); 279 280 } 281 282 283 public boolean isDownloadable(){ 284 if ( m_StorageName == null ){ 285 return false; 286 } else { 287 return (m_StorageName.trim().length()>0); 288 } 289 } 290 291 292 public String getUploadUsername(){ 293 if ( m_UploadUser != null && m_UploadUser.length()>0 ){ 294 JahiaUser user = ServicesRegistry.getInstance() 295 .getJahiaUserManagerService() 296 .lookupUser(m_UploadUser); 297 if ( user != null ){ 298 return user.getUsername(); 299 } 300 } 301 return ""; 302 } 303 304 public Object clone(){ 305 JahiaFile file = 306 new JahiaFile(this.getFilemanagerID(), 307 this.getFolderID(),this.getUploadUser(),this.getRealName(), 308 this.getStorageName(),this.getLastModifDate(),this.getSize(), 309 this.getType(),this.getTitle(),this.getDescr(),this.getVersion(),this.getState()); 310 file.setFileID(this.getFileID()); 311 return file; 312 } 313 314 } 315 | Popular Tags |