/** *######################################################################### * * A component of the Gatherer application, part of the Greenstone digital * library suite from the New Zealand Digital Library Project at the * University of Waikato, New Zealand. * * Author: John Thompson, Greenstone Digital Library, University of Waikato * * Copyright (C) 1999 New Zealand Digital Library Project * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *######################################################################## */ package org.greenstone.gatherer; import java.applet.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.net.*; import javax.swing.JApplet; import java.io.*; import javax.swing.*; import org.greenstone.gatherer.util.Utility; public class GathererApplet extends JApplet implements ActionListener { private Gatherer gatherer = null; protected String fullLibraryURL(String address) { String full_address = ""; // make sure the URL has protocol, host, and file if (address.startsWith("http:")) { // the address has all the necessary components full_address = address; } else if (address.startsWith("/")) { // there is not protocol and host URL document = getDocumentBase(); int port_no = document.getPort(); String port = (port_no>0) ? ":" + port_no : ""; full_address = "http://" + document.getHost() + port + address; } return full_address; } /* This is the entry point for the GLI applet */ public void init() { // Check if the user has agreed to the requested security settings try { // Work-around to reduce number of // 'Could not lock user prefs' error messages. // Thanks to Walter Schatz from the java forums. System.setProperty("java.util.prefs.syncInterval","2000000"); } catch (Exception exception) { getContentPane().add(new JLabel("Greenstone Librarian Interface Applet deactivated", JLabel.CENTER)); return; } // Ensure platform specific LAF try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception exception) { exception.printStackTrace(); } // Ensure the GLI user directory exists File gli_user_directory = Utility.setGLIUserFolder(getParameter("windowsHome")); if (!gli_user_directory.exists() && !gli_user_directory.mkdirs()) { System.err.println("Error: Unable to make directory: " + gli_user_directory.toString()); } // Set some global variables so we know how we're running Gatherer.isApplet = true; Gatherer.isGsdlRemote = true; String library_cgi = fullLibraryURL(getParameter("gwcgi")); Gatherer.cgiBase = library_cgi.substring(0, library_cgi.lastIndexOf('/') + 1); // String debug_param = getParameter("debug"); // if ((debug_param != null) && (debug_param.matches("true"))) { // go.debug = true; // } String[] args = { "-gsdl", gli_user_directory.toString(), "-library_url", library_cgi, }; // Create an instance of the Gatherer class, which will parse the args and prepare the rest of the GLI gatherer = new Gatherer(args); // Create a button for the user to press to open the GLI GUI JButton launch_GLI_button = new JButton("Launch Greenstone Librarian Interface ..."); launch_GLI_button.addActionListener(this); getContentPane().add(launch_GLI_button); } public void start() { System.err.println("Start called"); } public void stop() { System.err.println("Stop called"); } public void destroy() { System.err.println("Destroy called"); gatherer.exit(); System.err.println("Done gatherer exit."); } public void actionPerformed(ActionEvent e) { gatherer.openGUI(); // If there was an open collection last session, reopen it if (Gatherer.open_collection_file_path != null) { Gatherer.c_man.loadCollection(Gatherer.open_collection_file_path); } } }