org.apache.tapestry.valid
Class UrlValidator

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

public class UrlValidator
extends BaseValidator

Since:
3.0
Version:
$Id: UrlValidator.java 243791 2004-02-19 17:38:13Z hlship $

Field Summary
 
Fields inherited from class org.apache.tapestry.valid.BaseValidator
FIELD_SYMBOL, FORM_SYMBOL, FUNCTION_SYMBOL, VALIDATOR_SYMBOL
 
Constructor Summary
UrlValidator()
           
 
Method Summary
protected  String buildDisallowedProtocolMessage(IFormComponent field)
           
protected  String buildInvalidUrlFormatMessage(IFormComponent field)
           
protected  String buildMinimumLengthMessage(IFormComponent field)
           
 String getDisallowedProtocolMessage()
           
 String getInvalidUrlFormatMessage()
           
 int getMinimumLength()
           
 String getMinimumLengthMessage()
           
protected  String getPattern(String override, String key, Locale locale)
          Gets a pattern, either as the default value, or as a localized key.
 String getScriptPath()
           
protected  boolean isAllowedProtocol(String url)
           
protected  boolean isValidUrl(String url)
           
 void renderValidatorContribution(IFormComponent field, IMarkupWriter writer, IRequestCycle cycle)
          This implementation does nothing.
 void setAllowedProtocols(String protocols)
           
 void setDisallowedProtocolMessage(String string)
           
 void setInvalidUrlFormatMessage(String string)
           
 void setMinimumLength(int minimumLength)
           
 void setMinimumLengthMessage(String string)
           
 void setScriptPath(String scriptPath)
           
 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, 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

UrlValidator

public UrlValidator()
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)

isValidUrl

protected boolean isValidUrl(String url)

isAllowedProtocol

protected boolean isAllowedProtocol(String url)

getInvalidUrlFormatMessage

public String getInvalidUrlFormatMessage()

getMinimumLengthMessage

public String getMinimumLengthMessage()

setInvalidUrlFormatMessage

public void setInvalidUrlFormatMessage(String string)

getDisallowedProtocolMessage

public String getDisallowedProtocolMessage()

setDisallowedProtocolMessage

public void setDisallowedProtocolMessage(String string)

setMinimumLengthMessage

public void setMinimumLengthMessage(String string)

buildMinimumLengthMessage

protected String buildMinimumLengthMessage(IFormComponent field)

buildInvalidUrlFormatMessage

protected String buildInvalidUrlFormatMessage(IFormComponent field)

buildDisallowedProtocolMessage

protected String buildDisallowedProtocolMessage(IFormComponent field)

getPattern

protected String getPattern(String override,
                            String key,
                            Locale locale)
Description copied from class: BaseValidator
Gets a pattern, either as the default value, or as a localized key. If override is null, then the key from the org.apache.tapestry.valid.ValidationStrings ResourceBundle (in the specified locale) is used. The pattern can then be used with BaseValidator.formatString(String, Object[]).

Why do we not just lump these strings into TapestryStrings.properties? because TapestryStrings.properties is localized to the server's locale, which is fine for the logging, debugging and error messages it contains. For field validation, whose errors are visible to the end user normally, we want to localize to the page's locale.

Overrides:
getPattern in class BaseValidator
Parameters:
override - The override value for the localized string from the bundle.
key - used to lookup pattern from bundle, if override is null.
locale - used to get right localization of bundle.

setAllowedProtocols

public void setAllowedProtocols(String protocols)
Parameters:
protocols - comma separated list of allowed protocols