Ignore:
Timestamp:
2009-01-12T11:19:54+13:00 (15 years ago)
Author:
kjdon
Message:

updated the rtl-gli branch with files from trunk. Result of a merge 14807:18318

File:
1 edited

Legend:

Unmodified
Added
Removed
  • gli/branches/rtl-gli/src/org/greenstone/gatherer/Gatherer.java

    r14605 r18363  
    3636import javax.swing.plaf.*;
    3737import javax.swing.text.*;
     38
     39
    3840import org.greenstone.gatherer.Configuration;
    3941import org.greenstone.gatherer.GAuthenticator;
     42import org.greenstone.gatherer.FedoraInfo;
    4043import org.greenstone.gatherer.collection.CollectionManager;
    4144import org.greenstone.gatherer.feedback.ActionRecorderDialog;
     
    5154import org.greenstone.gatherer.gui.URLField;
    5255import org.greenstone.gatherer.gui.WarningDialog;
     56import org.greenstone.gatherer.gui.FedoraLogin;
    5357import org.greenstone.gatherer.remote.RemoteGreenstoneServer;
    5458import org.greenstone.gatherer.util.JarTools;
     
    7478        * in a line which maches this java regex:
    7579        * ^(.*)String\s*PROGRAM_VERSION\s*=\s*"trunk";
    76         * If change the daclaration and it no longer matches the regex, please
     80        * If change the declaration and it no longer matches the regex, please
    7781        * change the regex in the gs3-release-maker code and in this message
    7882        */
     83
    7984    static final public String PROGRAM_VERSION = "trunk";
    8085
    8186    static private Dimension size = new Dimension(800, 540);
     87    static public RemoteGreenstoneServer remoteGreenstoneServer = null;
    8288
    8389    /** Has the exit flag been set? */
     
    165171        // We don't have a local Greenstone!
    166172        go.gsdl_path = null;
     173        go.gsdl3_path=null;
     174        go.gsdl3_src_path=null;
    167175
    168176        // We have to use our own collect directory since we can't use the Greenstone one
    169177        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         }
    175178    }
    176179    // No, we have a local Greenstone
     
    186189    // More special code for running with a remote Greenstone
    187190    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";
    194199
    195200        File collect_directory = new File(Gatherer.getCollectDirectoryPath());
     
    198203        }
    199204    }
    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,
    202215         go.gliserver_url_string, go.debug, go.perl_path, go.no_load, go.filename, go.site_name,
    203216         go.servlet_path);
     
    205218
    206219
    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,
    208223             String library_url_string, String gliserver_url_string, boolean debug_enabled,
    209224             String perl_path, boolean no_load, String open_collection,
     
    245260    try {
    246261        // 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       
    249265        // Check we know where Perl is
    250266        Configuration.perl_path = perl_path;
     
    278294        }
    279295
    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       
    285331        // The "-library_url" option overwrites anything in the config files
    286332        if (library_url_string != null && library_url_string.length() > 0) {
     
    293339        }
    294340        }
     341 
    295342
    296343        // Check that we now know the Greenstone library URL, since we need this for previewing collections
     
    298345        if (Configuration.library_url == null) {
    299346        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         }
    308347        }
    309348
     
    321360        // If we're using a remote Greenstone we need to know where the gliserver script is
    322361        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         }
    338362
    339363        if (GS3) {
     
    348372        if (GS3 && Configuration.servlet_path == null) {
    349373        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);
    350381        }
    351382
     
    424455        open_collection_file_path = open_collection;
    425456        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);
    427459        }
    428460        if (no_load || open_collection_file_path.equals("")) {
     
    434466    }
    435467
     468   
    436469    // Create GUI Manager (last) or else suffer the death of a thousand NPE's
    437470    g_man = new GUIManager(size);
     
    443476    // If using a remote Greenstone we need to download the collection configurations now
    444477    if (Gatherer.isGsdlRemote) {
    445         if (RemoteGreenstoneServer.downloadCollectionConfigurations().equals("")) {
     478        if (remoteGreenstoneServer.downloadCollectionConfigurations().equals("")) {
    446479        // !! Something went wrong downloading the collection configurations
    447480        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    }
    453498
    454499    public void openGUI()
     
    511556    // If using a remote Greenstone we need to download the collection configurations now
    512557    if (Gatherer.isGsdlRemote) {
    513         if (RemoteGreenstoneServer.downloadCollectionConfigurations().equals("")) {
     558        if (remoteGreenstoneServer.downloadCollectionConfigurations().equals("")) {
    514559        // !! Something went wrong downloading the collection configurations
    515560        System.err.println("Error: Could not download collection configurations.");
     
    561606
    562607    // 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    }
    565612
    566613    // Flush debug
     
    574621    // If we're using a remote Greenstone server we need to make sure that all jobs have completed first
    575622    if (isGsdlRemote) {
    576         RemoteGreenstoneServer.exit();
     623        remoteGreenstoneServer.exit();
    577624    }
    578625
     
    715762        url = null;
    716763    }
     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    }
    717768    catch (Exception exception) {           
    718769        DebugStream.printStackTrace(exception);
     
    767818    static private void missingEXEC() {
    768819    WarningDialog dialog;
     820    String configPropertyName = "general.library_url"+Configuration.gliPropertyNameSuffix();
     821
    769822    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);
    775855    dialog.display();
    776856    dialog.dispose();
    777857    dialog = null;
    778858
    779     String library_url_string = Configuration.getString("general.library_url", true);
     859    String library_url_string = Configuration.getString(configPropertyName, true);
    780860    if (!library_url_string.equals("")) {
    781861        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        }
    782870        Configuration.library_url = new URL(library_url_string);
    783871        }
     
    789877
    790878
    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()
    792954    {
    793955    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
    801971    if (Gatherer.default_gliserver_url!=null){
    802972        dialog.setValueField(Gatherer.default_gliserver_url.toString());
    803973    }
     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        });
    804983   
    805984    dialog.display();
    806985    dialog.dispose();
    807986    dialog = null;
     987
    808988   
    809989    String gliserver_url_string = Configuration.getString("general.gliserver_url", true);
     
    10451225        //new way of detection of ImageMagick
    10461226        InputStreamReader isr = new InputStreamReader(image_magick_process.getInputStream());
     1227
    10471228            BufferedReader br = new BufferedReader(isr);
    10481229            // 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) {
    10511237            return true;
    10521238        } else {
    10531239                return false;
    10541240        }
     1241
    10551242        //return (image_magick_process.exitValue() == 0);
    10561243        }
Note: See TracChangeset for help on using the changeset viewer.