1 21 22 package org.armedbear.j; 23 24 import javax.swing.SwingUtilities ; 25 26 public final class FtpLoadProcess extends LoadProcess implements BackgroundProcess, 27 Constants 28 { 29 private FtpSession session; 30 private boolean fileIsDirectory; 31 private String listing; 32 33 public FtpLoadProcess(Buffer buffer, FtpFile file, FtpSession session) 34 { 35 super(buffer, file); 36 this.session = session; 37 } 38 39 public final String getListing() 40 { 41 return listing; 42 } 43 44 public final boolean fileIsDirectory() 45 { 46 return fileIsDirectory; 47 } 48 49 public void run() 50 { 51 Debug.assertTrue(buffer != null); 52 buffer.setBackgroundProcess(this); 53 doLoad(); 54 buffer.setBackgroundProcess(null); 55 } 56 57 private void doLoad() 58 { 59 Debug.assertTrue(session != null); 60 Debug.assertTrue(session.isLocked()); 61 session.setProgressNotifier(progressNotifier); 62 if (!session.verifyConnected()) { 63 if (!cancelled) { 64 if (errorRunnable != null) { 66 String text = session.getErrorText(); 67 if (text == null || text.length() == 0) { 68 text = "Unable to connect to " + file.getHostName() + " on port " + file.getPort(); 69 } 70 errorRunnable.setMessage(text); 71 SwingUtilities.invokeLater(errorRunnable); 72 } 73 } 74 return; 75 } 76 if (file.canonicalPath() == null || file.canonicalPath().equals("")) 77 file.setCanonicalPath(session.getLoginDirectory()); 78 int result = ERROR; 79 if (session.isDirectory(file.canonicalPath())) { 80 fileIsDirectory = true; 82 listing = session.getDirectoryListing((FtpFile)file); 83 if (listing != null) 84 result = SUCCESS; 85 } else if (session.isFile(file.canonicalPath())) { 86 listing = session.getDirectoryListingForFile(file.canonicalPath()); 88 cache = Utilities.getTempFile(); 89 if (cache != null) 90 result = session.get(file, cache, 0); 91 } else { 92 if (errorRunnable != null) 94 errorRunnable.setMessage("File not found"); 95 } 96 buffer.setBusy(false); 97 if (result == SUCCESS) { 98 if (successRunnable != null) 99 SwingUtilities.invokeLater(successRunnable); 100 } else { 101 deleteCache(); 102 if (result == CANCELLED) { 103 if (cancelRunnable != null) 104 SwingUtilities.invokeLater(cancelRunnable); 105 } else { 106 if (errorRunnable != null) 108 SwingUtilities.invokeLater(errorRunnable); 109 } 110 } 111 session.unlock(); 113 } 114 115 private void deleteCache() 116 { 117 if (cache != null) { 118 if (cache.isFile()) 119 cache.delete(); 120 cache = null; 121 } 122 } 123 } 124 | Popular Tags |