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

Last change on this file since 12119 was 10540, checked in by mdewsnip, 19 years ago

Added a "-use_remote_greenstone" argument, and added the "gliserver_url" argument to the configRemote.xml file.

  • Property svn:keywords set to Author Date Id Revision
File size: 8.9 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
41 public String collect_directory_path = null;
42 public String filename = null;
43 public String gliserver_url_string = null;
44 public String gsdl_path = null;
45 public String gsdl3_path = null;
46 public String gsdl3_src_path = null;
47 public String library_url_string = null;
48 public String local_library_path = null;
49 public String perl_path = null;
50 public String site_name = null; // for GS3
51 public String servlet_path = null;
52 public String wget_path = null;
53
54
55 public GetOpt(String[] args)
56 {
57 // Default dictionary. Only used for starting error messages.
58 Dictionary dictionary = new Dictionary(null, null);
59
60 // Parse arguments
61 int argument_index = 0;
62 String next_token = null;
63
64 while(argument_index < args.length || next_token != null) {
65 // 1. We start by attempting to parse an argument name. An argument
66 // must start with a '-', and should not contain spaces. If
67 // anything else is encountered it is ignored.
68
69 String argument_name = null;
70 if(next_token == null) {
71 next_token = args[argument_index];
72 argument_index++;
73 }
74
75 if(next_token.startsWith(StaticStrings.MINUS_CHARACTER)) {
76 // Trim second '-' just to be kind to Unixy-type people
77 if(next_token.startsWith(StaticStrings.MINUS_CHARACTER + StaticStrings.MINUS_CHARACTER)) {
78 argument_name = next_token.substring(1);
79 }
80 else {
81 argument_name = next_token;
82 }
83 }
84 next_token = null;
85 // 2. If we now have an argument name we continue by attempting
86 // to parse a value. A value is taken to be the sequence of
87 // space seperated Strings between the last argument name
88 // and up to but not including the next argument name. Of
89 // course an argument needn't have any value (ie -debug,
90 // -help), in which case value will be null.
91 if(argument_name != null) {
92 String argument_value = null;
93 StringBuffer argument_value_buffer = new StringBuffer("");
94 while(argument_index < args.length && next_token == null) {
95 next_token = args[argument_index];
96 argument_index++;
97 // If we just parsed an arbitary String then append it to value, followed by a single space
98 if(!next_token.startsWith(StaticStrings.MINUS_CHARACTER)) {
99 argument_value_buffer.append(next_token);
100 argument_value_buffer.append(StaticStrings.SPACE_CHARACTER);
101 next_token = null;
102 }
103 // If the argument token retrieved is an argument name,
104 // then leave it in next_token, which will cause the
105 // argument parsing process to move onto the next step.
106 }
107 // If a value now exists in argument buffer, retrieve
108 // it. Remove the last character as it will be an erroneous
109 // space.
110 if(argument_value_buffer.length() > 0) {
111 argument_value = argument_value_buffer.substring(0, argument_value_buffer.length() - 1);
112 }
113
114 // 3. We now have the argument name, and any associated
115 // value. We are ready to store the data in the
116 // appropriate variables.
117 DebugStream.println("Parsed Argument: name=" + argument_name + (argument_value != null ? (", value=" + argument_value) : ", no value"));
118 // 3a. First those arguments that have no associated value
119 if(argument_value == null) {
120 if(argument_name.equals(StaticStrings.HELP_ARGUMENT)) {
121 System.out.println(Dictionary.get("General.Usage"));
122 System.exit(0);
123 }
124 // Run GLI in debug mode. Produces debug log plus extra
125 // messages.
126 else if(argument_name.equals(StaticStrings.DEBUG_ARGUMENT)) {
127 debug = true;
128 }
129 // Run GLI with feedback enabled.
130 else if(argument_name.equals(StaticStrings.FEEDBACK_ARGUMENT)) {
131 feedback_enabled = true;
132 }
133 // Forces no loading on previous collection.
134 else if(argument_name.equals(StaticStrings.NO_LOAD_ARGUMENT)) {
135 no_load = true;
136 filename = null;
137 }
138 // Use a remote Greenstone rather than a local one
139 else if (argument_name.equals(StaticStrings.USE_REMOTE_GREENSTONE_ARGUMENT)) {
140 use_remote_greenstone = true;
141 }
142 }
143 // 3b. Now for those that do
144 else {
145 // Parse the path to the GSDL. Required argument.
146 if(argument_name.equals(StaticStrings.GSDL_ARGUMENT)) {
147 if(argument_value.endsWith(File.separator)) {
148 gsdl_path = argument_value;
149 }
150 else {
151 gsdl_path = argument_value + File.separator;
152 }
153 }
154 // GSDL3 path
155 if(argument_name.equals(StaticStrings.GSDL3_ARGUMENT)) {
156 if(argument_value.endsWith(File.separator)) {
157 gsdl3_path = argument_value;
158 }
159 else {
160 gsdl3_path = argument_value + File.separator;
161 }
162 }
163 // GSDL3 src path
164 if(argument_name.equals(StaticStrings.GSDL3_SRC_ARGUMENT)) {
165 if(argument_value.endsWith(File.separator)) {
166 gsdl3_src_path = argument_value;
167 }
168 else {
169 gsdl3_src_path = argument_value + File.separator;
170 }
171 }
172
173 else if (argument_name.equals(StaticStrings.SITE_ARGUMENT)) {
174 site_name = argument_value;
175 }
176 else if (argument_name.equals(StaticStrings.SERVLET_ARGUMENT)) {
177 servlet_path = argument_value;
178 }
179 // Specify a non-standard collect directory to use (for running one GLI in a network environment)
180 else if (argument_name.equals(StaticStrings.COLLECTDIR_ARGUMENT)) {
181 collect_directory_path = argument_value;
182 System.err.println("Non standard collect directory specified: " + collect_directory_path);
183 }
184 // Specify a collection to load initially. Could be used for file associations.
185 else if(argument_name.equals(StaticStrings.LOAD_ARGUMENT)) {
186 filename = argument_value;
187 no_load = false;
188 }
189 // Parse the file path of the local library server
190 else if (argument_name.equals(StaticStrings.LOCAL_LIBRARY_ARGUMENT)) {
191 local_library_path = argument_value;
192 }
193 // Manually specify the Greenstone library URL
194 else if (argument_name.equals(StaticStrings.LIBRARY_URL_ARGUMENT)) {
195 library_url_string = argument_value;
196 }
197 // Specify the URL to the gliserver CGI script for remote collection building
198 else if (argument_name.equals(StaticStrings.GLISERVER_URL_ARGUMENT)) {
199 gliserver_url_string = argument_value;
200 }
201 // Parse the path to PERL. If not provided it assumes
202 // perl should be availble on the PATH.
203 else if(argument_name.equals(StaticStrings.PERL_ARGUMENT)) {
204 perl_path = argument_value;
205 // Test whether this points to the Perl bin
206 // directory or the Perl executable itself.
207 File perl_file = new File(perl_path);
208 if(perl_file.isDirectory()) {
209 // If this is windows we create a child file
210 // perl.exe, otherwise we create perl
211 if(Utility.isWindows()) {
212 perl_file = new File(perl_file, Utility.PERL_EXECUTABLE_WINDOWS);
213 }
214 else {
215 perl_file = new File(perl_file, Utility.PERL_EXECUTABLE_UNIX);
216 }
217 // And store this new path.
218 perl_path = perl_file.getAbsolutePath();
219 perl_file = null;
220 }
221 // Otherwise it is fine as it is
222 }
223 // Parse the path to WGet
224 else if (argument_name.equals(StaticStrings.WGET_ARGUMENT)) {
225 // Check the specified WGet file exists
226 if (argument_value != null && !argument_value.equals("")) {
227 File wget_file = new File(argument_value);
228 if (wget_file.exists()) {
229 wget_path = argument_value;
230 }
231 }
232 }
233 }
234 }
235 // Argument name was null, nothing to be done.
236 }
237 next_token = null;
238 // Arguments all parsed.
239 }
240}
Note: See TracBrowser for help on using the repository browser.