// $Id: WildcardMatchOnNameFilter.java 63 2006-07-12 21:50:51Z edavis $
package thredds.crawlabledataset.filter;

import thredds.crawlabledataset.CrawlableDatasetFilter;
import thredds.crawlabledataset.CrawlableDataset;

/**
 * CrawlableDatasetFilter implementation that accepts datasets whose
 * names are matched by the given wildcard string. The wildcard string
 * can contain astrisks ("*") which match 0 or more characters and
 * question marks ("?") which match 0 or 1 character.
 *
 * @author edavis
 * @since Nov 5, 2005 12:51:56 PM
 */
public class WildcardMatchOnNameFilter implements CrawlableDatasetFilter
{
//  private static org.apache.commons.logging.Log log =
//          org.apache.commons.logging.LogFactory.getLog( WildcardMatchOnNameFilter.class );

  protected String wildcardString;
  protected java.util.regex.Pattern pattern;

  public WildcardMatchOnNameFilter( String wildcardString )
  {
    // Replace "." with "\.".
    this.wildcardString = wildcardString.replaceAll( "\\.", "\\\\." );

    // Replace "*" with ".*".
    this.wildcardString = this.wildcardString.replaceAll( "\\*", ".*");

    // Replace "?" with ".?".
    this.wildcardString = this.wildcardString.replaceAll( "\\?", ".?");

    this.pattern = java.util.regex.Pattern.compile( this.wildcardString );
  }

  public Object getConfigObject() { return wildcardString; }
  public String getWildcardString() { return wildcardString; }

  public boolean accept( CrawlableDataset dataset )
  {
    java.util.regex.Matcher matcher = this.pattern.matcher( dataset.getName() );
    if ( matcher.matches() ) return true;
    return false;
  }
}

@@ -904,24 +904,381 @@
 tring )%0A  %7B%0A
+    // Keep original wildcard string.%0A    this.wildcardString = wildcardString;%0A%0A    // Map wildcard to regular expresion.%0A    String regExp = mapWildcardToRegExp( wildcardString);%0A%0A    // Compile regular expression pattern%0A    this.pattern = java.util.regex.Pattern.compile( regExp );%0A  %7D%0A%0A  private String mapWildcardToRegExp( String wildcardString )%0A  %7B%0A
     // Repla
@@ -1295,29 +1295,24 @@
 h %22%5C.%22.%0A    
-this.
 wildcardStri
@@ -1392,29 +1392,24 @@
 h %22.*%22.%0A    
-this.
 wildcardStri
@@ -1405,37 +1405,32 @@
 ildcardString = 
-this.
 wildcardString.r
@@ -1485,29 +1485,24 @@
 h %22.?%22.%0A    
-this.
 wildcardStri
@@ -1506,21 +1506,16 @@
 tring = 
-this.
 wildcard
@@ -1551,66 +1551,24 @@
 %22);%0A
-%0A
     
-this.pattern = java.util.regex.Pattern.compile( this.
+%0A    return 
 wild
@@ -1577,18 +1577,16 @@
 rdString
- )
 ;%0A  %7D%0A%0A 

Fix TDS-2 bug, "datasetScan/filter element writes to XML incorrectly".