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.awt.event.ActionEvent;
|
---|
31 | import java.awt.event.ActionListener;
|
---|
32 | import java.io.*;
|
---|
33 | import java.net.*;
|
---|
34 | import javax.swing.JApplet;
|
---|
35 | import java.applet.*;
|
---|
36 |
|
---|
37 | import java.awt.*;
|
---|
38 | import java.awt.event.*;
|
---|
39 | import java.io.*;
|
---|
40 | import java.lang.*;
|
---|
41 | import java.net.*;
|
---|
42 | import java.util.*;
|
---|
43 | import javax.swing.*;
|
---|
44 | import javax.swing.plaf.*;
|
---|
45 | import javax.swing.text.*;
|
---|
46 | import org.greenstone.gatherer.Configuration;
|
---|
47 | import org.greenstone.gatherer.GAuthenticator;
|
---|
48 | import org.greenstone.gatherer.cdm.CommandTokenizer;
|
---|
49 | import org.greenstone.gatherer.collection.CollectionManager;
|
---|
50 | import org.greenstone.gatherer.feedback.ActionRecorderDialog;
|
---|
51 | import org.greenstone.gatherer.file.FileManager;
|
---|
52 | import org.greenstone.gatherer.file.FileAssociationManager;
|
---|
53 | import org.greenstone.gatherer.gui.Coloring;
|
---|
54 | import org.greenstone.gatherer.gui.GUIManager;
|
---|
55 | import org.greenstone.gatherer.gui.ModalDialog;
|
---|
56 | import org.greenstone.gatherer.gui.Splash;
|
---|
57 | import org.greenstone.gatherer.gui.URLField;
|
---|
58 | import org.greenstone.gatherer.gui.WarningDialog;
|
---|
59 | import org.greenstone.gatherer.msm.MDSTest;
|
---|
60 | import org.greenstone.gatherer.msm.MetadataSetManager;
|
---|
61 | import org.greenstone.gatherer.util.ArrayTools;
|
---|
62 | import org.greenstone.gatherer.util.GSDLSiteConfig;
|
---|
63 | import org.greenstone.gatherer.util.StaticStrings;
|
---|
64 | import org.greenstone.gatherer.util.Utility;
|
---|
65 | import sun.misc.*;
|
---|
66 |
|
---|
67 | public class GathererApplet extends JApplet implements ActionListener
|
---|
68 | {
|
---|
69 | Gatherer gatherer;
|
---|
70 | GUIManager g_man;
|
---|
71 | Dimension size = new Dimension(800, 540);
|
---|
72 |
|
---|
73 | protected String fullLibraryURL(String address)
|
---|
74 | {
|
---|
75 | String full_address = "";
|
---|
76 |
|
---|
77 | // make sure the URL has protocol, host, and file
|
---|
78 | if (address.startsWith("http:")) {
|
---|
79 | // the address has all the necessary components
|
---|
80 | full_address = address;
|
---|
81 | }
|
---|
82 | else if (address.startsWith("/")) {
|
---|
83 | // there is not protocol and host
|
---|
84 | URL document = getDocumentBase();
|
---|
85 | int port_no = document.getPort();
|
---|
86 |
|
---|
87 | String port = (port_no>0) ? ":" + port_no : "";
|
---|
88 | full_address = "http://" + document.getHost() + port + address;
|
---|
89 | }
|
---|
90 |
|
---|
91 | return full_address;
|
---|
92 | }
|
---|
93 |
|
---|
94 | public void init()
|
---|
95 | {
|
---|
96 | try {
|
---|
97 | // Work-around to reduce number of
|
---|
98 | // 'Could not lock user prefs' error messages.
|
---|
99 | // Thanks to Walter Schatz from the java forums.
|
---|
100 | System.setProperty("java.util.prefs.syncInterval","2000000");
|
---|
101 | }
|
---|
102 |
|
---|
103 | catch (Exception exception) {
|
---|
104 | // convenient way of finding out if user has agreed to
|
---|
105 | // to requested security settings
|
---|
106 |
|
---|
107 | JLabel lab
|
---|
108 | = new JLabel("Greenstone Librarian Interface Applet deactivated",
|
---|
109 | JLabel.CENTER);
|
---|
110 | getContentPane().add(lab);
|
---|
111 | return;
|
---|
112 | }
|
---|
113 |
|
---|
114 | // Ensure platform specific LAF
|
---|
115 | try {
|
---|
116 | UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
---|
117 | }
|
---|
118 | catch(Exception exception) {
|
---|
119 | exception.printStackTrace();
|
---|
120 | }
|
---|
121 |
|
---|
122 | String gwcgi = getParameter("gwcgi");
|
---|
123 | String library_cgi = fullLibraryURL(gwcgi);
|
---|
124 | int cgi_base_cut = library_cgi.lastIndexOf('/');
|
---|
125 | String cgi_base = library_cgi.substring(0,cgi_base_cut+1);
|
---|
126 |
|
---|
127 | gatherer = new Gatherer();
|
---|
128 |
|
---|
129 | String gli_user_folder = Utility.getGLIUserFolder().toString();
|
---|
130 |
|
---|
131 | String[] args = { "-gsdl", gli_user_folder,
|
---|
132 | "-library", library_cgi,
|
---|
133 | };
|
---|
134 |
|
---|
135 | GetOpt go = new GetOpt(args);
|
---|
136 |
|
---|
137 | if (go.feedback_enabled) {
|
---|
138 | // If feedback is enabled, set up the recorder dialog.
|
---|
139 | // Use the default locale for now - this will be changed by the
|
---|
140 | // Gatherer run method
|
---|
141 | Locale currLocale = Locale.getDefault();
|
---|
142 | ActionRecorderDialog dlg = new ActionRecorderDialog (currLocale);
|
---|
143 | gatherer.feedback_enabled = true;
|
---|
144 | gatherer.feedback_dialog = dlg;
|
---|
145 | }
|
---|
146 |
|
---|
147 | Gatherer.isGsdlRemote = true;
|
---|
148 | Gatherer.cgiBase = cgi_base;
|
---|
149 |
|
---|
150 | Utility.BASE_DIR = go.gsdl_path;
|
---|
151 | if (!Utility.BASE_DIR.endsWith(File.separator)) {
|
---|
152 | Utility.BASE_DIR += File.separator;
|
---|
153 | }
|
---|
154 |
|
---|
155 | Utility.CACHE_DIR = Utility.BASE_DIR + "cache" + File.separator;
|
---|
156 | Utility.HELP_DIR = Utility.BASE_DIR + "help" + File.separator;
|
---|
157 | Utility.METADATA_DIR = Utility.BASE_DIR + "metadata" + File.separator;
|
---|
158 | Utility.RECYCLE = Utility.BASE_DIR + "recycle" + File.separator;
|
---|
159 | Utility.RES_DIR = Utility.BASE_DIR + "resource" + File.separator;
|
---|
160 | Utility.WELCOME_DIR = Utility.BASE_DIR + "welcome" + File.separator;
|
---|
161 |
|
---|
162 | Configuration.TEMPLATE_CONFIG_XML = "xml/configRemote.xml";
|
---|
163 | Configuration.CONFIG_XML = "configRemote.xml";
|
---|
164 | Configuration.GS3_CONFIG_XML = "config3Remote.xml";
|
---|
165 |
|
---|
166 | File gli_user_dir = new File(gli_user_folder);
|
---|
167 | if (!gli_user_dir.exists()) {
|
---|
168 | gli_user_dir.mkdirs();
|
---|
169 | }
|
---|
170 |
|
---|
171 | File col_dir = new File(Utility.getCollectDir(go.gsdl_path));
|
---|
172 | if (!col_dir.exists()) {
|
---|
173 | col_dir.mkdir();
|
---|
174 | }
|
---|
175 |
|
---|
176 | File metadata_directory = new File(Utility.METADATA_DIR);
|
---|
177 | if (!metadata_directory.exists()) {
|
---|
178 | // digout metadata.zip from JAR file and unzip it
|
---|
179 | Utility.unzipFromJar(Utility.METADATA_ZIP,gli_user_folder);
|
---|
180 | }
|
---|
181 |
|
---|
182 | File plug_dat = new File(Utility.BASE_DIR + "plugins.dat");
|
---|
183 | if (!plug_dat.exists()) {
|
---|
184 | Utility.extractFromJar("plugins.dat",Utility.BASE_DIR);
|
---|
185 | }
|
---|
186 |
|
---|
187 | File class_dat = new File(Utility.BASE_DIR + "classifiers.dat");
|
---|
188 | if (!class_dat.exists()) {
|
---|
189 | Utility.extractFromJar("classifiers.dat",Utility.BASE_DIR);
|
---|
190 | }
|
---|
191 |
|
---|
192 | g_man = gatherer.init(size, go.gsdl_path, go.gsdl3_path,
|
---|
193 | go.exec_path, go.debug, go.perl_path,
|
---|
194 | go.no_load, go.filename, go.site_name,
|
---|
195 | go.servlet_path, go.mirroring_enabled,
|
---|
196 | go.wget_version_str, go.wget_path);
|
---|
197 |
|
---|
198 |
|
---|
199 | JButton bttn = new JButton("Launch Greenstone Librarian Interface ...");
|
---|
200 | bttn.addActionListener(this);
|
---|
201 | getContentPane().add(bttn);
|
---|
202 | }
|
---|
203 |
|
---|
204 |
|
---|
205 |
|
---|
206 | public void start()
|
---|
207 | {
|
---|
208 | System.err.println("Start called");
|
---|
209 | }
|
---|
210 |
|
---|
211 |
|
---|
212 |
|
---|
213 | public void stop()
|
---|
214 | {
|
---|
215 | System.err.println("Stop called");
|
---|
216 |
|
---|
217 | }
|
---|
218 |
|
---|
219 | public void destroy()
|
---|
220 | {
|
---|
221 | System.err.println("Destroy called");
|
---|
222 | gatherer.exit();
|
---|
223 | System.err.println("Done gatherer exit.");
|
---|
224 | }
|
---|
225 |
|
---|
226 | public void actionPerformed(ActionEvent e)
|
---|
227 | {
|
---|
228 | Splash splash = null;
|
---|
229 |
|
---|
230 | gatherer.run(size, splash, g_man);
|
---|
231 | }
|
---|
232 | }
|
---|