/jEdit/tags/jedit-4-0-pre3/org/gjt/sp/jedit/browser/BrowserIORequest.java

# · Java · 313 lines · 225 code · 28 blank · 60 comment · 5 complexity · 6eb87ecf06c557367db1c6de4c121b14 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 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.jEdit;
  27. import org.gjt.sp.jedit.MiscUtilities;
  28. import org.gjt.sp.util.WorkRequest;
  29. import org.gjt.sp.util.WorkThread;
  30. //}}}
  31. /**
  32. * A browser I/O request.
  33. * @author Slava Pestov
  34. * @version $Id: BrowserIORequest.java 3925 2001-11-30 11:40:16Z spestov $
  35. */
  36. public class BrowserIORequest extends WorkRequest
  37. {
  38. //{{{ Request types
  39. /**
  40. * Directory listing I/O request.
  41. */
  42. public static final int LIST_DIRECTORY = 0;
  43. /**
  44. * Delete file I/O request.
  45. */
  46. public static final int DELETE = 1;
  47. /**
  48. * Rename file I/O request.
  49. */
  50. public static final int RENAME = 2;
  51. /**
  52. * Make directory I/O request.
  53. */
  54. public static final int MKDIR = 3;
  55. //}}}
  56. //{{{ BrowserIORequest constructor
  57. /**
  58. * Creates a new browser I/O request.
  59. * @param type The request type
  60. * @param browser The VFS browser instance
  61. * @param path1 The first path name to operate on
  62. * @param path2 The second path name to operate on
  63. */
  64. public BrowserIORequest(int type, VFSBrowser browser,
  65. Object session, VFS vfs, String path1, String path2)
  66. {
  67. this.type = type;
  68. this.browser = browser;
  69. this.session = session;
  70. this.vfs = vfs;
  71. this.path1 = path1;
  72. this.path2 = path2;
  73. } //}}}
  74. //{{{ run() method
  75. public void run()
  76. {
  77. switch(type)
  78. {
  79. case LIST_DIRECTORY:
  80. listDirectory();
  81. break;
  82. case DELETE:
  83. delete();
  84. break;
  85. case RENAME:
  86. rename();
  87. break;
  88. case MKDIR:
  89. mkdir();
  90. break;
  91. }
  92. browser.endRequest();
  93. } //}}}
  94. //{{{ toString() method
  95. public String toString()
  96. {
  97. String typeString;
  98. switch(type)
  99. {
  100. case LIST_DIRECTORY:
  101. typeString = "LIST_DIRECTORY";
  102. break;
  103. case DELETE:
  104. typeString = "DELETE";
  105. break;
  106. case RENAME:
  107. typeString = "RENAME";
  108. break;
  109. case MKDIR:
  110. typeString = "MKDIR";
  111. break;
  112. default:
  113. typeString = "UNKNOWN!!!";
  114. break;
  115. }
  116. return getClass().getName() + "[type=" + typeString
  117. + ",vfs=" + vfs + ",path1=" + path1
  118. + ",path2=" + path2 + "]";
  119. } //}}}
  120. //{{{ Private members
  121. //{{{ Instance variables
  122. private int type;
  123. private VFSBrowser browser;
  124. private Object session;
  125. private VFS vfs;
  126. private String path1;
  127. private String path2;
  128. //}}}
  129. //{{{ listDirectory() method
  130. private void listDirectory()
  131. {
  132. VFS.DirectoryEntry[] directory = null;
  133. String[] args = { path1 };
  134. setStatus(jEdit.getProperty("vfs.status.listing-directory",args));
  135. try
  136. {
  137. setAbortable(true);
  138. path1 = vfs._canonPath(session,path1,browser);
  139. directory = vfs._listDirectory(session,path1,browser);
  140. }
  141. catch(IOException io)
  142. {
  143. setAbortable(false);
  144. String[] pp = { io.toString() };
  145. VFSManager.error(browser,path1,"ioerror.directory-error",pp);
  146. }
  147. catch(WorkThread.Abort a)
  148. {
  149. }
  150. finally
  151. {
  152. try
  153. {
  154. vfs._endVFSSession(session,browser);
  155. }
  156. catch(IOException io)
  157. {
  158. setAbortable(false);
  159. String[] pp = { io.toString() };
  160. VFSManager.error(browser,path1,"ioerror.directory-error",pp);
  161. }
  162. }
  163. setAbortable(false);
  164. browser.directoryLoaded(path1,directory);
  165. } //}}}
  166. //{{{ delete() method
  167. private void delete()
  168. {
  169. try
  170. {
  171. setAbortable(true);
  172. String[] args = { path1 };
  173. setStatus(jEdit.getProperty("vfs.status.deleting",args));
  174. try
  175. {
  176. path1 = vfs._canonPath(session,path1,browser);
  177. if(!vfs._delete(session,path1,browser))
  178. VFSManager.error(browser,path1,"ioerror.delete-error",null);
  179. }
  180. catch(IOException io)
  181. {
  182. String[] pp = { io.toString() };
  183. VFSManager.error(browser,path1,"ioerror.directory-error",pp);
  184. }
  185. }
  186. catch(WorkThread.Abort a)
  187. {
  188. }
  189. finally
  190. {
  191. try
  192. {
  193. vfs._endVFSSession(session,browser);
  194. }
  195. catch(IOException io)
  196. {
  197. String[] pp = { io.toString() };
  198. VFSManager.error(browser,path1,"ioerror.directory-error",pp);
  199. }
  200. }
  201. } //}}}
  202. //{{{ rename() method
  203. private void rename()
  204. {
  205. try
  206. {
  207. setAbortable(true);
  208. String[] args = { path1, path2 };
  209. setStatus(jEdit.getProperty("vfs.status.renaming",args));
  210. try
  211. {
  212. path1 = vfs._canonPath(session,path1,browser);
  213. path2 = vfs._canonPath(session,path2,browser);
  214. VFS.DirectoryEntry file = vfs._getDirectoryEntry(
  215. session,path2,browser);
  216. if(file != null)
  217. VFSManager.error(browser,path1,"ioerror.rename-exists",
  218. new String[] { path2 });
  219. else
  220. {
  221. if(!vfs._rename(session,path1,path2,browser))
  222. VFSManager.error(browser,path1,"ioerror.rename-error",
  223. new String[] { path2 });
  224. }
  225. }
  226. catch(IOException io)
  227. {
  228. String[] pp = { io.toString() };
  229. VFSManager.error(browser,path1,"ioerror.directory-error",pp);
  230. }
  231. }
  232. catch(WorkThread.Abort a)
  233. {
  234. }
  235. finally
  236. {
  237. try
  238. {
  239. vfs._endVFSSession(session,browser);
  240. }
  241. catch(IOException io)
  242. {
  243. String[] pp = { io.toString() };
  244. VFSManager.error(browser,path1,"ioerror.directory-error",pp);
  245. }
  246. }
  247. } //}}}
  248. //{{{ mkdir() method
  249. private void mkdir()
  250. {
  251. try
  252. {
  253. setAbortable(true);
  254. String[] args = { path1 };
  255. setStatus(jEdit.getProperty("vfs.status.mkdir",args));
  256. try
  257. {
  258. path1 = vfs._canonPath(session,path1,browser);
  259. if(!vfs._mkdir(session,path1,browser))
  260. VFSManager.error(browser,path1,"ioerror.mkdir-error",null);
  261. }
  262. catch(IOException io)
  263. {
  264. args[0] = io.toString();
  265. VFSManager.error(browser,path1,"ioerror",args);
  266. }
  267. }
  268. catch(WorkThread.Abort a)
  269. {
  270. }
  271. finally
  272. {
  273. try
  274. {
  275. vfs._endVFSSession(session,browser);
  276. }
  277. catch(IOException io)
  278. {
  279. String[] args = { io.toString() };
  280. VFSManager.error(browser,path1,"ioerror",args);
  281. }
  282. }
  283. } //}}}
  284. //}}}
  285. }