Documentation Center

Creating a custom content validator

You create a custom validator in Java by implementing the com.tridion.validation.ContentValidator interface. You then need to configure the validator in the cd_ugc_conf.xml configuration file.

About this task

You can activate a custom Validator , either on the website that your visitors visit or on the Community service where you enable storage and retrieval of submitted (visitor) comments and ratings.

Visitor website
The advantage of implementing your Content Validator on the website on which your visitors submit comments and ratings is that you have full access to their information. The website is also the first line of defense against spam and DDoS attacks. However, interacting with the User Generated Content database will be slower because you need to interact with the Web service using HTTP requests.
Community service
If you implement your Content Validator in the Community service, which enables storage and retrieval of submitted (visitor) comments and ratings, the Validator's access to the User Generated Content database is direct and consequently faster, but you have only limited access to visitor information.

Procedure

  1. Create and compile a Java class that implements the following interface:
    com.tridion.validation.ContentValidator
    To help you with your implementation, access your installation media and check the following Java source files in the folder Content Delivery\resources\samples\ugc\java\, which implement the built-in Content Validators:
    DoubleCommentVotingValidator.java
    This Validator is implemented on the Visitor website.
    DoubleCommentingValidator.java and DoubleRatingValidator.java
    These Validators are implemented on the Community service.
  2. Do one of the following:
    • If you are adding your custom Validator to the website, access the WEB-INF/classes/ subdirectory (Java) or the bin\config\ subfolder (.NET) of your web application.
    • If you are adding your custom Validator to the Community service, access its configuration location.
  3. Open the cd_ugc_conf.xml configuration file in a text editor.
  4. Uncomment the <ContentValidators> section, if commented out.
  5. Add a new ContentValidator element, with its Implementation attribute set to the name of your new Java class, for example:
    <ContentValidator Implementation="com.acme.validation.MyCustomValidator"/>
  6. If you implemented any configuration options for your content validator, add your configuration for the content validator.
  7. Save and close cd_ugc_conf.xml.
  8. Restart the Community service or web application.