source: main/trunk/gli/src/org/greenstone/gatherer/WebGatherer.java@ 32150

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

I changed gli4gs3.xsl to rewrite the applet page produced by PageAction.java to replace it with the JNLP Web Start version of GLI. Dr Bainbridge got this to work by changing the Librarian Interface link on the main page to have a download attribute, which will force the linked item to be downloaded. The download attribute is set to the name to assign to the downloaded item, the jnlp file. Now removing the unnecessary static GLIappWebStart.jnlp from the gli folder (as it used some fixed strings for dynamic values) and removed the unnecessary style.xsl and icons.xsl from default\transform as they were used by the now bypassed applet and were moreover GS2 styling.

File size: 8.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.awt.event.ActionEvent;
31import java.awt.event.ActionListener;
32import java.net.*;
33import javax.swing.JApplet;
34
35import java.io.*;
36//import javax.jnlp.*;
37import javax.swing.*;
38import org.greenstone.gatherer.util.JarTools;
39import org.greenstone.gatherer.util.UnzipTools;
40import org.greenstone.gatherer.util.Utility;
41
42import java.util.*;
43
44public class WebGatherer
45{
46
47 protected static String fullLibraryURL(String address)
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 }
56 /*else if (address.startsWith("/")) {
57 // there is not protocol and host
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();
61 int port_no = document.getPort();
62
63 String port = (port_no>0) ? ":" + port_no : "";
64 full_address = "http://" + document.getHost() + port + address;
65 }*/
66
67 return full_address;
68 }
69
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 }
75
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[])
78 {
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
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) {
125 System.err.println("Greenstone Librarian Interface Applet deactivated");
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()) {
141 String windows_home_parameter = windowsHome_arg;
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
158 Gatherer.isApplet = false;
159 String library_url_string = fullLibraryURL(gwcgi_arg);
160
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
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
171 // String debug_param = debug_arg;
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
196 File collect_directory = new File(Gatherer.getCollectDirectoryPath());
197 if (!collect_directory.exists()) {
198 if (JarTools.isInJar("collect.zip")) {
199 // Dig out collect.zip from JAR file and unzip it (thereby
200 // creating collect directory and descendants.
201 // This is done to seed gsdl home folder with config files
202 // for documented example collections so "base this on
203 // existing collection" works
204 unzipFromJar("collect.zip", Gatherer.getGLIUserDirectoryPath());
205 }
206 else {
207 // Prepare an empty collect dir for use
208 if (!collect_directory.mkdir()) {
209 System.err.println("Warning: Unable to make directory: " + collect_directory);
210 }
211 }
212 }
213
214 File metadata_directory = new File(Gatherer.getGLIMetadataDirectoryPath());
215 if (!metadata_directory.exists()) {
216 // dig out metadata.zip from JAR file and unzip it
217 unzipFromJar("metadata.zip", Gatherer.getGLIDirectoryPath());
218 }
219
220 // Create an instance of the Gatherer class, which will parse the args and prepare the rest of the GLI
221 gatherer = new Gatherer(args);
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.