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