1 19 20 package com.sslexplorer.networkplaces.model; 21 22 import java.text.NumberFormat ; 23 import java.text.SimpleDateFormat ; 24 import java.util.Calendar ; 25 26 import org.apache.commons.vfs.FileType; 27 28 import com.sslexplorer.policyframework.LaunchSession; 29 import com.sslexplorer.table.TableItem; 30 import com.sslexplorer.vfs.webdav.DAVUtilities; 31 32 41 public abstract class FileSystemItem implements TableItem, Comparable { 42 43 private String fileName; 44 private Calendar dateModified; 45 private String fileType; 46 private boolean checked; 47 private String bytes; 48 private long size; 49 private boolean sortFoldersFirst; 50 private boolean sortCaseSensitive; 51 private int idx; 52 private LaunchSession launchSession; 53 54 65 public FileSystemItem(LaunchSession launchSession, String fileName, Calendar dateModified, String fileType, boolean checked, long bytes, int idx) { 66 this.fileName = fileName; 67 this.dateModified = dateModified; 68 this.fileType = fileType; 69 this.checked = checked; 70 this.bytes = formatSize(bytes); 71 this.size = bytes; 72 this.launchSession = launchSession; 73 this.sortFoldersFirst = true; 74 this.sortCaseSensitive = false; 75 this.idx = idx; 76 } 77 78 84 public LaunchSession getLaunchSession() { 85 return launchSession; 86 } 87 88 91 public String getDateModified() { 92 return (new SimpleDateFormat ()).format(dateModified.getTime()); 93 } 94 95 98 public void setDateModified(Calendar dateModified) { 99 this.dateModified = dateModified; 100 } 101 102 105 public String getFileName() { 106 return fileName; 107 } 108 109 112 public String getEncodedFileName() { 113 return DAVUtilities.encodePath((getFileName())); 114 } 115 116 119 public void setFileName(String fileName) { 120 this.fileName = fileName; 121 } 122 123 126 public String getFileType() { 127 return fileType; 128 } 129 130 133 public void setFileType(String fileType) { 134 this.fileType = fileType; 135 } 136 137 140 public boolean getChecked() { 141 return checked; 142 } 143 144 147 public void setChecked(boolean checked) { 148 this.checked = checked; 149 } 150 151 154 public Object getColumnValue(int col) { 155 switch (col) { 156 case 0: 157 return this; 158 case 1: 159 return dateModified; 160 case 2: 161 return new Long (size); 162 } 163 return null; 164 } 165 166 169 public int compareTo(Object arg0) { 170 FileSystemItem fsi = (FileSystemItem) arg0; 171 int lessThan = -1; 172 int moreThan = 1; 173 if (!sortFoldersFirst) { 174 lessThan = 1; 175 moreThan = -1; 176 } 177 if (fsi.getFileType().equals(FileType.FOLDER.getName()) && this.getFileType().equals(FileType.FILE.getName())) { 178 return moreThan; 179 } else if (fsi.getFileType().equals(FileType.FILE.getName()) && this.getFileType().equals(FileType.FOLDER.getName())) { 180 return lessThan; 181 } else { 182 if (!sortCaseSensitive) 183 return fileName.compareToIgnoreCase(fsi.getFileName()); 184 else 185 return fileName.compareTo(fsi.getFileName()); 186 } 187 } 188 189 193 public abstract String onClick(String path); 194 195 198 public abstract String getWebFolderPath(); 199 200 203 public String getBytes() { 204 return bytes; 205 } 206 207 210 public void setBytes(long bytes) { 211 this.bytes = formatSize(bytes); 212 } 213 214 218 private String formatSizeDPS(String val) { 219 int position = 2 + 1; 220 if (val.indexOf(".") + position < val.length()) { 221 return val.substring(0, val.indexOf(".") + position); 222 } else { 223 return val; 224 } 225 } 226 227 private String formatSize(long bytes) { 228 229 NumberFormat formatMb = NumberFormat.getNumberInstance(); 230 NumberFormat formatGb = NumberFormat.getNumberInstance(); 231 NumberFormat formatKb = NumberFormat.getNumberInstance(); 232 233 if ((bytes / 1099511627776L) > 0) { 234 return formatSizeDPS(formatGb.format((double) bytes / 1099511627776L)) + " GB"; 236 } else if ((bytes / 1048576) > 0) { 237 return formatSizeDPS(formatMb.format((double) bytes / 1048576)) + " MB"; 239 } else { 240 return formatSizeDPS(formatKb.format((double) bytes / 1024)) + " KB"; 242 } 243 } 244 245 public boolean isSortFoldersFirst() { 246 return sortFoldersFirst; 247 } 248 249 public void setSortFoldersFirst(boolean sortFoldersFirst) { 250 this.sortFoldersFirst = sortFoldersFirst; 251 } 252 253 public boolean isSortCaseSensitive() { 254 return sortCaseSensitive; 255 } 256 257 public void setSortCaseSensitive(boolean sortCaseSensitive) { 258 this.sortCaseSensitive = sortCaseSensitive; 259 } 260 261 267 public String toString() { 268 return getFileName(); 269 } 270 271 public int getIdx() { 272 return idx; 273 } 274 275 } 276 | Popular Tags |