1
2
3
4 package org.rcfaces.core.internal.validator.impl;
5
6 import org.apache.commons.logging.Log;
7 import org.apache.commons.logging.LogFactory;
8 import org.rcfaces.core.internal.lang.StringAppender;
9 import org.rcfaces.core.validator.IClientValidatorContext;
10
11
12
13
14
15
16 public class NumFilter extends AbstractDynamicPatternTask {
17 private static final String REVISION = "$Revision: 1.2 $";
18
19 private static final Log LOG = LogFactory.getLog(NumFilter.class);
20
21 protected String getRegularExpression(IClientValidatorContext context) {
22 StringAppender sa = new StringAppender("[0-9");
23
24 if (getBoolParameter(context, "num.signed", false)) {
25 String sup = getParameter(context, "num.negSign", "-");
26 if (sup != null && sup.length() > 0) {
27 sa.append(buildEscaped(sup));
28 }
29 }
30
31 int showDecimal = 0;
32 String numDecimal = getParameter(context, "num.decimal");
33 if (numDecimal != null) {
34 if ("true".equalsIgnoreCase(numDecimal)) {
35 showDecimal = -1;
36 } else {
37 showDecimal = Integer.parseInt(numDecimal);
38 }
39 }
40
41 if (showDecimal != 0) {
42 String sup = getParameter(context, "num.decSign");
43 if (sup != null && sup.length() > 0) {
44 sa.append(buildEscaped(sup));
45 }
46 }
47
48 String sup = getParameter(context, "num.sepSign");
49 if (sup != null && sup.length() > 0) {
50 sa.append(buildEscaped(sup));
51 }
52
53 sa.append(']');
54
55 return sa.toString();
56 }
57 }