source: main/trunk/gli/src/org/greenstone/gatherer/GetOpt.java@ 32923

Last change on this file since 32923 was 32689, checked in by ak19, 5 years ago

If not testing, don't need GLI's GUI components to be assigned names. Leaves GLI more efficient when run as GLI proper, while GLI will do a bit more work when running GLI for testing.

  • Property svn:keywords set to Author Date Id Revision
File size: 11.6 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 and David Bainbridge,
9 * Greenstone Digital Library, University of Waikato
10 *
11 * Copyright (C) 1999 New Zealand Digital Library Project
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 *########################################################################
27 */
28package org.greenstone.gatherer;
29
30import java.io.*;
31import org.greenstone.gatherer.util.StaticStrings;
32import org.greenstone.gatherer.util.Utility;
33
34public class GetOpt
35{
36 public boolean testing_mode = false; // true if running GLI for tutorial testing: want names assigned to GUI components
37
38 public boolean debug = false;
39 public boolean feedback_enabled = false;
40 public boolean no_load = false;
41 public boolean use_remote_greenstone = false;
42 public boolean new_set = false;
43 public boolean run_gsdl3 = false;
44
45 public String client_operating_system = null;
46 public String collect_directory_path = null;
47 public String filename = null;
48 public String gliserver_url_string = null;
49 public String gsdl_path = null;
50 public String gsdl3_path = null;
51 public String gsdl3_src_path = null;
52 public String library_url_string = null;
53 public String local_library_path = null;
54 public String perl_path = null;
55 public String site_name = null; // for GS3
56 public String servlet_path = null;
57 public String metadata_path = null;
58
59 protected FedoraInfo fedora_info = null;
60
61 public GetOpt(String[] args)
62 {
63 // Default dictionary. Only used for starting error messages.
64 Dictionary dictionary = new Dictionary(null, null);
65
66 fedora_info = new FedoraInfo();
67
68 // Parse arguments
69 int argument_index = 0;
70 String next_token = null;
71
72 while(argument_index < args.length || next_token != null) {
73 // 1. We start by attempting to parse an argument name. An argument
74 // must start with a '-', and should not contain spaces. If
75 // anything else is encountered it is ignored.
76
77 String argument_name = null;
78 if(next_token == null) {
79 next_token = args[argument_index];
80 argument_index++;
81 }
82
83 if(next_token.startsWith(StaticStrings.MINUS_CHARACTER)) {
84 // Trim second '-' just to be kind to Unixy-type people
85 if(next_token.startsWith(StaticStrings.MINUS_CHARACTER + StaticStrings.MINUS_CHARACTER)) {
86 argument_name = next_token.substring(1);
87 }
88 else {
89 argument_name = next_token;
90 }
91 }
92 next_token = null;
93 // 2. If we now have an argument name we continue by attempting
94 // to parse a value. A value is taken to be the sequence of
95 // space seperated Strings between the last argument name
96 // and up to but not including the next argument name. Of
97 // course an argument needn't have any value (ie -debug,
98 // -help), in which case value will be null.
99 if(argument_name != null) {
100 String argument_value = null;
101 StringBuffer argument_value_buffer = new StringBuffer("");
102 while(argument_index < args.length && next_token == null) {
103 next_token = args[argument_index];
104 argument_index++;
105 // If we just parsed an arbitary String then append it to value, followed by a single space
106 if(!next_token.startsWith(StaticStrings.MINUS_CHARACTER)) {
107 argument_value_buffer.append(next_token);
108 argument_value_buffer.append(StaticStrings.SPACE_CHARACTER);
109 next_token = null;
110 }
111 // If the argument token retrieved is an argument name,
112 // then leave it in next_token, which will cause the
113 // argument parsing process to move onto the next step.
114 }
115 // If a value now exists in argument buffer, retrieve
116 // it. Remove the last character as it will be an erroneous
117 // space.
118 if(argument_value_buffer.length() > 0) {
119 argument_value = argument_value_buffer.substring(0, argument_value_buffer.length() - 1);
120 }
121
122 // 3. We now have the argument name, and any associated
123 // value. We are ready to store the data in the
124 // appropriate variables.
125 DebugStream.println("Parsed Argument: name=" + argument_name + (argument_value != null ? (", value=" + argument_value) : ", no value"));
126 // 3a. First those arguments that have no associated value
127 if(argument_value == null) {
128 if(argument_name.equals(StaticStrings.HELP_ARGUMENT)) {
129 System.out.println(Dictionary.get("General.Usage"));
130 System.exit(0);
131 }
132 // Run GLI in testing mode. Will assign names to GUI Components
133 else if(argument_name.equals(StaticStrings.TESTING_ARGUMENT)) {
134 testing_mode = true;
135 }
136 // Run GLI in debug mode. Produces debug log plus extra
137 // messages.
138 else if(argument_name.equals(StaticStrings.DEBUG_ARGUMENT)) {
139 debug = true;
140 }
141 // Run GLI with feedback enabled.
142 else if(argument_name.equals(StaticStrings.FEEDBACK_ARGUMENT)) {
143 feedback_enabled = true;
144 }
145 // Forces no loading on previous collection.
146 else if(argument_name.equals(StaticStrings.NO_LOAD_ARGUMENT)) {
147 no_load = true;
148 filename = null;
149 }
150 // Use a remote Greenstone rather than a local one
151 else if (argument_name.equals(StaticStrings.USE_REMOTE_GREENSTONE_ARGUMENT)) {
152 use_remote_greenstone = true;
153 //Use a remote Greenstone
154 }
155 else if (argument_name.equals(StaticStrings.GSDL3_ARGUMENT)){
156 //Use a remote Greenstone3
157 run_gsdl3=true;
158 }
159 else if (argument_name.equals(StaticStrings.NEW_METADATASET)) {
160 new_set = true;
161 }
162 else if(argument_name.equals(StaticStrings.FEDORA_MODE)) {
163 // Running FLI remotely
164 fedora_info.setActive(true);
165 }
166 }
167 // 3b. Now for those that do
168 else {
169 // Parse the path to the GSDL. Required argument.
170 if(argument_name.equals(StaticStrings.GSDL_ARGUMENT)) {
171 if(argument_value.endsWith(File.separator)) {
172 gsdl_path = argument_value;
173 }
174 else {
175 gsdl_path = argument_value + File.separator;
176 }
177 }
178 // GSDL3 path
179 if(argument_name.equals(StaticStrings.GSDL3_ARGUMENT)) {
180 if(argument_value.endsWith(File.separator)) {
181 gsdl3_path = argument_value;
182 }
183 else {
184 gsdl3_path = argument_value + File.separator;
185 }
186 }
187 // GSDL3 src path
188 if(argument_name.equals(StaticStrings.GSDL3_SRC_ARGUMENT)) {
189 if(argument_value.endsWith(File.separator)) {
190 gsdl3_src_path = argument_value;
191 }
192 else {
193 gsdl3_src_path = argument_value + File.separator;
194 }
195 }
196 // Client operating system
197 else if (argument_name.equals(StaticStrings.GSDLOS_ARGUMENT)) {
198 client_operating_system = argument_value;
199 }
200
201 else if (argument_name.equals(StaticStrings.SITE_ARGUMENT)) {
202 site_name = argument_value;
203 }
204 else if (argument_name.equals(StaticStrings.SERVLET_ARGUMENT)) {
205 servlet_path = argument_value;
206 }
207 // Specify a non-standard collect directory to use (for running one GLI in a network environment)
208 else if (argument_name.equals(StaticStrings.COLLECTDIR_ARGUMENT)) {
209 collect_directory_path = argument_value;
210 System.err.println("Non standard collect directory specified: " + collect_directory_path);
211 }
212 // Specify a collection to load initially. Could be used for file associations.
213 else if(argument_name.equals(StaticStrings.LOAD_ARGUMENT)) {
214 filename = argument_value;
215 no_load = false;
216 }
217 // Parse the file path of the local library server
218 else if (argument_name.equals(StaticStrings.LOCAL_LIBRARY_ARGUMENT)) {
219 local_library_path = argument_value;
220 }
221 // Manually specify the Greenstone library URL
222 else if (argument_name.equals(StaticStrings.LIBRARY_URL_ARGUMENT)) {
223 library_url_string = argument_value;
224 }
225 // Specify the URL to the gliserver CGI script for remote collection building
226 else if (argument_name.equals(StaticStrings.GLISERVER_URL_ARGUMENT)) {
227 gliserver_url_string = argument_value;
228 }
229 // Parse the path to PERL. If not provided it assumes
230 // perl should be available on the PATH.
231 else if(argument_name.equals(StaticStrings.PERL_ARGUMENT)) {
232 perl_path = argument_value;
233 // Test whether this points to the Perl bin
234 // directory or the Perl executable itself.
235 File perl_file = new File(perl_path);
236 if(perl_file.isDirectory()) {
237 // If this is windows we create a child file
238 // perl.exe, otherwise we create perl
239 if(Utility.isWindows()) {
240 perl_file = new File(perl_file, Utility.PERL_EXECUTABLE_WINDOWS);
241 }
242 else {
243 perl_file = new File(perl_file, Utility.PERL_EXECUTABLE_UNIX);
244 }
245 // And store this new path.
246 perl_path = perl_file.getAbsolutePath();
247 perl_file = null;
248 }
249 // Otherwise it is fine as it is
250 }
251 else if(argument_name.equals(StaticStrings.METADATA_PATH)){
252 if (argument_value != null && !argument_value.equals("")) {
253 File metadata_file = new File(argument_value);
254 if (metadata_file.exists()) {
255 metadata_path = argument_value;
256 }
257 }
258 }
259
260 // Fedora home - when running Fedora locally
261 if(argument_name.equals(StaticStrings.FEDORA_HOME)) {
262 if(argument_value.endsWith(File.separator)) {
263 fedora_info.setHome(argument_value);
264 }
265 else {
266 fedora_info.setHome(argument_value + File.separator);
267 }
268 }
269
270 if(argument_name.equals(StaticStrings.FEDORA_VERSION)) {
271 fedora_info.setVersion(argument_value);
272 }
273
274 // Fedora hostname
275 if(argument_name.equals(StaticStrings.FEDORA_HOSTNAME)) {
276 if(argument_value.endsWith(File.separator)) {
277 fedora_info.setHostname(argument_value);
278 }
279 else {
280 fedora_info.setHostname(argument_value + File.separator);
281 }
282 }
283 // Fedora port
284 if(argument_name.equals(StaticStrings.FEDORA_PORT)) {
285 if(argument_value.endsWith(File.separator)) {
286 fedora_info.setPort(argument_value);
287 }
288 else {
289 fedora_info.setPort(argument_value + File.separator);
290 }
291 }
292 // Fedora username
293 if(argument_name.equals(StaticStrings.FEDORA_USERNAME)) {
294 if(argument_value.endsWith(File.separator)) {
295 fedora_info.setUsername(argument_value);
296 }
297 else {
298 fedora_info.setUsername(argument_value + File.separator);
299 }
300 }
301 // Fedora password
302 if(argument_name.equals(StaticStrings.FEDORA_PASSWORD)) {
303 if(argument_value.endsWith(File.separator)) {
304 fedora_info.setPassword(argument_value);
305 }
306 else {
307 fedora_info.setPassword(argument_value + File.separator);
308 }
309 }
310 // Fedora protocol, e.g. http or https
311 if(argument_name.equals(StaticStrings.FEDORA_PROTOCOL)) {
312 if(argument_value.endsWith(File.separator)) {
313 fedora_info.setProtocol(argument_value);
314 }
315 else {
316 fedora_info.setProtocol(argument_value + File.separator);
317 }
318 }
319
320
321
322
323
324 }
325 }
326 // Argument name was null, nothing to be done.
327 }
328 next_token = null;
329 // Arguments all parsed.
330 }
331}
Note: See TracBrowser for help on using the repository browser.