tdcommon/src/main/java/thredds/server/catalog/CatalogScan.java
public CatalogBuilder makeCatalogFromDirectory(File baseDir, String matchRemaining, URI baseURI) throws IOException {
    String relLocation = (matchRemaining.length() >= 1) ? location + "/" + matchRemaining : location;
    String name = (matchRemaining.length() >= 1) ? getName() + "/" + matchRemaining : getName();
    File absLocation = new File( baseDir, relLocation);

    // it must be a directory
    Path wantDir = absLocation.toPath();
    if (!Files.exists(wantDir)) throw new FileNotFoundException("Requested catalog does not exist =" + absLocation);
    if (!Files.isDirectory(wantDir)) throw new FileNotFoundException("Not a directory =" + absLocation);

    // Setup and create catalog builder.
    CatalogBuilder catBuilder = new CatalogBuilder();
    catBuilder.setBaseURI(baseURI);
    assert this.getParentCatalog() != null;

    DatasetBuilder top = new DatasetBuilder(null);
    top.transferMetadata(this, true);
    top.setName(name);
    top.put(Dataset.Id, null); // no id for top
    catBuilder.addDataset(top);

    // first look for catalogs
    try (DirectoryStream<Path> ds = Files.newDirectoryStream(wantDir, "*.xml")) {
      for (Path p : ds) {
        if (!Files.isDirectory(p)) {
          String pfilename = p.getFileName().toString();
          String urlPath = pfilename;

          //String path = dataDirComplete.length() == 0 ? filename : dataDirComplete + "/" + filename;  // reletive starting from current directory
          CatalogRefBuilder catref = new CatalogRefBuilder(top);
          catref.setTitle(urlPath);
          catref.setHref(urlPath);
          top.addDataset(catref);
        }
      }
    }

    // now look for directories
    try (DirectoryStream<Path> ds = Files.newDirectoryStream(wantDir)) {
      for (Path dir : ds) {
        if (Files.isDirectory(dir)) {
          String dfilename = dir.getFileName().toString();
          String urlPath = (matchRemaining.length() >= 1) ? dfilename + "/" + matchRemaining : dfilename;

          CatalogRefBuilder catref = new CatalogRefBuilder(top);
          catref.setTitle(urlPath);
          catref.setHref(urlPath + "/"+ CATSCAN);
          catref.addToList(Dataset.Properties, new Property("CatalogScan", "true"));
          top.addDataset(catref);
        }
      }
    }

    return catBuilder;
  }
public CatalogBuilder makeCatalogFromDirectory(File baseDir, String matchRemaining, URI baseURI) throws IOException {
    String relLocation = (matchRemaining.length() >= 1) ? location + "/" + matchRemaining : location;
    String name = (matchRemaining.length() >= 1) ? getName() + "/" + matchRemaining : getName();
    File absLocation = new File( baseDir, relLocation);

    // it must be a directory
    Path wantDir = absLocation.toPath();
    if (!Files.exists(wantDir)) throw new FileNotFoundException("Requested catalog does not exist =" + absLocation);
    if (!Files.isDirectory(wantDir)) throw new FileNotFoundException("Not a directory =" + absLocation);

    // Setup and create catalog builder.
    CatalogBuilder catBuilder = new CatalogBuilder();
    catBuilder.setBaseURI(baseURI);
    assert this.getParentCatalog() != null;

    DatasetBuilder top = new DatasetBuilder(null);
    top.transferMetadata(this, true);
    top.setName(name);
    top.put(Dataset.Id, null); // no id for top
    catBuilder.addDataset(top);

    // first look for catalogs
    try (DirectoryStream<Path> ds = Files.newDirectoryStream(wantDir, "*.xml")) {
      for (Path p : ds) {
        if (!Files.isDirectory(p)) {
          String pfilename = p.getFileName().toString();
          String urlPath = pfilename;

          //String path = dataDirComplete.length() == 0 ? filename : dataDirComplete + "/" + filename;  // reletive starting from current directory
          CatalogRefBuilder catref = new CatalogRefBuilder(top);
          catref.setTitle(urlPath);
          catref.setHref(urlPath);
          top.addDataset(catref);
        }
      }
    }

    // now look for directories
    try (DirectoryStream<Path> ds = Files.newDirectoryStream(wantDir)) {
      for (Path dir : ds) {
        if (Files.isDirectory(dir)) {
          String dfilename = dir.getFileName().toString();
          String urlPath = (matchRemaining.length() >= 1) ? dfilename + "/" + matchRemaining : dfilename;

          CatalogRefBuilder catref = new CatalogRefBuilder(top);
          catref.setTitle(urlPath);
          catref.setHref(urlPath + "/"+ CATSCAN);
          catref.addToList(Dataset.Properties, new Property("CatalogScan", "true"));
          top.addDataset(catref);
        }
      }
    }

    return catBuilder;
  }
public CatalogBuilder makeCatalogFromDirectory ( File baseDir , String matchRemaining , URI baseURI ) throws IOException { String relLocation = ( matchRemaining . length ( ) >= 1 ) ? location + "/" + matchRemaining : location ; String name = ( matchRemaining . length ( ) >= 1 ) ? getName ( ) + "/" + matchRemaining : getName ( ) ; File absLocation = new File ( baseDir , relLocation ) ; // it must be a directory Path wantDir = absLocation . toPath ( ) ; if ( ! Files . exists ( wantDir ) ) throw new FileNotFoundException ( "Requested catalog does not exist =" + absLocation ) ; if ( ! Files . isDirectory ( wantDir ) ) throw new FileNotFoundException ( "Not a directory =" + absLocation ) ; // Setup and create catalog builder. CatalogBuilder catBuilder = new CatalogBuilder ( ) ; catBuilder . setBaseURI ( baseURI ) ; assert this . getParentCatalog ( ) != null ; DatasetBuilder top = new DatasetBuilder ( null ) ; top . transferMetadata ( this , true ) ; top . setName ( name ) ; top . put ( Dataset . Id , null ) ; // no id for top catBuilder . addDataset ( top ) ; // first look for catalogs try ( DirectoryStream < Path > ds = Files . newDirectoryStream ( wantDir , "*.xml" ) ) { for ( Path p : ds ) { if ( ! Files . isDirectory ( p ) ) { String pfilename = p . getFileName ( ) . toString ( ) ; String urlPath = pfilename ; //String path = dataDirComplete.length() == 0 ? filename : dataDirComplete + "/" + filename;  // reletive starting from current directory CatalogRefBuilder catref = new CatalogRefBuilder ( top ) ; catref . setTitle ( urlPath ) ; catref . setHref ( urlPath ) ; top . addDataset ( catref ) ; } } } // now look for directories try ( DirectoryStream < Path > ds = Files . newDirectoryStream ( wantDir ) ) { for ( Path dir : ds ) { if ( Files . isDirectory ( dir ) ) { String dfilename = dir . getFileName ( ) . toString ( ) ; String urlPath = ( matchRemaining . length ( ) >= 1 ) ? dfilename + "/" + matchRemaining : dfilename ; CatalogRefBuilder catref = new CatalogRefBuilder ( top ) ; catref . setTitle ( urlPath ) ; catref . setHref ( urlPath + "/" + CATSCAN ) ; catref . addToList ( Dataset . Properties , new Property ( "CatalogScan" , "true" ) ) ; top . addDataset ( catref ) ; } } } return catBuilder ; }
when we have a catalog built from a directory (filename == CATSCAN)
when we have a catalog built from a directory ( filename == CATSCAN )