Date: Thu, 28 Mar 2024 23:52:50 +0000 (UTC) Message-ID: <1340855528.25.1711669970538@5882edfa7d94> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_24_397533286.1711669970537" ------=_Part_24_397533286.1711669970537 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html
A field validator is a Java class which prevents from changing to the ne= xt panel if one or more input field content is not valid during the install= ation. If the chosen validator reports some field content to be false, a me= ssagebox is popped up with a defined (translated or untranslated content) a= nd the user will be unable to continue to the next panel.
Validators are bound to particular fields, each field can have zero, one= or more validators assigned in the user panel definition.
The validation itself is triggered when the user presses the Next button= to change to the nex panel. This change is prevented in case of a negative= validation, the user is forced to fix the bad input field values he previo= usly provided.
There are built-in validators available, and own, user-defined validator= implementations can be used.
Dedicated validators may support configuration parameters:
<field type=3D"..." variable=3D"...">
...
<valida= tor class=3D"..." ...>
<configuration>
<pa= ram_1>...</param_1>
...
<param_n>...= </param_n>
</configuration>
</validator></field>
The <configuration>
section is optional.
For making migration easier, there can be used still <para=
m name=3D"..." value=3D"..." />
entries instead or additiona=
lly to the newer <configuration>
definition. T=
his approach might be removed in one of the next major versions.
Parameter values may contain unresolved references to IzPack variables, = which are resolved at installation time.
The <configuration> section including variable resolution is fully= functional beginning from IzPack version 5.1.1.
Validators are bound to user input fields using the nested <validator= > element;
<= ;field type=3D"text" variable=3D"ora.db"> <spec txt=3D"SID:" id=3D"text.oraclesettings.sid" size=3D"3" set=3D""/= > <validator class=3D"com.izforge.izpack.panels.userinput.validator.NotE= mptyValidator" txt=3D"Invalid oracle SID!" id=3D"text.oraclesettings.error.= sid" /> </field>
Field validators can be combined with field= processors. Validation takes place before the field processor applies:
<fiel= d type=3D"password" align=3D"left" variable=3D"keystore.password"> <spec> <pwd txt=3D"Keystore Password:" size=3D"25" set=3D""/> <pwd txt=3D"Retype Password:" size=3D"25" set=3D""/> <processor class=3D"com.izforge.izpack.panels.userinput.processor.= PasswordEncryptionProcessor" backupVariable=3D"keystore.password.plain"> <configuration> <encryptionKey>xxx</encryptionKey> <algorithm>AES</algorithm> </configuration> </processor> </spec> <validator class=3D"com.izforge.izpack.panels.userinput.validator.Pas= swordEqualityValidator" txt=3D"Both keystore passwords must match." id=3D"key for the= error text"/> <validator class=3D"com.izforge.izpack.panels.userinput.validator.Pas= swordKeystoreValidator" txt=3D"Could not validate keystore with password and alias pr= ovided." id=3D"key for the error text"> <configuration> <keystoreFile>${ssl.keystore}</keystoreFile> <keystoreType>${ssl.keystore.type}</keystoreType> <keystoreAlias>${keystore.key.alias}</keystoreAlias> <skipValidation>${skip.keystore.validation}</skipValidati= on> </configuration> </validator> </field>
Built-in Validators
The NotEmptyValidator
simply checks that the user=
entered a non-null value into each subfield, and returns false o=
therwise.
<= ;field type=3D"rule" variable=3D"test.notempty"> <description align=3D"left" txt=3D"A description for a rule input fiel= d." id=3D"description.rule.1"/> <spec txt=3D"Please enter your phone number:" layout=3D"( N:3:3 ) N:3:= 3 - N:4:4 x N:5:5" resultFormat=3D"specialSeparator" separator=3D"."/> <validator class=3D"com.izforge.izpack.panels.userinput.validator.NotE= mptyValidator" txt=3D"The phone number is mandatory!" /> </field>
PasswordEqualityValidator
This validator uses a password field specification to compare the values= in each field for equality. Normally, this would be to ensure a password w= as typed correctly before any other validation takes place.
<field type= =3D"password" align=3D"left" variable=3D"the.password"> <spec> <pwd txt=3D"The Password:" size=3D"25" set=3D""/> <pwd txt=3D"Retype Password:" size=3D"25" set=3D""/> </spec> <validator class=3D"com.izforge.izpack.panels.userinput.validator.Pass= wordEqualityValidator" txt=3D"Both passwords must match." id=3D"lang pack key for the erro= r text"/> </field>
This validator uses the password field and parameters you send in from p= revious user input or predefined properties to open a keystore and optional= ly try to get a specified key.
You must specify the parameter 'keystoreFile', and optionally 'keystoreT= ype' (defaults to JKS), 'keystoreAlias' (to check for existence of a key), = and 'aliasPassword' (for trying to retrieve the key).
An additional parameter 'skipValidation' can be set to 'true' in a check= box and allow the validator framework to run, but not actually do the valid= ation.
Optionally checking the key password of multiple keys within a keystore = requires the keystore password (if different from the key password) be set = in the 'keystorePassword' parameter.
<field type= =3D"password" align=3D"left" variable=3D"keystore.password"> <spec> <pwd txt=3D"Keystore Password:" size=3D"25" set=3D""/> <pwd txt=3D"Retype Password:" size=3D"25" set=3D""/> </spec> <validator class=3D"com.izforge.izpack.panels.userinput.validator.Pass= wordEqualityValidator" txt=3D"Both keystore passwords must match." id=3D"key for t= he error text"/> <validator class=3D"com.izforge.izpack.panels.userinput.validator.Pass= wordKeystoreValidator" txt=3D"Could not validate keystore with password and alias = provided." id=3D"key for the error text"> <param name=3D"keystoreFile" value=3D"${ssl.keystore}"/> <param name=3D"keystoreType" value=3D"${ssl.keystore.type}"/> <param name=3D"keystoreAlias" value=3D"${keystore.key.alias}"/> <param name=3D"skipValidation" value=3D"${skip.keystore.validation}"= /> </validator> </field>
The RegularExpressionValidator checks that the user entered a = value which matches a specified regular expression, as accepted by the Jaka= rta Regexp library (http://jakarta.apache.org/regexp/). The= syntax of this implementation is described in the javadoc of the RE&n= bsp;class (http://jakarta.apac= he.org/regexp/apidocs/org/apache/regexp/RE.html).
You can specify the regular expression to be tested by passing a paramet= er with a name of pattern to the validator (via the param&nb= sp;element), with the regular expression as the value attribute. = For example, the following would validate an e-mail address:
The example of using Regexp validator in rule input field:
<field type= =3D"rule" variable=3D"EMAILaddress"> <spec txt=3D"Your Email address:" layout=3D"O:12:U @ O:8:40 A:4:4" set= =3D"0: 1:domain 2:com" resultFormat=3D"displayFormat" /> <validator class=3D"com.izforge.izpack.panels.userinput.validator.Regu= larExpressionValidator"
txt=3D"Invalid email address!"><= /pre><param na= me=3D"pattern" value=3D"[a-zA-Z0-9._-]{3,}@[a-zA-Z0-9._-]+([.][a-zA-Z0-9_-]= +)*[.][a-zA-Z0-9._-]{2,4}"/></validator= > </field>The example of using Regexp validator in text input field:
<field type= =3D"text" variable=3D"EMAILaddress"> <spec txt=3D"Your Email address:" set=3D"you@domain.com" size=3D"20" id=3D"= " /> <validator class=3D"com.izforge.izpack.panels.userinput.validator.RegularExpressionV= alidator" txt=3D"Invalid email address!"> <param name=3D"pattern" value=3D"[a-zA-Z0-9._-]{3,}@[a-zA-Z0-9._-]+([.][a-zA-Z0-9_-]+)*[.][= a-zA-Z0-9._-]{2,4}" /> </validator> </field>An example of using regexp validator in a password field (attribute text= wrapped for readability):
<field type= =3D"password" align=3D"left" variable=3D"db.password"> <spec> <pwd txt=3D"DB Password:" size=3D"25" set=3D""/> <pwd txt=3D"Retype Password:" size=3D"25" set=3D""/> </spec> <validator class=3D"com.izforge.izpack.panels.userinput.validator.Pass= wordEqualityValidator" txt=3D"Both DB passwords must match." id=3D"key for the err= or text"/> <validator class=3D"com.izforge.izpack.panels.userinput.validator.Regu= larExpressionValidator"
id=3D"key for the error text"> txt=3D"Service password must begin with a character and be 8= -20 mixed-case characters, numbers, and special characters [#@!$_]."><param na= me=3D"pattern" value=3D"^(?=3D[a-zA-Z])(?=3D.*[0-9])(?=3D.*[#@!$_]) (?=3D.*[A-Z])(?=3D.*[a-z])(?!.*[^a-zA-Z0-9#@!$_])(?!.*\s).{= 8,20}$"/> </validator> </field>You can test your own regular expressions using the handy applet at = ;http://jakarta.apache.org/regexp/applet.html.= p>
User-defined Validators= h3>
You can implement your own custom Validator implementation simply by cre= ating a new class which implements the co= m.izforge.izpack.panels.userinput.validator.Validator interface= . This interface specifies a single method: validate(ProcessingClient)= , which returns a boolean value. You can retrieve the value= entered by the user by casting the input ProcessingClient for example in t= he RuleInputField and call the RuleInputField.getText() = ;method. You can also retrieve any parameters to your custom Validator= by calling theRuleInputField.getValidatorParams() which returns = a java.util.Map object containing parameter names mapped to param= eter values. For an example, take a look at com.izforge.izpack.util.Re= gularExpressionValidator.