Site Manager Developer Manual / Version 2310
Table Of ContentsValidators are used to check the values of document properties at check-in time. If the validator throws a ValidationException, a window pops up which shows a message containing the exception message.
Interface to implement
Own validators must implement the interface
hox.corem.editor.validation.Validator2
with the method validate
.
Validator2
replaces the deprecated
Validator
interface which was memory consuming when it comes to the validation of Blobs.
Parameters to use
The validate
method gets the following parameters:
Parameter |
Type |
Description |
---|---|---|
document |
DocumentModel |
The document with the property to validate. The DocumentModel is for read access only, do not try to modify any document here |
|
|
The property type of the property to validate |
value |
Object |
The value of the property, not a PropertyModel but the value of the PropertyModel (see table below for the default types) |
|
Map |
A map indexed by property name of all the documents properties |
Table 4.3. Parameters of the validate method
Return types
The method returns a value. The type depends on the property which has been validated.
The properties have the following types:
Property | Default PropertyModel | Value |
---|---|---|
String | StringModel | String |
Integer | IntegerModel | Integer |
Date | CalendarModel | Calendar |
LinkList | LinkListModel | Object[] containing ResourceHolder objects |
XmlText | XmlPropertyModel | org.w3c.Document |
Blob | BlobModel | hox.corem.editor.proxy.BlobValue |
Table 4.4. Default types of the properties
General hints
Use the SimpleValidationException instead of ValidationException since ValidationException is abstract. The constructor takes parameters for error messages and hints for problem resolution, these parameters are in fact property names for the property file bundles (see the [CAP Editor API] for details).
Don't try to change any documents in the validator. Violating this rule may lead to deadlocks, inconsistent states, swallowed events etc. since the check-in locks the proxy, which prevents events from the server to be processed. Thus, you see inconsistent states in your validator.
Integrate your validator into the Site Manager
using editor.xml
You can integrate your validator into the Site Manager using the element
Validator
of the editor.xml
file as shown in
Example 4.3, “Integrate validator in editor.xml”.
<DocumentTypes> <DocumentType name="Dish"> <PropertyType name="Price" initialValue="30"/> <PropertyType name="Name"> <Validator class="com.customer.example.editor.SimpleValidator"/> </PropertyType> </DocumentType> </DocumentTypes>
Example 4.3. Integrate validator in editor.xml
Example:
The next example shows a validator which simply returns the value to be validated.
package com.customer.example.editor; import java.util.Map; import hox.corem.editor.proxy.*; import hox.corem.editor.validation.*; public class SimpleValidator implements Validator2 { public Object validate(DocumentModel doc, PropertyTypeModel pte, Object value, Map props) throws ValidationException { return value; } }
Example 4.4. Simple customized validator