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