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 | */
|
---|
37 | package org.greenstone.gatherer.gui;
|
---|
38 |
|
---|
39 | import java.awt.*;
|
---|
40 | import java.awt.event.*;
|
---|
41 | import java.io.*;
|
---|
42 | import java.net.*;
|
---|
43 | import java.util.*;
|
---|
44 | import javax.swing.*;
|
---|
45 | import javax.swing.border.*;
|
---|
46 | import javax.swing.event.*;
|
---|
47 | import javax.swing.tree.*;
|
---|
48 | import org.greenstone.gatherer.Configuration;
|
---|
49 | import org.greenstone.gatherer.DebugStream;
|
---|
50 | import org.greenstone.gatherer.Dictionary;
|
---|
51 | import org.greenstone.gatherer.Gatherer;
|
---|
52 | import org.greenstone.gatherer.file.WorkspaceTree;
|
---|
53 | import org.greenstone.gatherer.greenstone.LocalGreenstone;
|
---|
54 | import org.greenstone.gatherer.util.StaticStrings;
|
---|
55 | import org.greenstone.gatherer.util.Utility;
|
---|
56 | import org.greenstone.gatherer.download.Download;
|
---|
57 | import org.greenstone.gatherer.download.DownloadScrollPane;
|
---|
58 | import org.greenstone.gatherer.download.ServerInfoDialog;
|
---|
59 | import org.greenstone.gatherer.util.XMLTools;
|
---|
60 | import org.greenstone.gatherer.cdm.*;
|
---|
61 | import org.greenstone.gatherer.gui.*;
|
---|
62 | import org.w3c.dom.*;
|
---|
63 | import org.xml.sax.*;
|
---|
64 | import org.greenstone.gatherer.GAuthenticator;
|
---|
65 |
|
---|
66 | /**
|
---|
67 | * @author John Thompson, Greenstone Digital Library, University of Waikato
|
---|
68 | * @version 2.1
|
---|
69 | */
|
---|
70 | public 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 | getter.newDownloadJob((Download)download_map.get(mode) ,mode,proxy_url);
|
---|
501 | }
|
---|
502 | }
|
---|
503 | }
|
---|
504 |
|
---|
505 |
|
---|
506 | private boolean checkURL(boolean checkRequired){
|
---|
507 |
|
---|
508 | if (!updateArguments(checkRequired)){
|
---|
509 | return false;
|
---|
510 | }
|
---|
511 |
|
---|
512 | Download current_download = (Download)download_map.get(mode);
|
---|
513 | Argument arg_url = current_download.getArgument("url");
|
---|
514 |
|
---|
515 | if (arg_url == null) return true;
|
---|
516 |
|
---|
517 | String url_str = arg_url.getValue();
|
---|
518 | URL url = null;
|
---|
519 | try {
|
---|
520 | url = new URL(url_str);
|
---|
521 | }
|
---|
522 | catch(MalformedURLException error) {
|
---|
523 | JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("Mirroring.Invalid_URL"), Dictionary.get("Mirroring.Invalid_URL_Title"), JOptionPane.ERROR_MESSAGE);
|
---|
524 | return false;
|
---|
525 | }
|
---|
526 |
|
---|
527 | return true;
|
---|
528 | }
|
---|
529 |
|
---|
530 |
|
---|
531 | private boolean checkProxy(){
|
---|
532 |
|
---|
533 | proxy_url = null;
|
---|
534 |
|
---|
535 | Download current_download = (Download)download_map.get(mode);
|
---|
536 |
|
---|
537 | Argument arg = current_download.getArgument("proxy_on");
|
---|
538 |
|
---|
539 | if (arg == null) return true;
|
---|
540 |
|
---|
541 | // Determine if we have to use a proxy.
|
---|
542 | if(Configuration.get("general.use_proxy", true)) {
|
---|
543 |
|
---|
544 | String proxy_host = Configuration.getString("general.proxy_host", true);
|
---|
545 | String proxy_port = Configuration.getString("general.proxy_port", true);
|
---|
546 | // Find out whether the user has already authenticated themselves
|
---|
547 | String user_pass = "";
|
---|
548 | String address = proxy_host + ":" + proxy_port;
|
---|
549 |
|
---|
550 | int count = 0;
|
---|
551 | while(count < 3 && (user_pass = (String) GAuthenticator.authentications.get(address)) == null) {
|
---|
552 | Authenticator.requestPasswordAuthentication(proxy_host, null, Integer.parseInt(proxy_port), "http://", Dictionary.get("WGet.Prompt"), "HTTP");
|
---|
553 | count++;
|
---|
554 | }
|
---|
555 |
|
---|
556 | if(count >= 3) {
|
---|
557 | return false;
|
---|
558 | }
|
---|
559 |
|
---|
560 | if(user_pass.indexOf("@") != -1) {
|
---|
561 |
|
---|
562 | // 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
|
---|
563 | if (Utility.isWindows()) {
|
---|
564 |
|
---|
565 | arg.setValue("true");
|
---|
566 | arg.setAssigned(true);
|
---|
567 |
|
---|
568 | arg = current_download.getArgument("proxy_host");
|
---|
569 | arg.setValue(proxy_host);
|
---|
570 | arg.setAssigned(true);
|
---|
571 |
|
---|
572 | arg = current_download.getArgument("proxy_port");
|
---|
573 | arg.setValue(proxy_port);
|
---|
574 | arg.setAssigned(true);
|
---|
575 |
|
---|
576 | arg = current_download.getArgument("user_name");
|
---|
577 | arg.setValue(user_pass.substring(0, user_pass.indexOf("@")));
|
---|
578 | arg.setAssigned(true);
|
---|
579 |
|
---|
580 | arg = current_download.getArgument("user_password");
|
---|
581 | arg.setValue(user_pass.substring(user_pass.indexOf("@") + 1));
|
---|
582 | arg.setAssigned(true);
|
---|
583 | }
|
---|
584 | else{
|
---|
585 | String user_name = user_pass.substring(0, user_pass.indexOf("@"));
|
---|
586 | String user_pwd = user_pass.substring(user_pass.indexOf("@") + 1);
|
---|
587 | proxy_url = user_name+":"+user_pwd+"@"+proxy_host+":"+proxy_port+"/";
|
---|
588 |
|
---|
589 | }
|
---|
590 |
|
---|
591 | return true;
|
---|
592 | }
|
---|
593 | else{
|
---|
594 | return false;
|
---|
595 | }
|
---|
596 |
|
---|
597 | }
|
---|
598 |
|
---|
599 | return true;
|
---|
600 | }
|
---|
601 |
|
---|
602 | /*
|
---|
603 | private class PreferencesButtonActionListener
|
---|
604 | implements ActionListener {
|
---|
605 | public void actionPerformed(ActionEvent event) {
|
---|
606 | new Preferences(Preferences.CONNECTION_PREFS);
|
---|
607 | }
|
---|
608 | }*/
|
---|
609 |
|
---|
610 | private class InformationButtonActionListener
|
---|
611 | implements ActionListener {
|
---|
612 | public void actionPerformed(ActionEvent event) {
|
---|
613 | //turn off the check for find argument
|
---|
614 | Download current_download = (Download)download_map.get(mode);
|
---|
615 |
|
---|
616 | if (!checkProxy() || !checkURL(false) )return;
|
---|
617 |
|
---|
618 |
|
---|
619 | if(server_info != null) {
|
---|
620 | server_info.dispose();
|
---|
621 | }
|
---|
622 |
|
---|
623 |
|
---|
624 | Argument arg_url = current_download.getArgument("url");
|
---|
625 | String str_url = "";
|
---|
626 |
|
---|
627 | if( arg_url!= null && arg_url.isAssigned()) {
|
---|
628 | str_url = arg_url.getValue();
|
---|
629 | }
|
---|
630 |
|
---|
631 |
|
---|
632 | server_info = new ServerInfoDialog(str_url ,proxy_url, mode,(Download)download_map.get(mode));
|
---|
633 |
|
---|
634 | }
|
---|
635 | }
|
---|
636 |
|
---|
637 | private class PreferencesButtonActionListener
|
---|
638 | implements ActionListener {
|
---|
639 | public void actionPerformed(ActionEvent event) {
|
---|
640 | new Preferences(Preferences.CONNECTION_PREFS);
|
---|
641 | }
|
---|
642 | }
|
---|
643 | }
|
---|