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 on the Web site that your visitors visit or on the Community Web Service where you enable storage and retrieval of submitted (visitor) comments and ratings:

Visitor Web site
The advantage of implementing your Content Validator on the Web site on which your visitors submit comments and ratings is that you have full access to their information and the Web site 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 Web Service
If you implement your Content Validator in the Community Web Service, which you use to enable storage and retrieval of submitted (visitor) comments and ratings, your 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 the SDL Tridion 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 Web site.
    DoubleCommentingValidator.java and DoubleRatingValidator.java
    These Validators are implemented on the Community Web Service.
  2. Access the Visitor Web site or Community Web Service.
  3. Do one of the following:
    • If you use a .NET Web application, access the bin\config\ folder.
    • If you use a Java Web application, the WEB-INF/classes subdirectory.
  4. Open the cd_ugc_conf.xml configuration file in a text editor.
  5. Uncomment the <ContentValidators> section, if commented out.
  6. 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"/>
  7. If you implemented any configuration options for your content validator, add your configuration for the content validator.
  8. Save and close cd_ugc_conf.xml.
  9. Restart the Web application.