/** @(#) ListImagesBean.java 1.0 2000/10/10
 * Copyright (c) 2000 Larry Rodrigues
 **/
package viewer;
import java.io.*;
import java.awt.event.*;
import java.awt.*;
import java.awt.image.*;
import java.util.*;

 /** A server-side bean that list images from a remote directory.
   * It can be instantiated by a servlet or a JSP page.
   * @version 1.0  10 October 2000
   * @author Lawrence Rodrigues
   */
public class ListImagesBean{

   public ListImagesBean(){}

   public synchronized String[] listFiles(String dirstr){
      String fl[] = null;
      try {
         ExtensionFilter filter =  new ExtensionFilter("jpeg,gif,JPEG,GIF,JPG,jpg,png,PNG");
         File dir = new File(dirstr);
         fl = dir.list(filter);
      } catch (Exception e){System.out.println(e);}
      return fl;
   }

   class  ExtensionFilter implements FilenameFilter{
      private String extString;
      public ExtensionFilter(String ext){
         extString = ext;
      }
      public boolean accept(File dir, String name){
	       StringTokenizer st = new StringTokenizer(extString, ",");
         while(st.hasMoreTokens()){
               String str = st.nextToken();
               String tok = str.trim();
               if(name.endsWith(tok)){ return true;}
         }
         return false;
      }
   }
}