// CSC 442F - Software Engineering
// Software:    Calendar Client
// Component:   GetUsers class
// Description: Get user list

import java.io.*;
import java.util.*;
import java.awt.*;

public class GetUsers
{
  private StringTokenizer tokens;
 
  // Constructor 1 -- returns ALL users
  // ==================================
  public GetUsers(ClientSocket clientsocket, List userlist)
  {
    try 
    {
      clientsocket.Write("listallusers,");
      String buf = new String (clientsocket.Read()); 

      if (buf.regionMatches(false, 0 , "190", 0,  3))
      {
        tokens = new StringTokenizer (buf, ",");
        tokens.nextToken(); //throw away response number
        while (true)
        { 
          String buffer = new String (tokens.nextToken()); 
          if (buffer.regionMatches(false, 0 , "END", 0,  3))
 	          break;	            
          userlist.add (buffer); 
        }
      }     
    }   

    catch (IOException io)
    { 
    } 
  }


  // Constructor 2 -- Return users except for admin and exceptfor
  // ============================================================
  public GetUsers(ClientSocket clientsocket, List userlist, String exceptfor)
  {
    try 
    {
      clientsocket.Write("listallusers,");
      String buf = new String (clientsocket.Read()); 
    
      if (buf.regionMatches(false, 0 , "190", 0,  3))
      {
        tokens = new StringTokenizer (buf, ",");
        tokens.nextToken(); //throw away response number
        while (true)
        { 
          String buffer = new String (tokens.nextToken());
          if (buffer.regionMatches(false, 0 , "END", 0,  3))
 	          break;
          if (!buffer.equals(exceptfor) && !buffer.equals("admin") &&
              !buffer.endsWith("_personal"))
            userlist.add (buffer); 
        }
      }     
    }   

    catch (IOException io)
    { 
    } 

  }
} 
