org.springmodules.validation.valang.javascript
Class ValangJavaScriptTranslator

java.lang.Object
  extended by org.springmodules.validation.valang.javascript.ValangJavaScriptTranslator

public class ValangJavaScriptTranslator
extends Object

Translates a collection of valang validation rules into a JavaScript statement that is capable of validating a HTML form and writes this to a provided Writer. This class is not thread safe so it is recommended that a new instance be created each time a translation is required.

The generated JavaScript code is dependent on the code base found in the file "valang_codebase.js" having already been loaded into the page where the validation will occur.

Author:
Oliver Hutchison

Constructor Summary
ValangJavaScriptTranslator()
           
 
Method Summary
protected  void append(char c)
           
protected  void append(String string)
           
protected  void appendArrayValidators(Collection<ValidationRule> rules, MessageSourceAccessor messageSource)
           
protected  void appendJsString(String string)
           
protected  void appendValidationFunction(org.apache.commons.collections.Predicate p)
           
protected  void appendValidatorRule(BasicValidationRule rule, MessageSourceAccessor messageSource)
           
protected  void clearWriter()
           
protected  void doVisit(Object value)
           
static Reader getCodebaseReader()
          Returns a Reader for accessing the JavaScript codebase used by the translated validation rules.
protected  String getErrorMessage(BasicValidationRule rule, MessageSourceAccessor messageSource)
           
protected  String getNameForCustomFunction(Function f)
           
protected  String mathToFunctionName(AbstractMathFunction f)
           
protected  String operatorToFunctionName(Operator operator)
           
protected  void setWriter(Writer writer)
           
 void writeJavaScriptValangValidator(Writer writer, String name, boolean installSelfWithForm, Collection<ValidationRule> rules, MessageSourceAccessor messageSource)
          Translates the provided set of Valang BasicValidationRules into JavaScript code capable of validating a HTML form and outputs the translated code into the provided writer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ValangJavaScriptTranslator

public ValangJavaScriptTranslator()
Method Detail

getCodebaseReader

public static Reader getCodebaseReader()
Returns a Reader for accessing the JavaScript codebase used by the translated validation rules.


writeJavaScriptValangValidator

public void writeJavaScriptValangValidator(Writer writer,
                                           String name,
                                           boolean installSelfWithForm,
                                           Collection<ValidationRule> rules,
                                           MessageSourceAccessor messageSource)
                                    throws IOException
Translates the provided set of Valang BasicValidationRules into JavaScript code capable of validating a HTML form and outputs the translated code into the provided writer.

Parameters:
writer - the writer to output the JavaScript code into
name - the name of the command that is being validated
installSelfWithForm - should the generated JavaScript attempt to install its self with the form on creation
rules - the collection of BasicValidationRules to translate
messageSource - the message source accessor that will be used to resolve validation messages.
Throws:
IOException

setWriter

protected void setWriter(Writer writer)

clearWriter

protected void clearWriter()

append

protected void append(String string)
               throws IOException
Throws:
IOException

appendJsString

protected void appendJsString(String string)
                       throws IOException
Throws:
IOException

append

protected void append(char c)
               throws IOException
Throws:
IOException

appendArrayValidators

protected void appendArrayValidators(Collection<ValidationRule> rules,
                                     MessageSourceAccessor messageSource)
                              throws IOException
Throws:
IOException

appendValidatorRule

protected void appendValidatorRule(BasicValidationRule rule,
                                   MessageSourceAccessor messageSource)
                            throws IOException
Throws:
IOException

getErrorMessage

protected String getErrorMessage(BasicValidationRule rule,
                                 MessageSourceAccessor messageSource)

appendValidationFunction

protected void appendValidationFunction(org.apache.commons.collections.Predicate p)
                                 throws IOException
Throws:
IOException

doVisit

protected void doVisit(Object value)
                throws IOException
Throws:
IOException

getNameForCustomFunction

protected String getNameForCustomFunction(Function f)

operatorToFunctionName

protected String operatorToFunctionName(Operator operator)

mathToFunctionName

protected String mathToFunctionName(AbstractMathFunction f)


Copyright © 2009. All Rights Reserved.