1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.seasar.cubby.util; |
17 | |
|
18 | |
import java.text.SimpleDateFormat; |
19 | |
import java.util.Arrays; |
20 | |
import java.util.Collection; |
21 | |
import java.util.Date; |
22 | |
import java.util.Map; |
23 | |
|
24 | |
import org.seasar.framework.util.StringUtil; |
25 | |
|
26 | 0 | public class CubbyFunctions { |
27 | |
|
28 | |
public static Boolean contains(Object c, Object value) { |
29 | 2 | if (c instanceof Collection) { |
30 | 2 | return _contains((Collection<?>) c, value); |
31 | 0 | } else if (c != null && c.getClass().isArray()) { |
32 | 0 | return _contains(Arrays.asList((Object[]) c), value); |
33 | |
} else { |
34 | 0 | return false; |
35 | |
} |
36 | |
} |
37 | |
|
38 | |
public static Boolean _contains(Collection<?> c, Object value) { |
39 | 2 | return c.contains(value); |
40 | |
} |
41 | |
|
42 | |
public static Boolean containsKey(Map<?, ?> m, Object value) { |
43 | 0 | return m.containsKey(value); |
44 | |
} |
45 | |
|
46 | |
public static Boolean containsValue(Map<?, ?> m, Object value) { |
47 | 0 | return m.containsValue(value); |
48 | |
} |
49 | |
|
50 | |
public static String odd(Integer index, String classnames) { |
51 | 0 | String[] c = classnames.split(","); |
52 | 0 | return c[index % c.length]; |
53 | |
} |
54 | |
|
55 | |
public static String out(Object value) { |
56 | 102 | return value == null ? "" : escapeHtml(value.toString()); |
57 | |
} |
58 | |
|
59 | |
public static String escapeHtml(Object value) { |
60 | 108 | if (value == null) { |
61 | 0 | return ""; |
62 | |
} |
63 | |
String text; |
64 | 108 | if (value instanceof String) { |
65 | 107 | text = (String) value; |
66 | |
} else { |
67 | 1 | text = value.toString(); |
68 | |
} |
69 | 108 | text = StringUtil.replace(text, "&", "&"); |
70 | 108 | text = StringUtil.replace(text, "<", "<"); |
71 | 108 | text = StringUtil.replace(text, ">", ">"); |
72 | 108 | text = StringUtil.replace(text, "\"", """); |
73 | 108 | text = StringUtil.replace(text, "'", "'"); |
74 | 108 | return text; |
75 | |
} |
76 | |
|
77 | |
public static String dateFormat(Object date, String pattern) { |
78 | 0 | if (date instanceof Date) { |
79 | 0 | SimpleDateFormat format = new SimpleDateFormat(pattern); |
80 | 0 | return format.format(date); |
81 | |
} else { |
82 | 0 | return ""; |
83 | |
} |
84 | |
} |
85 | |
|
86 | |
} |