Future Computing Environments

WhoWhereEmail Service Code

// A G E N T
// .   .   .

// WhoWhereEmail.java

// (c) Anind Dey ... 1996


// ****************************************************************************

package cyberdesk.acton.service;

import	java.net.*;

import  cyberdesk.cameo.*;
import  cyberdesk.types.Name;


// ****************************************************************************

public class WhoWhereEmail extends ServiceApplet
  {
  protected CameoInterface[] initInterfaces()
    {
    CameoInterface[] interfaces = null;

    try
      {
      CameoProperty[] properties = new CameoProperty[ 1 ];
      properties[ 0 ] = new CameoProperty( "LookupEmailAddressFor", Class.forName( "cyberdesk.types.Name" ),
                                           "Lookup person's email address in the WhoWhere listings" );
      interfaces = new CameoInterface[ 1 ];
      interfaces[ 0 ] = new CameoInterface( "method", properties );
      }
    catch ( ClassNotFoundException e )
      {
      System.out.println( "WhoWhereEmail: class Name not found" );
      }

    return interfaces;
    }


  public void manipulate( CameoMessage msg )
    {
    if ( msg.getField( msg.PROPERTY ).equals( "LookupEmailAddressFor" ) )
      {
      try
        {
        String name = ( (Name)msg.getField( msg.DATA ) ).getName();
        name = spaces2pluses(name);

        String query = new String("name=" + name + "&match=inexact");
        URL search = new URL(new String("http://query1.whowhere.com/jwz/name.wsrch?" + query));
        getAppletContext().showDocument( search, "_whowhere" );
        }
      catch ( MalformedURLException e )
        {
        System.out.println( "WhoWhereEmail: MalformedURLException - " + e );
        }
      }
    }


/**
 * This private method takes a string and replaces all spaces with "+"'s.
 *
 * @return      string with spaces replaced by pluses
 * @param       s       incoming string
 */
    public String spaces2pluses(String s) {
      StringBuffer sb = new StringBuffer("");
      for (int i = 0; i < s.length(); i++) {
        if (s.charAt(i)==' ') {
          sb.append('+');
        }
        else if (s.charAt(i) == '&') {
          sb.append("%26");
        }
        else {
          sb.append(s.charAt(i));
        }
      }
      return sb.toString();
    }

}
// ****************************************************************************

Return to the CyberDesk sample code page.
Return to the CyberDesk home page.


Future Computing Environments Georgia Institute of Technology