Exemplo n.º 1
0
  private NetcdfDataset openDataset(
      InvDataset invDataset, boolean acquire, ucar.nc2.util.CancelTask task, Result result)
      throws IOException {

    IOException saveException = null;

    List<InvAccess> accessList =
        new ArrayList<InvAccess>(invDataset.getAccess()); // a list of all the accesses
    while (accessList.size() > 0) {
      InvAccess access = chooseDatasetAccess(accessList);

      // no valid access
      if (access == null) {
        result.errLog.format("No access that could be used in dataset %s %n", invDataset);
        if (saveException != null) throw saveException;
        return null;
      }

      String datasetLocation = access.getStandardUrlName();
      ServiceType serviceType = access.getService().getServiceType();
      if (debugOpen)
        System.out.println("ThreddsDataset.openDataset try " + datasetLocation + " " + serviceType);

      // deal with RESOLVER type
      if (serviceType == ServiceType.RESOLVER) {
        InvDatasetImpl rds = openResolver(datasetLocation, task, result);
        if (rds == null) return null;
        accessList = new ArrayList<InvAccess>(rds.getAccess());
        continue;
      }

      // ready to open it through netcdf API
      NetcdfDataset ds;

      // try to open
      try {
        ds = openDataset(access, acquire, task, result);

      } catch (IOException e) {
        result.errLog.format("Cant open %s %n err=%s%n", datasetLocation, e.getMessage());
        if (debugOpen) {
          System.out.println("Cant open= " + datasetLocation + " " + serviceType);
          e.printStackTrace();
        }

        accessList.remove(access);
        saveException = e;
        continue;
      }

      result.accessUsed = access;
      return ds;
    } // loop over accesses

    if (saveException != null) throw saveException;
    return null;
  }
  @Override
  public String getViewerLinkHtml(InvDatasetImpl ds, HttpServletRequest req) {
    InvAccess access = ds.getAccess(ServiceType.WMS);
    URI dataURI = access.getStandardUri();
    try {
      URI base = new URI(req.getRequestURL().toString());
      dataURI = base.resolve(dataURI);
    } catch (URISyntaxException e) {
      return "Error generating viewer link";
    }

    // ToDo Switch to use TdsContext.getContextPath()
    return "<a href='"
        + ServletUtil.getContextPath()
        + "/godiva2/godiva2.html?server="
        + dataURI.toString()
        + "'>Godiva2 (browser-based)</a>";
  }
 /** Returns true if this is a gridded dataset that is accessible via WMS. */
 @Override
 public boolean isViewable(InvDatasetImpl ds) {
   InvAccess access = ds.getAccess(ServiceType.WMS);
   return (access != null) && (ds.getDataType() == FeatureType.GRID);
 }