01: /**
02: *
03: * Licensed to the Apache Software Foundation (ASF) under one or more
04: * contributor license agreements. See the NOTICE file distributed with
05: * this work for additional information regarding copyright ownership.
06: * The ASF licenses this file to You under the Apache License, Version 2.0
07: * (the "License"); you may not use this file except in compliance with
08: * the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing, software
13: * distributed under the License is distributed on an "AS IS" BASIS,
14: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: * See the License for the specific language governing permissions and
16: * limitations under the License.
17: */package org.apache.openejb.jee;
18:
19: import java.util.ArrayList;
20: import java.util.LinkedHashMap;
21: import java.util.List;
22: import java.util.Locale;
23: import java.util.Map;
24:
25: /**
26: * @version $Revision: 581127 $ $Date: 2007-10-01 19:13:16 -0700 $
27: */
28: public class TextMap {
29:
30: protected Map<String, String> string = new LinkedHashMap<String, String>();
31:
32: public Text[] toArray() {
33: List<Text> list = new ArrayList<Text>();
34: for (Map.Entry<String, String> entry : string.entrySet()) {
35: list.add(new Text(entry.getKey(), entry.getValue()));
36: }
37: return list.toArray(new Text[] {});
38: }
39:
40: public void set(Text[] text) {
41: string.clear();
42: for (Text t : text) {
43: string.put(t.getLang(), t.getValue());
44: }
45: }
46:
47: public String get() {
48: return getLocal(string);
49: }
50:
51: private String getLocal(Map<String, ?> map) {
52: String lang = Locale.getDefault().getLanguage();
53: return (String) (map.get(lang) != null ? map.get(lang) : map
54: .get(null));
55: }
56:
57: }
|