net.sourceforge.stripes.validation
Class EmailTypeConverter

java.lang.Object
  extended by net.sourceforge.stripes.validation.EmailTypeConverter
All Implemented Interfaces:
TypeConverter<String>

public class EmailTypeConverter
extends Object
implements TypeConverter<String>

A faux TypeConverter that validates that the String supplied is a valid email address. Relies on javax.mail.internet.InternetAddress for the bulk of the work (note that this means in order to use this type converter you must have JavaMail available in your classpath).

If the String cannot be parsed, or it represents a "local" address (one with no @domain) a single error message will be generated. The error message is a scoped message with a default scope of converter.email and name invalidEmail. As a result error messages will be looked for in the following order:

Since:
Stripes 1.2
Author:
Tim Fennell

Constructor Summary
EmailTypeConverter()
           
 
Method Summary
 String convert(String input, Class<? extends String> targetType, Collection<ValidationError> errors)
          Validates the user input to ensure that it is a valid email address.
 void setLocale(Locale locale)
          Accepts the Locale provided, but does nothing with it since emails are Locale-less.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EmailTypeConverter

public EmailTypeConverter()
Method Detail

setLocale

public void setLocale(Locale locale)
Accepts the Locale provided, but does nothing with it since emails are Locale-less.

Specified by:
setLocale in interface TypeConverter<String>
Parameters:
locale - the locale that the TypeConverter will be converting from.

convert

public String convert(String input,
                      Class<? extends String> targetType,
                      Collection<ValidationError> errors)
Validates the user input to ensure that it is a valid email address.

Specified by:
convert in interface TypeConverter<String>
Parameters:
input - the String input, always a non-null non-empty String
targetType - realistically always String since java.lang.String is final
errors - a non-null collection of errors to populate in case of error
Returns:
the parsed address, or null if there are no errors. Note that the parsed address may be different from the input if extraneous characters were removed.


? Copyright 2005-2006, Stripes Development Team.