/jEdit/branches/4.4.x-merge-request-for-r18847-r18954-r19206-r19210/org/gjt/sp/jedit/browser/BrowserIORequest.java

# · Java · 343 lines · 248 code · 31 blank · 64 comment · 7 complexity · ac1f8c081fc84de6846361b7f6b61268 MD5 · raw file

  1. /*
  2. * BrowserIORequest.java - VFS browser I/O request
  3. * :tabSize=8:indentSize=8:noTabs=false:
  4. * :folding=explicit:collapseFolds=1:
  5. *
  6. * Copyright (C) 2000, 2003 Slava Pestov
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  21. */
  22. package org.gjt.sp.jedit.browser;
  23. //{{{ Imports
  24. import java.io.*;
  25. import org.gjt.sp.jedit.io.*;
  26. import org.gjt.sp.jedit.*;
  27. import org.gjt.sp.util.*;
  28. //}}}
  29. /**
  30. * A browser I/O request.
  31. * @author Slava Pestov
  32. * @version $Id: BrowserIORequest.java 12504 2008-04-22 23:12:43Z ezust $
  33. */
  34. class BrowserIORequest extends WorkRequest
  35. {
  36. //{{{ Request types
  37. /**
  38. * Directory listing I/O request.
  39. */
  40. public static final int LIST_DIRECTORY = 0;
  41. /**
  42. * Delete file I/O request.
  43. */
  44. public static final int DELETE = 1;
  45. /**
  46. * Rename file I/O request.
  47. */
  48. public static final int RENAME = 2;
  49. /**
  50. * Make directory I/O request.
  51. */
  52. public static final int MKDIR = 3;
  53. //}}}
  54. //{{{ BrowserIORequest constructor
  55. /**
  56. * Creates a new browser I/O request.
  57. * @param type The request type
  58. * @param browser The VFS browser instance
  59. * @param path1 The first path name to operate on
  60. * @param path2 The second path name to operate on
  61. * @param loadInfo A two-element array filled out by the request;
  62. * element 1 is the canonical path, element 2 is the file list.
  63. */
  64. BrowserIORequest(int type, VFSBrowser browser,
  65. Object session, VFS vfs, String path1, String path2,
  66. Object[] loadInfo)
  67. {
  68. this.type = type;
  69. this.browser = browser;
  70. this.session = session;
  71. this.vfs = vfs;
  72. this.path1 = path1;
  73. this.path2 = path2;
  74. this.loadInfo = loadInfo;
  75. } //}}}
  76. //{{{ run() method
  77. public void run()
  78. {
  79. switch(type)
  80. {
  81. case LIST_DIRECTORY:
  82. listDirectory();
  83. break;
  84. case DELETE:
  85. delete();
  86. break;
  87. case RENAME:
  88. rename();
  89. break;
  90. case MKDIR:
  91. mkdir();
  92. break;
  93. }
  94. } //}}}
  95. //{{{ toString() method
  96. public String toString()
  97. {
  98. String typeString;
  99. switch(type)
  100. {
  101. case LIST_DIRECTORY:
  102. typeString = "LIST_DIRECTORY";
  103. break;
  104. case DELETE:
  105. typeString = "DELETE";
  106. break;
  107. case RENAME:
  108. typeString = "RENAME";
  109. break;
  110. case MKDIR:
  111. typeString = "MKDIR";
  112. break;
  113. default:
  114. typeString = "UNKNOWN!!!";
  115. break;
  116. }
  117. return getClass().getName() + "[type=" + typeString
  118. + ",vfs=" + vfs + ",path1=" + path1
  119. + ",path2=" + path2 + "]";
  120. } //}}}
  121. //{{{ Private members
  122. //{{{ Instance variables
  123. private int type;
  124. private VFSBrowser browser;
  125. private Object session;
  126. private VFS vfs;
  127. private String path1;
  128. private String path2;
  129. private Object[] loadInfo;
  130. //}}}
  131. //{{{ listDirectory() method
  132. private void listDirectory()
  133. {
  134. VFSFile[] directory = null;
  135. String[] args = { path1 };
  136. setStatus(jEdit.getProperty("vfs.status.listing-directory",args));
  137. String canonPath = path1;
  138. try
  139. {
  140. setAbortable(true);
  141. canonPath = vfs._canonPath(session,path1,browser);
  142. directory = vfs._listFiles(session,canonPath,browser);
  143. }
  144. catch(IOException io)
  145. {
  146. setAbortable(false);
  147. Log.log(Log.ERROR,this,io);
  148. String[] pp = { io.toString() };
  149. VFSManager.error(browser,path1,"ioerror.directory-error",pp);
  150. }
  151. catch(WorkThread.Abort a)
  152. {
  153. }
  154. finally
  155. {
  156. try
  157. {
  158. vfs._endVFSSession(session,browser);
  159. }
  160. catch(IOException io)
  161. {
  162. setAbortable(false);
  163. Log.log(Log.ERROR,this,io);
  164. String[] pp = { io.toString() };
  165. VFSManager.error(browser,path1,"ioerror.directory-error",pp);
  166. }
  167. }
  168. setAbortable(false);
  169. loadInfo[0] = canonPath;
  170. loadInfo[1] = directory;
  171. } //}}}
  172. //{{{ delete() method
  173. private void delete()
  174. {
  175. try
  176. {
  177. setAbortable(true);
  178. String[] args = { path1 };
  179. setStatus(jEdit.getProperty("vfs.status.deleting",args));
  180. try
  181. {
  182. path1 = vfs._canonPath(session,path1,browser);
  183. if(!vfs._delete(session,path1,browser))
  184. VFSManager.error(browser,path1,"ioerror.delete-error",null);
  185. }
  186. catch(IOException io)
  187. {
  188. setAbortable(false);
  189. Log.log(Log.ERROR,this,io);
  190. String[] pp = { io.toString() };
  191. VFSManager.error(browser,path1,"ioerror.directory-error",pp);
  192. }
  193. }
  194. catch(WorkThread.Abort a)
  195. {
  196. }
  197. finally
  198. {
  199. try
  200. {
  201. vfs._endVFSSession(session,browser);
  202. }
  203. catch(IOException io)
  204. {
  205. setAbortable(false);
  206. Log.log(Log.ERROR,this,io);
  207. String[] pp = { io.toString() };
  208. VFSManager.error(browser,path1,"ioerror.directory-error",pp);
  209. }
  210. }
  211. } //}}}
  212. //{{{ rename() method
  213. private void rename()
  214. {
  215. try
  216. {
  217. setAbortable(true);
  218. String[] args = { path1, path2 };
  219. setStatus(jEdit.getProperty("vfs.status.renaming",args));
  220. try
  221. {
  222. path1 = vfs._canonPath(session,path1,browser);
  223. path2 = vfs._canonPath(session,path2,browser);
  224. VFSFile file = vfs._getFile(session,path2,browser);
  225. if(file != null)
  226. {
  227. if((OperatingSystem.isCaseInsensitiveFS())
  228. && path1.equalsIgnoreCase(path2))
  229. {
  230. // allow user to change name
  231. // case
  232. }
  233. else
  234. {
  235. VFSManager.error(browser,path1,
  236. "ioerror.rename-exists",
  237. new String[] { path2 });
  238. return;
  239. }
  240. }
  241. if(!vfs._rename(session,path1,path2,browser))
  242. VFSManager.error(browser,path1,"ioerror.rename-error",
  243. new String[] { path2 });
  244. }
  245. catch(IOException io)
  246. {
  247. setAbortable(false);
  248. Log.log(Log.ERROR,this,io);
  249. String[] pp = { io.toString() };
  250. VFSManager.error(browser,path1,"ioerror.directory-error",pp);
  251. }
  252. }
  253. catch(WorkThread.Abort a)
  254. {
  255. }
  256. finally
  257. {
  258. try
  259. {
  260. vfs._endVFSSession(session,browser);
  261. }
  262. catch(IOException io)
  263. {
  264. setAbortable(false);
  265. Log.log(Log.ERROR,this,io);
  266. String[] pp = { io.toString() };
  267. VFSManager.error(browser,path1,"ioerror.directory-error",pp);
  268. }
  269. }
  270. } //}}}
  271. //{{{ mkdir() method
  272. private void mkdir()
  273. {
  274. try
  275. {
  276. setAbortable(true);
  277. String[] args = { path1 };
  278. setStatus(jEdit.getProperty("vfs.status.mkdir",args));
  279. try
  280. {
  281. path1 = vfs._canonPath(session,path1,browser);
  282. if(!vfs._mkdir(session,path1,browser))
  283. VFSManager.error(browser,path1,"ioerror.mkdir-error",null);
  284. }
  285. catch(IOException io)
  286. {
  287. setAbortable(false);
  288. Log.log(Log.ERROR,this,io);
  289. args[0] = io.toString();
  290. VFSManager.error(browser,path1,"ioerror",args);
  291. }
  292. }
  293. catch(WorkThread.Abort a)
  294. {
  295. }
  296. finally
  297. {
  298. try
  299. {
  300. vfs._endVFSSession(session,browser);
  301. }
  302. catch(IOException io)
  303. {
  304. setAbortable(false);
  305. Log.log(Log.ERROR,this,io);
  306. String[] args = { io.toString() };
  307. VFSManager.error(browser,path1,"ioerror",args);
  308. }
  309. }
  310. } //}}}
  311. //}}}
  312. }