source: other-projects/FileTransfer-WebSocketPair/testGXTWithGreenstone/src/org/greenstone/gatherer/GetOpt.java

Last change on this file was 33053, checked in by ak19, 5 years ago

I still had some stuff of Nathan Kelly's (FileTransfer-WebSocketPair) sitting on my USB. Had already commited the Themes folder at the time, 2 years back. Not sure if he wanted this additional folder commited. But I didn't want to delete it and decided it will be better off on SVN. When we use his project, if we find we didn't need this test folder, we can remove it from svn then.

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