001: /*
002: * BrowserIORequest.java - VFS browser I/O request
003: * :tabSize=8:indentSize=8:noTabs=false:
004: * :folding=explicit:collapseFolds=1:
005: *
006: * Copyright (C) 2000, 2003 Slava Pestov
007: *
008: * This program is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU General Public License
010: * as published by the Free Software Foundation; either version 2
011: * of the License, or any later version.
012: *
013: * This program is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
016: * GNU General Public License for more details.
017: *
018: * You should have received a copy of the GNU General Public License
019: * along with this program; if not, write to the Free Software
020: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
021: */
022:
023: package org.gjt.sp.jedit.browser;
024:
025: //{{{ Imports
026: import java.io.*;
027: import org.gjt.sp.jedit.io.*;
028: import org.gjt.sp.jedit.*;
029: import org.gjt.sp.util.*;
030:
031: //}}}
032:
033: /**
034: * A browser I/O request.
035: * @author Slava Pestov
036: * @version $Id: BrowserIORequest.java 5197 2005-03-09 23:46:09Z spestov $
037: */
038: class BrowserIORequest extends WorkRequest {
039: //{{{ Request types
040: /**
041: * Directory listing I/O request.
042: */
043: public static final int LIST_DIRECTORY = 0;
044:
045: /**
046: * Delete file I/O request.
047: */
048: public static final int DELETE = 1;
049:
050: /**
051: * Rename file I/O request.
052: */
053: public static final int RENAME = 2;
054:
055: /**
056: * Make directory I/O request.
057: */
058: public static final int MKDIR = 3;
059:
060: //}}}
061:
062: //{{{ BrowserIORequest constructor
063: /**
064: * Creates a new browser I/O request.
065: * @param type The request type
066: * @param browser The VFS browser instance
067: * @param path1 The first path name to operate on
068: * @param path2 The second path name to operate on
069: * @param loadInfo A two-element array filled out by the request;
070: * element 1 is the canonical path, element 2 is the file list.
071: */
072: BrowserIORequest(int type, VFSBrowser browser, Object session,
073: VFS vfs, String path1, String path2, Object[] loadInfo) {
074: this .type = type;
075: this .browser = browser;
076: this .session = session;
077: this .vfs = vfs;
078: this .path1 = path1;
079: this .path2 = path2;
080: this .loadInfo = loadInfo;
081: } //}}}
082:
083: //{{{ run() method
084: public void run() {
085: switch (type) {
086: case LIST_DIRECTORY:
087: listDirectory();
088: break;
089: case DELETE:
090: delete();
091: break;
092: case RENAME:
093: rename();
094: break;
095: case MKDIR:
096: mkdir();
097: break;
098: }
099: } //}}}
100:
101: //{{{ toString() method
102: public String toString() {
103: String typeString;
104: switch (type) {
105: case LIST_DIRECTORY:
106: typeString = "LIST_DIRECTORY";
107: break;
108: case DELETE:
109: typeString = "DELETE";
110: break;
111: case RENAME:
112: typeString = "RENAME";
113: break;
114: case MKDIR:
115: typeString = "MKDIR";
116: break;
117: default:
118: typeString = "UNKNOWN!!!";
119: break;
120: }
121:
122: return getClass().getName() + "[type=" + typeString + ",vfs="
123: + vfs + ",path1=" + path1 + ",path2=" + path2 + "]";
124: } //}}}
125:
126: //{{{ Private members
127:
128: //{{{ Instance variables
129: private int type;
130: private VFSBrowser browser;
131: private Object session;
132: private VFS vfs;
133: private String path1;
134: private String path2;
135: private Object[] loadInfo;
136:
137: //}}}
138:
139: //{{{ listDirectory() method
140: private void listDirectory() {
141: VFSFile[] directory = null;
142:
143: String[] args = { path1 };
144: setStatus(jEdit.getProperty("vfs.status.listing-directory",
145: args));
146:
147: String canonPath = path1;
148:
149: try {
150: setAbortable(true);
151:
152: canonPath = vfs._canonPath(session, path1, browser);
153: directory = vfs._listFiles(session, canonPath, browser);
154: } catch (IOException io) {
155: setAbortable(false);
156: Log.log(Log.ERROR, this , io);
157: String[] pp = { io.toString() };
158: VFSManager.error(browser, path1, "ioerror.directory-error",
159: pp);
160: } catch (WorkThread.Abort a) {
161: } finally {
162: try {
163: vfs._endVFSSession(session, browser);
164: } catch (IOException io) {
165: setAbortable(false);
166: Log.log(Log.ERROR, this , io);
167: String[] pp = { io.toString() };
168: VFSManager.error(browser, path1,
169: "ioerror.directory-error", pp);
170: }
171: }
172:
173: setAbortable(false);
174:
175: loadInfo[0] = canonPath;
176: loadInfo[1] = directory;
177: } //}}}
178:
179: //{{{ delete() method
180: private void delete() {
181: try {
182: setAbortable(true);
183: String[] args = { path1 };
184: setStatus(jEdit.getProperty("vfs.status.deleting", args));
185:
186: try {
187: path1 = vfs._canonPath(session, path1, browser);
188:
189: if (!vfs._delete(session, path1, browser))
190: VFSManager.error(browser, path1,
191: "ioerror.delete-error", null);
192: } catch (IOException io) {
193: setAbortable(false);
194: Log.log(Log.ERROR, this , io);
195: String[] pp = { io.toString() };
196: VFSManager.error(browser, path1,
197: "ioerror.directory-error", pp);
198: }
199: } catch (WorkThread.Abort a) {
200: } finally {
201: try {
202: vfs._endVFSSession(session, browser);
203: } catch (IOException io) {
204: setAbortable(false);
205: Log.log(Log.ERROR, this , io);
206: String[] pp = { io.toString() };
207: VFSManager.error(browser, path1,
208: "ioerror.directory-error", pp);
209: }
210: }
211: } //}}}
212:
213: //{{{ rename() method
214: private void rename() {
215: try {
216: setAbortable(true);
217: String[] args = { path1, path2 };
218: setStatus(jEdit.getProperty("vfs.status.renaming", args));
219:
220: try {
221: path1 = vfs._canonPath(session, path1, browser);
222: path2 = vfs._canonPath(session, path2, browser);
223:
224: VFSFile file = vfs._getFile(session, path2, browser);
225: if (file != null) {
226: if ((OperatingSystem.isCaseInsensitiveFS())
227: && path1.equalsIgnoreCase(path2)) {
228: // allow user to change name
229: // case
230: } else {
231: VFSManager.error(browser, path1,
232: "ioerror.rename-exists",
233: new String[] { path2 });
234: return;
235: }
236: }
237:
238: if (!vfs._rename(session, path1, path2, browser))
239: VFSManager.error(browser, path1,
240: "ioerror.rename-error",
241: new String[] { path2 });
242: } catch (IOException io) {
243: setAbortable(false);
244: Log.log(Log.ERROR, this , io);
245: String[] pp = { io.toString() };
246: VFSManager.error(browser, path1,
247: "ioerror.directory-error", pp);
248: }
249: } catch (WorkThread.Abort a) {
250: } finally {
251: try {
252: vfs._endVFSSession(session, browser);
253: } catch (IOException io) {
254: setAbortable(false);
255: Log.log(Log.ERROR, this , io);
256: String[] pp = { io.toString() };
257: VFSManager.error(browser, path1,
258: "ioerror.directory-error", pp);
259: }
260: }
261: } //}}}
262:
263: //{{{ mkdir() method
264: private void mkdir() {
265: try {
266: setAbortable(true);
267: String[] args = { path1 };
268: setStatus(jEdit.getProperty("vfs.status.mkdir", args));
269:
270: try {
271: path1 = vfs._canonPath(session, path1, browser);
272:
273: if (!vfs._mkdir(session, path1, browser))
274: VFSManager.error(browser, path1,
275: "ioerror.mkdir-error", null);
276: } catch (IOException io) {
277: setAbortable(false);
278: Log.log(Log.ERROR, this , io);
279: args[0] = io.toString();
280: VFSManager.error(browser, path1, "ioerror", args);
281: }
282: } catch (WorkThread.Abort a) {
283: } finally {
284: try {
285: vfs._endVFSSession(session, browser);
286: } catch (IOException io) {
287: setAbortable(false);
288: Log.log(Log.ERROR, this , io);
289: String[] args = { io.toString() };
290: VFSManager.error(browser, path1, "ioerror", args);
291: }
292: }
293: } //}}}
294:
295: //}}}
296: }
|