org.springmodules.validation.valang.javascript
Class ValangJavaScriptTranslator
java.lang.Object
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
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
ValangJavaScriptTranslator
public ValangJavaScriptTranslator()
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
BasicValidationRule
s 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 intoname
- the name of the command that is being validatedinstallSelfWithForm
- should the generated JavaScript attempt to install
its self with the form on creationrules
- the collection of BasicValidationRule
s to translatemessageSource
- 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.