source: gli/trunk/src/org/greenstone/gatherer/gui/DownloadPane.java@ 17621

Last change on this file since 17621 was 17621, checked in by ak19, 16 years ago

Correction to previous changes I made to GAuthenticator: it now only uses any previously stored values for username and password when the GAuthenticator operates in the new DOWNLOAD mode, which is set (and soon thereafter restored to the default REGULAR mode) in DownloadPane.java for (wget) downloads.

  • Property svn:keywords set to Author Date Id Revision
File size: 25.1 KB
Line 
1/**
2 *#########################################################################
3 *
4 * A component of the Gatherer application, part of the Greenstone digital
5 * library suite from the New Zealand Digital Library Project at the
6 * University of Waikato, New Zealand.
7 *
8 * <BR><BR>
9 *
10 * Author: John Thompson, Greenstone Digital Library, University of Waikato
11 *
12 * <BR><BR>
13 *
14 * Copyright (C) 1999 New Zealand Digital Library Project
15 *
16 * <BR><BR>
17 *
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
22 *
23 * <BR><BR>
24 *
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
29 *
30 * <BR><BR>
31 *
32 * You should have received a copy of the GNU General Public License
33 * along with this program; if not, write to the Free Software
34 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
35 *########################################################################
36 */
37package org.greenstone.gatherer.gui;
38
39import java.awt.*;
40import java.awt.event.*;
41import java.io.*;
42import java.net.*;
43import java.util.*;
44import javax.swing.*;
45import javax.swing.border.*;
46import javax.swing.event.*;
47import javax.swing.tree.*;
48import org.greenstone.gatherer.Configuration;
49import org.greenstone.gatherer.DebugStream;
50import org.greenstone.gatherer.Dictionary;
51import org.greenstone.gatherer.Gatherer;
52import org.greenstone.gatherer.file.WorkspaceTree;
53import org.greenstone.gatherer.greenstone.LocalGreenstone;
54import org.greenstone.gatherer.util.StaticStrings;
55import org.greenstone.gatherer.util.Utility;
56import org.greenstone.gatherer.download.Download;
57import org.greenstone.gatherer.download.DownloadScrollPane;
58import org.greenstone.gatherer.download.ServerInfoDialog;
59import org.greenstone.gatherer.util.XMLTools;
60import org.greenstone.gatherer.cdm.*;
61import org.greenstone.gatherer.gui.*;
62import org.w3c.dom.*;
63import org.xml.sax.*;
64import org.greenstone.gatherer.GAuthenticator;
65
66/**
67 * @author John Thompson, Greenstone Digital Library, University of Waikato
68 * @version 2.1
69 */
70public class DownloadPane
71 extends JPanel {
72
73 static final private Dimension LABEL_SIZE = new Dimension(225, 25);
74 static final private Dimension TREE_SIZE = new Dimension(150, 500);
75 static final private String CONTENTS[] = { "DOWNLOAD.MODE.WebDownload", "DOWNLOAD.MODE.MediaWikiDownload", "DOWNLOAD.MODE.OAIDownload", "DOWNLOAD.MODE.ZDownload" , "DOWNLOAD.MODE.SRWDownload"};
76
77 private boolean download_button_enabled = false;
78 private boolean ready = false;
79
80 private JPanel options_pane;
81 // TODO should use Vector to store all loaded downloads!!
82
83 private DesignTree tree;
84 private HashMap download_map;
85 private ServerInfoDialog server_info;
86 private JScrollPane list_scroll;
87 private DownloadScrollPane getter;
88 private String mode = null;
89 private TreePath previous_path;
90 private String proxy_url = "";
91
92 /** Main System code */
93 public DownloadPane() {
94 super();
95
96 // TODO: Download the WDownload and the download panel fixed!!
97 getter = new DownloadScrollPane();
98 getter.start();
99 list_scroll = getter.getDownloadJobList();
100
101 // TODO should use Vector to store all loaded downloads!!
102 String lang = Configuration.getLanguage();
103 download_map = new HashMap();
104 download_map.put("Web", loadDownload("WebDownload",lang));
105 download_map.put("MediaWiki", loadDownload("MediaWikiDownload",lang));
106 download_map.put("OAI", loadDownload("OAIDownload",lang));
107 download_map.put("Z3950", loadDownload("Z3950Download",lang));
108 download_map.put("SRW", loadDownload("SRWDownload",lang));
109
110 // Creation
111 tree = new DesignTree();
112 options_pane = new JPanel();
113
114
115 JButton clear_cache_button = new GLIButton(Dictionary.get("Mirroring.ClearCache"), Dictionary.get("Mirroring.ClearCache_Tooltip"));
116 clear_cache_button.setEnabled(true);
117 clear_cache_button.setMnemonic(KeyEvent.VK_C);
118
119 JButton download_button = new GLIButton(Dictionary.get("Mirroring.Download"), Dictionary.get("Mirroring.Download_Tooltip"));
120 download_button.setEnabled(true);
121 download_button.setMnemonic(KeyEvent.VK_D);
122
123 JButton information_button = new GLIButton(Dictionary.get("Download.ServerInformation"), Dictionary.get("Download.ServerInformation_Tooltip"));
124 information_button.setEnabled(true);
125 information_button.setMnemonic(KeyEvent.VK_S);
126
127
128 JButton preferences_button = new GLIButton(Dictionary.get("Mirroring.Preferences"), Dictionary.get("Mirroring.Preferences_Tooltip"));
129 preferences_button.setEnabled(true);
130 preferences_button.setMnemonic(KeyEvent.VK_P);
131
132 // Connect
133 clear_cache_button.addActionListener(new ClearCacheListener());
134 download_button.addActionListener(new DownloadButtonListener());
135 preferences_button.addActionListener(new PreferencesButtonActionListener());
136 information_button.addActionListener(new InformationButtonActionListener());
137 tree.addTreeSelectionListener(new TreeListener());
138
139 // Add to Panel
140 JPanel button_pane = new JPanel();
141 button_pane.setLayout(new FlowLayout(FlowLayout.CENTER,20,5));
142 button_pane.setBorder(BorderFactory.createEtchedBorder());
143 button_pane.add(clear_cache_button);
144 button_pane.add(download_button);
145 button_pane.add(information_button);
146 button_pane.add(preferences_button);
147
148 JPanel tree_pane = new JPanel();
149 tree_pane.setLayout(new BorderLayout());
150 tree_pane.add(new JScrollPane(tree), BorderLayout.CENTER);
151 tree_pane.setPreferredSize(TREE_SIZE);
152
153
154 Color colour_two = Configuration.getColor("coloring.collection_tree_background", false);
155 options_pane.setBackground(colour_two);
156 options_pane.setBorder(BorderFactory.createEtchedBorder());
157
158
159 JScrollPane options_scroll_pane = new JScrollPane(options_pane);
160 JSplitPane mode_pane = new JSplitPane();
161 mode_pane.setBorder(BorderFactory.createEmptyBorder(0,0,0,0));
162 mode_pane.add(tree_pane,JSplitPane.LEFT);
163 mode_pane.add(options_scroll_pane,JSplitPane.RIGHT);
164 mode_pane.setDividerLocation(TREE_SIZE.width);
165
166 JPanel edit_pane = new JPanel();
167 edit_pane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(2,0,0,0), BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder("Download Setting"), BorderFactory.createEmptyBorder(2,2,2,2))));
168 edit_pane.setLayout(new BorderLayout());
169 edit_pane.add(mode_pane,BorderLayout.CENTER);
170 edit_pane.add(button_pane,BorderLayout.PAGE_END);
171
172 // Add to "this"
173 setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
174 setLayout(new GridLayout(2,1));
175 add(edit_pane);
176 add(list_scroll);
177
178 mode = "Web";
179 generateOptions(options_pane,(Download)download_map.get(mode));
180 previous_path = tree.getSelectionPath();
181 }
182
183 /** System Utilities */
184 public void modeChanged(int gli_mode) {
185 // do nothing at this stage - should we be renewing download options??
186 }
187
188 private void addHeader(String name, Color color, JPanel target_pane) {
189 JPanel header = new JPanel();
190 header.setBackground(color);
191 JPanel inner_pane = new JPanel();
192 inner_pane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(5,5,5,5), BorderFactory.createRaisedBevelBorder()));
193 inner_pane.setBackground(color);
194 JLabel header_label = new JLabel("<html><strong>" + name + "</strong></html>");
195 header_label.setBackground(Configuration.getColor("coloring.collection_heading_background", false));
196 header_label.setHorizontalAlignment(JLabel.CENTER);
197 header_label.setOpaque(true);
198
199 // Layout
200 inner_pane.setLayout(new BorderLayout());
201 inner_pane.add(header_label, BorderLayout.CENTER);
202
203 header.setLayout(new BorderLayout());
204 header.add(inner_pane, BorderLayout.CENTER);
205 target_pane.add(header);
206 }
207
208 /** Supporting Functions */
209 private Download loadDownload(String download_name, String lang) {
210 Document document = null;
211 InputStream input_stream = null;
212
213 try {
214 if (Gatherer.isGsdlRemote) {
215 StringBuffer launch_str = new StringBuffer();
216 launch_str.append(Gatherer.cgiBase);
217 launch_str.append("launch");
218 launch_str.append("?cmd=downloadinfo.pl&xml=&language=");
219 launch_str.append(lang);
220 launch_str.append("&plug=");
221 launch_str.append(download_name);
222
223 String launch = launch_str.toString();
224 System.err.println("*** launch = " + launch);
225
226 URL launch_url = new URL(launch);
227 URLConnection launch_connection = launch_url.openConnection();
228 input_stream = launch_connection.getInputStream();
229 }
230 else {
231 ArrayList args_list = new ArrayList();
232 String args[] = null;
233 if(Utility.isWindows()) {
234 if(Configuration.perl_path != null) {
235 args_list.add(Configuration.perl_path);
236 }
237 else {
238 args_list.add("Perl.exe");
239 }
240 }
241 args_list.add(LocalGreenstone.getBinScriptDirectoryPath()+"downloadinfo.pl");
242 args_list.add("-xml");
243 args_list.add("-language");
244 args_list.add(lang);
245 args_list.add(download_name);
246
247 // Create the process.
248 args = (String []) args_list.toArray(new String[0]);
249 Runtime runtime = Runtime.getRuntime();
250 DebugStream.println("Getting Download Info: "+args_list);
251 Process process = runtime.exec(args);
252
253 input_stream = process.getErrorStream();
254 }
255
256 document = XMLTools.parseXML(input_stream);
257 }
258 catch (Exception error) {
259 System.err.println("Failed when trying to parse: " + download_name);
260 error.printStackTrace();
261 }
262
263 if(document != null) {
264 return parseXML(document.getDocumentElement());
265 }
266
267 return null;
268 }
269
270 private Download parseXML(Node root) {
271 Download download = new Download();
272 String node_name = null;
273 for (Node node = root.getFirstChild(); node != null; node = node.getNextSibling()) {
274 node_name = node.getNodeName();
275 if(node_name.equalsIgnoreCase("Name")) {
276 String name = XMLTools.getValue(node);
277 download.setName(name);
278 }
279 else if (node_name.equalsIgnoreCase("Desc")) {
280 download.setDescription(XMLTools.getValue(node));
281 }
282 else if (node_name.equalsIgnoreCase("Abstract")) {
283 download.setIsAbstract(XMLTools.getValue(node).equalsIgnoreCase(StaticStrings.YES_STR));
284 }
285 else if(node_name.equalsIgnoreCase("Arguments")) {
286 for(Node arg = node.getFirstChild(); arg != null; arg = arg.getNextSibling()) {
287 node_name = arg.getNodeName();
288 if(node_name.equalsIgnoreCase("Option")) {
289 Argument argument = new Argument((Element)arg);
290 argument.parseXML((Element)arg);
291 argument.setValue(argument.getDefaultValue());
292 download.addArgument(argument);
293 }
294
295 }
296 }
297 else if(node_name.equalsIgnoreCase("DownloadInfo")) {
298 Download super_download = parseXML(node);
299 download.setSuper(super_download);
300 }
301 }
302
303 if(download.getName() != null) {
304 return download;
305 }
306 return null;
307 }
308
309 /** Update the previous setup */
310 private boolean updateArguments(boolean checkRequired)
311 {
312 boolean cont = true;
313 for(int i = 0; i < options_pane.getComponentCount(); i++) {
314
315 Component component = options_pane.getComponent(i);
316 if(component instanceof ArgumentControl) {
317 cont = cont && ((ArgumentControl)component).updateArgument(checkRequired);
318 }
319 }
320
321 if(cont){return true; }
322
323 return false;
324 }
325
326 /** Generate Controls for Options */
327 /* at some stage we should think about which options should be shown for
328 * different modes. Currently, always show all options (unless hidden)*/
329 private void generateOptions(JPanel options_pane, ArgumentContainer data) {
330 options_pane.removeAll();
331 /** Create the current option panel */
332
333 ArrayList arguments = data.getArguments(true, false);
334 int mode = Configuration.getMode();
335 ArrayList added_arguments = new ArrayList();
336
337 for(int i = 0; i < arguments.size(); i++) {
338 Argument argument = (Argument) arguments.get(i);
339
340 if (argument.isHiddenGLI()) continue;
341 ArgumentControl argument_control = new ArgumentControl(argument,false,null);
342 added_arguments.add(argument_control);
343 }
344
345
346 options_pane.setLayout(new GridLayout(added_arguments.size(),1));
347 for(int i = 0; i < added_arguments.size(); i++) {
348 options_pane.add((ArgumentControl)added_arguments.get(i));
349
350 }
351 }
352
353 /** Behaviour Functions */
354 public void afterDisplay() {
355 ready = true;
356 }
357
358
359 public void gainFocus() {
360 if(!ready) {
361 return;
362 }
363
364 // It is also a good time to determine if the download should be enabled - ie if its allowed to be enabled and a valid URL is present in the field.
365 download_button_enabled = true;
366 //download_button.setEnabled(download_button_enabled);
367 }
368
369
370
371 public void refresh(int refresh_reason, boolean ready)
372 {
373 }
374
375 /** Private classes */
376 /** This tree provides a 'table of contents' for the various components of the design process (collection configuration in more technical terms). */
377 private class DesignTree extends JTree {
378
379 private DesignNode root = null;
380 /** Constructor. Automatically generates all of the nodes, in the order of CONTENTS. */
381 public DesignTree() {
382 super();
383 resetModel(Configuration.getMode());
384 expandRow(0);
385 setRootVisible(false);
386 setSelectionRow(0);
387 }
388
389 /** Reset the model used by the design page contents tree. This is necessary to hide the partitions entry when in lower detail modes
390 * @param mode the current detail mode as an int
391 */
392 public void resetModel(int mode) {
393 root = new DesignNode("DOWNLOAD.MODE.Root");
394 // Now add the design categories.
395 for(int i = 0; i < CONTENTS.length; i++) {
396 root.add(new DesignNode(CONTENTS[i]));
397 }
398 this.setModel(new DefaultTreeModel(root));
399 updateUI();
400 }
401 /** Set the current view to the one specified.
402 * @param type the name of the desired view as a String
403 */
404 public void setSelectedView(String type) {
405 type = Dictionary.get(type);
406 for(int i = 0; i < root.getChildCount(); i++) {
407 DesignNode child = (DesignNode) root.getChildAt(i);
408 if(child.toString().equals(type)) {
409 TreePath path = new TreePath(child.getPath());
410 setSelectionPath(path);
411 }
412 }
413 }
414 }
415
416 /** A tree node that retains a reference to one of the possible design sub-views relating to the different sub-managers. */
417 private class DesignNode extends DefaultMutableTreeNode {
418 /** Constructor.
419 * @param object The <strong>Object</strong> assigned to this node.
420 */
421 public DesignNode(String object) {
422 super(object);
423 }
424 /** Retrieve a textual representation of the object.
425 * @return a String
426 */
427 public String toString() {
428 // return Dictionary.get("CDM.GUI." + (String)getUserObject());
429 return Dictionary.get((String) getUserObject());
430 }
431 }
432
433 /** Listens for selection changes in the 'contents' tree, and switches to the appropriate view. */
434 private class TreeListener
435 implements TreeSelectionListener {
436 /** Called whenever the selection changes, we must update the view so it matches the node selected.
437 * @param event A <strong>TreeSelectionEvent</strong> containing more information about the tree selection.
438 * @see org.greenstone.gatherer.cdm.ClassifierManager
439 * @see org.greenstone.gatherer.cdm.CollectionDesignManager
440 * @see org.greenstone.gatherer.cdm.CollectionMetaManager
441 * @see org.greenstone.gatherer.cdm.FormatManager
442 * @see org.greenstone.gatherer.cdm.LanguageManager
443 * @see org.greenstone.gatherer.cdm.MetadataSetView
444 * @see org.greenstone.gatherer.cdm.SubcollectionManager
445 * @see org.greenstone.gatherer.cdm.TranslationView
446 * @see org.greenstone.gatherer.cdm.PlugInManager
447 */
448 public void valueChanged(TreeSelectionEvent event) {
449 if(!tree.isSelectionEmpty()) {
450 TreePath path = tree.getSelectionPath();
451
452 DesignNode node = (DesignNode)path.getLastPathComponent();
453 String type = (String)node.getUserObject();
454 Gatherer.g_man.wait(true);
455 if(type == CONTENTS[0]) {
456 mode = "Web";
457 generateOptions(options_pane,(Download)download_map.get(mode));
458 }
459 else if(type == CONTENTS[1]) {
460 mode = "MediaWiki";
461 generateOptions(options_pane,(Download)download_map.get(mode));
462 }
463 else if(type == CONTENTS[2]) {
464 mode = "OAI";
465 generateOptions(options_pane,(Download)download_map.get(mode));
466 }
467 else if(type == CONTENTS[3]) {
468 mode = "Z3950";
469 generateOptions(options_pane,(Download)download_map.get(mode));
470 }
471 else if(type == CONTENTS[4]) {
472 mode = "SRW";
473 generateOptions(options_pane,(Download)download_map.get(mode));
474 }
475 tree.setSelectionPath(path);
476 previous_path = path;
477 repaint();
478
479 Gatherer.g_man.wait(false);
480 }
481 }
482 }
483
484 private class ClearCacheListener
485 implements ActionListener {
486 public void actionPerformed(ActionEvent event) {
487 // Retrieve the cache folder and delete it.
488 Utility.delete(Utility.getCacheDir());
489 // ...and refresh the node in the workspace tree to show it's all gone
490 Gatherer.g_man.refreshWorkspaceTree(WorkspaceTree.DOWNLOADED_FILES_CHANGED);
491 }
492 }
493
494 private class DownloadButtonListener
495 implements ActionListener {
496 public void actionPerformed(ActionEvent event) {
497
498 if(checkURL(true) && checkProxy() == true) {
499
500 // Proxy settings are now set. Check that the url is not a redirect, else get
501 // redirect url (we do this step in order to avoid some unintuitive behaviour from wget)
502 Download current_download = (Download)download_map.get(mode);
503 Argument arg_url = current_download.getArgument("url");
504 if(arg_url != null) { // it's null for z3950 and possibly for other downloaders
505 String url_str = arg_url.getValue();
506 String redirect_url_str = getRedirectURL(url_str);
507
508 // only update the Argument and its GUI ArgumentControl if the URL
509 // has in fact changed
510 if(!url_str.equals(redirect_url_str)) {
511 arg_url.setValue(redirect_url_str);
512 updateArgument(arg_url, redirect_url_str);
513 }
514 }
515 getter.newDownloadJob((Download)download_map.get(mode) ,mode,proxy_url);
516 }
517 }
518 }
519
520 /**
521 * The Java code here will retrieve the page at the given url. If the response code is
522 * a redirect, it will get the redirect url so that wget may be called with the proper url.
523 * This preprocessing of the URL is necessary because:
524 * Wget does not behave the way the browser does when faced with urls of the form
525 * http://www.englishhistory.net/tudor/citizens and if that page does not exist.
526 * The directory listing with a slash at the end (http://www.englishhistory.net/tudor/citizens/)
527 * does exist, however. In order to prevent wget from assuming that the root URL
528 * to traverse is http://www.englishhistory.net/tudor/ instead of the intended
529 * http://www.englishhistory.net/tudor/citizens/, we need give wget the redirect location
530 * that's returned when we initially make a request for http://www.englishhistory.net/tudor/citizens
531 * The proper url is sent back in the Location header, allowing us to bypass wget's
532 * unexpected behaviour.
533 * This method ensures that urls like http://www.nzdl.org/niupepa also continue to work:
534 * there is no http://www.nzdl.org/niupepa/ page, because this url actually redirects to an
535 * entirely different URL.
536 * @return the redirect url for the given url if any redirection is involved, or the
537 * url_str.
538 */
539 private String getRedirectURL(String url_str) {
540 HttpURLConnection connection = null;
541 if(url_str.startsWith("http:")) { // only test http urls
542 try {
543 URL url = new URL(url_str);
544 connection = (HttpURLConnection)url.openConnection(); //new HttpURLConnection(url);
545 // don't let it automatically follow redirects, since we want to
546 // find out whether we are dealing with redirects in the first place
547 connection.setInstanceFollowRedirects(false);
548
549 // now check for whether we get a redirect response
550 // HTTP Codes 3xx are redirects, http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
551 int responseCode = connection.getResponseCode();
552 if(responseCode >= 300 && responseCode < 400) {
553 String responseMsg = connection.getResponseMessage();
554
555 // Get the Location header since this specifies the new location of the resource
556 String location = connection.getHeaderField("Location");
557
558 // this becomes the url that wget should download from
559 url_str = location.trim();
560 }
561
562 connection.disconnect();
563 } catch(Exception e) {
564 if(connection != null) {
565 connection.disconnect();
566 }
567 System.err.println("Checking redirection. Tried to connect to "
568 + url_str + ",\nbut got exception: " + e);
569 }
570 }
571
572 return url_str;
573 }
574
575
576 /** For a string-based Argument whose value has changed, this method
577 * updates the GUI ArgumentControl's value correspondingly. */
578 private void updateArgument(Argument arg, String value) {
579 for(int i = 0; i < options_pane.getComponentCount(); i++) {
580 Component component = options_pane.getComponent(i);
581 if(component instanceof ArgumentControl) {
582 ArgumentControl control = (ArgumentControl)component;
583 if(control.getArgument() == arg) {
584 control.setValue(value);
585 control.repaint();
586 }
587 }
588 }
589 }
590
591 private boolean checkURL(boolean checkRequired){
592
593 if (!updateArguments(checkRequired)){
594 return false;
595 }
596
597 Download current_download = (Download)download_map.get(mode);
598 Argument arg_url = current_download.getArgument("url");
599
600 if (arg_url == null) return true;
601
602 String url_str = arg_url.getValue();
603 URL url = null;
604 try {
605 url = new URL(url_str);
606 }
607 catch(MalformedURLException error) {
608 JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("Mirroring.Invalid_URL"), Dictionary.get("Mirroring.Invalid_URL_Title"), JOptionPane.ERROR_MESSAGE);
609 return false;
610 }
611
612 return true;
613 }
614
615
616 private boolean checkProxy(){
617
618 proxy_url = null;
619
620 Download current_download = (Download)download_map.get(mode);
621
622 Argument arg = current_download.getArgument("proxy_on");
623
624 if (arg == null) return true;
625
626 // Determine if we have to use a proxy.
627 if(Configuration.get("general.use_proxy", true)) {
628
629 String proxy_host = Configuration.getString("general.proxy_host", true);
630 String proxy_port = Configuration.getString("general.proxy_port", true);
631 // Find out whether the user has already authenticated themselves
632 String user_pass = "";
633 String address = proxy_host + ":" + proxy_port;
634
635 int count = 0;
636 // Only for wget, need to avoid a second automatic authentication popup (first asks
637 // the proxy authentication for wget, and the second will ask the same for the realm)
638 GAuthenticator.setMode(GAuthenticator.DOWNLOAD);
639 while(count < 3 && (user_pass = (String) GAuthenticator.authentications.get(address)) == null) {
640 Authenticator.requestPasswordAuthentication(proxy_host, null, Integer.parseInt(proxy_port), "http://", Dictionary.get("WGet.Prompt"), "HTTP");
641 count++;
642 }
643 GAuthenticator.setMode(GAuthenticator.REGULAR); // reset the state to default (of how the authentication popup functions)
644 if(count >= 3) {
645 return false;
646 }
647
648 if(user_pass.indexOf("@") != -1) {
649
650 // Write the use proxy command - we don't do this anymore, instead we set environment variables - hopefully these can't be spied on like the follwoing can (using ps) - actually the environment stuff didn't work for windows, so lets go back to this
651 if (Utility.isWindows()) {
652
653 arg.setValue("true");
654 arg.setAssigned(true);
655
656 arg = current_download.getArgument("proxy_host");
657 arg.setValue(proxy_host);
658 arg.setAssigned(true);
659
660 arg = current_download.getArgument("proxy_port");
661 arg.setValue(proxy_port);
662 arg.setAssigned(true);
663
664 arg = current_download.getArgument("user_name");
665 arg.setValue(user_pass.substring(0, user_pass.indexOf("@")));
666 arg.setAssigned(true);
667
668 arg = current_download.getArgument("user_password");
669 arg.setValue(user_pass.substring(user_pass.indexOf("@") + 1));
670 arg.setAssigned(true);
671 }
672 else{
673 String user_name = user_pass.substring(0, user_pass.indexOf("@"));
674 String user_pwd = user_pass.substring(user_pass.indexOf("@") + 1);
675 proxy_url = user_name+":"+user_pwd+"@"+proxy_host+":"+proxy_port+"/";
676
677 }
678
679 return true;
680 }
681 else{
682 return false;
683 }
684
685 }
686
687 return true;
688 }
689
690 /*
691 private class PreferencesButtonActionListener
692 implements ActionListener {
693 public void actionPerformed(ActionEvent event) {
694 new Preferences(Preferences.CONNECTION_PREFS);
695 }
696 }*/
697
698 private class InformationButtonActionListener
699 implements ActionListener {
700 public void actionPerformed(ActionEvent event) {
701 //turn off the check for find argument
702 Download current_download = (Download)download_map.get(mode);
703
704 if (!checkProxy() || !checkURL(false) )return;
705
706
707 if(server_info != null) {
708 server_info.dispose();
709 }
710
711
712 Argument arg_url = current_download.getArgument("url");
713 String str_url = "";
714
715 if( arg_url!= null && arg_url.isAssigned()) {
716 str_url = arg_url.getValue();
717 }
718
719
720 server_info = new ServerInfoDialog(str_url ,proxy_url, mode,(Download)download_map.get(mode));
721
722 }
723 }
724
725 private class PreferencesButtonActionListener
726 implements ActionListener {
727 public void actionPerformed(ActionEvent event) {
728 new Preferences(Preferences.CONNECTION_PREFS);
729 }
730 }
731}
Note: See TracBrowser for help on using the repository browser.