PageRenderTime 58ms CodeModel.GetById 4ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
Java | 345 lines | 250 code | 31 blank | 64 comment | 8 complexity | 2bb462ecb964f85627c4a813525bd794 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 5053 2004-05-29 01:55:26Z 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 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. VFS.DirectoryEntry[] 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._listDirectory(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. VFS.DirectoryEntry file = vfs._getDirectoryEntry(
  225. session,path2,browser);
  226. if(file != null)
  227. {
  228. if((OperatingSystem.isDOSDerived()
  229. || OperatingSystem.isMacOS())
  230. && path1.equalsIgnoreCase(path2))
  231. {
  232. // allow user to change name
  233. // case
  234. }
  235. else
  236. {
  237. VFSManager.error(browser,path1,
  238. "ioerror.rename-exists",
  239. new String[] { path2 });
  240. return;
  241. }
  242. }
  243. if(!vfs._rename(session,path1,path2,browser))
  244. VFSManager.error(browser,path1,"ioerror.rename-error",
  245. new String[] { path2 });
  246. }
  247. catch(IOException io)
  248. {
  249. setAbortable(false);
  250. Log.log(Log.ERROR,this,io);
  251. String[] pp = { io.toString() };
  252. VFSManager.error(browser,path1,"ioerror.directory-error",pp);
  253. }
  254. }
  255. catch(WorkThread.Abort a)
  256. {
  257. }
  258. finally
  259. {
  260. try
  261. {
  262. vfs._endVFSSession(session,browser);
  263. }
  264. catch(IOException io)
  265. {
  266. setAbortable(false);
  267. Log.log(Log.ERROR,this,io);
  268. String[] pp = { io.toString() };
  269. VFSManager.error(browser,path1,"ioerror.directory-error",pp);
  270. }
  271. }
  272. } //}}}
  273. //{{{ mkdir() method
  274. private void mkdir()
  275. {
  276. try
  277. {
  278. setAbortable(true);
  279. String[] args = { path1 };
  280. setStatus(jEdit.getProperty("vfs.status.mkdir",args));
  281. try
  282. {
  283. path1 = vfs._canonPath(session,path1,browser);
  284. if(!vfs._mkdir(session,path1,browser))
  285. VFSManager.error(browser,path1,"ioerror.mkdir-error",null);
  286. }
  287. catch(IOException io)
  288. {
  289. setAbortable(false);
  290. Log.log(Log.ERROR,this,io);
  291. args[0] = io.toString();
  292. VFSManager.error(browser,path1,"ioerror",args);
  293. }
  294. }
  295. catch(WorkThread.Abort a)
  296. {
  297. }
  298. finally
  299. {
  300. try
  301. {
  302. vfs._endVFSSession(session,browser);
  303. }
  304. catch(IOException io)
  305. {
  306. setAbortable(false);
  307. Log.log(Log.ERROR,this,io);
  308. String[] args = { io.toString() };
  309. VFSManager.error(browser,path1,"ioerror",args);
  310. }
  311. }
  312. } //}}}
  313. //}}}
  314. }