cdm/src/main/java/ucar/nc2/dataset/DatasetUrl.java
static public DatasetUrl findDatasetUrl(String orgLocation) throws IOException {
    ServiceType svctype = null;

    // Canonicalize the location
    String location = StringUtil2.replace(orgLocation.trim(), '\\', "/");
    List<String> allprotocols = DatasetUrl.getProtocols(location);

    String trueurl = location;
    String leadprotocol;
    if (allprotocols.size() == 0) {
      leadprotocol = "file";  // The location has no leading protocols, assume file:
    } else {
      leadprotocol = allprotocols.get(0);
    }

    // Priority in deciding
    // the service type is as follows.
    // 1. "protocol" tag in fragment
    // 2. specific protocol in fragment
    // 3. leading protocol
    // 4. path extension
    // 5. contact the server (if defined)

    // temporarily remove any trailing query or fragment
    String fragment = null;
    int pos = trueurl.lastIndexOf('#');
    if (pos >= 0) {
      fragment = trueurl.substring(pos + 1, trueurl.length());
      trueurl = trueurl.substring(0, pos);
    }
    pos = location.lastIndexOf('?');
    String query = null;
    if (pos >= 0) {
      query = trueurl.substring(pos + 1, trueurl.length());
      trueurl = trueurl.substring(0, pos);
    }
    if (fragment != null)
      svctype = searchFragment(fragment);

    if (svctype == null) // See if leading protocol tells us how to interpret
      svctype = decodeLeadProtocol(leadprotocol);

    if (svctype == null) // See if path tells us how to interpret
      svctype = searchPath(trueurl);

    if (svctype == null) {
      //There are several possibilities at this point; all of which
      // require further info to disambiguate
      //  - we have file://<path> or file:<path>; we need to see if
      //    the extension can help, otherwise, start defaulting.
      //  - we have a simple url: e.g. http://... ; contact the server
      if (leadprotocol.equals("file")) {
        svctype = decodePathExtension(trueurl); // look at the path extension
        if(svctype == null && checkIfNcml(new File(location))) {
          svctype = ServiceType.NCML;
        }
      } else {
        svctype = disambiguateHttp(trueurl);
        // special cases
        if ((svctype == null || svctype == ServiceType.HTTPServer)) {
          // ncml file being served over http?
          if (checkIfRemoteNcml(trueurl)) {
            svctype = ServiceType.NCML;
          }
        }
      }
    }

    if (svctype == ServiceType.NCML) { // ??
      // If lead protocol was null and then pretend it was a file
      // Note that technically, this should be 'file://'
      trueurl = (allprotocols.size() == 0 ? "file:" + trueurl : location);
    }

    // Add back the query and fragment (if any)
    if (query != null || fragment != null) {
      StringBuilder buf = new StringBuilder(trueurl);
      if (query != null) {
        buf.append('?');
        buf.append(query);
      }
      if (fragment != null) {
        buf.append('#');
        buf.append(fragment);
      }
      trueurl = buf.toString();
    }
    return new DatasetUrl(svctype, trueurl);
  }
