1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package net.sf.fridaymvc.metadata.commons;
18
19 import java.util.regex.Pattern;
20
21 import net.sf.fridaymvc.Parameters;
22 import net.sf.fridaymvc.RunData;
23
24 /***
25 * @author <a href="mailto:arto.pastinen@ofw.fi">Arto Pastinen</a>
26 * @version $Id: RegExpValidatorAttribute.java,v 1.1 2004/11/23 20:35:58 artsi Exp $
27 */
28
29 public class RegExpValidatorAttribute {
30 private String id;
31 private String fieldName;
32 private String regexp;
33
34 public RegExpValidatorAttribute(String id, String fieldName, String regexp) {
35 setId(id);
36 setFieldName(fieldName);
37 setRegexp(regexp);
38 }
39
40 /***
41 * @return Returns the fieldName.
42 */
43 public String getFieldName() {
44 return this.fieldName;
45 }
46 /***
47 * @param fieldName The fieldName to set.
48 */
49 public void setFieldName(String fieldName) {
50 this.fieldName = fieldName;
51 }
52 /***
53 * @return Returns the regexp.
54 */
55 public String getRegexp() {
56 return this.regexp;
57 }
58 /***
59 * @param regexp The regexp to set.
60 */
61 public void setRegexp(String regexp) {
62 this.regexp = regexp;
63 }
64 /***
65 * @return Returns the id.
66 */
67 public String getId() {
68 return this.id;
69 }
70 /***
71 * @param id The id to set.
72 */
73 public void setId(String regexpId) {
74 this.id = regexpId;
75 }
76
77 public boolean passValidation() {
78 Parameters p = RunData.getInstance().getParameters();
79 String tmp = p.getPrefix();
80 p.setPrefix("action.");
81 try {
82 return Pattern.matches(getRegexp(), p.get(getFieldName()));
83 }
84 catch(Throwable t) {
85
86 return false;
87 }
88 finally {
89 p.setPrefix(tmp);
90 }
91 }
92
93
94
95
96 public boolean equals(Object obj) {
97 if(obj instanceof RegExpValidatorAttribute) {
98 if(((RegExpValidatorAttribute) obj).getId().equals(getId())) return true;
99 return false;
100 }
101 return false;
102 }
103
104
105
106
107 public int hashCode() {
108 return getId().hashCode();
109 }
110 }