Esempio n. 1
0
 /**
  * Creates an instance bound to url. If <code>acceptDeflate</code> is true then HTTP Request
  * headers will indicate to servers that this client can accept compressed documents.
  *
  * @param urlString Connect to this URL.
  * @param acceptCompress true if this client will accept compressed responses
  * @throws FileNotFoundException thrown if <code>urlString</code> is not a valid URL, or a
  *     filename which exists on the system.
  */
 public DConnect2(String urlString, boolean acceptCompress) throws FileNotFoundException {
   int ceIndex = urlString.indexOf('?');
   if (ceIndex != -1) {
     this.urlString = urlString.substring(0, ceIndex);
     String expr = urlString.substring(ceIndex);
     int selIndex = expr.indexOf('&');
     if (selIndex != -1) {
       this.projString = expr.substring(0, selIndex);
       this.selString = expr.substring(selIndex);
     } else {
       this.projString = expr;
       this.selString = "";
     }
   } else {
     this.urlString = urlString;
     this.projString = this.selString = "";
   }
   this.acceptCompress = acceptCompress;
   // capture encoded url
   this.urlStringEncoded = EscapeStrings.escapeURL(this.urlString);
   // Check out the URL to see if it is file://
   try {
     URL testURL = new URL(urlString);
     if ("file".equals(testURL.getProtocol())) {
       filePath = testURL.getPath();
       // See if .dds and .dods files exist
       File f = new File(filePath + ".dds");
       if (!f.canRead()) {
         throw new FileNotFoundException("file not readable: " + urlString + ".dds");
       }
       f = new File(filePath + ".dods");
       if (!f.canRead()) {
         throw new FileNotFoundException("file not readable: " + urlString + ".dods");
       }
     }
     /* Set the server version cause we won't get it from anywhere */
     ver = new ServerVersion(ServerVersion.DAP2_PROTOCOL_VERSION, ServerVersion.XDAP);
   } catch (DAP2Exception ex) {
     throw new FileNotFoundException("Cannot set server version");
   } catch (MalformedURLException e) {
     throw new FileNotFoundException("Malformed URL: " + urlString);
   }
 }
Esempio n. 2
0
 /**
  * Returns the DAS object from the dataset referenced by this object's URL. The DAS object is
  * referred to by appending `.das' to the end of a DODS URL.
  *
  * @return the DAS associated with the referenced dataset.
  * @throws MalformedURLException if the URL given to the constructor has an error
  * @throws IOException if an error connecting to the remote server
  * @throws ParseException if the DAS parser returned an error
  * @throws DASException on an error constructing the DAS
  * @throws DAP2Exception if an error returned by the remote server
  */
 public DAS getDAS() throws IOException, ParseException, DAP2Exception {
   DASCommand command = new DASCommand();
   if (filePath != null) { // url was file:
     File daspath = new File(filePath + ".das");
     // See if the das file exists
     if (daspath.canRead()) {
       command.process(new FileInputStream(daspath));
     }
   } else if (stream != null) {
     command.process(stream);
   } else { // assume url is remote
     try {
       openConnection(urlStringEncoded + ".das" + projString + selString, command);
     } catch (DAP2Exception de) {
       // if(de.getErrorCode() != DAP2Exception.NO_SUCH_FILE)
       // throw de;  // rethrow
     }
   }
   return command.das;
 }
Esempio n. 3
0
  /**
   * Returns the `Data object' from the dataset referenced by this object's URL given the constraint
   * expression CE. Note that the Data object is really just a DDS object with data bound to the
   * variables. The DDS will probably contain fewer variables (and those might have different types)
   * than in the DDS returned by getDDS() because that method returns the entire DDS (but without
   * any data) while this method returns only those variables listed in the projection part of the
   * constraint expression.
   *
   * <p>Note that if CE is an empty String then the entire dataset will be returned, unless a
   * "sticky" CE has been specified in the constructor.
   *
   * @param CE The constraint expression to be applied to this request by the server. This is
   *     combined with any CE given in the constructor.
   * @param statusUI the <code>StatusUI</code> object to use for GUI updates and user cancellation
   *     notification (may be null).
   * @param btf The <code>BaseTypeFactory</code> to build the member variables in the DDS with.
   * @return The <code>DataDDS</code> object that results from applying the given CE, combined with
   *     this object's sticky CE, on the referenced dataset.
   * @throws MalformedURLException if the URL given to the constructor has an error
   * @throws IOException if any error connecting to the remote server
   * @throws ParseException if the DDS parser returned an error
   * @throws DDSException on an error constructing the DDS
   * @throws DAP2Exception if any error returned by the remote server
   */
  public DataDDS getData(String CE, StatusUI statusUI, BaseTypeFactory btf)
      throws MalformedURLException, IOException, ParseException, DDSException, DAP2Exception {

    DataDDS dds = new DataDDS(ver, btf);
    DataDDSCommand command = new DataDDSCommand(dds, statusUI);
    command.setURL(urlString + "?" + CE);
    if (filePath != null) { // url is file:
      File dodspath = new File(filePath + ".dods");
      // See if the dods file exists
      if (dodspath.canRead()) {
        /* WARNING: any constraints are ignored in reading the file */
        command.process(new FileInputStream(dodspath));
      }
    } else if (stream != null) {
      command.process(stream);
    } else {
      String urls = urlStringEncoded + ".dods" + EscapeStrings.escapeURLQuery(getCompleteCE(CE));
      openConnection(urls, command);
    }
    return command.dds;
  }