source: other-projects/FileTransfer-WebSocketPair/testGXTWithGreenstone/src/org/greenstone/gatherer/download/ServerInfoDialog.java@ 33053

Last change on this file since 33053 was 33053, checked in by ak19, 5 years ago

I still had some stuff of Nathan Kelly's (FileTransfer-WebSocketPair) sitting on my USB. Had already commited the Themes folder at the time, 2 years back. Not sure if he wanted this additional folder commited. But I didn't want to delete it and decided it will be better off on SVN. When we use his project, if we find we didn't need this test folder, we can remove it from svn then.

File size: 4.6 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.Utility;
18
19public class ServerInfoDialog extends JDialog
20{
21 static private Dimension SIZE = new Dimension(500, 300);
22 private String url;
23 private String mode;
24 private JPanel info_list_pane;
25 private JScrollPane info_scroll_pane;
26 private JDialog info_dialog;
27 private Download download;
28 private String proxy_url;
29
30 public ServerInfoDialog(String url, String proxy_url, String mode, Download download) {
31 super();
32 this.url = url;
33 this.mode = mode;
34 this.download = download;
35 this.proxy_url = proxy_url;
36 this.info_dialog = this;
37
38 this.setSize(SIZE);
39
40 JButton close_button = new GLIButton(Dictionary.get("General.Close"),Dictionary.get("General.Close_Tooltip"));
41 close_button.setEnabled(true);
42 close_button.addActionListener(new ActionListener() {
43 public void actionPerformed(ActionEvent event) {
44 info_dialog.dispose();
45 }
46 });
47
48 JPanel button_pane = new JPanel();
49 button_pane.setLayout(new FlowLayout());
50 button_pane.setBorder(BorderFactory.createEtchedBorder());
51 button_pane.add(close_button);
52
53 info_list_pane = new JPanel();
54 info_list_pane.setLayout(new BoxLayout(info_list_pane, BoxLayout.Y_AXIS));
55 info_list_pane.setBorder(BorderFactory.createEtchedBorder());
56 getServerInfo();
57
58 info_scroll_pane = new JScrollPane(info_list_pane);
59
60 JPanel information_pane = new JPanel();
61 information_pane.setLayout(new BorderLayout());
62 information_pane.setBorder(BorderFactory.createEtchedBorder());
63 information_pane.add(info_scroll_pane,BorderLayout.CENTER);
64
65 JPanel main_pane = new JPanel();
66 main_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
67 main_pane.setLayout(new BorderLayout());
68 main_pane.add(information_pane,BorderLayout.CENTER);
69 main_pane.add(button_pane,BorderLayout.SOUTH);
70
71 Container main_container = this.getContentPane();
72 main_container.add(main_pane);
73
74 // Show
75 Dimension screen_size = Configuration.screen_size;
76 setLocation((screen_size.width - SIZE.width) / 2, (screen_size.height - SIZE.height) / 2);
77 setVisible(true);
78
79 }
80
81 private void getServerInfo()
82 {
83 ArrayList commands = new ArrayList();
84 commands.add(Configuration.perl_path);
85 commands.add("-S");
86 commands.add(LocalGreenstone.getBinScriptDirectoryPath()+"downloadfrom.pl");
87 commands.add("-info");
88 commands.add("-download_mode");
89 commands.add(mode);
90
91 ArrayList all_arg = download.getArguments(true,false);
92 for (int i = 0; i < all_arg.size(); i++) {
93 Argument argument = (Argument) all_arg.get(i);
94
95 if(argument.isAssigned()) {
96 commands.add("-" + argument.getName());
97 if(argument.getType() != Argument.FLAG) {
98 commands.add(argument.getValue());
99 }
100 }
101 }
102
103 String[] command = (String[]) commands.toArray(new String[0]);
104 DebugStream.println("Getting server info: "+commands);
105 try {
106 String [] env = null;
107 Process prcs = null;
108 Runtime rt = Runtime.getRuntime();
109
110 if (Utility.isWindows()) {
111 prcs = rt.exec(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[4];
118 proxy_url = proxy_url.replaceAll("http://","");
119 env[0] = "http_proxy=http://"+proxy_url;
120 env[1] = "ftp_proxy=ftp://"+proxy_url;
121 env[2] = "GSDLHOME=" + Configuration.gsdl_path;
122 env[3] = "GSDLOS=" + Gatherer.client_operating_system;
123 prcs = rt.exec(command, env);
124 }
125 else {
126 // Will inherit the GLI's environment, with GSDLHOME and GSDLOS set
127 prcs = rt.exec(command);
128 }
129 }
130
131 InputStreamReader isr = new InputStreamReader(prcs.getErrorStream());
132 BufferedReader br = new BufferedReader(isr);
133 String line;
134 // Capture the standard error stream and seach for two particular occurances.
135 while ((line = br.readLine()) != null && !line.trim().equals("<<Finished>>")) {
136
137 JLabel a_label = new JLabel(line);
138 a_label.setAlignmentX(Component.LEFT_ALIGNMENT);
139 info_list_pane.add(a_label);
140 }
141
142 } catch (Exception ioe) {
143
144 }
145
146 }
147
148}
Note: See TracBrowser for help on using the repository browser.