1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kns.web.comparator;
17
18 import org.apache.commons.collections.comparators.ComparableComparator;
19 import org.apache.commons.lang.StringUtils;
20 import org.displaytag.model.Cell;
21 import org.kuali.rice.core.api.util.type.TypeUtils;
22 import org.kuali.rice.krad.comparator.NumericValueComparator;
23 import org.kuali.rice.krad.comparator.StringValueComparator;
24 import org.kuali.rice.krad.comparator.TemporalValueComparator;
25
26 import java.util.Comparator;
27 import java.util.regex.Matcher;
28 import java.util.regex.Pattern;
29
30
31
32
33
34
35 @Deprecated
36 public class CellComparatorHelper {
37
38 static private Pattern HREF_ENCLOSURE = Pattern.compile("<a [^>]+>([^<]*)</a>.*", Pattern.MULTILINE);
39
40
41
42
43
44
45
46
47
48 static public String getSanitizedStaticValue(Cell cell) {
49 if (null == cell) {
50 return null;
51 }
52
53 return null == cell.getStaticValue() ? null : getSanitizedStaticValue(cell.getStaticValue().toString());
54 }
55
56
57
58
59
60
61
62
63 static public String getSanitizedStaticValue(String staticValue) {
64
65 if (null == staticValue) {
66 return null;
67 }
68
69 staticValue = StringUtils.replace(staticValue, "\r", "");
70 staticValue = StringUtils.replace(staticValue, "\n", "");
71 staticValue = StringUtils.replace(staticValue, "\t", "");
72
73 String sanitizedValue = staticValue;
74
75
76 Matcher matcher = HREF_ENCLOSURE.matcher(staticValue);
77 if (matcher.matches()) {
78
79 sanitizedValue = matcher.group(1).trim();
80
81 }
82
83
84 while (sanitizedValue.endsWith(" ")) {
85
86 sanitizedValue = sanitizedValue.substring(0, sanitizedValue.length() - 6).trim();
87
88 }
89
90 return sanitizedValue;
91
92 }
93
94
95
96
97
98
99
100 public static Comparator getAppropriateComparatorForPropertyClass(Class propClass) {
101
102 if (propClass == null) {
103 return new NullCellComparator();
104 }
105 else if (TypeUtils.isDecimalClass(propClass) || TypeUtils.isIntegralClass(propClass)) {
106 return new NumericCellComparator();
107 }
108 else if (TypeUtils.isTemporalClass(propClass)) {
109 return new TemporalCellComparator();
110 }
111 else if (String.class.equals(propClass)) {
112
113 return new StringCellComparator();
114 }
115 else {
116 return ComparableComparator.getInstance();
117 }
118 }
119
120
121
122
123
124
125 public static Comparator getAppropriateValueComparatorForPropertyClass(Class propClass) {
126 if (propClass == null) {
127 return NullValueComparator.getInstance();
128 }
129 else if (TypeUtils.isDecimalClass(propClass) || TypeUtils.isIntegralClass(propClass)) {
130 return NumericValueComparator.getInstance();
131 }
132 else if (TypeUtils.isTemporalClass(propClass)) {
133 return TemporalValueComparator.getInstance();
134 }
135 else if (String.class.equals(propClass)) {
136
137 return StringValueComparator.getInstance();
138 }
139 else {
140 return ComparableComparator.getInstance();
141 }
142 }
143 }