Changeset 2131


Ignore:
Timestamp:
2001-03-08T02:10:35+13:00 (23 years ago)
Author:
say1
Message:

getior now works properly

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/java-client/org/nzdl/gsdl/SimpleClient.java

    r2130 r2131  
    2727// java libraries we're using
    2828import java.io.BufferedReader;
     29import java.io.DataInputStream;
    2930import java.io.File;
    3031import java.io.FileInputStream;
     
    3233import java.io.FileReader;
    3334import java.io.IOException;
     35import java.io.InputStream;
    3436import java.io.InputStreamReader;
    3537import java.io.LineNumberReader;
     
    9294  /** The IOR that was specified on the commandline */
    9395  String IORFromCommandLine = null;
     96  /** The URL that was specified on the commandline */
     97  String URLFromCommandLine = null;
    9498  /** The collection to query */
    9599  String collectionNameToQuery = "";
     
    105109  int verbosity = 2;
    106110
     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
    107117  /**
    108118   * Basic no-args constructor. Not recommended for normal use,
     
    129139    // read our prevously seed IORs ...
    130140    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
    144157    if (nzdl == null) {
    145       String IOR = getIorKey(IORFileName);
    146       System.err.println("ior = " + IOR);
    147       System.err.println("after IOR");
     158      IOR = getIorKey(IORFileName);
    148159      attemptToInitialise(args, null, IOR);
    149160    }
    150161   
    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      }
    156186    }
    157187   
    158188    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    }
    159208  }
    160209
     
    357406    s += "Short form Long form                Explanation\n";
    358407    s += "-h         --help                   Print this help text\n";
     408    s += "-u <url>   --URL <url>              Use <url> to connect\n";
    359409    s += "-I <IOR>   --IOR <IOR>              Use <IOR> to connect\n";
    360410    s += "-f <file>  --file <IOR>             Look for an IOR if <file>\n";
     
    377427    System.err.println("in parseArgs");
    378428   
    379     LongOpt[] longopts = new LongOpt[9];
     429    LongOpt[] longopts = new LongOpt[10];
    380430    int i = 0;
    381431    StringBuffer sb = new StringBuffer();
     
    383433    longopts[i++]  = new LongOpt("help",                  LongOpt.NO_ARGUMENT,       null, 'h');
    384434    longopts[i++]  = new LongOpt("IOR",                   LongOpt.REQUIRED_ARGUMENT, null, 'I');
     435    longopts[i++]  = new LongOpt("URL",                   LongOpt.REQUIRED_ARGUMENT, null, 'u');
    385436    longopts[i++]  = new LongOpt("file",                  LongOpt.REQUIRED_ARGUMENT, null, 'f');
    386437    longopts[i++]  = new LongOpt("collection",            LongOpt.REQUIRED_ARGUMENT, null, 'c');
     
    392443    Getopt g = new Getopt("org.nzdl.gsdl.SimpleClient",
    393444                          args,
    394                           "hI:f:c:aq:dv:Q",
     445                          "hI:f:c:aq:dv:Qu:",
    395446                          longopts);
    396447    int c;
     
    405456        case 'I':
    406457      IORFromCommandLine = g.getOptarg();
     458          break;
     459        case 'u':
     460      URLFromCommandLine = g.getOptarg();
    407461          break;
    408462        case 'f':
Note: See TracChangeset for help on using the changeset viewer.