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

Last change on this file since 13594 was 13594, checked in by mdewsnip, 17 years ago

Moved the LocalGreenstone class into the "greenstone" package.

  • Property svn:keywords set to Author Date Id Revision
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 if (Utility.isWindows()) {
85 commands.add(Configuration.perl_path);
86 commands.add("-S");
87 }
88 commands.add(LocalGreenstone.getBinScriptDirectoryPath()+"downloadfrom.pl");
89 commands.add("-info");
90 commands.add("-download_mode");
91 commands.add(mode);
92
93 ArrayList all_arg = download.getArguments(true,false);
94 for (int i = 0; i < all_arg.size(); i++) {
95 Argument argument = (Argument) all_arg.get(i);
96
97 if(argument.isAssigned()) {
98 commands.add("-" + argument.getName());
99 if(argument.getType() != Argument.FLAG) {
100 commands.add(argument.getValue());
101 }
102 }
103 }
104
105 String[] command = (String[]) commands.toArray(new String[0]);
106 DebugStream.println("Getting server info: "+commands);
107 try {
108 String [] env = null;
109 Process prcs = null;
110 Runtime rt = Runtime.getRuntime();
111
112 if (Utility.isWindows()) {
113 prcs = rt.exec(command);
114 }
115 else {
116 if (proxy_url != null && !proxy_url.equals("")) {
117 // Specify proxies as environment variables
118 // Need to manually specify GSDLHOME and GSDLOS also
119 env = new String[4];
120 proxy_url = proxy_url.replaceAll("http://","");
121 env[0] = "http_proxy=http://"+proxy_url;
122 env[1] = "ftp_proxy=ftp://"+proxy_url;
123 env[2] = "GSDLHOME=" + Configuration.gsdl_path;
124 env[3] = "GSDLOS=" + Gatherer.client_operating_system;
125 prcs = rt.exec(command, env);
126 }
127 else {
128 // Will inherit the GLI's environment, with GSDLHOME and GSDLOS set
129 prcs = rt.exec(command);
130 }
131 }
132
133 InputStreamReader isr = new InputStreamReader(prcs.getErrorStream());
134 BufferedReader br = new BufferedReader(isr);
135 String line;
136 // Capture the standard error stream and seach for two particular occurances.
137 while ((line = br.readLine()) != null && !line.trim().equals("<<Finished>>")) {
138
139 JLabel a_label = new JLabel(line);
140 a_label.setAlignmentX(Component.LEFT_ALIGNMENT);
141 info_list_pane.add(a_label);
142 }
143
144 } catch (Exception ioe) {
145
146 }
147
148 }
149
150}
Note: See TracBrowser for help on using the repository browser.