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 public class CubbyFunctions {
27
28 public static Boolean contains(Object c, Object value) {
29 if (c instanceof Collection) {
30 return _contains((Collection<?>) c, value);
31 } else if (c != null && c.getClass().isArray()) {
32 return _contains(Arrays.asList((Object[]) c), value);
33 } else {
34 return false;
35 }
36 }
37
38 public static Boolean _contains(Collection<?> c, Object value) {
39 return c.contains(value);
40 }
41
42 public static Boolean containsKey(Map<?, ?> m, Object value) {
43 return m.containsKey(value);
44 }
45
46 public static Boolean containsValue(Map<?, ?> m, Object value) {
47 return m.containsValue(value);
48 }
49
50 public static String odd(Integer index, String classnames) {
51 String[] c = classnames.split(",");
52 return c[index % c.length];
53 }
54
55 public static String out(Object value) {
56 return value == null ? "" : escapeHtml(value.toString());
57 }
58
59 public static String escapeHtml(Object value) {
60 if (value == null) {
61 return "";
62 }
63 String text;
64 if (value instanceof String) {
65 text = (String) value;
66 } else {
67 text = value.toString();
68 }
69 text = StringUtil.replace(text, "&", "&");
70 text = StringUtil.replace(text, "<", "<");
71 text = StringUtil.replace(text, ">", ">");
72 text = StringUtil.replace(text, "\"", """);
73 text = StringUtil.replace(text, "'", "'");
74 return text;
75 }
76
77 public static String dateFormat(Object date, String pattern) {
78 if (date instanceof Date) {
79 SimpleDateFormat format = new SimpleDateFormat(pattern);
80 return format.format(date);
81 } else {
82 return "";
83 }
84 }
85
86 }