- Timestamp:
- 2009-01-12T11:19:54+13:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
gli/branches/rtl-gli/src/org/greenstone/gatherer/Gatherer.java
r14605 r18363 36 36 import javax.swing.plaf.*; 37 37 import javax.swing.text.*; 38 39 38 40 import org.greenstone.gatherer.Configuration; 39 41 import org.greenstone.gatherer.GAuthenticator; 42 import org.greenstone.gatherer.FedoraInfo; 40 43 import org.greenstone.gatherer.collection.CollectionManager; 41 44 import org.greenstone.gatherer.feedback.ActionRecorderDialog; … … 51 54 import org.greenstone.gatherer.gui.URLField; 52 55 import org.greenstone.gatherer.gui.WarningDialog; 56 import org.greenstone.gatherer.gui.FedoraLogin; 53 57 import org.greenstone.gatherer.remote.RemoteGreenstoneServer; 54 58 import org.greenstone.gatherer.util.JarTools; … … 74 78 * in a line which maches this java regex: 75 79 * ^(.*)String\s*PROGRAM_VERSION\s*=\s*"trunk"; 76 * If change the d aclaration and it no longer matches the regex, please80 * If change the declaration and it no longer matches the regex, please 77 81 * change the regex in the gs3-release-maker code and in this message 78 82 */ 83 79 84 static final public String PROGRAM_VERSION = "trunk"; 80 85 81 86 static private Dimension size = new Dimension(800, 540); 87 static public RemoteGreenstoneServer remoteGreenstoneServer = null; 82 88 83 89 /** Has the exit flag been set? */ … … 165 171 // We don't have a local Greenstone! 166 172 go.gsdl_path = null; 173 go.gsdl3_path=null; 174 go.gsdl3_src_path=null; 167 175 168 176 // We have to use our own collect directory since we can't use the Greenstone one 169 177 setCollectDirectoryPath(getGLIUserDirectoryPath() + "collect" + File.separator); 170 if (go.run_gsdl3){171 GS3=true;172 go.gsdl3_path=null;173 go.gsdl3_src_path=null;174 }175 178 } 176 179 // No, we have a local Greenstone … … 186 189 // More special code for running with a remote Greenstone 187 190 if (isGsdlRemote) { 188 Configuration.TEMPLATE_CONFIG_XML = "xml/configRemote.xml"; 189 if (!go.run_gsdl3){ 190 Configuration.CONFIG_XML = "configRemote.xml"; 191 }else{ 192 Configuration.GS3_CONFIG_XML = "config3Remote.xml"; 193 } 191 if (go.fedora_info.isActive()) { 192 Configuration.TEMPLATE_CONFIG_XML = "xml/" + Configuration.FEDORA_CONFIG_PREFIX + "configRemote.xml"; 193 } 194 else { 195 Configuration.TEMPLATE_CONFIG_XML = "xml/configRemote.xml"; 196 } 197 198 Configuration.CONFIG_XML = "configRemote.xml"; 194 199 195 200 File collect_directory = new File(Gatherer.getCollectDirectoryPath()); … … 198 203 } 199 204 } 200 201 init(go.gsdl_path, go.gsdl3_path, go.gsdl3_src_path, go.local_library_path, go.library_url_string, 205 else { 206 if (go.fedora_info.isActive()) { 207 Configuration.TEMPLATE_CONFIG_XML = "xml/" + Configuration.FEDORA_CONFIG_PREFIX + Configuration.CONFIG_XML; 208 } 209 // else, the CONFIG_XML uses the default config file, which is for the local GS server 210 } 211 212 init(go.gsdl_path, go.gsdl3_path, go.gsdl3_src_path, 213 go.fedora_info, 214 go.local_library_path, go.library_url_string, 202 215 go.gliserver_url_string, go.debug, go.perl_path, go.no_load, go.filename, go.site_name, 203 216 go.servlet_path); … … 205 218 206 219 207 public void init(String gsdl_path, String gsdl3_path, String gsdl3_src_path, String local_library_path, 220 public void init(String gsdl_path, String gsdl3_path, String gsdl3_src_path, 221 FedoraInfo fedora_info, 222 String local_library_path, 208 223 String library_url_string, String gliserver_url_string, boolean debug_enabled, 209 224 String perl_path, boolean no_load, String open_collection, … … 245 260 try { 246 261 // Load GLI config file 247 new Configuration(getGLIUserDirectoryPath(), gsdl_path, gsdl3_path, gsdl3_src_path, site_name); 248 262 new Configuration(getGLIUserDirectoryPath(), gsdl_path, gsdl3_path, gsdl3_src_path, site_name, 263 fedora_info); 264 249 265 // Check we know where Perl is 250 266 Configuration.perl_path = perl_path; … … 278 294 } 279 295 280 // Start up the local library server, if that's what we want 281 if (Utility.isWindows() && local_library_path != null && !isGsdlRemote && !GS3) { 282 LocalLibraryServer.start(gsdl_path, local_library_path); 283 } 284 296 if (fedora_info.isActive()) { 297 popupFedoraInfo(); 298 } 299 300 // Finally, we're ready to find out the version of the remote Greenstone server 301 if(isGsdlRemote) { 302 // instantiate the RemoteGreenstoneServer object first 303 remoteGreenstoneServer = new RemoteGreenstoneServer(); 304 305 int greenstoneVersion = 2; 306 requestGLIServerURL(); 307 gliserver_url_string = Configuration.gliserver_url.toString(); 308 309 greenstoneVersion = remoteGreenstoneServer.getGreenstoneVersion(); 310 // Display the version to make error reports a lot more useful 311 System.err.println("Remote Greenstone server version: " + greenstoneVersion); 312 if(greenstoneVersion >= 3) { 313 this.GS3 = true; 314 Configuration.prepareForGS3(); 315 } 316 317 if(fedora_info.isActive()) { 318 // when GS server is remote, FEDORA_HOME resides on the remote server side, 319 // but we know the library URL from user-provided information 320 library_url_string = fedora_info.getLibraryURL(); 321 } else { 322 library_url_string = remoteGreenstoneServer.getLibraryURL(Configuration.gliserver_url.toString()); 323 } 324 } 325 else { // local greenstone: Start up the local library server, if that's what we want 326 if (Utility.isWindows() && local_library_path != null && !GS3) { 327 LocalLibraryServer.start(gsdl_path, local_library_path); 328 } 329 } 330 285 331 // The "-library_url" option overwrites anything in the config files 286 332 if (library_url_string != null && library_url_string.length() > 0) { … … 293 339 } 294 340 } 341 295 342 296 343 // Check that we now know the Greenstone library URL, since we need this for previewing collections … … 298 345 if (Configuration.library_url == null) { 299 346 missingEXEC(); 300 if ((Configuration.library_url!=null) && isGsdlRemote && (gliserver_url_string==null)){301 if (GS3){302 default_gliserver_url = new URL(Configuration.library_url.toString() + "/cgi-bin/gliserver4gs3.pl");303 }else{304 default_gliserver_url = new URL(Configuration.library_url.toString().substring(0,Configuration.library_url.toString().lastIndexOf("/library")) + "/gliserver.pl");305 }306 missingGLIServer();307 }308 347 } 309 348 … … 321 360 // If we're using a remote Greenstone we need to know where the gliserver script is 322 361 DebugStream.println("Configuration.gliserver_url = " + Configuration.gliserver_url); 323 if (isGsdlRemote) {324 if (Configuration.gliserver_url == null) {325 if (Configuration.library_url != null) {326 if (GS3){327 default_gliserver_url = new URL(Configuration.library_url.toString() + "/cgi-bin/gliserver4gs3.pl");328 }else{329 default_gliserver_url = new URL(Configuration.library_url.toString().substring(0,Configuration.library_url.toString().lastIndexOf("/library")) + "/gliserver.pl");330 }331 }332 missingGLIServer();333 }334 if (Configuration.gliserver_url != null) {335 gliserver_url_string = Configuration.gliserver_url.toString();336 }337 }338 362 339 363 if (GS3) { … … 348 372 if (GS3 && Configuration.servlet_path == null) { 349 373 Configuration.servlet_path = servlet_config.getServletPath(Configuration.site_name); 374 } 375 376 // ensure that a directory called 'cache' exists in the GLI user directory 377 File user_cache_dir = new File(Gatherer.getGLIUserCacheDirectoryPath()); 378 System.err.println("User cache dir: " + Gatherer.getGLIUserCacheDirectoryPath()); 379 if (!user_cache_dir.exists() && !user_cache_dir.mkdir()) { 380 System.err.println("Warning: Unable to make directory: " + user_cache_dir); 350 381 } 351 382 … … 424 455 open_collection_file_path = open_collection; 425 456 if (open_collection_file_path == null) { 426 open_collection_file_path = Configuration.getString("general.open_collection", true); 457 open_collection_file_path = Configuration.getString( 458 "general.open_collection"+Configuration.gliPropertyNameSuffix(), true); 427 459 } 428 460 if (no_load || open_collection_file_path.equals("")) { … … 434 466 } 435 467 468 436 469 // Create GUI Manager (last) or else suffer the death of a thousand NPE's 437 470 g_man = new GUIManager(size); … … 443 476 // If using a remote Greenstone we need to download the collection configurations now 444 477 if (Gatherer.isGsdlRemote) { 445 if ( RemoteGreenstoneServer.downloadCollectionConfigurations().equals("")) {478 if (remoteGreenstoneServer.downloadCollectionConfigurations().equals("")) { 446 479 // !! Something went wrong downloading the collection configurations 447 480 System.err.println("Error: Could not download collection configurations."); 448 System.exit(0); 449 } 450 } 451 452 } 481 if(!Gatherer.isApplet) { // don't close the browser if it is an applet! 482 System.exit(0); 483 } 484 } 485 } 486 } 487 488 489 /** Returns the correct version of the (local or remote) Greenstone server if init() has already been called. */ 490 public static int serverVersionNumber() { 491 return GS3 ? 3 : 2; 492 } 493 494 /** Returns "Server: version number" if init() has already been called. */ 495 public static String getServerVersionAsString() { 496 return "Server: v" + serverVersionNumber(); 497 } 453 498 454 499 public void openGUI() … … 511 556 // If using a remote Greenstone we need to download the collection configurations now 512 557 if (Gatherer.isGsdlRemote) { 513 if ( RemoteGreenstoneServer.downloadCollectionConfigurations().equals("")) {558 if (remoteGreenstoneServer.downloadCollectionConfigurations().equals("")) { 514 559 // !! Something went wrong downloading the collection configurations 515 560 System.err.println("Error: Could not download collection configurations."); … … 561 606 562 607 // Get the gui to deallocate 563 g_man.destroy(); 564 g_man_built = false; 608 if(g_man != null) { 609 g_man.destroy(); 610 g_man_built = false; 611 } 565 612 566 613 // Flush debug … … 574 621 // If we're using a remote Greenstone server we need to make sure that all jobs have completed first 575 622 if (isGsdlRemote) { 576 RemoteGreenstoneServer.exit();623 remoteGreenstoneServer.exit(); 577 624 } 578 625 … … 715 762 url = null; 716 763 } 764 catch(java.net.ConnectException connectException) { 765 JOptionPane.showMessageDialog(g_man, Dictionary.get("Preferences.Connection.Library_Path_Connection_Failure", Configuration.library_url.toString()), Dictionary.get("General.Warning"), JOptionPane.WARNING_MESSAGE); 766 DebugStream.println(connectException.getMessage()); 767 } 717 768 catch (Exception exception) { 718 769 DebugStream.printStackTrace(exception); … … 767 818 static private void missingEXEC() { 768 819 WarningDialog dialog; 820 String configPropertyName = "general.library_url"+Configuration.gliPropertyNameSuffix(); 821 769 822 if (GS3) { 770 dialog = new WarningDialog("warning.MissingEXEC", Dictionary.get("MissingEXEC_GS3.Title"), Dictionary.get("MissingEXEC_GS3.Message"), "general.library_url", false); 771 }else { 772 dialog = new WarningDialog("warning.MissingEXEC", Dictionary.get("MissingEXEC.Title"), Dictionary.get("MissingEXEC.Message"), "general.library_url", false); 773 } 774 dialog.setValueField(new URLField(Configuration.getColor("coloring.editable_foreground", false), Configuration.getColor("coloring.editable_background", false))); 823 // Warning dialog with no cancel button and no "turn off warning" checkbox 824 dialog = new WarningDialog("warning.MissingEXEC", Dictionary.get("MissingEXEC_GS3.Title"), Dictionary.get("MissingEXEC_GS3.Message"), configPropertyName, false, false); 825 } else { // local case 826 dialog = new WarningDialog("warning.MissingEXEC", Dictionary.get("MissingEXEC.Title"), Dictionary.get("MissingEXEC.Message"), configPropertyName, false); 827 } 828 829 JTextField field = new URLField.Text(Configuration.getColor("coloring.editable_foreground", false), Configuration.getColor("coloring.editable_background", false)); 830 831 // Set the default library URL to the tomcat server and port number 832 // specified in the build.properties located in the gsdl3_src_path 833 if (GS3) { 834 String host = "localhost"; 835 String port = "8080"; 836 837 File buildPropsFile = new File(Configuration.gsdl3_src_path + File.separator + "build.properties"); 838 if(buildPropsFile.exists()) { 839 Properties props = new Properties(); 840 try{ 841 props.load(new FileInputStream(buildPropsFile)); 842 host = props.getProperty("tomcat.server", host); 843 port = props.getProperty("tomcat.port", port); 844 }catch(Exception e){ 845 DebugStream.println("Could not load build.properties file"); 846 System.err.println("Could not load build.properties file"); 847 } 848 props = null; 849 } 850 String defaultURL = "http://"+host+":"+port+"/"+"greenstone3/library"; 851 field.setText(defaultURL); 852 field.selectAll(); 853 } 854 dialog.setValueField(field); 775 855 dialog.display(); 776 856 dialog.dispose(); 777 857 dialog = null; 778 858 779 String library_url_string = Configuration.getString( "general.library_url", true);859 String library_url_string = Configuration.getString(configPropertyName, true); 780 860 if (!library_url_string.equals("")) { 781 861 try { 862 // WarningDialog does not allow invalid URLs, so the following is ignored: 863 // make sure the URL the user provided contains the http:// prefix 864 // and then save the corrected URL 865 if(!library_url_string.startsWith("http://") 866 && !library_url_string.startsWith("https://")) { 867 library_url_string = "http://"+library_url_string; 868 Configuration.setString(configPropertyName, true, configPropertyName); 869 } 782 870 Configuration.library_url = new URL(library_url_string); 783 871 } … … 789 877 790 878 791 static private void missingGLIServer() 879 880 /** Prints a warning message about a missing library path, which means the final collection cannot be previewed in the Gatherer. 881 */ 882 static private void popupFedoraInfo() { 883 884 FedoraLogin dialog = new FedoraLogin("Fedora Login", false); 885 886 if (Configuration.library_url == null) { 887 888 String library_url_string = dialog.getLibraryURL(); 889 if (!library_url_string.equals("")) { 890 try { 891 Configuration.library_url = new URL(library_url_string); 892 } 893 catch (MalformedURLException exception) { 894 DebugStream.printStackTrace(exception); 895 } 896 } 897 } 898 899 boolean showLogin = true; 900 do { 901 if(!dialog.loginRequested()) { // user pressed cancel to exit the FedoraLogin dialog 902 System.exit(0); 903 } else { 904 showLogin = dialog.loginRequested(); 905 String hostname = dialog.getHostname(); 906 String port = dialog.getPort(); 907 String username = dialog.getUsername(); 908 String password = dialog.getPassword(); 909 String protocol = dialog.getProtocol(); 910 911 Configuration.fedora_info.setHostname(hostname); 912 Configuration.fedora_info.setPort(port); 913 Configuration.fedora_info.setUsername(username); 914 Configuration.fedora_info.setPassword(password); 915 Configuration.fedora_info.setProtocol(protocol); 916 917 String ping_url_str = protocol + "://" + hostname + ":" + port + "/fedora"; 918 String login_str = username + ":" + password; 919 920 String login_encoding = new sun.misc.BASE64Encoder().encode(login_str.getBytes()); 921 922 try { 923 URL ping_url = new URL(ping_url_str); 924 URLConnection uc = ping_url.openConnection(); 925 uc.setRequestProperty ("Authorization", "Basic " + login_encoding); 926 // Attempt to access some content ... 927 InputStream content = (InputStream)uc.getInputStream(); 928 929 // if no exception occurred in the above, we would have come here: 930 showLogin = false; 931 dialog.dispose(); 932 } 933 catch (Exception exception) { 934 // TODO: move into dictionary 935 String[] errorMessage = {"Failed to connect to the Fedora server.", "It might not be running, or", 936 "incorrect username and/or password."}; 937 dialog.setErrorMessage(errorMessage); 938 //DebugStream.printStackTrace(exception); 939 // exception occurred, show the dialog again (do this after printing to 940 // debugStream, else the above does not get done for some reason). 941 dialog.setVisible(true); 942 } 943 } 944 } while(showLogin); 945 946 dialog = null; // no more need of the dialog 947 948 // Now we are connected. 949 } 950 951 952 953 static private void requestGLIServerURL() 792 954 { 793 955 WarningDialog dialog; 794 if (GS3) { 795 dialog = new WarningDialog("warning.MissingGLIServer", Dictionary.get("MissingGLIServer_GS3.Title"), Dictionary.get("MissingGLIServer_GS3.Message"), "general.gliserver_url", false); 796 }else { 797 dialog = new WarningDialog("warning.MissingGLIServer", Dictionary.get("MissingGLIServer.Title"), Dictionary.get("MissingGLIServer.Message"), "general.gliserver_url", false); 798 } 799 dialog.setValueField(new URLField(Configuration.getColor("coloring.editable_foreground", false), Configuration.getColor("coloring.editable_background", false))); 800 956 String[] defaultURLs = { 957 "http://localhost:8080/greenstone3/cgi-bin/gliserver.pl", 958 "http://localhost:8080/gsdl/cgi-bin/gliserver.pl" 959 }; 960 961 // Warning dialog with no cancel button and no "turn off warning" checkbox 962 // (since user-input of the gliserver script is mandatory) 963 dialog = new WarningDialog("warning.MissingGLIServer", Dictionary.get("MissingGLIServer.Title"), Dictionary.get("MissingGLIServer.Message"), "general.gliserver_url", false, false); 964 965 dialog.setValueField(new URLField.DropDown(Configuration.getColor("coloring.editable_foreground", false), 966 Configuration.getColor("coloring.editable_background", false), 967 defaultURLs, "general.gliserver_url", 968 "general.open_collection"+Configuration.gliPropertyNameSuffix(), 969 "gliserver.pl")); 970 801 971 if (Gatherer.default_gliserver_url!=null){ 802 972 dialog.setValueField(Gatherer.default_gliserver_url.toString()); 803 973 } 974 975 // A WarningDialog cannot always be made to respond (let alone to exit the program) on close. We 976 // handle the response of this particular WarningDialog here: a URL for gliserver.pl is a crucial 977 // piece of user-provided data. Therefore, if no URL was entered for gliserver.pl, it'll exit safely. 978 dialog.addWindowListener(new WindowAdapter() { 979 public void windowClosing(WindowEvent e) { 980 Gatherer.exit(); 981 } 982 }); 804 983 805 984 dialog.display(); 806 985 dialog.dispose(); 807 986 dialog = null; 987 808 988 809 989 String gliserver_url_string = Configuration.getString("general.gliserver_url", true); … … 1045 1225 //new way of detection of ImageMagick 1046 1226 InputStreamReader isr = new InputStreamReader(image_magick_process.getInputStream()); 1227 1047 1228 BufferedReader br = new BufferedReader(isr); 1048 1229 // Capture the standard output stream and seach for two particular occurances: Version and ImageMagick. 1049 String line = br.readLine().toLowerCase(); 1050 if (line.indexOf("version") != -1 || line.indexOf("imagemagick") != -1) { 1230 1231 String line = br.readLine(); 1232 if (line == null) { 1233 return false; 1234 } 1235 String lc_line = line.toLowerCase(); 1236 if (lc_line.indexOf("version") != -1 || lc_line.indexOf("imagemagick") != -1) { 1051 1237 return true; 1052 1238 } else { 1053 1239 return false; 1054 1240 } 1241 1055 1242 //return (image_magick_process.exitValue() == 0); 1056 1243 }
Note:
See TracChangeset
for help on using the changeset viewer.