01: //WebOnSwing - Web Application Framework
02: //Copyright (C) 2004 Fernando Damian Petrola
03: //
04: //This library is free software; you can redistribute it and/or
05: //modify it under the terms of the GNU Lesser General Public
06: //License as published by the Free Software Foundation; either
07: //version 2.1 of the License, or (at your option) any later version.
08: //
09: //This library is distributed in the hope that it will be useful,
10: //but WITHOUT ANY WARRANTY; without even the implied warranty of
11: //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: //Lesser General Public License for more details.
13: //
14: //You should have received a copy of the GNU Lesser General Public
15: //License along with this library; if not, write to the Free Software
16: //Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17:
18: package net.ar.webonswing.swing.components.validators;
19:
20: import javax.swing.*;
21:
22: import net.ar.webonswing.*;
23: import net.ar.webonswing.helpers.*;
24: import net.ar.webonswing.swing.components.validators.contributors.*;
25:
26: import org.apache.regexp.*;
27:
28: public class JRegularExpressionValidator extends JValidator {
29: protected String re;
30: protected RE matcher;
31:
32: public JRegularExpressionValidator() {
33: setContributor();
34: }
35:
36: public JRegularExpressionValidator(JComponent aComponentToValidate,
37: String aMessage, String aGroupMessage,
38: boolean hasRemoteValidation, String aRe) {
39: super (aComponentToValidate, aMessage, aGroupMessage,
40: hasRemoteValidation);
41:
42: setRe(aRe);
43: setContributor();
44: }
45:
46: protected void setContributor() {
47: WosFramework.assignContributor(this ,
48: RegularExpressionValidatorUIContributor.class);
49: }
50:
51: protected boolean performValidation() {
52: return matcher.match(getComponentValue(componentToValidate));
53: }
54:
55: public String getRe() {
56: return re;
57: }
58:
59: public void setRe(String aString) {
60: re = aString;
61:
62: try {
63: matcher = new RE(re);
64: } catch (RESyntaxException e) {
65: throw new WebOnSwingException(
66: "Error in regular expression", e);
67: }
68: }
69: }
|