source: main/trunk/gli/src/org/greenstone/gatherer/download/ServerInfoDialog.java@ 31820

Last change on this file since 31820 was 31820, checked in by ak19, 7 years ago

The changes necessary for GLI's Java code to work properly with a wget that can handle https. Next step is to compile up wget with open_ssl so that it supports https. So far tested against the system wget (which supports https) after copying this into the GS2 location in gs2build/bin/linux, since that's the location which GS uses to load wget from.

  • Property svn:keywords set to Author Date Id Revision
File size: 5.2 KB
Line 
1package org.greenstone.gatherer.download;
2
3import java.awt.*;
4import java.awt.event.*;
5import javax.swing.*;
6import javax.swing.border.*;
7import javax.swing.event.*;
8import java.io.*;
9import java.util.ArrayList;
10import org.greenstone.gatherer.cdm.Argument;
11import org.greenstone.gatherer.Configuration;
12import org.greenstone.gatherer.DebugStream;
13import org.greenstone.gatherer.Dictionary;
14import org.greenstone.gatherer.Gatherer;
15import org.greenstone.gatherer.greenstone.LocalGreenstone;
16import org.greenstone.gatherer.gui.*;
17import org.greenstone.gatherer.util.SafeProcess;
18import org.greenstone.gatherer.util.Utility;
19
20public class ServerInfoDialog extends JDialog
21{
22 static private Dimension SIZE = new Dimension(500, 300);
23 private String url;
24 private String mode;
25 private JPanel info_list_pane;
26 private JScrollPane info_scroll_pane;
27 private JDialog info_dialog;
28 private Download download;
29 private String proxy_url;
30
31 public ServerInfoDialog(String url, String proxy_url, String mode, Download download) {
32 super();
33 this.url = url;
34 this.mode = mode;
35 this.download = download;
36 this.proxy_url = proxy_url;
37 this.info_dialog = this;
38
39 this.setSize(SIZE);
40
41 JButton close_button = new GLIButton(Dictionary.get("General.Close"),Dictionary.get("General.Close_Tooltip"));
42 close_button.setEnabled(true);
43 close_button.addActionListener(new ActionListener() {
44 public void actionPerformed(ActionEvent event) {
45 info_dialog.dispose();
46 }
47 });
48
49 JPanel button_pane = new JPanel();
50 button_pane.setLayout(new FlowLayout());
51 button_pane.setBorder(BorderFactory.createEtchedBorder());
52 button_pane.add(close_button);
53
54 info_list_pane = new JPanel();
55 info_list_pane.setLayout(new BoxLayout(info_list_pane, BoxLayout.Y_AXIS));
56 info_list_pane.setBorder(BorderFactory.createEtchedBorder());
57 getServerInfo();
58
59 info_scroll_pane = new JScrollPane(info_list_pane);
60
61 JPanel information_pane = new JPanel();
62 information_pane.setLayout(new BorderLayout());
63 information_pane.setBorder(BorderFactory.createEtchedBorder());
64 information_pane.add(info_scroll_pane,BorderLayout.CENTER);
65
66 JPanel main_pane = new JPanel();
67 main_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
68 main_pane.setLayout(new BorderLayout());
69 main_pane.add(information_pane,BorderLayout.CENTER);
70 main_pane.add(button_pane,BorderLayout.SOUTH);
71
72 Container main_container = this.getContentPane();
73 main_container.add(main_pane);
74
75 // Show
76 Dimension screen_size = Configuration.screen_size;
77 setLocation((screen_size.width - SIZE.width) / 2, (screen_size.height - SIZE.height) / 2);
78 setVisible(true);
79
80 }
81
82 private void getServerInfo()
83 {
84 ArrayList commands = new ArrayList();
85 commands.add(Configuration.perl_path);
86 commands.add("-S");
87 commands.add(LocalGreenstone.getBinScriptDirectoryPath()+"downloadfrom.pl");
88 commands.add("-info");
89 commands.add("-download_mode");
90 commands.add(mode);
91
92 ArrayList all_arg = download.getArguments(true,false);
93 for (int i = 0; i < all_arg.size(); i++) {
94 Argument argument = (Argument) all_arg.get(i);
95
96 if(argument.isAssigned()) {
97 commands.add("-" + argument.getName());
98 if(argument.getType() != Argument.FLAG) {
99 commands.add(argument.getValue());
100 }
101 }
102 }
103
104 String[] command = (String[]) commands.toArray(new String[0]);
105 DebugStream.println("Getting server info: "+commands);
106 try {
107 String [] env = null;
108 SafeProcess prcs = null;
109
110 if (Utility.isWindows()) {
111 prcs = new SafeProcess(command);
112 }
113 else {
114 if (proxy_url != null && !proxy_url.equals("")) {
115 // Specify proxies as environment variables
116 // Need to manually specify GSDLHOME and GSDLOS also
117 env = new String[5];
118 proxy_url = proxy_url.replaceAll("http://","");
119 env[0] = "http_proxy=http://"+proxy_url;
120 env[1] = "https_proxy=http://"+proxy_url; // yes, HTTP protocol for https:// too
121 // see also https://wiki.archlinux.org/index.php/proxy_settings
122 env[2] = "ftp_proxy=ftp://"+proxy_url;
123 env[3] = "GSDLHOME=" + Configuration.gsdl_path;
124 env[4] = "GSDLOS=" + Gatherer.client_operating_system;
125 prcs = new SafeProcess(command, env, null);
126 }
127 else {
128 // Will inherit the GLI's environment, with GSDLHOME and GSDLOS set
129 prcs = new SafeProcess(command);
130 }
131 }
132
133 // special processing of Process' stderr stream:
134 // Search the process standard error stream and seach for two particular occurences.
135 int exitVal = prcs.runProcess(null, new ProcErrStreamLineByLineHandler());
136
137 } catch (Exception ioe) {
138 ioe.printStackTrace();
139 }
140
141 }
142
143 private class ProcErrStreamLineByLineHandler extends SafeProcess.LineByLineHandler
144 {
145 public ProcErrStreamLineByLineHandler() {
146 super(SafeProcess.STDERR); // sets this.source
147 }
148
149 public void gotLine(String line) {
150 // Check the current line from the standard error stream and seach for two particular occurences.
151 if (!line.trim().equals("<<Finished>>")) {
152
153 JLabel a_label = new JLabel(line);
154 a_label.setAlignmentX(Component.LEFT_ALIGNMENT);
155 ServerInfoDialog.this.info_list_pane.add(a_label);
156 }
157 }
158 public void gotException(Exception e) {
159 e.printStackTrace();
160 }
161 }
162}
Note: See TracBrowser for help on using the repository browser.