Changeset 10242


Ignore:
Timestamp:
2005-07-13T14:10:18+12:00 (19 years ago)
Author:
mdewsnip
Message:

Moved a lot of the duplicated code out of GathererProg and GathererApplet and into Gatherer.

Location:
trunk/gli/src/org/greenstone/gatherer
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/Gatherer.java

    r10239 r10242  
    6363public class Gatherer
    6464{
     65    static private Dimension size = new Dimension(800, 540);
     66
    6567    /** Has the exit flag been set? */
    6668    public boolean exit = false;
     
    7981    static public FileManager f_man;
    8082    /** A public reference to the GUIManager. */
    81     static public GUIManager g_man;
     83    static public GUIManager g_man = null;
    8284    static private boolean g_man_built = false;
    8385
     
    8890
    8991    static public boolean isApplet = false;
    90     static public boolean isGsdlRemote = false;
     92    static public boolean isGsdlRemote = true;
    9193    static public String cgiBase = "";
    9294
     
    112114
    113115
    114     public Gatherer()
     116    public Gatherer(String[] args)
    115117    {
    116118    this.self = this;
    117 
    118119    JarTools.initialise(this);
    119     }
    120 
    121 
    122     public GUIManager init(Dimension size, String gsdl_path, String gsdl3_path, String local_library_path,
    123                String library_url_string, boolean debug_enabled, String perl_path,
    124                boolean no_load, String open_collection,
    125                String site_name, String servlet_path, String wget_path)
     120
     121    GetOpt go = new GetOpt(args);
     122
     123    // If feedback is enabled, set up the recorder dialog
     124    if (go.feedback_enabled) {
     125        // Use the default locale for now - this will be changed by the Gatherer run method
     126        feedback_enabled = true;
     127        feedback_dialog = new ActionRecorderDialog(Locale.getDefault());
     128    }
     129
     130    if (go.collect_directory_path != null) {
     131        // Use non-standard collect directory (for when running one GLI in a network environment)
     132        Gatherer.setCollectDirectoryPath(go.collect_directory_path);
     133    }
     134
     135    // Special code for running with a remote Greenstone
     136    if (isGsdlRemote) {
     137        File gli_user_directory = Utility.getGLIUserFolder();
     138
     139        Utility.BASE_DIR = gli_user_directory.toString();
     140        if (!Utility.BASE_DIR.endsWith(File.separator)) {
     141        Utility.BASE_DIR += File.separator;
     142        }
     143
     144        Utility.METADATA_DIR = Utility.BASE_DIR + "metadata" + File.separator;
     145        Utility.TMP_DIR = Utility.BASE_DIR + "tmp" + File.separator;
     146
     147        Configuration.TEMPLATE_CONFIG_XML = "xml/configRemote.xml";
     148        Configuration.CONFIG_XML = "configRemote.xml";
     149        Configuration.GS3_CONFIG_XML = "config3Remote.xml";
     150
     151        Gatherer.setCollectDirectoryPath(go.gsdl_path + "collect" + File.separator);
     152        File col_dir = new File(Gatherer.getCollectDirectoryPath());
     153        if (!col_dir.exists()) {
     154
     155        if (JarTools.isInJar(Utility.COLLECT_ZIP)) {
     156            // Dig out collect.zip from JAR file and unzip it (thereby
     157            // creating collect directory and descendants.
     158            //   This is done to seed gsdl home folder with config files
     159            //   for documented example collections so "base this on
     160            //   existing collection" works
     161            Utility.unzipFromJar(Utility.COLLECT_ZIP, gli_user_directory.toString());
     162        }
     163        else {
     164            // Prepare an empty collect dir for general use
     165            if (!col_dir.mkdir()) {
     166            System.err.println("Warning: Unable to make directory: " + col_dir.toString());
     167            }
     168        }
     169        }
     170
     171        File tmp_dir = new File(Utility.TMP_DIR);
     172        if (!tmp_dir.exists()) {
     173        if (!tmp_dir.mkdir()) {
     174            System.err.println("Warning: Unable to make directory: " + tmp_dir.toString());
     175        }
     176
     177        String username = System.getProperty("user.name");
     178        if ((username != null) && (username != "")) {
     179            File user_tmp_dir = new File(Utility.TMP_DIR + File.separator + username);
     180            if (!user_tmp_dir.exists()) {
     181            if (!user_tmp_dir.mkdir()) {
     182                System.err.println("Warning: Unable to make directory: " + user_tmp_dir.toString());
     183            }
     184            }
     185        }
     186        }
     187
     188        File metadata_directory = new File(Utility.METADATA_DIR);
     189        if (!metadata_directory.exists()) {
     190        // dig out metadata.zip from JAR file and unzip it
     191        Utility.unzipFromJar(Utility.METADATA_ZIP, gli_user_directory.toString());
     192        }
     193
     194        File plug_dat = new File(Utility.BASE_DIR + "plugins.dat");
     195        if (!plug_dat.exists()) {
     196        JarTools.extractFromJar("plugins.dat", Utility.BASE_DIR, false);
     197        }
     198
     199        File class_dat = new File(Utility.BASE_DIR + "classifiers.dat");
     200        if (!class_dat.exists()) {
     201        JarTools.extractFromJar("classifiers.dat", Utility.BASE_DIR, false);
     202        }
     203    }
     204
     205    init(go.gsdl_path, go.gsdl3_path, go.local_library_path, go.library_url_string, go.debug,
     206         go.perl_path, go.no_load, go.filename, go.site_name, go.servlet_path, go.wget_path);
     207    }
     208
     209
     210    public void init(String gsdl_path, String gsdl3_path, String local_library_path,
     211             String library_url_string, boolean debug_enabled, String perl_path,
     212             boolean no_load, String open_collection,
     213             String site_name, String servlet_path, String wget_path)
    126214    {
    127215    if (gsdl3_path != null && !gsdl3_path.equals("")) {
     
    329417    // Create GUI Manager (last) or else suffer the death of a thousand NPE's
    330418    g_man = new GUIManager(size);
    331     return g_man;
    332     }
    333 
    334 
    335     public void run(Dimension size, GUIManager g_man)
     419    }
     420
     421
     422    public void openGUI()
    336423    {
    337424    // Size and place the frame on the screen
  • trunk/gli/src/org/greenstone/gatherer/GathererApplet.java

    r10240 r10242  
    3434import javax.swing.JApplet;
    3535
    36 import java.awt.*;
    3736import java.io.*;
    38 import java.util.*;
    3937import javax.swing.*;
    40 import org.greenstone.gatherer.Configuration;
    41 import org.greenstone.gatherer.feedback.ActionRecorderDialog;
    42 import org.greenstone.gatherer.gui.GUIManager;
    43 import org.greenstone.gatherer.util.JarTools;
    4438import org.greenstone.gatherer.util.Utility;
    45 import org.greenstone.gatherer.shell.GShell;
    4639
    4740
    4841public class GathererApplet extends JApplet implements ActionListener
    4942{
    50     Gatherer gatherer;
    51     GUIManager g_man;
    52     Dimension size = new Dimension(800, 540);
     43    private Gatherer gatherer = null;
     44
    5345
    5446    protected String fullLibraryURL(String address)
     
    7365    }
    7466
     67
     68    /* This is the entry point for the GLI applet */
    7569    public void init()
    7670    {
     71    // Check if the user has agreed to the requested security settings
    7772    try {
    7873        // Work-around to reduce number of
     
    8176        System.setProperty("java.util.prefs.syncInterval","2000000");
    8277    }
    83 
    8478    catch (Exception exception) {
    85         // convenient way of finding out if user has agreed to
    86         // to requested security settings
    87 
    88         JLabel lab
    89         = new JLabel("Greenstone Librarian Interface Applet deactivated",
    90                  JLabel.CENTER);
    91         getContentPane().add(lab);
     79        getContentPane().add(new JLabel("Greenstone Librarian Interface Applet deactivated", JLabel.CENTER));
    9280        return;
    9381    }
     
    10189    }
    10290
    103     String gwcgi = getParameter("gwcgi");
    104     String library_cgi = fullLibraryURL(gwcgi);
    105     int cgi_base_cut = library_cgi.lastIndexOf('/');
    106     String cgi_base = library_cgi.substring(0,cgi_base_cut+1);
    107 
    108         String windows_home = getParameter("windowsHome");
    109         File gli_user_directory = Utility.setGLIUserFolder(windows_home);
    110     if (!gli_user_directory.exists()) {
    111         if (!gli_user_directory.mkdirs()) {
    112             System.err.println("Warning: Unable to make directory: " + gli_user_directory.toString());
    113         }
     91    // Ensure the GLI user directory exists
     92        File gli_user_directory = Utility.setGLIUserFolder(getParameter("windowsHome"));
     93    if (!gli_user_directory.exists() && !gli_user_directory.mkdirs()) {
     94        System.err.println("Error: Unable to make directory: " + gli_user_directory.toString());
    11495    }
    11596
    116     gatherer = new Gatherer();
     97    // Set some global variables so we know how we're running
     98    Gatherer.isApplet = true;
     99    Gatherer.isGsdlRemote = true;
     100    String library_cgi = fullLibraryURL(getParameter("gwcgi"));
     101    Gatherer.cgiBase = library_cgi.substring(0, library_cgi.lastIndexOf('/') + 1);
     102
     103        // String debug_param = getParameter("debug");
     104        // if ((debug_param != null) && (debug_param.matches("true"))) {
     105        //     go.debug = true;
     106        // }
    117107
    118108    String[] args = { "-gsdl", gli_user_directory.toString(),
     
    120110                    };
    121111
    122     GetOpt go = new GetOpt(args);
     112    // Create an instance of the Gatherer class, which will parse the args and prepare the rest of the GLI
     113    gatherer = new Gatherer(args);
    123114
    124         String debug_param = getParameter("debug");
    125 
    126         if ((debug_param != null) && (debug_param.matches("true"))) {
    127             go.debug = true;
    128         }
    129 
    130     if (go.feedback_enabled) {
    131         // If feedback is enabled, set up the recorder dialog. 
    132         // Use the default locale for now - this will be changed by the
    133         // Gatherer run method
    134         Locale currLocale = Locale.getDefault();
    135         ActionRecorderDialog dlg = new ActionRecorderDialog (currLocale);
    136         gatherer.feedback_enabled = true;
    137         gatherer.feedback_dialog = dlg;
    138     }
    139 
    140     Gatherer.isApplet = true;
    141     Gatherer.isGsdlRemote = true;
    142     Gatherer.cgiBase = cgi_base;
    143 
    144     Utility.BASE_DIR = go.gsdl_path;
    145     if (!Utility.BASE_DIR.endsWith(File.separator)) {
    146         Utility.BASE_DIR += File.separator;
    147     }
    148 
    149     Utility.METADATA_DIR = Utility.BASE_DIR + "metadata" + File.separator;
    150     Utility.TMP_DIR = Utility.BASE_DIR + "tmp" + File.separator;
    151 
    152     Configuration.TEMPLATE_CONFIG_XML = "xml/configRemote.xml";
    153     Configuration.CONFIG_XML = "configRemote.xml";
    154     Configuration.GS3_CONFIG_XML = "config3Remote.xml";
    155 
    156     Gatherer.setCollectDirectoryPath(go.gsdl_path + "collect" + File.separator);
    157     File col_dir = new File(Gatherer.getCollectDirectoryPath());
    158     if (!col_dir.exists()) {
    159 
    160         if (JarTools.isInJar(Utility.COLLECT_ZIP)) {
    161         // Dig out collect.zip from JAR file and unzip it (thereby
    162         // creating collect directory and descendants.
    163         //   This is done to seed gsdl home folder with config files
    164         //   for documented example collections so "base this on
    165         //   existing collection" works
    166         Utility.unzipFromJar(Utility.COLLECT_ZIP,gli_user_directory.toString());
    167         }
    168         else {
    169         // Prepare an empty collect dir for general use
    170         if (!col_dir.mkdir()) {
    171             System.err.println("Warning: Unable to make directory: " + col_dir.toString());
    172         }
    173         }
    174         }
    175 
    176    
    177         File tmp_dir = new File(Utility.TMP_DIR);
    178         if (!tmp_dir.exists()) {
    179             if (!tmp_dir.mkdir()) {
    180         System.err.println("Warning: Unable to make directory: " + tmp_dir.toString());
    181         }
    182 
    183         String username = System.getProperty("user.name");
    184         if ((username != null) && (username != "")) {
    185         File user_tmp_dir = new File(Utility.TMP_DIR + File.separator + username);
    186         if (!user_tmp_dir.exists()) {
    187             if (!user_tmp_dir.mkdir()) {
    188             System.err.println("Warning: Unable to make directory: " + user_tmp_dir.toString());
    189             }
    190         }
    191         }
    192         }
    193 
    194     File metadata_directory = new File(Utility.METADATA_DIR);
    195     if (!metadata_directory.exists()) {
    196         // dig out metadata.zip from JAR file and unzip it
    197         Utility.unzipFromJar(Utility.METADATA_ZIP, gli_user_directory.toString());
    198     }
    199 
    200     File plug_dat = new File(Utility.BASE_DIR + "plugins.dat");
    201     if (!plug_dat.exists()) {
    202         JarTools.extractFromJar("plugins.dat", Utility.BASE_DIR, false);
    203     }
    204 
    205     File class_dat = new File(Utility.BASE_DIR + "classifiers.dat");
    206     if (!class_dat.exists()) {
    207         JarTools.extractFromJar("classifiers.dat", Utility.BASE_DIR, false);
    208     }
    209    
    210     g_man = gatherer.init(size, go.gsdl_path, go.gsdl3_path, go.local_library_path,
    211                     go.library_url_string, go.debug, go.perl_path,
    212                     go.no_load, go.filename, go.site_name,
    213                     go.servlet_path, go.wget_path);
    214 
    215     JButton bttn = new JButton("Launch Greenstone Librarian Interface ...");
    216     bttn.addActionListener(this);
    217     getContentPane().add(bttn);
     115    // Create a button for the user to press to open the GLI GUI
     116    JButton launch_GLI_button = new JButton("Launch Greenstone Librarian Interface ...");
     117    launch_GLI_button.addActionListener(this);
     118    getContentPane().add(launch_GLI_button);
    218119    }
    219120
     
    240141    }
    241142
     143
    242144    public void actionPerformed(ActionEvent e)
    243145    {
    244     gatherer.run(size, g_man);
     146    gatherer.openGUI();
    245147
    246     // If there was an open collection last session, reopen it.
     148    // If there was an open collection last session, reopen it
    247149    if (Gatherer.open_collection_file_path != null) {
    248150        Gatherer.c_man.loadCollection(Gatherer.open_collection_file_path);
  • trunk/gli/src/org/greenstone/gatherer/GathererProg.java

    r9877 r10242  
    66 * University of Waikato, New Zealand.
    77 *
    8  * Author: John Thompson, Greenstone Digital Library, University of Waikato
     8 * Author: John Thompson, NZDL Project, University of Waikato
    99 *
    10  * Copyright (C) 1999 New Zealand Digital Library Project
     10 * Copyright (C) 2005 New Zealand Digital Library Project
    1111 *
    1212 * This program is free software; you can redistribute it and/or modify
     
    2828
    2929
    30 import java.awt.*;
    3130import java.io.*;
    32 import java.util.*;
    3331import javax.swing.*;
    34 import org.greenstone.gatherer.feedback.ActionRecorderDialog;
    35 import org.greenstone.gatherer.gui.GUIManager;
    3632import org.greenstone.gatherer.util.Utility;
    3733
    3834
    39 /** Containing the main() method for the Gatherer, this class is the
    40  * starting point for the rest of the application. Using GetOpt and
    41  * GathererBase it first parses the command line arguments, preparing to
    42  * update the configuration as required. Next it loads several important
    43  * support classes such as the Configuration and Dictionary. Finally it
    44  * creates the other important managers and sends them on their way.
    45  * @author John Thompson, Greenstone Digital Library, University of Waikato
    46  * @version 2.3
     35/**
     36 * Containing the main() method, this class is the entry point for the
     37 * stand-alone (non-Applet) GLI. The main point of this class is to set
     38 * some stand-alone specific properties and then create an instance of the
     39 * Gatherer class.
     40 * @author John Thompson, NZDL Project, University of Waikato
    4741 */
    4842public class GathererProg
    4943{
    50     /** The entry point into the Gatherer. Parses arguments.
     44    /** The entry point into the stand-alone GLI.
    5145     * @param args A collection of arguments that may include: initial screen size, dictionary, path to the GSDL etc.
    52      * @see java.io.File
    53      * @see java.io.FileInputStream
    54      * @see java.lang.Exception
    55      * @see java.util.Properties
    56      * @see org.greenstone.gatherer.Dictionary
    57      * @see org.greenstone.gatherer.Gatherer
    5846     */
    59     static public void main(String[] args) {
     47    static public void main(String[] args)
     48    {
    6049    // A serious hack, but its good enough to stop crappy 'Could not
    6150    // lock user prefs' error messages.  Thanks to Walter Schatz from
    6251    // the java forums.
    6352    System.setProperty("java.util.prefs.syncInterval","2000000");
    64     // => results in One message every 600 hours!
     53    // => results in one message every 600 hours!
    6554
    6655    // Ensure platform specific LAF
     
    7362
    7463    // Ensure the GLI user directory exists
    75     File gli_user_directory = Utility.setGLIUserFolder(null); // # defaults to user's home area
    76     if (!gli_user_directory.exists()) {
    77         gli_user_directory.mkdirs();
     64        File gli_user_directory = Utility.setGLIUserFolder(null);  // Defaults to user's home area
     65    if (!gli_user_directory.exists() && !gli_user_directory.mkdirs()) {
     66        System.err.println("Error: Unable to make directory: " + gli_user_directory.toString());
    7867    }
    7968
    80     Gatherer gatherer = new Gatherer();
     69    // Create an instance of the Gatherer class, which will parse the args and prepare the rest of the GLI
     70    Gatherer gatherer = new Gatherer(args);
    8171
    82     Dimension size = new Dimension(800, 540);
     72    // Display the GUI immediately
     73    gatherer.openGUI();
    8374
    84     GetOpt go = new GetOpt(args);
    85 
    86     if (go.feedback_enabled) {
    87         // If feedback is enabled, set up the recorder dialog.
    88         // Use the default locale for now - this will be changed by the
    89         // Gatherer run method
    90         Locale currLocale = Locale.getDefault();
    91         ActionRecorderDialog dlg = new ActionRecorderDialog (currLocale);
    92         gatherer.feedback_enabled = true;
    93         gatherer.feedback_dialog = dlg;
    94     }
    95 
    96     if (go.collect_directory_path != null) {
    97         // Use non-standard collect directory (for when running one GLI in a network environment)
    98         Gatherer.setCollectDirectoryPath(go.collect_directory_path);
    99     }
    100 
    101     GUIManager g_man
    102         = gatherer.init(size, go.gsdl_path, go.gsdl3_path, go.local_library_path,
    103                  go.library_url_string, go.debug, go.perl_path,
    104                  go.no_load, go.filename, go.site_name,
    105                  go.servlet_path, go.wget_path);
    106     gatherer.run(size, g_man);
    107 
    108     // If there was an open collection last session, reopen it.
     75    // If there was an open collection last session, reopen it
    10976    if (Gatherer.open_collection_file_path != null) {
    11077        Gatherer.c_man.loadCollection(Gatherer.open_collection_file_path);
  • trunk/gli/src/org/greenstone/gatherer/GetOpt.java

    r9339 r10242  
    3939
    4040    public String collect_directory_path = null;
    41     public String extra = null;
    4241    public String filename = null;
    4342    public String gsdl_path = null;
Note: See TracChangeset for help on using the changeset viewer.