01: package net.sf.jportlet.portlet.descriptor;
02:
03: import java.util.Locale;
04: import java.util.Map;
05:
06: import net.sf.jportlet.portlet.PortletException;
07:
08: /**
09: * The <code>LanguageDescriptor</code> contains language sensitive information
10: * of a portlet
11: *
12: * @author <a href="mailto:tchbansi@sourceforge.net">Herve Tchepannou</a>
13: */
14: public class LanguageDescriptor {
15: //~ Instance fields --------------------------------------------------------
16:
17: private String _description;
18: private String _keywords;
19: private String _locale;
20: private String _title;
21: private String _titleShort;
22:
23: //~ Methods ----------------------------------------------------------------
24:
25: public static LanguageDescriptor find(Locale locale, Map languages,
26: String defaultLocale) {
27: LanguageDescriptor lang = (LanguageDescriptor) languages
28: .get(locale.toString());
29:
30: if (lang == null) {
31: String language = locale.getLanguage();
32: String country = locale.getCountry();
33: String variant = locale.getVariant();
34:
35: /* country */
36: if ((variant != null) && (variant.length() > 0)) {
37: lang = (LanguageDescriptor) languages.get(language
38: + "_" + country);
39: }
40:
41: /* lang */
42: if ((lang == null) && (country != null)
43: && (country.length() > 0)) {
44: lang = (LanguageDescriptor) languages.get(language);
45: }
46: }
47:
48: return (lang != null) ? lang : (LanguageDescriptor) languages
49: .get(defaultLocale);
50: }
51:
52: public String getDescription() {
53: return _description;
54: }
55:
56: public String getKeywords() {
57: return _keywords;
58: }
59:
60: public String getLocale() {
61: return _locale;
62: }
63:
64: public String getTitle() {
65: return _title;
66: }
67:
68: public String getTitleShort() {
69: return _titleShort;
70: }
71:
72: public void setDescription(String description) {
73: _description = description;
74: }
75:
76: public void setKeywords(String keywords) {
77: _keywords = keywords;
78: }
79:
80: public void setLocale(String locale) throws PortletException {
81: _locale = locale;
82: }
83:
84: public void setTitle(String title) {
85: _title = title;
86: }
87:
88: public void setTitleShort(String titleShort) {
89: _titleShort = titleShort;
90: }
91: }
|