static public DatasetUrl findDatasetUrl(String orgLocation) throws IOException {
    ServiceType svctype = null;

    // Canonicalize the location
    String location = StringUtil2.replace(orgLocation.trim(), '\\', "/");
    List<String> allprotocols = DatasetUrl.getProtocols(location);

    String trueurl = location;
    String leadprotocol;
    if (allprotocols.size() == 0) {
      leadprotocol = "file";  // The location has no leading protocols, assume file:
    } else {
      leadprotocol = allprotocols.get(0);
    }

    // Priority in deciding
    // the service type is as follows.
    // 1. "protocol" tag in fragment
    // 2. specific protocol in fragment
    // 3. leading protocol
    // 4. path extension
    // 5. contact the server (if defined)

    // temporarily remove any trailing query or fragment
    String fragment = null;
    int pos = trueurl.lastIndexOf('#');
    if (pos >= 0) {
      fragment = trueurl.substring(pos + 1, trueurl.length());
      trueurl = trueurl.substring(0, pos);
    }
    pos = location.lastIndexOf('?');
    String query = null;
    if (pos >= 0) {
      query = trueurl.substring(pos + 1, trueurl.length());
      trueurl = trueurl.substring(0, pos);
    }
    if (fragment != null)
      svctype = searchFragment(fragment);

    if (svctype == null) // See if leading protocol tells us how to interpret
      svctype = decodeLeadProtocol(leadprotocol);

    if (svctype == null) // See if path tells us how to interpret
      svctype = searchPath(trueurl);

    if (svctype == null) {
      //There are several possibilities at this point; all of which
      // require further info to disambiguate
      //  - we have file://<path> or file:<path>; we need to see if
      //    the extension can help, otherwise, start defaulting.
      //  - we have a simple url: e.g. http://... ; contact the server
      if (leadprotocol.equals("file")) {
        svctype = decodePathExtension(trueurl); // look at the path extension
        if(svctype == null && checkIfNcml(new File(location))) {
          svctype = ServiceType.NCML;
        }
      } else {
        svctype = disambiguateHttp(trueurl);
        // special cases
        if ((svctype == null || svctype == ServiceType.HTTPServer)) {
          // ncml file being served over http?
          if (checkIfRemoteNcml(trueurl)) {
            svctype = ServiceType.NCML;
          }
        }
      }
    }

    if (svctype == ServiceType.NCML) { // ??
      // If lead protocol was null and then pretend it was a file
      // Note that technically, this should be 'file://'
      trueurl = (allprotocols.size() == 0 ? "file:" + trueurl : location);
    }

    // Add back the query and fragment (if any)
    if (query != null || fragment != null) {
      StringBuilder buf = new StringBuilder(trueurl);
      if (query != null) {
        buf.append('?');
        buf.append(query);
      }
      if (fragment != null) {
        buf.append('#');
        buf.append(fragment);
      }
      trueurl = buf.toString();
    }
    return new DatasetUrl(svctype, trueurl);
  }
static public DatasetUrl findDatasetUrl ( String orgLocation ) throws IOException { ServiceType svctype = null ; // Canonicalize the location String location = StringUtil2 . replace ( orgLocation . trim ( ) , ' ' , "/" ) ; List < String > allprotocols = DatasetUrl . getProtocols ( location ) ; String trueurl = location ; String leadprotocol ; if ( allprotocols . size ( ) == 0 ) { leadprotocol = "file" ; // The location has no leading protocols, assume file: } else { leadprotocol = allprotocols . get ( 0 ) ; } // Priority in deciding // the service type is as follows. // 1. "protocol" tag in fragment // 2. specific protocol in fragment // 3. leading protocol // 4. path extension // 5. contact the server (if defined) // temporarily remove any trailing query or fragment String fragment = null ; int pos = trueurl . lastIndexOf ( ' ' ) ; if ( pos >= 0 ) { fragment = trueurl . substring ( pos + 1 , trueurl . length ( ) ) ; trueurl = trueurl . substring ( 0 , pos ) ; } pos = location . lastIndexOf ( ' ' ) ; String query = null ; if ( pos >= 0 ) { query = trueurl . substring ( pos + 1 , trueurl . length ( ) ) ; trueurl = trueurl . substring ( 0 , pos ) ; } if ( fragment != null ) svctype = searchFragment ( fragment ) ; if ( svctype == null ) // See if leading protocol tells us how to interpret svctype = decodeLeadProtocol ( leadprotocol ) ; if ( svctype == null ) // See if path tells us how to interpret svctype = searchPath ( trueurl ) ; if ( svctype == null ) { //There are several possibilities at this point; all of which // require further info to disambiguate //  - we have file://<path> or file:<path>; we need to see if //    the extension can help, otherwise, start defaulting. //  - we have a simple url: e.g. http://... ; contact the server if ( leadprotocol . equals ( "file" ) ) { svctype = decodePathExtension ( trueurl ) ; // look at the path extension if ( svctype == null && checkIfNcml ( new File ( location ) ) ) { svctype = ServiceType . NCML ; } } else { svctype = disambiguateHttp ( trueurl ) ; // special cases if ( ( svctype == null || svctype == ServiceType . HTTPServer ) ) { // ncml file being served over http? if ( checkIfRemoteNcml ( trueurl ) ) { svctype = ServiceType . NCML ; } } } } if ( svctype == ServiceType . NCML ) { // ?? // If lead protocol was null and then pretend it was a file // Note that technically, this should be 'file://' trueurl = ( allprotocols . size ( ) == 0 ? "file:" + trueurl : location ) ; } // Add back the query and fragment (if any) if ( query != null || fragment != null ) { StringBuilder buf = new StringBuilder ( trueurl ) ; if ( query != null ) { buf . append ( ' ' ) ; buf . append ( query ) ; } if ( fragment != null ) { buf . append ( ' ' ) ; buf . append ( fragment ) ; } trueurl = buf . toString ( ) ; } return new DatasetUrl ( svctype , trueurl ) ; }
///////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////