legacy/src/main/java/thredds/catalog/util/CatalogUtils.java
public static List<InvCatalogRef> findAllCatRefsInDatasetTree( List<InvDataset> datasets, StringBuilder log, boolean onlyRelativeUrls )
    {
        List<InvCatalogRef> catRefList = new ArrayList<InvCatalogRef>();
        for ( InvDataset invds : datasets )
        {
            InvDatasetImpl curDs = (InvDatasetImpl) invds;

            if ( curDs instanceof InvDatasetScan)
                continue;

            if ( curDs instanceof InvCatalogRef )
            {
                InvCatalogRef catRef = (InvCatalogRef) curDs;
                String name = catRef.getName();
                String href = catRef.getXlinkHref();
                URI uri;
                try
                {
                    uri = new URI( href );
                }
                catch ( URISyntaxException e )
                {
                    log.append( log.length() > 0 ? "\n" : "" )
                            .append( "***WARN - CatalogRef [").append(name)
                            .append("] with bad HREF [" ).append( href ).append( "] " );
                    continue;
                }
                if ( onlyRelativeUrls && uri.isAbsolute() )
                    continue;

                catRefList.add( catRef );
                continue;
            }

            if ( curDs.hasNestedDatasets() )
                catRefList.addAll( findAllCatRefsInDatasetTree( curDs.getDatasets(), log, onlyRelativeUrls ) );
        }
        return catRefList;
    }
public static List<InvCatalogRef> findAllCatRefsInDatasetTree( List<InvDataset> datasets, StringBuilder log, boolean onlyRelativeUrls )
    {
        List<InvCatalogRef> catRefList = new ArrayList<InvCatalogRef>();
        for ( InvDataset invds : datasets )
        {
            InvDatasetImpl curDs = (InvDatasetImpl) invds;

            if ( curDs instanceof InvDatasetScan)
                continue;

            if ( curDs instanceof InvCatalogRef )
            {
                InvCatalogRef catRef = (InvCatalogRef) curDs;
                String name = catRef.getName();
                String href = catRef.getXlinkHref();
                URI uri;
                try
                {
                    uri = new URI( href );
                }
                catch ( URISyntaxException e )
                {
                    log.append( log.length() > 0 ? "\n" : "" )
                            .append( "***WARN - CatalogRef [").append(name)
                            .append("] with bad HREF [" ).append( href ).append( "] " );
                    continue;
                }
                if ( onlyRelativeUrls && uri.isAbsolute() )
                    continue;

                catRefList.add( catRef );
                continue;
            }

            if ( curDs.hasNestedDatasets() )
                catRefList.addAll( findAllCatRefsInDatasetTree( curDs.getDatasets(), log, onlyRelativeUrls ) );
        }
        return catRefList;
    }
public static List < InvCatalogRef > findAllCatRefsInDatasetTree ( List < InvDataset > datasets , StringBuilder log , boolean onlyRelativeUrls ) { List < InvCatalogRef > catRefList = new ArrayList < InvCatalogRef > ( ) ; for ( InvDataset invds : datasets ) { InvDatasetImpl curDs = ( InvDatasetImpl ) invds ; if ( curDs instanceof InvDatasetScan ) continue ; if ( curDs instanceof InvCatalogRef ) { InvCatalogRef catRef = ( InvCatalogRef ) curDs ; String name = catRef . getName ( ) ; String href = catRef . getXlinkHref ( ) ; URI uri ; try { uri = new URI ( href ) ; } catch ( URISyntaxException e ) { log . append ( log . length ( ) > 0 ? "\n" : "" ) . append ( "***WARN - CatalogRef [" ) . append ( name ) . append ( "] with bad HREF [" ) . append ( href ) . append ( "] " ) ; continue ; } if ( onlyRelativeUrls && uri . isAbsolute ( ) ) continue ; catRefList . add ( catRef ) ; continue ; } if ( curDs . hasNestedDatasets ( ) ) catRefList . addAll ( findAllCatRefsInDatasetTree ( curDs . getDatasets ( ) , log , onlyRelativeUrls ) ) ; } return catRefList ; }
Find all catalogRef elements in the dataset tree formed by the given dataset list.

@param datasets         the list of datasets from which to find all the catalogRefs
@param log              StringBuilder into which any messages will be written
@param onlyRelativeUrls only include catalogRefs with relative HREF URLs if true, otherwise include all catalogRef datasets
@return the list of catalogRef datasets
Find all catalogRef elements in the dataset tree formed by the given dataset list .