1 22 23 package org.gjt.sp.jedit.browser; 24 25 import java.io.*; 27 import org.gjt.sp.jedit.io.*; 28 import org.gjt.sp.jedit.*; 29 import org.gjt.sp.util.*; 30 32 37 class BrowserIORequest extends WorkRequest 38 { 39 43 public static final int LIST_DIRECTORY = 0; 44 45 48 public static final int DELETE = 1; 49 50 53 public static final int RENAME = 2; 54 55 58 public static final int MKDIR = 3; 59 61 71 BrowserIORequest(int type, VFSBrowser browser, 72 Object session, VFS vfs, String path1, String path2, 73 Object [] loadInfo) 74 { 75 this.type = type; 76 this.browser = browser; 77 this.session = session; 78 this.vfs = vfs; 79 this.path1 = path1; 80 this.path2 = path2; 81 this.loadInfo = loadInfo; 82 } 84 public void run() 86 { 87 switch(type) 88 { 89 case LIST_DIRECTORY: 90 listDirectory(); 91 break; 92 case DELETE: 93 delete(); 94 break; 95 case RENAME: 96 rename(); 97 break; 98 case MKDIR: 99 mkdir(); 100 break; 101 } 102 } 104 public String toString() 106 { 107 String typeString; 108 switch(type) 109 { 110 case LIST_DIRECTORY: 111 typeString = "LIST_DIRECTORY"; 112 break; 113 case DELETE: 114 typeString = "DELETE"; 115 break; 116 case RENAME: 117 typeString = "RENAME"; 118 break; 119 case MKDIR: 120 typeString = "MKDIR"; 121 break; 122 default: 123 typeString = "UNKNOWN!!!"; 124 break; 125 } 126 127 return getClass().getName() + "[type=" + typeString 128 + ",vfs=" + vfs + ",path1=" + path1 129 + ",path2=" + path2 + "]"; 130 } 132 134 private int type; 136 private VFSBrowser browser; 137 private Object session; 138 private VFS vfs; 139 private String path1; 140 private String path2; 141 private Object [] loadInfo; 142 144 private void listDirectory() 146 { 147 VFSFile[] directory = null; 148 149 String [] args = { path1 }; 150 setStatus(jEdit.getProperty("vfs.status.listing-directory",args)); 151 152 String canonPath = path1; 153 154 try 155 { 156 setAbortable(true); 157 158 canonPath = vfs._canonPath(session,path1,browser); 159 directory = vfs._listFiles(session,canonPath,browser); 160 } 161 catch(IOException io) 162 { 163 setAbortable(false); 164 Log.log(Log.ERROR,this,io); 165 String [] pp = { io.toString() }; 166 VFSManager.error(browser,path1,"ioerror.directory-error",pp); 167 } 168 catch(WorkThread.Abort a) 169 { 170 } 171 finally 172 { 173 try 174 { 175 vfs._endVFSSession(session,browser); 176 } 177 catch(IOException io) 178 { 179 setAbortable(false); 180 Log.log(Log.ERROR,this,io); 181 String [] pp = { io.toString() }; 182 VFSManager.error(browser,path1,"ioerror.directory-error",pp); 183 } 184 } 185 186 setAbortable(false); 187 188 loadInfo[0] = canonPath; 189 loadInfo[1] = directory; 190 } 192 private void delete() 194 { 195 try 196 { 197 setAbortable(true); 198 String [] args = { path1 }; 199 setStatus(jEdit.getProperty("vfs.status.deleting",args)); 200 201 try 202 { 203 path1 = vfs._canonPath(session,path1,browser); 204 205 206 if(!vfs._delete(session,path1,browser)) 207 VFSManager.error(browser,path1,"ioerror.delete-error",null); 208 } 209 catch(IOException io) 210 { 211 setAbortable(false); 212 Log.log(Log.ERROR,this,io); 213 String [] pp = { io.toString() }; 214 VFSManager.error(browser,path1,"ioerror.directory-error",pp); 215 } 216 } 217 catch(WorkThread.Abort a) 218 { 219 } 220 finally 221 { 222 try 223 { 224 vfs._endVFSSession(session,browser); 225 } 226 catch(IOException io) 227 { 228 setAbortable(false); 229 Log.log(Log.ERROR,this,io); 230 String [] pp = { io.toString() }; 231 VFSManager.error(browser,path1,"ioerror.directory-error",pp); 232 } 233 } 234 } 236 private void rename() 238 { 239 try 240 { 241 setAbortable(true); 242 String [] args = { path1, path2 }; 243 setStatus(jEdit.getProperty("vfs.status.renaming",args)); 244 245 try 246 { 247 path1 = vfs._canonPath(session,path1,browser); 248 path2 = vfs._canonPath(session,path2,browser); 249 250 VFSFile file = vfs._getFile(session,path2,browser); 251 if(file != null) 252 { 253 if((OperatingSystem.isCaseInsensitiveFS()) 254 && path1.equalsIgnoreCase(path2)) 255 { 256 } 259 else 260 { 261 VFSManager.error(browser,path1, 262 "ioerror.rename-exists", 263 new String [] { path2 }); 264 return; 265 } 266 } 267 268 if(!vfs._rename(session,path1,path2,browser)) 269 VFSManager.error(browser,path1,"ioerror.rename-error", 270 new String [] { path2 }); 271 } 272 catch(IOException io) 273 { 274 setAbortable(false); 275 Log.log(Log.ERROR,this,io); 276 String [] pp = { io.toString() }; 277 VFSManager.error(browser,path1,"ioerror.directory-error",pp); 278 } 279 } 280 catch(WorkThread.Abort a) 281 { 282 } 283 finally 284 { 285 try 286 { 287 vfs._endVFSSession(session,browser); 288 } 289 catch(IOException io) 290 { 291 setAbortable(false); 292 Log.log(Log.ERROR,this,io); 293 String [] pp = { io.toString() }; 294 VFSManager.error(browser,path1,"ioerror.directory-error",pp); 295 } 296 } 297 } 299 private void mkdir() 301 { 302 try 303 { 304 setAbortable(true); 305 String [] args = { path1 }; 306 setStatus(jEdit.getProperty("vfs.status.mkdir",args)); 307 308 try 309 { 310 path1 = vfs._canonPath(session,path1,browser); 311 312 if(!vfs._mkdir(session,path1,browser)) 313 VFSManager.error(browser,path1,"ioerror.mkdir-error",null); 314 } 315 catch(IOException io) 316 { 317 setAbortable(false); 318 Log.log(Log.ERROR,this,io); 319 args[0] = io.toString(); 320 VFSManager.error(browser,path1,"ioerror",args); 321 } 322 } 323 catch(WorkThread.Abort a) 324 { 325 } 326 finally 327 { 328 try 329 { 330 vfs._endVFSSession(session,browser); 331 } 332 catch(IOException io) 333 { 334 setAbortable(false); 335 Log.log(Log.ERROR,this,io); 336 String [] args = { io.toString() }; 337 VFSManager.error(browser,path1,"ioerror",args); 338 } 339 } 340 } 342 } 344 | Popular Tags |