View Javadoc

1   /*
2    * $HeadURL: $
3    * $Date: $
4    * $Revision: $
5    * $Author: $
6    * 
7    * Copyright (c) 2005 MindTree Consulting Ltd. 
8    * 
9    * This file is part of Insight.
10   * 
11   * Insight is free software: you can redistribute it and/or modify it under the 
12   * terms of the GNU General Public License as published by the Free Software 
13   * Foundation, either version 3 of the License, or (at your option) any later 
14   * version.
15   * 
16   * Insight is distributed in the hope that it will be useful, but 
17   * WITHOUT ANY WARRANTY; without even the implied warranty of 
18   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General 
19   * Public License for more details.
20   * 
21   * You should have received a copy of the GNU General Public License along with 
22   * Insight.  If not, see <http://www.gnu.org/licenses/>.
23   */
24  
25  package com.mindtree.techworks.insight.download.sftpbrowse.test;
26  
27  import java.awt.Dimension;
28  import java.awt.HeadlessException;
29  import java.awt.Rectangle;
30  import java.awt.event.WindowAdapter;
31  import java.awt.event.WindowEvent;
32  import java.io.File;
33  import java.io.IOException;
34  import java.net.PasswordAuthentication;
35  import java.util.logging.LogManager;
36  import java.util.logging.Logger;
37  
38  import javax.swing.JFileChooser;
39  import javax.swing.JFrame;
40  
41  import com.mindtree.techworks.insight.download.ftpbrowse.FTPFileFile;
42  import com.mindtree.techworks.insight.download.ftpbrowse.test.FileChooserTestFrame;
43  import com.mindtree.techworks.insight.download.sftpbrowse.SFTPBrowseException;
44  import com.mindtree.techworks.insight.download.sftpbrowse.SFTPRemoteFileSystemView;
45  import com.mindtree.techworks.insight.gui.widgets.InsightRemoteFileChooser;
46  
47  
48  /**
49   * TODO
50   * 
51   * 
52   * @author Bindul Bhowmik
53   * @version $Revision: 27 $ $Date: 2007-12-16 04:58:03 -0700 (Sun, 16 Dec 2007) $
54   * 
55   */
56  public class SFTPFileChooserTestFrame extends JFrame {
57  	/**
58  	 * Used for object serialization
59  	 */
60  	private static final long serialVersionUID = -4542730691957729838L;
61  	
62  	/**
63  	 * Logger
64  	 */
65  	private static final Logger logger = Logger.getLogger(FileChooserTestFrame.class.getName());
66  
67  	/**
68  	 * @throws java.awt.HeadlessException
69  	 */
70  	public SFTPFileChooserTestFrame() throws HeadlessException {
71  
72  		super();
73  		//        this.setSize(500, 300);
74  		addWindowListener(new WindowAdapter() {
75  			public void windowClosing(WindowEvent aEvent) {
76  				System.exit(0);
77  			}
78  		});
79  		Dimension dim = getToolkit().getScreenSize();
80  		Rectangle abounds = getBounds();
81  		setLocation((dim.width - abounds.width) / 2,
82  				(dim.height - abounds.height) / 2);
83  		setVisible(true);
84  
85  		char[] password = "spnr".toCharArray();
86  		PasswordAuthentication passwordAuthentication = new PasswordAuthentication("spnr", password);
87  
88  		SFTPRemoteFileSystemView remoteFileSystemView = null;
89  		try {
90  			remoteFileSystemView = new SFTPRemoteFileSystemView(
91  					"cendantstp", null,passwordAuthentication, this);
92  		} catch (SFTPBrowseException e) {
93  			e.printStackTrace();
94  			System.exit(1);
95  		}
96  		JFileChooser fileChooser = new InsightRemoteFileChooser(remoteFileSystemView);
97  		fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
98  		fileChooser.setMultiSelectionEnabled(true);
99  //		fileChooser.showOpenDialog(this);
100 		File[] selectedFiles = null;
101 		if (fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
102 			selectedFiles = fileChooser.getSelectedFiles();
103 			for (int i = 0; i < selectedFiles.length; i++ ) {
104 				if (selectedFiles[i] instanceof FTPFileFile) {
105 					FTPFileFile ftpFile = (FTPFileFile) selectedFiles[i];
106 					logger.fine(ftpFile.getName());
107 					logger.fine(ftpFile.getPath());
108 				} else {
109 					logger.fine(selectedFiles[i].toString());
110 					logger.fine(selectedFiles[i].getAbsolutePath());
111 				}
112 			}
113 		}
114 		remoteFileSystemView.disconnect();
115 //		try {
116 //		if (null != selectedFiles) {
117 //			FTPClient ftpClient = new FTPClient();
118 //			InetAddress inetAddress = InetAddress.getByName(url.getHost());
119 //			ftpClient.connect(inetAddress);
120 //			if (!FTPReply.isPositiveCompletion(ftpClient.getReplyCode())) {
121 //				throw new FTPBrowseException(ftpClient.getReplyString());
122 //			}
123 //			if (null != passwordAuthentication) {
124 //				ftpClient.login(passwordAuthentication.getUserName(),
125 //						new StringBuffer().append(
126 //								passwordAuthentication.getPassword())
127 //								.toString());
128 //			}
129 //			String parentDir = System.getProperty("user.dir");
130 //			for (int i = 0; i < selectedFiles.length; i++ ) {
131 //				FTPFileFile file = (FTPFileFile)selectedFiles[i];
132 //				logger.fine(file.getPath());
133 //				FileOutputStream fos = new FileOutputStream(new File("d:/junk/ftp/test.txt" ));
134 //				logger.fine("" + ftpClient.retrieveFile(file.getPath().replaceAll("\\\\","/"), fos));
135 //				fos.close();
136 //			}
137 //		}
138 //		} catch (UnknownHostException e) {
139 //			e.printStackTrace();
140 //		} catch (SocketException e) {
141 //			e.printStackTrace();
142 //		} catch (IOException e) {
143 //			e.printStackTrace();
144 //		}
145 		
146 		System.exit(0);
147 	}
148 
149 	/**
150 	 * Summa method
151 	 * @param args
152 	 */
153 	public static void main(String[] args) {
154 		/*
155 		 * Logging properties
156 		 */
157 		LogManager logManager = LogManager.getLogManager();
158 		try {
159 			logManager
160 					.readConfiguration(FileChooserTestFrame.class.getClassLoader()
161 							.getResourceAsStream("com/mindtree/logging/download/ftpbrowse/test/logging.properties"));
162 		} catch (SecurityException e1) {
163 			// TODO Auto-generated catch block
164 			e1.printStackTrace();
165 		} catch (IOException e1) {
166 			// TODO Auto-generated catch block
167 			e1.printStackTrace();
168 		}
169 
170 
171 		try {
172 			SFTPFileChooserTestFrame fileChooserTestFrame = new SFTPFileChooserTestFrame();
173 			fileChooserTestFrame.getHeight();
174 		} catch (HeadlessException e) {
175 			// TODO Auto-generated catch block
176 			e.printStackTrace();
177 		}
178 	}
179 }