1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.myfaces.commons.validator;
20
21 import javax.faces.application.FacesMessage;
22 import javax.faces.component.UIComponent;
23 import javax.faces.context.FacesContext;
24 import javax.faces.validator.ValidatorException;
25
26 import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFValidator;
27 import org.apache.myfaces.commons.util.MessageUtils;
28
29
30
31
32
33
34
35
36 @JSFValidator(
37 name = "mcv:validateISBN",
38 tagClass = "org.apache.myfaces.commons.validator.ValidateISBNTag",
39 serialuidtag = "5230653358032218656L")
40 public class ISBNValidator extends ValidatorBase {
41
42
43
44
45 public static final String VALIDATOR_ID = "org.apache.myfaces.commons.validator.ISBN";
46
47
48
49
50 public static final String ISBN_MESSAGE_ID = "org.apache.myfaces.commons.validator.ISBN.INVALID";
51
52
53
54
55 private org.apache.commons.validator.ISBNValidator isbnValidator;
56
57 public ISBNValidator(){
58 isbnValidator = new org.apache.commons.validator.ISBNValidator();
59 }
60
61
62
63
64
65 public void validate(
66 FacesContext facesContext,
67 UIComponent uiComponent,
68 Object value)
69 throws ValidatorException {
70
71
72 if (facesContext == null) throw new NullPointerException("facesContext");
73 if (uiComponent == null) throw new NullPointerException("uiComponent");
74
75 if (value == null)
76 {
77 return;
78 }
79
80 if (!isbnValidator.isValid( value.toString())) {
81 Object[] args = {value.toString()};
82 String message = getMessage();
83 if (null == message) message = ISBN_MESSAGE_ID;
84
85 throw new ValidatorException(MessageUtils.getMessage(FacesMessage.SEVERITY_ERROR, message, args));
86 }
87
88
89 }
90
91 }