source: trunk/gli/src/org/greenstone/gatherer/GathererApplet.java@ 10363

Last change on this file since 10363 was 10363, checked in by mdewsnip, 19 years ago

Moved some applet specific code out of Gatherer.java and into GathererApplet.java.

  • Property svn:keywords set to Author Date Id Revision
File size: 6.4 KB
Line 
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
28package org.greenstone.gatherer;
29
30import java.applet.*;
31import java.awt.event.ActionEvent;
32import java.awt.event.ActionListener;
33import java.net.*;
34import javax.swing.JApplet;
35
36import java.io.*;
37import javax.swing.*;
38import org.greenstone.gatherer.util.JarTools;
39import org.greenstone.gatherer.util.Utility;
40import org.greenstone.gatherer.util.ZipTools;
41
42
43public class GathererApplet extends JApplet implements ActionListener
44{
45 private Gatherer gatherer = null;
46
47
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
69
70 /* This is the entry point for the GLI applet */
71 public void init()
72 {
73 // Check if the user has agreed to the requested security settings
74 try {
75 // Work-around to reduce number of
76 // 'Could not lock user prefs' error messages.
77 // Thanks to Walter Schatz from the java forums.
78 System.setProperty("java.util.prefs.syncInterval","2000000");
79 }
80 catch (Exception exception) {
81 getContentPane().add(new JLabel("Greenstone Librarian Interface Applet deactivated", JLabel.CENTER));
82 return;
83 }
84
85 // Ensure platform specific LAF
86 try {
87 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
88 }
89 catch (Exception exception) {
90 exception.printStackTrace();
91 }
92
93 // Determine the GLI user directory path
94 String gli_user_directory_path = System.getProperty("user.home") + File.separator;
95 if (Utility.isWindows()) {
96 String windows_home_parameter = getParameter("windowsHome");
97 if (windows_home_parameter != null && !windows_home_parameter.equals("")) {
98 gli_user_directory_path = windows_home_parameter + File.separator + "GLI" + File.separator;
99 }
100 else {
101 gli_user_directory_path += "Application Data" + File.separator + "Greenstone" + File.separator + "GLI" + File.separator;
102 }
103 }
104 else {
105 gli_user_directory_path += ".gli" + File.separator;
106 }
107 Gatherer.setGLIUserDirectoryPath(gli_user_directory_path);
108
109 // Ensure the GLI user directory exists
110 File gli_user_directory = new File(gli_user_directory_path);
111 if (!gli_user_directory.exists() && !gli_user_directory.mkdirs()) {
112 System.err.println("Error: Unable to make directory: " + gli_user_directory.toString());
113 }
114
115 // If we're running as an applet we don't have a local GLI, so use the user directory path as the GLI path
116 Gatherer.setGLIDirectoryPath(gli_user_directory_path);
117
118 // Set some global variables so we know how we're running
119 Gatherer.isApplet = true;
120 Gatherer.isGsdlRemote = true;
121 String library_cgi = fullLibraryURL(getParameter("gwcgi"));
122 Gatherer.cgiBase = library_cgi.substring(0, library_cgi.lastIndexOf('/') + 1);
123
124 // String debug_param = getParameter("debug");
125 // if ((debug_param != null) && (debug_param.matches("true"))) {
126 // go.debug = true;
127 // }
128
129 String[] args = { "-gsdl", gli_user_directory.toString(),
130 "-library_url", library_cgi,
131 };
132
133 File collect_directory = new File(Gatherer.getCollectDirectoryPath());
134 if (!collect_directory.exists()) {
135 if (JarTools.isInJar("collect.zip")) {
136 // Dig out collect.zip from JAR file and unzip it (thereby
137 // creating collect directory and descendants.
138 // This is done to seed gsdl home folder with config files
139 // for documented example collections so "base this on
140 // existing collection" works
141 ZipTools.unzipFromJar("collect.zip", Gatherer.getGLIUserDirectoryPath());
142 }
143 else {
144 // Prepare an empty collect dir for use
145 if (!collect_directory.mkdir()) {
146 System.err.println("Warning: Unable to make directory: " + collect_directory);
147 }
148 }
149 }
150
151 File metadata_directory = new File(Gatherer.getGLIMetadataDirectoryPath());
152 if (!metadata_directory.exists()) {
153 // dig out metadata.zip from JAR file and unzip it
154 ZipTools.unzipFromJar("metadata.zip", Gatherer.getGLIDirectoryPath());
155 }
156
157 // Create an instance of the Gatherer class, which will parse the args and prepare the rest of the GLI
158 gatherer = new Gatherer(args);
159
160 // Create a button for the user to press to open the GLI GUI
161 JButton launch_GLI_button = new JButton("Launch Greenstone Librarian Interface ...");
162 launch_GLI_button.addActionListener(this);
163 getContentPane().add(launch_GLI_button);
164 }
165
166
167
168 public void start()
169 {
170 System.err.println("Start called");
171 }
172
173
174
175 public void stop()
176 {
177 System.err.println("Stop called");
178
179 }
180
181 public void destroy()
182 {
183 System.err.println("Destroy called");
184 gatherer.exit();
185 System.err.println("Done gatherer exit.");
186 }
187
188
189 public void actionPerformed(ActionEvent e)
190 {
191 gatherer.openGUI();
192
193 // If there was an open collection last session, reopen it
194 if (Gatherer.open_collection_file_path != null) {
195 Gatherer.c_man.loadCollection(Gatherer.open_collection_file_path);
196 }
197 }
198}
Note: See TracBrowser for help on using the repository browser.