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

Last change on this file since 32153 was 32153, checked in by ak19, 6 years ago

2 Bugfixes and tidying up errorhandling in JarTools. 1. Dr Bainbridge fixed issue surrounding env.Path rather than env.PATH being used on Windows, while the empty env.PATH was being concatenated as a variable name by build.xml. This resulted in a cyclical reference, noticed when running the GLI Web Start Application (converted from GLI Applet). Fix is in build.xml. 2. My bugfix to WebGatherer.java, the new GLI Web Start Application. The collectionDir wasn't set correctly until the Gatherer object was instantiated, but the collect dir needed to be known by other code beforehand. So shifted the Gatherer object instantiation up a bit. 3. Can't yet reproduce the Exception seen twice before when running GLI Web Start application. The exception was thrown in ZipTools.java. Tested by rerunning the applet repeatedly, but it hasn't struck again yet. Perhaps it's been fixed now because of the other changes?

  • Property svn:keywords set to Author Date Id Revision
File size: 7.7 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.UnzipTools;
40import org.greenstone.gatherer.util.Utility;
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 JarTools.initialise(this);
74
75 // Check if the user has agreed to the requested security settings
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) {
83 getContentPane().add(new JLabel("Greenstone Librarian Interface Applet deactivated", JLabel.CENTER));
84 return;
85 }
86
87 // Ensure platform specific LAF
88 try {
89 //UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
90 UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
91 }
92 catch (Exception exception) {
93 exception.printStackTrace();
94 }
95
96 // Determine the GLI user directory path
97 String gli_user_directory_path = System.getProperty("user.home") + File.separator;
98 if (Utility.isWindows()) {
99 String windows_home_parameter = getParameter("windowsHome");
100 if (windows_home_parameter != null && !windows_home_parameter.equals("")) {
101 gli_user_directory_path = windows_home_parameter + File.separator + "GLI" + File.separator;
102 }
103 else {
104 gli_user_directory_path += "Application Data" + File.separator + "Greenstone" + File.separator + "GLI" + File.separator;
105 }
106 }
107 else {
108 gli_user_directory_path += ".gli" + File.separator;
109 }
110 Gatherer.setGLIUserDirectoryPath(gli_user_directory_path);
111
112 // If we're running as an applet we don't have a local GLI, so use the user directory path as the GLI path
113 Gatherer.setGLIDirectoryPath(gli_user_directory_path);
114
115 // Set some global variables so we know how we're running
116 Gatherer.isApplet = true;
117 String library_url_string = fullLibraryURL(getParameter("gwcgi"));
118
119 String gs3 = getParameter("gsdl3");
120 boolean isGS3 = (gs3 == null || !gs3.equals("true")) ? false : true;
121
122 String gliserver_url_string;
123 if(!isGS3) {
124 gliserver_url_string = library_url_string.substring(0, library_url_string.lastIndexOf('/') + 1) + "gliserver.pl";
125 } else {
126 gliserver_url_string = library_url_string + "/cgi-bin/gliserver.pl";
127 }
128
129 // String debug_param = getParameter("debug");
130 // if ((debug_param != null) && (debug_param.matches("true"))) {
131 // go.debug = true;
132 // }
133
134 String[] args;
135 if(!isGS3) {
136 String[] gs2_args = {
137 "-use_remote_greenstone",
138 "-gliserver_url", gliserver_url_string,
139 "-library_url", library_url_string,
140 // "-debug",
141 };
142 args = gs2_args;
143 } else { // >= GS3
144 String[] gs3_args = {
145 "-use_remote_greenstone",
146 "-gliserver_url", gliserver_url_string,
147 "-library_url", library_url_string,
148 "-gsdl3",
149 //"-debug",
150 };
151 args = gs3_args;
152 }
153
154 // For WebGatherer.java, which uses Java Web Start over JNLP to run the repurposed "applet" as application,
155 // it turned out that for GS3, we need the collectionDirectoryPath set for the subsequent code to work.
156 // In WebGatherer.java, moved the instantiation of the Gatherer object here, but to avoid major changes to
157 // this GathererApplet.java class, just calling the relevant line in Gatherer() constructor at this stage:
158 Gatherer.setCollectDirectoryPath(Gatherer.getGLIUserDirectoryPath() + "collect" + File.separator);
159
160 File collect_directory = new File(Gatherer.getCollectDirectoryPath());
161 if (!collect_directory.exists()) {
162 if (JarTools.isInJar("collect.zip")) {
163 // Dig out collect.zip from JAR file and unzip it (thereby
164 // creating collect directory and descendants.
165 // This is done to seed gsdl home folder with config files
166 // for documented example collections so "base this on
167 // existing collection" works
168 unzipFromJar("collect.zip", Gatherer.getGLIUserDirectoryPath());
169 }
170 else {
171 // Prepare an empty collect dir for use
172 if (!collect_directory.mkdir()) {
173 System.err.println("Warning: Unable to make directory: " + collect_directory);
174 }
175 }
176 }
177
178 File metadata_directory = new File(Gatherer.getGLIMetadataDirectoryPath());
179 if (!metadata_directory.exists()) {
180 // dig out metadata.zip from JAR file and unzip it
181 unzipFromJar("metadata.zip", Gatherer.getGLIDirectoryPath());
182 }
183
184 // Create an instance of the Gatherer class, which will parse the args and prepare the rest of the GLI
185 gatherer = new Gatherer(args);
186
187 // Create a button for the user to press to open the GLI GUI
188 JButton launch_GLI_button = new JButton("Launch Greenstone Librarian Interface ...");
189 launch_GLI_button.addActionListener(this);
190 getContentPane().add(launch_GLI_button);
191 }
192
193
194 public void start()
195 {
196 System.err.println("Start called");
197 }
198
199
200 public void stop()
201 {
202 System.err.println("Stop called");
203 }
204
205
206 public void destroy()
207 {
208 System.err.println("Destroy called");
209 gatherer.exit();
210 gatherer = null;
211 System.err.println("Done gatherer exit.");
212 }
213
214
215 public void actionPerformed(ActionEvent e)
216 {
217 gatherer.openGUI();
218 }
219
220
221 /**
222 * Method which unzips a given metadata resource.
223 * @param jar_zip_fname The name of the jar file as a <strong>String</strong>.
224 * @param dst_dir The destination directory for unzipping, also as a <strong>String</strong>.
225 * @see JarTools.extractFromJar(String, String, boolean)
226 */
227 static public void unzipFromJar(String jar_zip_fname, String dst_dir)
228 {
229 if (!dst_dir.endsWith(File.separator)) {
230 dst_dir += File.separator;
231 }
232
233 JarTools.extractFromJar(jar_zip_fname, dst_dir, true);
234 UnzipTools.unzipFile(dst_dir + jar_zip_fname, dst_dir);
235 }
236}
Note: See TracBrowser for help on using the repository browser.