Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
DefaultMessagesBehaviour |
|
| 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.controller.impl; | |
17 | ||
18 | import static org.seasar.cubby.CubbyConstants.RES_MESSAGES; | |
19 | ||
20 | import java.util.Enumeration; | |
21 | import java.util.HashMap; | |
22 | import java.util.Locale; | |
23 | import java.util.Map; | |
24 | import java.util.ResourceBundle; | |
25 | ||
26 | import org.seasar.cubby.controller.MessagesBehaviour; | |
27 | ||
28 | /** | |
29 | * メッセージの振る舞いのデフォルト実装です。 | |
30 | * | |
31 | * @author baba | |
32 | * @since 1.0.3 | |
33 | */ | |
34 | 1 | public class DefaultMessagesBehaviour implements MessagesBehaviour { |
35 | ||
36 | /** リソースバンドル、完全指定されたクラス名の基底名。 */ | |
37 | 1 | private String baseName = RES_MESSAGES; |
38 | ||
39 | /** | |
40 | * リソースバンドル、完全指定されたクラス名の基底名を取得します。 | |
41 | */ | |
42 | public String getBaseName() { | |
43 | 0 | return baseName; |
44 | } | |
45 | ||
46 | /** | |
47 | * リソースバンドル、完全指定されたクラス名の基底名を設定します。 | |
48 | * | |
49 | * @param baseName | |
50 | * リソースバンドル、完全指定されたクラス名の基底名 | |
51 | */ | |
52 | public void setBaseName(final String baseName) { | |
53 | 0 | this.baseName = baseName; |
54 | 0 | } |
55 | ||
56 | /** | |
57 | * {@inheritDoc} | |
58 | */ | |
59 | public ResourceBundle getBundle(final Locale locale) { | |
60 | 2 | final ResourceBundle bundle = ResourceBundle.getBundle(baseName, |
61 | locale == null ? Locale.getDefault() : locale); | |
62 | 2 | return bundle; |
63 | } | |
64 | ||
65 | /** | |
66 | * {@inheritDoc} | |
67 | */ | |
68 | public Map<String, String> toMap(final ResourceBundle bundle) { | |
69 | 1 | final Map<String, String> map = new HashMap<String, String>(); |
70 | 1 | for (final Enumeration<String> keys = bundle.getKeys(); keys |
71 | 14 | .hasMoreElements();) { |
72 | 13 | final String key = keys.nextElement(); |
73 | 13 | final String value = bundle.getString(key); |
74 | 13 | map.put(key, value); |
75 | 13 | } |
76 | 1 | return map; |
77 | } | |
78 | ||
79 | } |