1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.seasar.teeda.core.taglib.core; |
17 | |
|
18 | |
import java.util.Locale; |
19 | |
import java.util.MissingResourceException; |
20 | |
import java.util.ResourceBundle; |
21 | |
|
22 | |
import javax.faces.component.UIViewRoot; |
23 | |
import javax.faces.context.FacesContext; |
24 | |
import javax.faces.el.ValueBinding; |
25 | |
import javax.faces.internal.ValueBindingUtil; |
26 | |
import javax.faces.webapp.UIComponentTag; |
27 | |
import javax.servlet.jsp.JspException; |
28 | |
import javax.servlet.jsp.tagext.Tag; |
29 | |
import javax.servlet.jsp.tagext.TagSupport; |
30 | |
|
31 | |
import org.seasar.framework.log.Logger; |
32 | |
import org.seasar.framework.util.AssertionUtil; |
33 | |
import org.seasar.teeda.core.util.ResourceBundleMap; |
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | 5 | public class LoadBundleTag extends TagSupport { |
40 | |
|
41 | 2 | private static Logger logger = Logger.getLogger(LoadBundleTag.class); |
42 | |
|
43 | |
private static final long serialVersionUID = 1L; |
44 | |
|
45 | |
private String basename; |
46 | |
|
47 | |
private String var; |
48 | |
|
49 | |
public void setBasename(String basename) { |
50 | 5 | this.basename = basename; |
51 | 5 | } |
52 | |
|
53 | |
public void setVar(String var) { |
54 | 4 | this.var = var; |
55 | 4 | } |
56 | |
|
57 | |
public String getBasename() { |
58 | 5 | return basename; |
59 | |
} |
60 | |
|
61 | |
public String getVar() { |
62 | 1 | return var; |
63 | |
} |
64 | |
|
65 | |
public int doStartTag() throws JspException { |
66 | 4 | FacesContext context = FacesContext.getCurrentInstance(); |
67 | 4 | AssertionUtil.assertNotNull("FacesContext", context); |
68 | |
|
69 | 4 | UIViewRoot viewRoot = context.getViewRoot(); |
70 | 4 | AssertionUtil.assertNotNull("ViewRoot", viewRoot); |
71 | |
|
72 | 4 | Locale locale = viewRoot.getLocale(); |
73 | 4 | if (locale == null) { |
74 | 0 | locale = context.getApplication().getDefaultLocale(); |
75 | |
} |
76 | 4 | String bname = null; |
77 | 4 | final String basename = getBasename(); |
78 | 4 | if (basename != null) { |
79 | 4 | if (UIComponentTag.isValueReference(basename)) { |
80 | 0 | ValueBinding vb = ValueBindingUtil.createValueBinding(context, |
81 | |
basename); |
82 | 0 | bname = (String) vb.getValue(context); |
83 | |
} else { |
84 | 4 | bname = basename; |
85 | |
} |
86 | |
} |
87 | |
final ResourceBundle bundle; |
88 | |
try { |
89 | 4 | bundle = ResourceBundle.getBundle(bname, locale, Thread |
90 | |
.currentThread().getContextClassLoader()); |
91 | 1 | } catch (MissingResourceException e) { |
92 | 1 | logger.error("Resource bundle '" + bname + "' could not be found"); |
93 | 1 | return Tag.SKIP_BODY; |
94 | 3 | } |
95 | |
|
96 | 3 | context.getExternalContext().getRequestMap().put(var, |
97 | |
new ResourceBundleMap(bundle)); |
98 | |
|
99 | 3 | return Tag.SKIP_BODY; |
100 | |
} |
101 | |
|
102 | |
public void release() { |
103 | 1 | basename = null; |
104 | 1 | var = null; |
105 | 1 | } |
106 | |
|
107 | |
} |