01: /* ServletLabelResovler.java
02:
03: {{IS_NOTE
04: Purpose:
05:
06: Description:
07:
08: History:
09: Mon Jun 12 13:58:56 2006, Created by tomyeh
10: }}IS_NOTE
11:
12: Copyright (C) 2006 Potix Corporation. All Rights Reserved.
13:
14: {{IS_RIGHT
15: }}IS_RIGHT
16: */
17: package org.zkoss.web.util.resource;
18:
19: import org.zkoss.util.resource.Labels;
20: import org.zkoss.xel.VariableResolver;
21: import org.zkoss.xel.XelException;
22:
23: import org.zkoss.web.servlet.xel.RequestContext;
24: import org.zkoss.web.servlet.xel.RequestContexts;
25:
26: /**
27: * Used with {@link Labels} to resolve XEL expressions in labels.
28: *
29: * @author tomyeh
30: */
31: public class ServletLabelResovler implements VariableResolver {
32: public ServletLabelResovler() {
33: }
34:
35: //VariableResolver//
36: public Object resolveVariable(String name) throws XelException {
37: final Object o = Labels.getLabel(name);
38: if (o != null)
39: return o;
40:
41: final RequestContext jc = RequestContexts.getCurrent();
42: if (jc != null) {
43: final VariableResolver parent = jc.getVariableResolver();
44: if (parent != null)
45: return parent.resolveVariable(name);
46: }
47: return null;
48: }
49: }
|