org.apache.tapestry.valid
Class EmailValidator

java.lang.Object
  extended by org.apache.tapestry.valid.BaseValidator
      extended by org.apache.tapestry.valid.EmailValidator
All Implemented Interfaces:
IValidator

public class EmailValidator
extends BaseValidator

Simple validation of email strings, to enforce required, and minimum length (maximum length is enforced in the client browser, by setting a maximum input length on the text field).

Since:
2.3
Version:
$Id: EmailValidator.java 243791 2004-02-19 17:38:13Z hlship $
Author:
Malcolm Edgar

Field Summary
 
Fields inherited from class org.apache.tapestry.valid.BaseValidator
FIELD_SYMBOL, FORM_SYMBOL, FUNCTION_SYMBOL, VALIDATOR_SYMBOL
 
Constructor Summary
EmailValidator()
           
 
Method Summary
protected  String buildInvalidEmailFormatMessage(IFormComponent field)
           
protected  String buildMinimumLengthMessage(IFormComponent field)
           
 String getInvalidEmailFormatMessage()
           
 int getMinimumLength()
           
 String getMinimumLengthMessage()
           
 String getScriptPath()
           
protected  boolean isValidEmail(String email)
          Return true if the email format is valid.
 void renderValidatorContribution(IFormComponent field, IMarkupWriter writer, IRequestCycle cycle)
          This implementation does nothing.
 void setInvalidEmailFormatMessage(String string)
          Overrides the invalid-email-format bundle key.
 void setMinimumLength(int minimumLength)
           
 void setMinimumLengthMessage(String string)
          Overrides the field-too-short bundle key.
 void setScriptPath(String scriptPath)
          Allows a developer to use the existing validation logic with a different client-side script.
 Object toObject(IFormComponent field, String input)
          Converts input, submitted by the client, into an object value.
 String toString(IFormComponent field, Object value)
          Invoked during rendering to convert an object value (which may be null) to a String.
 
Methods inherited from class org.apache.tapestry.valid.BaseValidator
buildRequiredMessage, checkRequired, formatString, formatString, formatString, getPattern, getRequiredMessage, isClientScriptingEnabled, isRequired, processValidatorScript, setClientScriptingEnabled, setRequired, setRequiredMessage
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EmailValidator

public EmailValidator()
Method Detail

toString

public String toString(IFormComponent field,
                       Object value)
Description copied from interface: IValidator
Invoked during rendering to convert an object value (which may be null) to a String. It is acceptible to return null. The string will be the VALUE attribute of the HTML text field.


toObject

public Object toObject(IFormComponent field,
                       String input)
                throws ValidatorException
Description copied from interface: IValidator
Converts input, submitted by the client, into an object value. May return null if the input is null (and the required flag is false).

The input string will already have been trimmed. It may be null.

Throws:
ValidatorException - if the string cannot be converted into an object, or the object is not valid (due to other constraints).

getMinimumLength

public int getMinimumLength()

setMinimumLength

public void setMinimumLength(int minimumLength)

renderValidatorContribution

public void renderValidatorContribution(IFormComponent field,
                                        IMarkupWriter writer,
                                        IRequestCycle cycle)
Description copied from class: BaseValidator
This implementation does nothing. Subclasses may supply their own implementation.

Specified by:
renderValidatorContribution in interface IValidator
Overrides:
renderValidatorContribution in class BaseValidator

getScriptPath

public String getScriptPath()

setScriptPath

public void setScriptPath(String scriptPath)
Allows a developer to use the existing validation logic with a different client-side script. This is often sufficient to allow application-specific error presentation (perhaps by using DHTML to update the content of a <span> tag, or to use a more sophisticated pop-up window than window.alert()).


isValidEmail

protected boolean isValidEmail(String email)
Return true if the email format is valid.

Parameters:
email - the email string to validate
Returns:
true if the email format is valid

getInvalidEmailFormatMessage

public String getInvalidEmailFormatMessage()
Since:
3.0

getMinimumLengthMessage

public String getMinimumLengthMessage()
Since:
3.0

setInvalidEmailFormatMessage

public void setInvalidEmailFormatMessage(String string)
Overrides the invalid-email-format bundle key. Parameter {0} is the display name of the field.

Since:
3.0

setMinimumLengthMessage

public void setMinimumLengthMessage(String string)
Overrides the field-too-short bundle key. Parameter {0} is the minimum length. Parameter {1} is the display name of the field.

Since:
3.0

buildMinimumLengthMessage

protected String buildMinimumLengthMessage(IFormComponent field)
Since:
3.0

buildInvalidEmailFormatMessage

protected String buildInvalidEmailFormatMessage(IFormComponent field)
Since:
3.0