source: main/trunk/gli/src/org/greenstone/gatherer/WebGatherer.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?

File size: 8.5 KB
RevLine 
[32138]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.awt.event.ActionEvent;
31import java.awt.event.ActionListener;
32import java.net.*;
33import javax.swing.JApplet;
34
35import java.io.*;
[32139]36//import javax.jnlp.*;
[32138]37import javax.swing.*;
38import org.greenstone.gatherer.util.JarTools;
39import org.greenstone.gatherer.util.UnzipTools;
40import org.greenstone.gatherer.util.Utility;
41
[32139]42import java.util.*;
[32138]43
[32139]44public class WebGatherer
[32138]45{
46
[32139]47 protected static String fullLibraryURL(String address)
[32138]48 {
49 String full_address = "";
50
51 // make sure the URL has protocol, host, and file
52 if (address.startsWith("http:")) {
53 // the address has all the necessary components
54 full_address = address;
55 }
[32139]56 /*else if (address.startsWith("/")) {
[32138]57 // there is not protocol and host
[32139]58 // JNLP replacement for applet getDocumentBase, https://stackoverflow.com/questions/6371493/java-web-start-getdocumentbase
59 BasicService bs = (BasicService) ServiceManager.lookup("javax.jnlp.BasicService");
60 URL document = bs.getCodeBase();
[32138]61 int port_no = document.getPort();
62
63 String port = (port_no>0) ? ":" + port_no : "";
64 full_address = "http://" + document.getHost() + port + address;
[32139]65 }*/
[32138]66
67 return full_address;
68 }
69
[32139]70 static private String getParameter(String cmd_arg, String flagName) {
71 int start_index = cmd_arg.indexOf(flagName) + flagName.length();
72 cmd_arg = cmd_arg.substring(start_index);
73 return cmd_arg;
74 }
[32138]75
[32139]76 /* This is the entry point for the Java Web Start version of GLI (a rewrite of GathererApplet as a Java Web Start application) */
77 static public void main(String cmdArgs[])
[32138]78 {
[32139]79 Gatherer gatherer = null;
80 JarTools.initialise(WebGatherer.class);
81
82 String gwcgi_arg = null;
83 String gsdl3_arg = "false"; // String, "true" or "false"
84 String windowsHome_arg = null;
85 String debug_arg = "false"; // String, "true" or "false"
86
87 for(int i = 0; i<cmdArgs.length; i++) {
88 ///System.err.println("*** cmdarg " + i + " = " + cmdArgs[i]);
89
90 if(cmdArgs[i].contains("gwcgi=")) {
91 gwcgi_arg = getParameter(cmdArgs[i], "gwcgi=");
92 } else if(cmdArgs[i].contains("gsdl3=")) {
93 gsdl3_arg = getParameter(cmdArgs[i], "gsdl3=");
94 } else if(cmdArgs[i].contains("windowsHome=")) {
95 windowsHome_arg = getParameter(cmdArgs[i], "windowsHome=");
96 } else if(cmdArgs[i].contains("debug=")) {
97 debug_arg = getParameter(cmdArgs[i], "debug=");
98 }
99 }
100
101 ///System.err.println("*** gwcgi_arg = " + gwcgi_arg);
102 ///System.err.println("*** gsdl3_arg = " + gsdl3_arg);
103 // More debugging:
104 Map<String,String> envMap = System.getenv();
105 Set<Map.Entry<String,String>> entries = envMap.entrySet();
106 Iterator<Map.Entry<String, String>> i = entries.iterator();
107 System.err.println("*** ENVIRONMENT: ");
108 while(i.hasNext()) {
109 Map.Entry<String, String> entry = i.next();
110 String key = entry.getKey();
111 String value = entry.getValue();
112 System.err.println("*** key = " + key);
113 System.err.println("*** val = " + value);
114 }
115 // End debugging
[32138]116
117 // Check if the user has agreed to the requested security settings
118 try {
119 // Work-around to reduce number of
120 // 'Could not lock user prefs' error messages.
121 // Thanks to Walter Schatz from the java forums.
122 System.setProperty("java.util.prefs.syncInterval","2000000");
123 }
124 catch (Exception exception) {
[32139]125 System.err.println("Greenstone Librarian Interface Applet deactivated");
[32138]126 return;
127 }
128
129 // Ensure platform specific LAF
130 try {
131 //UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
132 UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
133 }
134 catch (Exception exception) {
135 exception.printStackTrace();
136 }
137
138 // Determine the GLI user directory path
139 String gli_user_directory_path = System.getProperty("user.home") + File.separator;
140 if (Utility.isWindows()) {
[32139]141 String windows_home_parameter = windowsHome_arg;
[32138]142 if (windows_home_parameter != null && !windows_home_parameter.equals("")) {
143 gli_user_directory_path = windows_home_parameter + File.separator + "GLI" + File.separator;
144 }
145 else {
146 gli_user_directory_path += "Application Data" + File.separator + "Greenstone" + File.separator + "GLI" + File.separator;
147 }
148 }
149 else {
150 gli_user_directory_path += ".gli" + File.separator;
151 }
152 Gatherer.setGLIUserDirectoryPath(gli_user_directory_path);
153
154 // If we're running as an applet we don't have a local GLI, so use the user directory path as the GLI path
155 Gatherer.setGLIDirectoryPath(gli_user_directory_path);
156
157 // Set some global variables so we know how we're running
[32139]158 Gatherer.isApplet = false;
159 String library_url_string = fullLibraryURL(gwcgi_arg);
[32138]160
[32150]161 String gs3 = gsdl3_arg; // but we'll pass -use_remote_greenstone below, to ensure we use the branch of the code that does connects a GLI on a client machine to a remote GS3 server
[32138]162 boolean isGS3 = (gs3 == null || !gs3.equals("true")) ? false : true;
163
164 String gliserver_url_string;
165 if(!isGS3) {
166 gliserver_url_string = library_url_string.substring(0, library_url_string.lastIndexOf('/') + 1) + "gliserver.pl";
167 } else {
168 gliserver_url_string = library_url_string + "/cgi-bin/gliserver.pl";
169 }
170
[32139]171 // String debug_param = debug_arg;
[32138]172 // if ((debug_param != null) && (debug_param.matches("true"))) {
173 // go.debug = true;
174 // }
175
176 String[] args;
177 if(!isGS3) {
178 String[] gs2_args = {
179 "-use_remote_greenstone",
180 "-gliserver_url", gliserver_url_string,
181 "-library_url", library_url_string,
182 // "-debug",
183 };
184 args = gs2_args;
185 } else { // >= GS3
186 String[] gs3_args = {
187 "-use_remote_greenstone",
188 "-gliserver_url", gliserver_url_string,
189 "-library_url", library_url_string,
190 "-gsdl3",
191 //"-debug",
192 };
193 args = gs3_args;
194 }
195
[32153]196 // Create an instance of the Gatherer class, which will parse the args and prepare the rest of the GLI
197 gatherer = new Gatherer(args); // Do this early as it will also call Gatherer.setCollectDirectoryPath(), because we need that to have been set hereafter.
198
[32138]199 File collect_directory = new File(Gatherer.getCollectDirectoryPath());
200 if (!collect_directory.exists()) {
201 if (JarTools.isInJar("collect.zip")) {
202 // Dig out collect.zip from JAR file and unzip it (thereby
203 // creating collect directory and descendants.
204 // This is done to seed gsdl home folder with config files
205 // for documented example collections so "base this on
206 // existing collection" works
207 unzipFromJar("collect.zip", Gatherer.getGLIUserDirectoryPath());
208 }
209 else {
210 // Prepare an empty collect dir for use
211 if (!collect_directory.mkdir()) {
212 System.err.println("Warning: Unable to make directory: " + collect_directory);
213 }
214 }
215 }
216
217 File metadata_directory = new File(Gatherer.getGLIMetadataDirectoryPath());
218 if (!metadata_directory.exists()) {
219 // dig out metadata.zip from JAR file and unzip it
220 unzipFromJar("metadata.zip", Gatherer.getGLIDirectoryPath());
221 }
222
223 gatherer.openGUI();
224 }
225
226
227 /**
228 * Method which unzips a given metadata resource.
229 * @param jar_zip_fname The name of the jar file as a <strong>String</strong>.
230 * @param dst_dir The destination directory for unzipping, also as a <strong>String</strong>.
231 * @see JarTools.extractFromJar(String, String, boolean)
232 */
233 static public void unzipFromJar(String jar_zip_fname, String dst_dir)
234 {
235 if (!dst_dir.endsWith(File.separator)) {
236 dst_dir += File.separator;
237 }
238
239 JarTools.extractFromJar(jar_zip_fname, dst_dir, true);
240 UnzipTools.unzipFile(dst_dir + jar_zip_fname, dst_dir);
241 }
242}
Note: See TracBrowser for help on using the repository browser.