5 package org
.spirit
.spring
.validate
;
7 import org
.apache
.commons
.logging
.Log
;
8 import org
.apache
.commons
.logging
.LogFactory
;
9 import org
.apache
.commons
.validator
.UrlValidator
;
10 import org
.spirit
.form
.BotListEntityLinksForm
;
11 import org
.springframework
.validation
.Errors
;
12 import org
.springframework
.validation
.ValidationUtils
;
13 import org
.springframework
.validation
.Validator
;
16 * This is class is used by botverse (used for rover updates).
17 * @author Berlin Brown
20 public class BotListEntityLinksRoverValidator
implements Validator
{
22 private Log log
= LogFactory
.getLog(getClass());
23 public static final String ROVER_VERIFY
= "672073419141141";
26 * @see org.springframework.validation.Validator#supports(java.lang.Class)
28 public boolean supports(Class post
) {
29 return BotListEntityLinksForm
.class.isAssignableFrom(post
);
33 * Check for a valid url entry.
35 private boolean isValidUrl(String url
) {
36 String
[] schemes
= { "http","https" };
37 UrlValidator urlValidator
= new UrlValidator(schemes
, UrlValidator
.NO_FRAGMENTS
);
38 return urlValidator
.isValid(url
);
43 * @see org.springframework.validation.Validator#validate(java.lang.Object, org.springframework.validation.Errors)
45 public void validate(Object obj
, Errors errors
) {
47 BotListEntityLinksForm form
= (BotListEntityLinksForm
) obj
;
49 ValidationUtils
.rejectIfEmptyOrWhitespace(errors
,
50 "urlTitle", "required", "* Title Field is required.");
51 ValidationUtils
.rejectIfEmptyOrWhitespace(errors
,
52 "mainUrl", "required", "* Please submit a URL.");
53 ValidationUtils
.rejectIfEmptyOrWhitespace(errors
,
54 "keywords", "required", "* Please enter keyword tags (space separated).");
56 if ((form
!= null) && (form
.getMainUrl() != null)) {
57 String url
= form
.getMainUrl();
58 if (!this.isValidUrl(url
)) {
59 errors
.reject("mainUrl", "* Please enter a valid url address (for example: http://www.url.com)");
64 && (form
.getRoverVerify() != null)) {
65 if (!form
.getRoverVerify().trim().equals(ROVER_VERIFY
)) {
66 errors
.reject("userSolution", "* Please enter the correct verify value.");