Subversion Repositories general

Rev

Rev 962 | Blame | Compare with Previous | Last modification | View Log | RSS feed

package ak.photoalbum.util;

import java.io.File;
import java.io.FileFilter;
import java.util.List;
import java.util.Set;
import java.util.HashSet;
import java.util.Iterator;

public class ImagesFilter
  implements FileFilter
{
  Set extentions = new HashSet();

  public ImagesFilter(List imagesMasks)
  {
    for(Iterator i = imagesMasks.iterator(); i.hasNext(); ) {
      String mask = (String)i.next();

      if(mask.startsWith("*.")) mask = mask.substring(2);

      extentions.add(mask.toLowerCase());
    }
  }

  public boolean accept(File pathname)
  {
    if(pathname.getName().startsWith(".")) // skip hidden
      return false;

    if(pathname.isDirectory()) {
      return true;
    }
    else{
      return extentions.contains(FileUtils.extractFileExt(
        pathname.getName().toLowerCase()));
    }
  }
}