Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
CubbyFunctions |
|
| 0.0;0 |
1 | /* | |
2 | * Copyright 2004-2008 the Seasar Foundation and the Others. | |
3 | * | |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | * you may not use this file except in compliance with the License. | |
6 | * You may obtain a copy of the License at | |
7 | * | |
8 | * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | * | |
10 | * Unless required by applicable law or agreed to in writing, software | |
11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, | |
13 | * either express or implied. See the License for the specific language | |
14 | * governing permissions and limitations under the License. | |
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 | /** | |
25 | * CubbyのJSP EL functionsを提供します。 | |
26 | * | |
27 | * @author baba | |
28 | * @since 1.0.0 | |
29 | * @deprecated {@link org.seasar.cubby.tags.CubbyFunctions} を使用してください。 | |
30 | */ | |
31 | @Deprecated | |
32 | 0 | public class CubbyFunctions { |
33 | ||
34 | /** | |
35 | * 配列やコレクションに指定したオブジェクトが含まれるかどうかを判定します。 | |
36 | * | |
37 | * @param collection | |
38 | * 配列や{@link Collection コレクション} | |
39 | * @param obj | |
40 | * 配列やコレクションにあるかどうかを調べる要素 | |
41 | * @return 配列やコレクションに指定したオブジェクトが含まれる場合は <code>true</code>、そうでない場合は | |
42 | * <code>false</code> | |
43 | */ | |
44 | public static Boolean contains(final Object collection, final Object obj) { | |
45 | 2 | if (collection instanceof Collection) { |
46 | 2 | return _contains((Collection<?>) collection, obj); |
47 | 0 | } else if (collection != null && collection.getClass().isArray()) { |
48 | 0 | return _contains(Arrays.asList((Object[]) collection), obj); |
49 | } else { | |
50 | 0 | return false; |
51 | } | |
52 | } | |
53 | ||
54 | /** | |
55 | * 指定された要素が{@link Collection}内にあるかどうかを示します。 | |
56 | * | |
57 | * @param collection | |
58 | * コレクション | |
59 | * @param obj | |
60 | * コレクションにあるかどうかを調べる要素 | |
61 | * @return 指定された要素が{@link Collection}内にある場合は <code>true</code>、そうでない場合は | |
62 | * <code>false</code> | |
63 | */ | |
64 | private static Boolean _contains(final Collection<?> collection, | |
65 | final Object obj) { | |
66 | 2 | return collection.contains(obj); |
67 | } | |
68 | ||
69 | /** | |
70 | * {@link Map}に指定したキーが含まれるかどうかを判定します。 | |
71 | * | |
72 | * @param map | |
73 | * マップ | |
74 | * @param key | |
75 | * マップにあるかどうかが判定されるキー | |
76 | * @return {@link Map}に指定したキーが含まれる場合は <code>true</code>、そうでない場合は | |
77 | * <code>false</code> | |
78 | */ | |
79 | public static Boolean containsKey(final Map<?, ?> map, final Object key) { | |
80 | 0 | return map.containsKey(key); |
81 | } | |
82 | ||
83 | /** | |
84 | * {@link Map}に指定した値が含まれるかどうかを判定します。 | |
85 | * | |
86 | * @param map | |
87 | * マップ | |
88 | * @param value | |
89 | * マップにあるかどうかを判定される値 | |
90 | * @return {@link Map}に指定した値が含まれる場合は <code>true</code>、そうでない場合は | |
91 | * <code>false</code> | |
92 | */ | |
93 | public static Boolean containsValue(final Map<?, ?> map, final Object value) { | |
94 | 0 | return map.containsValue(value); |
95 | } | |
96 | ||
97 | /** | |
98 | * 指定したカンマ区切りの文字列をインデックス値でサイクルして出力します。 | |
99 | * <p> | |
100 | * 主に行毎に色分けする場合に CSS のクラス名を出力する場合に使用します。 | |
101 | * </p> | |
102 | * | |
103 | * @param index | |
104 | * インデックス | |
105 | * @param classNames | |
106 | * カンマ区切りの文字列 | |
107 | * @return 指定したインデックスに対応する文字列 | |
108 | */ | |
109 | public static String odd(final Integer index, final String classNames) { | |
110 | 0 | final String[] c = classNames.split(","); |
111 | 0 | return c[index % c.length]; |
112 | } | |
113 | ||
114 | /** | |
115 | * HTMLをエスケープします。 | |
116 | * <p> | |
117 | * JSTLのoutタグの代わりに使用します。EL式で出力された文字列はエスケープされないため、エスケープを行いたい場合はこのfunctionを使用します。 | |
118 | * </p> | |
119 | * | |
120 | * @param str | |
121 | * エスケープする文字列 | |
122 | * @return エスケープされた HTML | |
123 | */ | |
124 | public static String out(final Object str) { | |
125 | 0 | return str == null ? "" : CubbyUtils.escapeHtml(str.toString()); |
126 | } | |
127 | ||
128 | /** | |
129 | * {@link Date}型のオブジェクトをフォーマットして出力します。 | |
130 | * <p> | |
131 | * JSTL の dateFormat タグの代わりに使用します。 | |
132 | * </p> | |
133 | * | |
134 | * @param date | |
135 | * 日付/時刻文字列にフォーマットする日付/時刻値 | |
136 | * @param pattern | |
137 | * 日付と時刻のフォーマットを記述するパターン | |
138 | * @return フォーマットされた日付/時刻文字列 | |
139 | */ | |
140 | public static String dateFormat(final Object date, final String pattern) { | |
141 | 0 | if (date instanceof Date) { |
142 | 0 | final SimpleDateFormat format = new SimpleDateFormat(pattern); |
143 | 0 | return format.format(date); |
144 | } else { | |
145 | 0 | return ""; |
146 | } | |
147 | } | |
148 | ||
149 | } |