PageRenderTime 51ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/jEdit/tags/jedit-4-2-pre4/org/gjt/sp/jedit/browser/BrowserIORequest.java

#
Java | 348 lines | 252 code | 31 blank | 65 comment | 8 complexity | 039f1ea7b3050d46f223c6396d847481 MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
  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 4842 2003-08-04 00:23:07Z spestov $
  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 node Only used for type == LIST_DIRECTORY
  62. * @param loadInfo A two-element array filled out by the request;
  63. * element 1 is the canonical path, element 2 is the file list.
  64. */
  65. BrowserIORequest(int type, VFSBrowser browser,
  66. Object session, VFS vfs, String path1, String path2,
  67. Object node, Object[] loadInfo)
  68. {
  69. this.type = type;
  70. this.browser = browser;
  71. this.session = session;
  72. this.vfs = vfs;
  73. this.path1 = path1;
  74. this.path2 = path2;
  75. this.node = node;
  76. this.loadInfo = loadInfo;
  77. } //}}}
  78. //{{{ run() method
  79. public void run()
  80. {
  81. switch(type)
  82. {
  83. case LIST_DIRECTORY:
  84. listDirectory();
  85. break;
  86. case DELETE:
  87. delete();
  88. break;
  89. case RENAME:
  90. rename();
  91. break;
  92. case MKDIR:
  93. mkdir();
  94. break;
  95. }
  96. } //}}}
  97. //{{{ toString() method
  98. public String toString()
  99. {
  100. String typeString;
  101. switch(type)
  102. {
  103. case LIST_DIRECTORY:
  104. typeString = "LIST_DIRECTORY";
  105. break;
  106. case DELETE:
  107. typeString = "DELETE";
  108. break;
  109. case RENAME:
  110. typeString = "RENAME";
  111. break;
  112. case MKDIR:
  113. typeString = "MKDIR";
  114. break;
  115. default:
  116. typeString = "UNKNOWN!!!";
  117. break;
  118. }
  119. return getClass().getName() + "[type=" + typeString
  120. + ",vfs=" + vfs + ",path1=" + path1
  121. + ",path2=" + path2 + "]";
  122. } //}}}
  123. //{{{ Private members
  124. //{{{ Instance variables
  125. private int type;
  126. private VFSBrowser browser;
  127. private Object session;
  128. private VFS vfs;
  129. private String path1;
  130. private String path2;
  131. private Object node;
  132. private Object[] loadInfo;
  133. //}}}
  134. //{{{ listDirectory() method
  135. private void listDirectory()
  136. {
  137. VFS.DirectoryEntry[] directory = null;
  138. String[] args = { path1 };
  139. setStatus(jEdit.getProperty("vfs.status.listing-directory",args));
  140. String canonPath = path1;
  141. try
  142. {
  143. setAbortable(true);
  144. canonPath = vfs._canonPath(session,path1,browser);
  145. directory = vfs._listDirectory(session,canonPath,browser);
  146. }
  147. catch(IOException io)
  148. {
  149. setAbortable(false);
  150. Log.log(Log.ERROR,this,io);
  151. String[] pp = { io.toString() };
  152. VFSManager.error(browser,path1,"ioerror.directory-error",pp);
  153. }
  154. catch(WorkThread.Abort a)
  155. {
  156. }
  157. finally
  158. {
  159. try
  160. {
  161. vfs._endVFSSession(session,browser);
  162. }
  163. catch(IOException io)
  164. {
  165. setAbortable(false);
  166. Log.log(Log.ERROR,this,io);
  167. String[] pp = { io.toString() };
  168. VFSManager.error(browser,path1,"ioerror.directory-error",pp);
  169. }
  170. }
  171. setAbortable(false);
  172. loadInfo[0] = canonPath;
  173. loadInfo[1] = directory;
  174. } //}}}
  175. //{{{ delete() method
  176. private void delete()
  177. {
  178. try
  179. {
  180. setAbortable(true);
  181. String[] args = { path1 };
  182. setStatus(jEdit.getProperty("vfs.status.deleting",args));
  183. try
  184. {
  185. path1 = vfs._canonPath(session,path1,browser);
  186. if(!vfs._delete(session,path1,browser))
  187. VFSManager.error(browser,path1,"ioerror.delete-error",null);
  188. }
  189. catch(IOException io)
  190. {
  191. setAbortable(false);
  192. Log.log(Log.ERROR,this,io);
  193. String[] pp = { io.toString() };
  194. VFSManager.error(browser,path1,"ioerror.directory-error",pp);
  195. }
  196. }
  197. catch(WorkThread.Abort a)
  198. {
  199. }
  200. finally
  201. {
  202. try
  203. {
  204. vfs._endVFSSession(session,browser);
  205. }
  206. catch(IOException io)
  207. {
  208. setAbortable(false);
  209. Log.log(Log.ERROR,this,io);
  210. String[] pp = { io.toString() };
  211. VFSManager.error(browser,path1,"ioerror.directory-error",pp);
  212. }
  213. }
  214. } //}}}
  215. //{{{ rename() method
  216. private void rename()
  217. {
  218. try
  219. {
  220. setAbortable(true);
  221. String[] args = { path1, path2 };
  222. setStatus(jEdit.getProperty("vfs.status.renaming",args));
  223. try
  224. {
  225. path1 = vfs._canonPath(session,path1,browser);
  226. path2 = vfs._canonPath(session,path2,browser);
  227. VFS.DirectoryEntry file = vfs._getDirectoryEntry(
  228. session,path2,browser);
  229. if(file != null)
  230. {
  231. if((OperatingSystem.isDOSDerived()
  232. || OperatingSystem.isMacOS())
  233. && path1.equalsIgnoreCase(path2))
  234. {
  235. // allow user to change name
  236. // case
  237. }
  238. else
  239. {
  240. VFSManager.error(browser,path1,
  241. "ioerror.rename-exists",
  242. new String[] { path2 });
  243. return;
  244. }
  245. }
  246. if(!vfs._rename(session,path1,path2,browser))
  247. VFSManager.error(browser,path1,"ioerror.rename-error",
  248. new String[] { path2 });
  249. }
  250. catch(IOException io)
  251. {
  252. setAbortable(false);
  253. Log.log(Log.ERROR,this,io);
  254. String[] pp = { io.toString() };
  255. VFSManager.error(browser,path1,"ioerror.directory-error",pp);
  256. }
  257. }
  258. catch(WorkThread.Abort a)
  259. {
  260. }
  261. finally
  262. {
  263. try
  264. {
  265. vfs._endVFSSession(session,browser);
  266. }
  267. catch(IOException io)
  268. {
  269. setAbortable(false);
  270. Log.log(Log.ERROR,this,io);
  271. String[] pp = { io.toString() };
  272. VFSManager.error(browser,path1,"ioerror.directory-error",pp);
  273. }
  274. }
  275. } //}}}
  276. //{{{ mkdir() method
  277. private void mkdir()
  278. {
  279. try
  280. {
  281. setAbortable(true);
  282. String[] args = { path1 };
  283. setStatus(jEdit.getProperty("vfs.status.mkdir",args));
  284. try
  285. {
  286. path1 = vfs._canonPath(session,path1,browser);
  287. if(!vfs._mkdir(session,path1,browser))
  288. VFSManager.error(browser,path1,"ioerror.mkdir-error",null);
  289. }
  290. catch(IOException io)
  291. {
  292. setAbortable(false);
  293. Log.log(Log.ERROR,this,io);
  294. args[0] = io.toString();
  295. VFSManager.error(browser,path1,"ioerror",args);
  296. }
  297. }
  298. catch(WorkThread.Abort a)
  299. {
  300. }
  301. finally
  302. {
  303. try
  304. {
  305. vfs._endVFSSession(session,browser);
  306. }
  307. catch(IOException io)
  308. {
  309. setAbortable(false);
  310. Log.log(Log.ERROR,this,io);
  311. String[] args = { io.toString() };
  312. VFSManager.error(browser,path1,"ioerror",args);
  313. }
  314. }
  315. } //}}}
  316. //}}}
  317. }