Changeset 2131
- Timestamp:
- 2001-03-08T02:10:35+13:00 (23 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/java-client/org/nzdl/gsdl/SimpleClient.java
r2130 r2131 27 27 // java libraries we're using 28 28 import java.io.BufferedReader; 29 import java.io.DataInputStream; 29 30 import java.io.File; 30 31 import java.io.FileInputStream; … … 32 33 import java.io.FileReader; 33 34 import java.io.IOException; 35 import java.io.InputStream; 34 36 import java.io.InputStreamReader; 35 37 import java.io.LineNumberReader; … … 92 94 /** The IOR that was specified on the commandline */ 93 95 String IORFromCommandLine = null; 96 /** The URL that was specified on the commandline */ 97 String URLFromCommandLine = null; 94 98 /** The collection to query */ 95 99 String collectionNameToQuery = ""; … … 105 109 int verbosity = 2; 106 110 111 String[] urlsCompiledIn = 112 { 113 "http://nikau.cs.waikato.ac.nz/~say1/gsdl/cgi-bin/getior", 114 "http://www.nzdl.org/cgi-bin/getior" 115 }; 116 107 117 /** 108 118 * Basic no-args constructor. Not recommended for normal use, … … 129 139 // read our prevously seed IORs ... 130 140 knownIORs = new Properties(); 131 132 File file = new File(propertiesFileName); 133 try { 134 if (file.exists()) { 135 knownIORs.load(new FileInputStream(file)); 136 } 137 } catch (IOException i) { 138 System.err.println("Error reading properties file:" + i); 139 } 140 141 if (IORFromCommandLine != null) 142 attemptToInitialise(args, null, IORFromCommandLine); 143 141 String IOR = null; 142 143 // try a URL from the command line 144 if (URLFromCommandLine != null) { 145 IOR = getIORfromURL(URLFromCommandLine); 146 attemptToInitialise(args, null, IOR); 147 } 148 149 // try an IOR from the command line 150 if (IORFromCommandLine != null && nzdl == null) { 151 IOR = IORFromCommandLine; 152 attemptToInitialise(args, null, IOR); 153 } 154 155 // try an IOR from a file (the filename may have been 156 // given from teh commandline 144 157 if (nzdl == null) { 145 String IOR = getIorKey(IORFileName); 146 System.err.println("ior = " + IOR); 147 System.err.println("after IOR"); 158 IOR = getIorKey(IORFileName); 148 159 attemptToInitialise(args, null, IOR); 149 160 } 150 161 151 Enumeration e = knownIORs.keys(); 152 while (e.hasMoreElements() && nzdl == null) { 153 String IOR = (String) e.nextElement(); 154 attemptToInitialise(args, null, IOR); 155 162 // try the compiled-in URLs 163 if (nzdl == null) { 164 for (int i=0;( i<urlsCompiledIn.length && nzdl == null );i++) { 165 IOR = getIORfromURL(urlsCompiledIn[i]); 166 attemptToInitialise(args, null,IOR); 167 } 168 } 169 170 // the knownIORs is the last resort 171 if (nzdl == null) { 172 File file = new File(propertiesFileName); 173 try { 174 if (file.exists()) { 175 knownIORs.load(new FileInputStream(file)); 176 } 177 } catch (IOException i) { 178 System.err.println("Error reading properties file:" + i); 179 } 180 181 Enumeration e = knownIORs.keys(); 182 while (e.hasMoreElements() && nzdl == null) { 183 IOR = (String) e.nextElement(); 184 attemptToInitialise(args, null, IOR); 185 } 156 186 } 157 187 158 188 knownIORs.put(IOR,""); 189 } 190 191 public String getIORfromURL(String str) 192 { 193 194 String ior = null; 195 196 try { 197 System.err.println("Looking for a URL at:" + str); 198 URL url = new URL(str); 199 InputStream his = url.openStream(); 200 DataInputStream dhis = new DataInputStream(his) ; 201 ior = dhis.readLine(); 202 return ior; 203 } catch (Throwable throwable) { 204 System.err.println("NzdlHosts::getIOR() unable to construct or read URL \"" + 205 str + "\", \"" + ior + "\": " + throwable); 206 return ""; 207 } 159 208 } 160 209 … … 357 406 s += "Short form Long form Explanation\n"; 358 407 s += "-h --help Print this help text\n"; 408 s += "-u <url> --URL <url> Use <url> to connect\n"; 359 409 s += "-I <IOR> --IOR <IOR> Use <IOR> to connect\n"; 360 410 s += "-f <file> --file <IOR> Look for an IOR if <file>\n"; … … 377 427 System.err.println("in parseArgs"); 378 428 379 LongOpt[] longopts = new LongOpt[ 9];429 LongOpt[] longopts = new LongOpt[10]; 380 430 int i = 0; 381 431 StringBuffer sb = new StringBuffer(); … … 383 433 longopts[i++] = new LongOpt("help", LongOpt.NO_ARGUMENT, null, 'h'); 384 434 longopts[i++] = new LongOpt("IOR", LongOpt.REQUIRED_ARGUMENT, null, 'I'); 435 longopts[i++] = new LongOpt("URL", LongOpt.REQUIRED_ARGUMENT, null, 'u'); 385 436 longopts[i++] = new LongOpt("file", LongOpt.REQUIRED_ARGUMENT, null, 'f'); 386 437 longopts[i++] = new LongOpt("collection", LongOpt.REQUIRED_ARGUMENT, null, 'c'); … … 392 443 Getopt g = new Getopt("org.nzdl.gsdl.SimpleClient", 393 444 args, 394 "hI:f:c:aq:dv:Q ",445 "hI:f:c:aq:dv:Qu:", 395 446 longopts); 396 447 int c; … … 405 456 case 'I': 406 457 IORFromCommandLine = g.getOptarg(); 458 break; 459 case 'u': 460 URLFromCommandLine = g.getOptarg(); 407 461 break; 408 462 case 'f':
Note:
See TracChangeset
for help on using the changeset viewer.