1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.springmodules.validation.bean.conf.loader.xml.handler;
18
19 import org.springframework.util.StringUtils;
20 import org.springmodules.validation.bean.conf.ValidationConfigurationException;
21 import org.springmodules.validation.bean.rule.AbstractValidationRule;
22 import org.springmodules.validation.bean.rule.RegExpValidationRule;
23 import org.w3c.dom.Element;
24
25
26
27
28
29
30
31 public class RegExpRuleElementHandler extends AbstractPropertyValidationElementHandler {
32
33 private static final String ELEMENT_NAME = "regexp";
34
35 private static final String EXPRESSION_ATTR = "expression";
36
37
38
39
40 public RegExpRuleElementHandler(String namespaceUri) {
41 super(ELEMENT_NAME, namespaceUri);
42 }
43
44 protected AbstractValidationRule createValidationRule(Element element) {
45 String expression = element.getAttribute(EXPRESSION_ATTR);
46 if (!StringUtils.hasText(expression)) {
47 throw new ValidationConfigurationException("Element '" + ELEMENT_NAME + "' must have an 'expression' attribute");
48 }
49 return new RegExpValidationRule(expression);
50 }
51
52 }