KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > jstl > el > SetLocaleTag


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  * Free SoftwareFoundation, Inc.
23  * 59 Temple Place, Suite 330
24  * Boston, MA 02111-1307 USA
25  *
26  * @author Scott Ferguson
27  */

28
29 package com.caucho.jstl.el;
30
31 import com.caucho.el.Expr;
32 import com.caucho.jsp.PageContextImpl;
33 import com.caucho.util.L10N;
34
35 import javax.el.ELContext;
36 import javax.el.ELException;
37 import javax.servlet.jsp.JspException JavaDoc;
38 import javax.servlet.jsp.jstl.core.Config;
39 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
40 import java.util.Locale JavaDoc;
41
42 /**
43  * Sets the i18n locale bundle for the current page.
44  */

45 public class SetLocaleTag extends TagSupport JavaDoc {
46   private static L10N L = new L10N(SetBundleTag.class);
47   
48   private Expr _valueExpr;
49   private Expr _variantExpr;
50   private String JavaDoc _scope;
51
52   /**
53    * Sets the JSP-EL expression for the locale value.
54    */

55   public void setValue(Expr value)
56   {
57     _valueExpr = value;
58   }
59
60   /**
61    * Sets the JSP-EL expression for the variant value.
62    */

63   public void setVariant(Expr variant)
64   {
65     _variantExpr = variant;
66   }
67
68   /**
69    * Sets the scope to store the bundle.
70    */

71   public void setScope(String JavaDoc scope)
72   {
73     _scope = scope;
74   }
75
76   /**
77    * Process the tag.
78    */

79   public int doStartTag()
80     throws JspException JavaDoc
81   {
82     try {
83       PageContextImpl pageContext = (PageContextImpl) this.pageContext;
84       ELContext env = pageContext.getELContext();
85
86       Object JavaDoc valueObj = _valueExpr.evalObject(env);
87       Locale JavaDoc locale = null;
88
89       if (valueObj instanceof Locale JavaDoc) {
90     locale = (Locale JavaDoc) valueObj;
91       }
92       else if (valueObj instanceof String JavaDoc) {
93     String JavaDoc variant = null;
94
95     if (_variantExpr != null)
96       variant = _variantExpr.evalString(env);
97
98     locale = pageContext.getLocale((String JavaDoc) valueObj, variant);
99       }
100
101       CoreSetTag.setValue(pageContext, Config.FMT_LOCALE, _scope, locale);
102
103       return SKIP_BODY;
104     } catch (ELException e) {
105       throw new JspException JavaDoc(e);
106     }
107   }
108 }
109
Popular Tags