[7738] | 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 | */
|
---|
| 27 |
|
---|
| 28 | package org.greenstone.gatherer;
|
---|
| 29 |
|
---|
[9092] | 30 | import java.applet.*;
|
---|
[7738] | 31 | import java.awt.event.ActionEvent;
|
---|
| 32 | import java.awt.event.ActionListener;
|
---|
| 33 | import java.net.*;
|
---|
| 34 | import javax.swing.JApplet;
|
---|
| 35 |
|
---|
[9092] | 36 | import java.io.*;
|
---|
[7738] | 37 | import javax.swing.*;
|
---|
[10363] | 38 | import org.greenstone.gatherer.util.JarTools;
|
---|
[13328] | 39 | import org.greenstone.gatherer.util.UnzipTools;
|
---|
[7738] | 40 | import org.greenstone.gatherer.util.Utility;
|
---|
| 41 |
|
---|
[9058] | 42 |
|
---|
[7738] | 43 | public class GathererApplet extends JApplet implements ActionListener
|
---|
| 44 | {
|
---|
[10242] | 45 | private Gatherer gatherer = null;
|
---|
[7738] | 46 |
|
---|
[10242] | 47 |
|
---|
[7738] | 48 | protected String fullLibraryURL(String address)
|
---|
| 49 | {
|
---|
| 50 | String full_address = "";
|
---|
| 51 |
|
---|
| 52 | // make sure the URL has protocol, host, and file
|
---|
| 53 | if (address.startsWith("http:")) {
|
---|
| 54 | // the address has all the necessary components
|
---|
| 55 | full_address = address;
|
---|
| 56 | }
|
---|
| 57 | else if (address.startsWith("/")) {
|
---|
| 58 | // there is not protocol and host
|
---|
| 59 | URL document = getDocumentBase();
|
---|
| 60 | int port_no = document.getPort();
|
---|
| 61 |
|
---|
| 62 | String port = (port_no>0) ? ":" + port_no : "";
|
---|
| 63 | full_address = "http://" + document.getHost() + port + address;
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | return full_address;
|
---|
| 67 | }
|
---|
| 68 |
|
---|
[10242] | 69 |
|
---|
| 70 | /* This is the entry point for the GLI applet */
|
---|
[7738] | 71 | public void init()
|
---|
| 72 | {
|
---|
[11951] | 73 | JarTools.initialise(this);
|
---|
| 74 |
|
---|
[10242] | 75 | // Check if the user has agreed to the requested security settings
|
---|
[7923] | 76 | try {
|
---|
| 77 | // Work-around to reduce number of
|
---|
| 78 | // 'Could not lock user prefs' error messages.
|
---|
| 79 | // Thanks to Walter Schatz from the java forums.
|
---|
| 80 | System.setProperty("java.util.prefs.syncInterval","2000000");
|
---|
| 81 | }
|
---|
| 82 | catch (Exception exception) {
|
---|
[10242] | 83 | getContentPane().add(new JLabel("Greenstone Librarian Interface Applet deactivated", JLabel.CENTER));
|
---|
[7923] | 84 | return;
|
---|
| 85 | }
|
---|
| 86 |
|
---|
[7738] | 87 | // Ensure platform specific LAF
|
---|
| 88 | try {
|
---|
| 89 | UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
---|
| 90 | }
|
---|
[9092] | 91 | catch (Exception exception) {
|
---|
[7738] | 92 | exception.printStackTrace();
|
---|
| 93 | }
|
---|
| 94 |
|
---|
[10342] | 95 | // Determine the GLI user directory path
|
---|
| 96 | String gli_user_directory_path = System.getProperty("user.home") + File.separator;
|
---|
| 97 | if (Utility.isWindows()) {
|
---|
| 98 | String windows_home_parameter = getParameter("windowsHome");
|
---|
| 99 | if (windows_home_parameter != null && !windows_home_parameter.equals("")) {
|
---|
| 100 | gli_user_directory_path = windows_home_parameter + File.separator + "GLI" + File.separator;
|
---|
| 101 | }
|
---|
| 102 | else {
|
---|
| 103 | gli_user_directory_path += "Application Data" + File.separator + "Greenstone" + File.separator + "GLI" + File.separator;
|
---|
| 104 | }
|
---|
| 105 | }
|
---|
| 106 | else {
|
---|
| 107 | gli_user_directory_path += ".gli" + File.separator;
|
---|
| 108 | }
|
---|
| 109 | Gatherer.setGLIUserDirectoryPath(gli_user_directory_path);
|
---|
| 110 |
|
---|
[10362] | 111 | // If we're running as an applet we don't have a local GLI, so use the user directory path as the GLI path
|
---|
| 112 | Gatherer.setGLIDirectoryPath(gli_user_directory_path);
|
---|
| 113 |
|
---|
[10242] | 114 | // Set some global variables so we know how we're running
|
---|
| 115 | Gatherer.isApplet = true;
|
---|
[10367] | 116 | String library_url_string = fullLibraryURL(getParameter("gwcgi"));
|
---|
[7738] | 117 |
|
---|
[17000] | 118 | String gs3 = getParameter("gsdl3");
|
---|
| 119 | boolean isGS3 = (gs3 == null || !gs3.equals("true")) ? false : true;
|
---|
| 120 |
|
---|
| 121 | String gliserver_url_string;
|
---|
| 122 | if(!isGS3) {
|
---|
| 123 | gliserver_url_string = library_url_string.substring(0, library_url_string.lastIndexOf('/') + 1) + "gliserver.pl";
|
---|
| 124 | } else {
|
---|
| 125 | gliserver_url_string = library_url_string + "/cgi-bin/gliserver.pl";
|
---|
| 126 | }
|
---|
| 127 |
|
---|
[10242] | 128 | // String debug_param = getParameter("debug");
|
---|
| 129 | // if ((debug_param != null) && (debug_param.matches("true"))) {
|
---|
| 130 | // go.debug = true;
|
---|
| 131 | // }
|
---|
| 132 |
|
---|
[17000] | 133 | String[] args;
|
---|
| 134 | if(!isGS3) {
|
---|
| 135 | String[] gs2_args = {
|
---|
| 136 | "-use_remote_greenstone",
|
---|
| 137 | "-gliserver_url", gliserver_url_string,
|
---|
| 138 | "-library_url", library_url_string,
|
---|
| 139 | // "-debug",
|
---|
| 140 | };
|
---|
| 141 | args = gs2_args;
|
---|
| 142 | } else { // >= GS3
|
---|
| 143 | String[] gs3_args = {
|
---|
| 144 | "-use_remote_greenstone",
|
---|
| 145 | "-gliserver_url", gliserver_url_string,
|
---|
| 146 | "-library_url", library_url_string,
|
---|
| 147 | "-gsdl3",
|
---|
| 148 | //"-debug",
|
---|
| 149 | };
|
---|
| 150 | args = gs3_args;
|
---|
| 151 | }
|
---|
| 152 |
|
---|
[10363] | 153 | File collect_directory = new File(Gatherer.getCollectDirectoryPath());
|
---|
| 154 | if (!collect_directory.exists()) {
|
---|
| 155 | if (JarTools.isInJar("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
|
---|
[10726] | 161 | unzipFromJar("collect.zip", Gatherer.getGLIUserDirectoryPath());
|
---|
[10363] | 162 | }
|
---|
| 163 | else {
|
---|
| 164 | // Prepare an empty collect dir for use
|
---|
| 165 | if (!collect_directory.mkdir()) {
|
---|
| 166 | System.err.println("Warning: Unable to make directory: " + collect_directory);
|
---|
| 167 | }
|
---|
| 168 | }
|
---|
| 169 | }
|
---|
| 170 |
|
---|
| 171 | File metadata_directory = new File(Gatherer.getGLIMetadataDirectoryPath());
|
---|
| 172 | if (!metadata_directory.exists()) {
|
---|
| 173 | // dig out metadata.zip from JAR file and unzip it
|
---|
[10726] | 174 | unzipFromJar("metadata.zip", Gatherer.getGLIDirectoryPath());
|
---|
[10363] | 175 | }
|
---|
| 176 |
|
---|
[10242] | 177 | // Create an instance of the Gatherer class, which will parse the args and prepare the rest of the GLI
|
---|
| 178 | gatherer = new Gatherer(args);
|
---|
[7738] | 179 |
|
---|
[10242] | 180 | // Create a button for the user to press to open the GLI GUI
|
---|
| 181 | JButton launch_GLI_button = new JButton("Launch Greenstone Librarian Interface ...");
|
---|
| 182 | launch_GLI_button.addActionListener(this);
|
---|
| 183 | getContentPane().add(launch_GLI_button);
|
---|
[7738] | 184 | }
|
---|
| 185 |
|
---|
| 186 |
|
---|
| 187 | public void start()
|
---|
| 188 | {
|
---|
| 189 | System.err.println("Start called");
|
---|
| 190 | }
|
---|
| 191 |
|
---|
| 192 |
|
---|
| 193 | public void stop()
|
---|
| 194 | {
|
---|
| 195 | System.err.println("Stop called");
|
---|
| 196 | }
|
---|
| 197 |
|
---|
[10726] | 198 |
|
---|
[7738] | 199 | public void destroy()
|
---|
| 200 | {
|
---|
| 201 | System.err.println("Destroy called");
|
---|
| 202 | gatherer.exit();
|
---|
[17004] | 203 | // Don't do the following: on reloading the applet in the browser
|
---|
| 204 | // the browser (tested on Firefox) crashes if gatherer set to null here.
|
---|
| 205 | //gatherer = null;
|
---|
[7738] | 206 | System.err.println("Done gatherer exit.");
|
---|
| 207 | }
|
---|
| 208 |
|
---|
[10242] | 209 |
|
---|
[7738] | 210 | public void actionPerformed(ActionEvent e)
|
---|
| 211 | {
|
---|
[10242] | 212 | gatherer.openGUI();
|
---|
[7738] | 213 | }
|
---|
[10726] | 214 |
|
---|
| 215 |
|
---|
| 216 | /**
|
---|
| 217 | * Method which unzips a given metadata resoure.
|
---|
| 218 | * @param jar_zip_fname The name of the jar file as a <strong>String</strong>.
|
---|
| 219 | * @param dst_dir The destination directory for unzipping, also as a <strong>String</strong>.
|
---|
| 220 | * @see JarTools.extractFromJar(String, String, boolean)
|
---|
| 221 | */
|
---|
| 222 | static public void unzipFromJar(String jar_zip_fname, String dst_dir)
|
---|
| 223 | {
|
---|
| 224 | if (!dst_dir.endsWith(File.separator)) {
|
---|
| 225 | dst_dir += File.separator;
|
---|
| 226 | }
|
---|
| 227 |
|
---|
| 228 | JarTools.extractFromJar(jar_zip_fname, dst_dir, true);
|
---|
[13328] | 229 | UnzipTools.unzipFile(dst_dir + jar_zip_fname, dst_dir);
|
---|
[10726] | 230 | }
|
---|
[7738] | 231 | }
|
---|