KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > gjt > sp > jedit > browser > BrowserIORequest


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
23 package org.gjt.sp.jedit.browser;
24
25 //{{{ Imports
26
import java.io.*;
27 import org.gjt.sp.jedit.io.*;
28 import org.gjt.sp.jedit.*;
29 import org.gjt.sp.util.*;
30 //}}}
31

32 /**
33  * A browser I/O request.
34  * @author Slava Pestov
35  * @version $Id: BrowserIORequest.java 5197 2005-03-09 23:46:09Z spestov $
36  */

37 class BrowserIORequest extends WorkRequest
38 {
39     //{{{ Request types
40
/**
41      * Directory listing I/O request.
42      */

43     public static final int LIST_DIRECTORY = 0;
44
45     /**
46      * Delete file I/O request.
47      */

48     public static final int DELETE = 1;
49
50     /**
51      * Rename file I/O request.
52      */

53     public static final int RENAME = 2;
54
55     /**
56      * Make directory I/O request.
57      */

58     public static final int MKDIR = 3;
59     //}}}
60

61     //{{{ BrowserIORequest constructor
62
/**
63      * Creates a new browser I/O request.
64      * @param type The request type
65      * @param browser The VFS browser instance
66      * @param path1 The first path name to operate on
67      * @param path2 The second path name to operate on
68      * @param loadInfo A two-element array filled out by the request;
69      * element 1 is the canonical path, element 2 is the file list.
70      */

71     BrowserIORequest(int type, VFSBrowser browser,
72         Object JavaDoc session, VFS vfs, String JavaDoc path1, String JavaDoc path2,
73         Object JavaDoc[] 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     } //}}}
83

84     //{{{ run() method
85
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     } //}}}
103

104     //{{{ toString() method
105
public String JavaDoc toString()
106     {
107         String JavaDoc 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     } //}}}
131

132     //{{{ Private members
133

134     //{{{ Instance variables
135
private int type;
136     private VFSBrowser browser;
137     private Object JavaDoc session;
138     private VFS vfs;
139     private String JavaDoc path1;
140     private String JavaDoc path2;
141     private Object JavaDoc[] loadInfo;
142     //}}}
143

144     //{{{ listDirectory() method
145
private void listDirectory()
146     {
147         VFSFile[] directory = null;
148
149         String JavaDoc[] args = { path1 };
150         setStatus(jEdit.getProperty("vfs.status.listing-directory",args));
151
152         String JavaDoc 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 JavaDoc[] 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 JavaDoc[] 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     } //}}}
191

192     //{{{ delete() method
193
private void delete()
194     {
195         try
196         {
197             setAbortable(true);
198             String JavaDoc[] 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 JavaDoc[] 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 JavaDoc[] pp = { io.toString() };
231                 VFSManager.error(browser,path1,"ioerror.directory-error",pp);
232             }
233         }
234     } //}}}
235

236     //{{{ rename() method
237
private void rename()
238     {
239         try
240         {
241             setAbortable(true);
242             String JavaDoc[] 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                         // allow user to change name
257
// case
258
}
259                     else
260                     {
261                         VFSManager.error(browser,path1,
262                             "ioerror.rename-exists",
263                             new String JavaDoc[] { 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 JavaDoc[] { path2 });
271             }
272             catch(IOException io)
273             {
274                 setAbortable(false);
275                 Log.log(Log.ERROR,this,io);
276                 String JavaDoc[] 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 JavaDoc[] pp = { io.toString() };
294                 VFSManager.error(browser,path1,"ioerror.directory-error",pp);
295             }
296         }
297     } //}}}
298

299     //{{{ mkdir() method
300
private void mkdir()
301     {
302         try
303         {
304             setAbortable(true);
305             String JavaDoc[] 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 JavaDoc[] args = { io.toString() };
337                 VFSManager.error(browser,path1,"ioerror",args);
338             }
339         }
340     } //}}}
341

342     //}}}
343
}
344
Popular Tags