source: trunk/gli/src/org/greenstone/gatherer/Gatherer.java@ 10610

Last change on this file since 10610 was 10575, checked in by mdewsnip, 19 years ago

Made URLField far simpler and more accurate. Removed the crazy regular expressions and now just attempts to create a URL object to validate the string.

  • Property svn:keywords set to Author Date Id Revision
File size: 34.0 KB
Line 
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 * Author: John Thompson, Greenstone Digital Library, University of Waikato
9 *
10 * Copyright (C) 1999 New Zealand Digital Library Project
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 *########################################################################
26 */
27package org.greenstone.gatherer;
28
29import java.awt.*;
30import java.awt.event.*;
31import java.io.*;
32import java.lang.*;
33import java.net.*;
34import java.util.*;
35import javax.swing.*;
36import javax.swing.plaf.*;
37import javax.swing.text.*;
38import org.greenstone.gatherer.Configuration;
39import org.greenstone.gatherer.GAuthenticator;
40import org.greenstone.gatherer.cdm.ClassifierManager;
41import org.greenstone.gatherer.cdm.PluginManager;
42import org.greenstone.gatherer.collection.CollectionManager;
43import org.greenstone.gatherer.feedback.ActionRecorderDialog;
44import org.greenstone.gatherer.file.FileManager;
45import org.greenstone.gatherer.file.FileAssociationManager;
46import org.greenstone.gatherer.gui.GUIManager;
47import org.greenstone.gatherer.gui.URLField;
48import org.greenstone.gatherer.gui.WarningDialog;
49import org.greenstone.gatherer.util.JarTools;
50import org.greenstone.gatherer.util.StaticStrings;
51import org.greenstone.gatherer.util.Utility;
52import org.greenstone.gatherer.util.ZipTools;
53
54
55/** Containing the top-level "core" for the Gatherer, this class is the
56 * common core for the GLI application and applet. It first parses the
57 * command line arguments, preparing to update the configuration as
58 * required. Next it loads several important support classes such as the
59 * Configuration and Dictionary. Finally it creates the other important
60 * managers and sends them on their way.
61 * @author John Thompson, Greenstone Digital Library, University of Waikato
62 * @version 2.3
63 */
64public class Gatherer
65{
66 static private Dimension size = new Dimension(800, 540);
67
68 /** Has the exit flag been set? */
69 static public boolean exit = false;
70
71 static private String gli_directory_path = null;
72 static private String gli_user_directory_path = null;
73
74 /** All of the external applications that must exit before we close the Gatherer. */
75 static private Vector apps = new Vector();
76 static private String non_standard_collect_directory_path = null;
77 static public String open_collection_file_path = null;
78 /** A public reference to the FileAssociationManager. */
79 static public FileAssociationManager assoc_man;
80 /** A public reference to the CollectionManager. */
81 static public CollectionManager c_man;
82 /** a reference to the Servlet Configuration is GS3 */
83 static public ServletConfiguration servlet_config;
84 /** A public reference to the FileManager. */
85 static public FileManager f_man;
86 /** A public reference to the GUIManager. */
87 static public GUIManager g_man = null;
88 static private boolean g_man_built = false;
89
90 /** We are using the GLI for GS3 */
91 static public boolean GS3 = false;
92
93 static public boolean isApplet = false;
94 static public boolean isGsdlRemote = false;
95 static public String cgiBase = null;
96
97 // feedback stuff
98 /** is the feedback feature enabled? */
99 static public boolean feedback_enabled = true;
100 /** the action recorder dialog */
101 static public ActionRecorderDialog feedback_dialog = null;
102
103 // Refresh reasons
104 static public final int COLLECTION_OPENED = 0;
105 static public final int COLLECTION_CLOSED = 1;
106 static public final int COLLECTION_REBUILT = 2;
107 static public final int PREFERENCES_CHANGED = 3;
108
109
110 /** Magic to allow Enter to fire the default button. */
111 static {
112 KeyStroke enter = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0);
113 Keymap map = JTextComponent.getKeymap(JTextComponent.DEFAULT_KEYMAP);
114 map.removeKeyStrokeBinding(enter);
115 }
116
117
118 public Gatherer(String[] args)
119 {
120 JarTools.initialise(this);
121
122 GetOpt go = new GetOpt(args);
123
124 // If feedback is enabled, set up the recorder dialog
125 if (go.feedback_enabled) {
126 // Use the default locale for now - this will be changed by the Gatherer run method
127 feedback_enabled = true;
128 feedback_dialog = new ActionRecorderDialog(Locale.getDefault());
129 }
130
131 // Are we using a remote Greenstone?
132 if (go.use_remote_greenstone) {
133 isGsdlRemote = true;
134
135 // We don't have a local Greenstone!
136 go.gsdl_path = null;
137
138 // We have to use our own collect directory since we can't use the Greenstone one
139 setCollectDirectoryPath(getGLIUserDirectoryPath() + "collect" + File.separator);
140 }
141 // No, we have a local Greenstone
142 else {
143 LocalGreenstone.setDirectoryPath(go.gsdl_path);
144 }
145
146 // Users may specify a non-standard collect directory (eg. when running one GLI in a network environment)
147 if (go.collect_directory_path != null) {
148 setCollectDirectoryPath(go.collect_directory_path);
149 }
150
151 // More special code for running with a remote Greenstone
152 if (isGsdlRemote) {
153 Configuration.TEMPLATE_CONFIG_XML = "xml/configRemote.xml";
154 Configuration.CONFIG_XML = "configRemote.xml";
155 Configuration.GS3_CONFIG_XML = "config3Remote.xml";
156
157 File collect_directory = new File(Gatherer.getCollectDirectoryPath());
158 if (!collect_directory.exists() && !collect_directory.mkdir()) {
159 System.err.println("Warning: Unable to make directory: " + collect_directory);
160 }
161
162 File plugins_dat_file = new File(getGLIUserDirectoryPath() + "plugins.dat");
163 if (!plugins_dat_file.exists()) {
164 JarTools.extractFromJar("plugins.dat", getGLIUserDirectoryPath(), false);
165 }
166
167 File classifiers_dat_file = new File(getGLIUserDirectoryPath() + "classifiers.dat");
168 if (!classifiers_dat_file.exists()) {
169 JarTools.extractFromJar("classifiers.dat", getGLIUserDirectoryPath(), false);
170 }
171 }
172
173 init(go.gsdl_path, go.gsdl3_path, go.gsdl3_src_path, go.local_library_path, go.library_url_string,
174 go.gliserver_url_string, go.debug, go.perl_path, go.no_load, go.filename, go.site_name,
175 go.servlet_path, go.wget_path);
176 }
177
178
179 public void init(String gsdl_path, String gsdl3_path, String gsdl3_src_path, String local_library_path,
180 String library_url_string, String gliserver_url_string, boolean debug_enabled,
181 String perl_path, boolean no_load, String open_collection,
182 String site_name, String servlet_path, String wget_path)
183 {
184 if (gsdl3_path != null && !gsdl3_path.equals("")) {
185 this.GS3 = true;
186 } else {
187 gsdl3_path = null;
188 gsdl3_src_path = null;
189 }
190
191 // Create the debug stream if required
192 if (debug_enabled) {
193 DebugStream.enableDebugging();
194
195 Calendar now = Calendar.getInstance();
196 String debug_file_path = "debug" + now.get(Calendar.DATE) + "-" + now.get(Calendar.MONTH) + "-" + now.get(Calendar.YEAR) + ".txt";
197
198 // Debug file is created in the user's GLI directory
199 debug_file_path = getGLIUserDirectoryPath() + debug_file_path;
200 DebugStream.println("Debug file path: " + debug_file_path);
201 DebugStream.setDebugFile(debug_file_path);
202 DebugStream.print(System.getProperties());
203 }
204
205 try {
206 // Load GLI config file
207 new Configuration(getGLIUserDirectoryPath(), gsdl_path, gsdl3_path, gsdl3_src_path, site_name);
208 if (Configuration.just_updated_config_xml_file) {
209 // Delete the plugins.dat and classifiers.dat files
210 PluginManager.clearPluginCache();
211 ClassifierManager.clearClassifierCache();
212 }
213
214 if (GS3) {
215 // Load Greenstone 3 servelt configuration
216 servlet_config = new ServletConfiguration(gsdl3_path);
217 }
218
219 // Check we know where Perl is
220 Configuration.perl_path = perl_path;
221 if (isGsdlRemote && Utility.isWindows() && Configuration.perl_path != null) {
222 if (Configuration.perl_path.toLowerCase().endsWith("perl.exe")) {
223 Configuration.perl_path = Configuration.perl_path.substring(0, Configuration.perl_path.length() - "perl.exe".length());
224 }
225 if (Configuration.perl_path.endsWith(File.separator)) {
226 Configuration.perl_path = Configuration.perl_path.substring(0, Configuration.perl_path.length() - File.separator.length());
227 }
228 }
229
230 if (GS3 && Configuration.servlet_path == null) {
231 Configuration.servlet_path = servlet_config.getServletPath(Configuration.site_name);
232 }
233
234 // the feedback dialog has been loaded with a default locale,
235 // now set the user specified one
236 if (feedback_enabled && feedback_dialog != null) {
237 feedback_dialog.setLocale(Configuration.getLocale("general.locale", true));
238 }
239
240 // Read Dictionary
241 new Dictionary(Configuration.getLocale("general.locale", true), Configuration.getFont("general.font", true));
242
243 // check that we are using Sun Java
244 String java_vendor = System.getProperty("java.vendor");
245 if (!java_vendor.equals("Sun Microsystems Inc.")) {
246 System.err.println(Dictionary.get("General.NotSunJava", java_vendor));
247 }
248
249 // Unless we're using remote building, we need to know where the local Greenstone is
250 if (!isGsdlRemote && gsdl_path == null) {
251 missingGSDL();
252 }
253
254 // Start up the local library server, if that's what we want
255 if (Utility.isWindows() && local_library_path != null && !isGsdlRemote && !GS3) {
256 LocalLibraryServer.start(gsdl_path, local_library_path);
257 }
258
259 // The "-library_url" option overwrites anything in the config files
260 if (library_url_string != null && library_url_string.length() > 0) {
261 try {
262 System.err.println("Setting library_url to " + library_url_string + "...");
263 Configuration.library_url = new URL(library_url_string);
264 }
265 catch (MalformedURLException error) {
266 DebugStream.printStackTrace(error);
267 }
268 }
269
270 // Check that we now know the Greenstone library URL, since we need this for previewing collections
271 DebugStream.println("Configuration.library_url = " + Configuration.library_url);
272 if (Configuration.library_url == null) {
273 missingEXEC();
274 }
275
276 // The "-gliserver_url" option overwrites anything in the config files
277 if (gliserver_url_string != null && gliserver_url_string.length() > 0) {
278 try {
279 System.err.println("Setting gliserver_url to " + gliserver_url_string + "...");
280 Configuration.gliserver_url = new URL(gliserver_url_string);
281 }
282 catch (MalformedURLException error) {
283 DebugStream.printStackTrace(error);
284 }
285 }
286
287 // If we're using a remote Greenstone we need to know where the gliserver script is
288 DebugStream.println("Configuration.gliserver_url = " + Configuration.gliserver_url);
289 if (isGsdlRemote) {
290 if (Configuration.gliserver_url == null) {
291 missingGLIServer();
292 }
293 if (Configuration.gliserver_url != null) {
294 gliserver_url_string = Configuration.gliserver_url.toString();
295 cgiBase = gliserver_url_string.substring(0, gliserver_url_string.lastIndexOf('/') + 1);
296 }
297 }
298
299 // Check for ImageMagick
300 if (Gatherer.isGsdlRemote) {
301 DebugStream.println("Not checking for ImageMagick.");
302 }
303 else if (!(new ImageMagickTest()).found()) {
304 // Time for a warning message
305 missingImageMagick();
306 }
307
308 if (Gatherer.isGsdlRemote) {
309 DebugStream.println("Not checking for perl path/exe");
310 }
311 else {
312 // Perl path is a little different as it is perfectly ok to
313 // start the GLI without providing a perl path
314 boolean found_perl = false;
315 if (Configuration.perl_path != null) {
316 // See if the file pointed to actually exists
317 File perl_file = new File(Configuration.perl_path);
318 found_perl = perl_file.exists();
319 perl_file = null;
320 }
321 if (Configuration.perl_path == null || !found_perl) {
322 // Run test to see if we can run perl as is.
323 PerlTest perl_test = new PerlTest();
324 if (perl_test.found()) {
325 // If so replace the perl path with the system
326 // default (or null for unix).
327 Configuration.perl_path = perl_test.toString();
328 found_perl = true;
329 }
330 }
331 if (!found_perl) {
332 // Time for an error message.
333 missingPERL();
334 }
335 }
336
337 boolean download_workflow = Configuration.get("workflow.download", false);
338 if (download_workflow) {
339 // If the WGet path hasn't been specified by the user, try the Greenstone one
340 if (wget_path == null) {
341 String wget_file_path = gsdl_path + "bin" + File.separator;
342 if (Utility.isWindows()) {
343 wget_file_path += "windows" + File.separator + "wget.exe";
344 }
345 else if (Utility.isMac()) {
346 wget_file_path += "darwin" + File.separator + "wget";
347 }
348 else {
349 wget_file_path += "linux" + File.separator + "wget";
350 }
351 if (new File(wget_file_path).exists()) {
352 wget_path = wget_file_path;
353 }
354 }
355
356 // If we still don't have a WGet path, give up (there isn't anything else we can do)
357 String wget_version_str = null;
358 if (wget_path == null) {
359 wget_version_str = StaticStrings.NO_WGET_STR;
360 missingWGET();
361 }
362 // Otherwise check the version of WGet
363 else {
364 wget_version_str = testWGetVersion(wget_path);
365 if (wget_version_str.equals(StaticStrings.WGET_OLD_STR)) {
366 oldWGET();
367 }
368 }
369
370 // Store the new values in the configuration
371 DebugStream.println("WGet path: " + wget_path);
372 Configuration.setWGetPath(wget_path);
373 Configuration.setWGetVersion(wget_version_str);
374 }
375
376 // Set the default font for all Swing components.
377 FontUIResource default_font = Configuration.getFont("general.font", true);
378 Enumeration keys = UIManager.getDefaults().keys();
379 while (keys.hasMoreElements()) {
380 Object key = keys.nextElement();
381 Object value = UIManager.get(key);
382 if (value instanceof FontUIResource) {
383 UIManager.put(key, default_font);
384 }
385 }
386
387 // Set up proxy
388 setProxy();
389 // Now we set up an Authenticator
390 Authenticator.setDefault(new GAuthenticator());
391
392 assoc_man = new FileAssociationManager();
393 // Create File Manager
394 f_man = new FileManager();
395 // Create Collection Manager
396 c_man = new CollectionManager();
397
398 if (GS3) {
399 if (site_name==null) {
400 site_name = Configuration.site_name;
401 servlet_path = null; // need to reset this
402 }
403 if (servlet_path == null) {
404 servlet_path = Configuration.getServletPath();
405 }
406 }
407
408 open_collection_file_path = open_collection;
409 if (open_collection_file_path == null) {
410 open_collection_file_path = Configuration.getString("general.open_collection", true);
411 }
412 if (no_load || open_collection_file_path.equals("")) {
413 open_collection_file_path = null;
414 }
415 }
416 catch (Exception exception) {
417 DebugStream.printStackTrace(exception);
418 }
419
420 // Create GUI Manager (last) or else suffer the death of a thousand NPE's
421 g_man = new GUIManager(size);
422 }
423
424
425 public void openGUI()
426 {
427 // Size and place the frame on the screen
428 Rectangle bounds = Configuration.getBounds("general.bounds", true);
429 if (bounds == null) {
430 // Choose a sensible default value
431 bounds = new Rectangle(0, 0, 640, 480);
432 }
433
434 // Ensure width and height are reasonable
435 size = bounds.getSize();
436 if (size.width < 640) {
437 size.width = 640;
438 }
439 else if (size.width > Configuration.screen_size.width) {
440 size.width = Configuration.screen_size.width;
441 }
442 if (size.height < 480) {
443 size.height = 480;
444 }
445 else if (size.height > Configuration.screen_size.height) {
446 size.height = Configuration.screen_size.height;
447 }
448
449 if (!g_man_built) {
450
451 g_man.display();
452
453 // Place the window in the desired location on the screen, if this is do-able (not under most linux window managers apparently. In fact you're lucky if they listen to any of your screen size requests).
454 g_man.setLocation(bounds.x, bounds.y);
455 g_man.setVisible(true);
456
457 // After the window has been made visible, check that it is in the correct place
458 // sometimes java places a window not in the correct place,
459 // but with an offset. If so, we work out what the offset is
460 // and change the desired location to take that into account
461 Point location = g_man.getLocation();
462 int x_offset = bounds.x - location.x;
463 int y_offset = bounds.y - location.y;
464 // If not, offset the window to move it into the correct location
465 if (x_offset > 0 || y_offset > 0) {
466 ///ystem.err.println("changing the location to "+(bounds.x + x_offset)+" "+ (bounds.y + y_offset));
467 g_man.setLocation(bounds.x + x_offset, bounds.y + y_offset);
468 }
469
470 // The 'after-display' triggers several events which don't occur until after the visual components are actually available on screen. Examples of these would be the various html renderings, as they can't happen offscreen.
471 g_man.afterDisplay();
472 g_man_built = true;
473 }
474 else {
475 g_man.setVisible(true);
476 }
477 }
478
479
480 /** Exits the Gatherer after ensuring that things needing saving are saved.
481 * @see java.io.FileOutputStream
482 * @see java.io.PrintStream
483 * @see java.lang.Exception
484 * @see javax.swing.JOptionPane
485 * @see org.greenstone.gatherer.Configuration
486 * @see org.greenstone.gatherer.collection.CollectionManager
487 * @see org.greenstone.gatherer.gui.GUIManager
488 */
489 static public void exit()
490 {
491 System.err.println("In Gatherer.exit()...");
492 exit = true;
493
494 // Save the file associations
495 if (assoc_man != null) {
496 assoc_man.save();
497 assoc_man = null;
498 }
499
500 // Get the gui to deallocate
501 g_man.destroy();
502 g_man_built = false;
503
504 // Flush debug
505 DebugStream.closeDebugStream();
506
507 // If we started a server, we should try to stop it.
508 if (LocalLibraryServer.isRunning() == true) {
509 LocalLibraryServer.stop();
510 }
511
512 // Make sure we haven't started up any processes that are still running
513 if (apps.size() == 0) {
514 // If we're running as an applet we don't actually quit (just hide the main GLI window)
515 if (!Gatherer.isApplet) {
516 // This is the end...
517 System.exit(0);
518 }
519 }
520 else {
521 JOptionPane.showMessageDialog(g_man, Dictionary.get("General.Outstanding_Processes"), Dictionary.get("General.Outstanding_Processes_Title"), JOptionPane.ERROR_MESSAGE);
522 g_man.setVisible(false);
523 }
524 }
525
526
527 /** Returns the path of the Greenstone "collect" directory. */
528 static public String getCollectDirectoryPath()
529 {
530 if (non_standard_collect_directory_path != null) {
531 return non_standard_collect_directory_path;
532 }
533
534 if (!GS3) {
535 return Configuration.gsdl_path + "collect" + File.separator;
536 }
537 else {
538 return getSitesDirectoryPath() + Configuration.site_name + File.separator + "collect" + File.separator;
539 }
540 }
541
542
543 /** Returns the path of the GLI directory. */
544 static public String getGLIDirectoryPath()
545 {
546 return gli_directory_path;
547 }
548
549
550 /** Returns the path of the GLI "metadata" directory. */
551 static public String getGLIMetadataDirectoryPath()
552 {
553 return getGLIDirectoryPath() + "metadata" + File.separator;
554 }
555
556
557 /** Returns the path of the GLI user directory. */
558 static public String getGLIUserDirectoryPath()
559 {
560 return gli_user_directory_path;
561 }
562
563
564 /** Returns the path of the GLI user "cache" directory. */
565 static public String getGLIUserCacheDirectoryPath()
566 {
567 return getGLIUserDirectoryPath() + "cache" + File.separator;
568 }
569
570
571 /** Returns the path of the GLI user "log" directory. */
572 static public String getGLIUserLogDirectoryPath()
573 {
574 return getGLIUserDirectoryPath() + "log" + File.separator;
575 }
576
577
578 static public String getSitesDirectoryPath()
579 {
580 return Configuration.gsdl3_path + "sites" + File.separator;
581 }
582
583
584 static public void setCollectDirectoryPath(String collect_directory_path)
585 {
586 non_standard_collect_directory_path = collect_directory_path;
587 if (!non_standard_collect_directory_path.endsWith(File.separator)) {
588 non_standard_collect_directory_path = non_standard_collect_directory_path + File.separator;
589 }
590 }
591
592
593 static public void setGLIDirectoryPath(String gli_directory_path_arg)
594 {
595 gli_directory_path = gli_directory_path_arg;
596 }
597
598
599 static public void setGLIUserDirectoryPath(String gli_user_directory_path_arg)
600 {
601 gli_user_directory_path = gli_user_directory_path_arg;
602
603 // Ensure the GLI user directory exists
604 File gli_user_directory = new File(gli_user_directory_path);
605 if (!gli_user_directory.exists() && !gli_user_directory.mkdirs()) {
606 System.err.println("Error: Unable to make directory: " + gli_user_directory);
607 }
608 }
609
610
611 static public void refresh(int refresh_reason)
612 {
613 if (g_man != null) {
614 g_man.refresh(refresh_reason, c_man.ready());
615 }
616
617 // Now is a good time to force a garbage collect
618 System.gc();
619 }
620
621
622 // used to send reload coll messages to the tomcat server
623 static public void configGS3Server(String site, String command) {
624
625 try {
626 // need to add the servlet name to the exec address
627 String raw_url = Configuration.library_url.toString() + Configuration.getServletPath() + command;
628 URL url = new URL(raw_url);
629 DebugStream.println("Action: " + raw_url);
630 HttpURLConnection library_connection = (HttpURLConnection) url.openConnection();
631 int response_code = library_connection.getResponseCode();
632 if(HttpURLConnection.HTTP_OK <= response_code && response_code < HttpURLConnection.HTTP_MULT_CHOICE) {
633 DebugStream.println("200 - Complete.");
634 }
635 else {
636 DebugStream.println("404 - Failed.");
637 }
638 url = null;
639 }
640 catch (Exception exception) {
641 DebugStream.printStackTrace(exception);
642 }
643 }
644
645
646 /** Used to 'spawn' a new child application when a file is double clicked.
647 * @param file The file to open
648 * @see org.greenstone.gatherer.Gatherer.ExternalApplication
649 */
650 static public void spawnApplication(File file) {
651 String [] commands = assoc_man.getCommand(file);
652 if(commands != null) {
653 ExternalApplication app = new ExternalApplication(commands);
654 apps.add(app);
655 app.start();
656 }
657 else {
658 ///ystem.err.println("No open command available.");
659 }
660 }
661
662
663 static public void spawnApplication(String command)
664 {
665 ExternalApplication app = new ExternalApplication(command);
666 apps.add(app);
667 app.start();
668 }
669
670
671 /** Used to 'spawn' a new browser application or reset an existing one when the preview button is clicked
672 * @param url The url to open the browser at
673 * @see org.greenstone.gatherer.Gatherer.BrowserApplication
674 */
675 static public void spawnBrowser(String url) {
676 String command = assoc_man.getBrowserCommand(url);
677 if (command != null) {
678 BrowserApplication app = new BrowserApplication(command, url);
679 apps.add(app);
680 app.start();
681 }
682 else {
683 ///ystem.err.println("No browser command available.");
684 }
685 }
686
687
688 /** Prints a warning message about a missing library path, which means the final collection cannot be previewed in the Gatherer.
689 */
690 static private void missingEXEC() {
691 WarningDialog dialog;
692 if (GS3) {
693 dialog = new WarningDialog("warning.MissingEXEC_GS3", "MissingEXEC_GS3.Title", Dictionary.get("MissingEXEC_GS3.Message"), "general.library_url", false);
694 }
695 else {
696 dialog = new WarningDialog("warning.MissingEXEC", "MissingEXEC.Title", Dictionary.get("MissingEXEC.Message"), "general.library_url", false);
697 }
698 dialog.setValueField(new URLField(Configuration.getColor("coloring.editable_foreground", false), Configuration.getColor("coloring.editable_background", false)));
699 dialog.display();
700 dialog.dispose();
701 dialog = null;
702
703 String library_url_string = Configuration.getString("general.library_url", true);
704 if (!library_url_string.equals("")) {
705 try {
706 Configuration.library_url = new URL(library_url_string);
707 }
708 catch (MalformedURLException exception) {
709 DebugStream.printStackTrace(exception);
710 }
711 }
712 }
713
714
715 static private void missingGLIServer()
716 {
717 WarningDialog dialog = new WarningDialog("warning.MissingGLIServer", "MissingGLIServer.Title", Dictionary.get("MissingGLIServer.Message"), "general.gliserver_url", false);
718 dialog.setValueField(new URLField(Configuration.getColor("coloring.editable_foreground", false), Configuration.getColor("coloring.editable_background", false)));
719 dialog.display();
720 dialog.dispose();
721 dialog = null;
722
723 String gliserver_url_string = Configuration.getString("general.gliserver_url", true);
724 if (!gliserver_url_string.equals("")) {
725 try {
726 Configuration.gliserver_url = new URL(gliserver_url_string);
727 }
728 catch (MalformedURLException exception) {
729 DebugStream.printStackTrace(exception);
730 }
731 }
732 }
733
734
735 /** Prints a warning message about a missing GSDL path, which although not fatal pretty much ensures nothing will work properly in the GLI.
736 */
737 static private void missingGSDL() {
738 WarningDialog dialog = new WarningDialog("warning.MissingGSDL", "MissingGSDL.Title", Dictionary.get("MissingGSDL.Message"), null, false);
739 dialog.display();
740 dialog.dispose();
741 dialog = null;
742 }
743
744 /** Prints a warning message about missing a valid ImageMagick path, which although not fatal means building image collections won't work */
745 static private void missingImageMagick() {
746 WarningDialog dialog = new WarningDialog("warning.MissingImageMagick", "MissingImageMagick.Title", Dictionary.get("MissingImageMagick.Message"), null, false);
747 dialog.display();
748 dialog.dispose();
749 dialog = null;
750 }
751
752 /** Prints a warning message about missing a valid PERL path, which although not fatal pretty much ensures no collection creation/building will work properly in the GLI. */
753 static private void missingPERL() {
754 WarningDialog dialog = new WarningDialog("warning.MissingPERL", "MissingPERL.Title", Dictionary.get("MissingPERL.Message"), null, false);
755 dialog.display();
756 dialog.dispose();
757 dialog = null;
758 }
759
760 /** Prints a warning message about missing a valid WGet path, which although not fatal means mirroring won't work */
761 static public void missingWGET() {
762 WarningDialog dialog = new WarningDialog("warning.MissingWGET", "MissingWGET.Title", Dictionary.get("MissingWGET.Message"), null, false);
763 dialog.display();
764 dialog.dispose();
765 dialog = null;
766 }
767
768 /** Prints a warning message about having an old version of WGet. not fatal, but mirroring may not work properly */
769 static public void oldWGET() {
770 WarningDialog dialog = new WarningDialog("warning.OldWGET", "OldWGET.Title", Dictionary.get("OldWGET.Message"), null, false);
771 dialog.display();
772 dialog.dispose();
773 dialog = null;
774 }
775
776
777 /** Sets up the proxy connection by setting JVM Environment flags and creating a new Authenticator.
778 * @see java.lang.Exception
779 * @see java.lang.System
780 * @see java.net.Authenticator
781 * @see org.greenstone.gatherer.Configuration
782 * @see org.greenstone.gatherer.GAuthenticator
783 */
784 static public void setProxy() {
785 try {// Can throw several exceptions
786 if(Configuration.get("general.use_proxy", true)) {
787 System.setProperty("http.proxyType", "4");
788 System.setProperty("http.proxyHost", Configuration.getString("general.proxy_host", true));
789 System.setProperty("http.proxyPort", Configuration.getString("general.proxy_port", true));
790 System.setProperty("http.proxySet", "true");
791 } else {
792 System.setProperty("http.proxySet", "false");
793 }
794 } catch (Exception error) {
795 DebugStream.println("Error in Gatherer.initProxy(): " + error);
796 DebugStream.printStackTrace(error);
797 }
798 }
799
800
801 // TODO fill this in
802 private String testWGetVersion(String wget_path) {
803 return StaticStrings.WGET_STR;
804 }
805
806 /** This private class contains an instance of an external application running within a JVM shell. It is important that this process sits in its own thread, but its more important that when we exit the Gatherer we don't actually System.exit(0) the Gatherer object until the user has volunteerily ended all of these child processes. Otherwise when we quit the Gatherer any changes the users may have made in external programs will be lost and the child processes are automatically deallocated. */
807 static private class ExternalApplication
808 extends Thread {
809 private Process process = null;
810 /** The initial command string given to this sub-process. */
811 private String command = null;
812 private String[] commands = null;
813 /** Constructor.
814 * @param command The initial command <strong>String</strong>.
815 */
816 public ExternalApplication(String command) {
817 this.command = command;
818 }
819
820 public ExternalApplication(String[] commands) {
821 this.commands = commands;
822 }
823 /** We start the child process inside a new thread so it doesn't block the rest of Gatherer.
824 * @see java.lang.Exception
825 * @see java.lang.Process
826 * @see java.lang.Runtime
827 * @see java.lang.System
828 * @see java.util.Vector
829 */
830 public void run() {
831 // Call an external process using the args.
832 try {
833 if(commands != null) {
834 StringBuffer whole_command = new StringBuffer();
835 for(int i = 0; i < commands.length; i++) {
836 whole_command.append(commands[i]);
837 whole_command.append(" ");
838 }
839 DebugStream.println("Running " + whole_command.toString());
840 Runtime rt = Runtime.getRuntime();
841 process = rt.exec(commands);
842 process.waitFor();
843 }
844 else {
845 DebugStream.println("Running " + command);
846 Runtime rt = Runtime.getRuntime();
847 process = rt.exec(command);
848 process.waitFor();
849 }
850 }
851 catch (Exception exception) {
852 DebugStream.printStackTrace(exception);
853 }
854 // Remove ourself from Gatherer list of threads.
855 apps.remove(this);
856 // Call exit if we were the last outstanding child process thread.
857 if (apps.size() == 0 && exit == true) {
858 System.exit(0);
859 }
860 }
861 public void stopExternalApplication() {
862 if(process != null) {
863 process.destroy();
864 }
865 }
866 }
867 /** This private class contains an instance of an external application running within a JVM shell. It is important that this process sits in its own thread, but its more important that when we exit the Gatherer we don't actually System.exit(0) the Gatherer object until the user has volunteerily ended all of these child processes. Otherwise when we quit the Gatherer any changes the users may have made in external programs will be lost and the child processes are automatically deallocated. */
868 static private class BrowserApplication
869 extends Thread {
870 private Process process = null;
871 /** The initial command string given to this sub-process. */
872 private String command = null;
873 private String url = null;
874 private String[] commands = null;
875
876 public BrowserApplication(String command, String url) {
877 StringTokenizer st = new StringTokenizer(command);
878 int num_tokens = st.countTokens();
879 this.commands = new String [num_tokens];
880 int i=0;
881 while (st.hasMoreTokens()) {
882 commands[i] = st.nextToken();
883 i++;
884 }
885 //this.commands = commands;
886 this.url = url;
887 }
888 /** We start the child process inside a new thread so it doesn't block the rest of Gatherer.
889 * @see java.lang.Exception
890 * @see java.lang.Process
891 * @see java.lang.Runtime
892 * @see java.lang.System
893 * @see java.util.Vector
894 */
895 public void run() {
896 // Call an external process using the args.
897 if(commands == null) {
898 apps.remove(this);
899 return;
900 }
901 try {
902 String prog_name = commands[0];
903 String lower_name = prog_name.toLowerCase();
904 if (lower_name.indexOf("mozilla") != -1 || lower_name.indexOf("netscape") != -1) {
905 DebugStream.println("found mozilla or netscape, trying remote it");
906 // mozilla and netscape, try using a remote command to get things in the same window
907 String [] new_commands = new String[] {prog_name, "-raise", "-remote", "openURL("+url+",new-tab)"};
908 printArray(new_commands);
909
910 Runtime rt = Runtime.getRuntime();
911 process = rt.exec(new_commands);
912 int exitCode = process.waitFor();
913 if (exitCode != 0) { // if Netscape or mozilla was not open
914 DebugStream.println("couldn't do remote, trying original command");
915 printArray(commands);
916 process = rt.exec(commands); // try the original command
917 }
918 } else {
919 // just run what we have been given
920 StringBuffer whole_command = new StringBuffer();
921 for(int i = 0; i < commands.length; i++) {
922 whole_command.append(commands[i]);
923 whole_command.append(" ");
924 }
925 DebugStream.println("Running " + whole_command.toString());
926 Runtime rt = Runtime.getRuntime();
927 process = rt.exec(commands);
928 process.waitFor();
929 }
930 }
931
932 catch (Exception exception) {
933 DebugStream.printStackTrace(exception);
934 }
935 // Remove ourself from Gatherer list of threads.
936 apps.remove(this);
937 // Call exit if we were the last outstanding child process thread.
938 if (apps.size() == 0 && exit == true) {
939 System.exit(0);
940 }
941 }
942 public void printArray(String [] array) {
943 for(int i = 0; i < array.length; i++) {
944 DebugStream.print(array[i]+" ");
945 System.err.println(array[i]+" ");
946 }
947 }
948 public void stopBrowserApplication() {
949 if(process != null) {
950 process.destroy();
951 }
952 }
953 }
954
955
956 private class ImageMagickTest
957 {
958 public boolean found()
959 {
960 try {
961 String[] command = new String[2];
962 command[0] = (Utility.isWindows() ? "identify.exe" : "identify");
963 command[1] = "-version";
964 Process image_magick_process = Runtime.getRuntime().exec(command);
965 image_magick_process.waitFor();
966 return (image_magick_process.exitValue() == 0);
967 }
968 catch (Exception exception) {
969 return false;
970 }
971 }
972 }
973
974
975 private class PerlTest
976 {
977 private String[] command = new String[2];
978
979 public PerlTest()
980 {
981 command[0] = (Utility.isWindows() ? Utility.PERL_EXECUTABLE_WINDOWS : Utility.PERL_EXECUTABLE_UNIX);
982 command[1] = "-version";
983 }
984
985 public boolean found()
986 {
987 try {
988 Process perl_process = Runtime.getRuntime().exec(command);
989 perl_process.waitFor();
990 return (perl_process.exitValue() == 0);
991 }
992 catch (Exception exception) {
993 return false;
994 }
995 }
996
997 public String toString() {
998 return command[0];
999 }
1000 }
1001}
Note: See TracBrowser for help on using the repository browser.