View Javadoc

1   /*
2    * Copyright 2002,2004 The Apache Software Foundation.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.apache.commons.jelly.tags.fmt;
17  
18  import org.apache.commons.jelly.JellyTagException;
19  import org.apache.commons.jelly.XMLOutput;
20  import org.apache.commons.jelly.TagSupport;
21  import org.apache.commons.jelly.expression.Expression;
22  import java.util.Locale;
23  
24  /***
25   * Support for tag handlers for <setLocale>, the bundle setting
26   * tag in JSTL.
27   * @author <a href="mailto:willievu@yahoo.com">Willie Vu</a>
28   * @version $Revision: 155420 $
29   *
30   */
31  public class SetBundleTag extends TagSupport {
32  
33      private String var;
34  
35      private Expression basename;
36  
37      private String scope;
38  
39      /*** Creates a new instance of SetBundleTag */
40      public SetBundleTag() {
41      }
42  
43      /***
44       * Evaluates this tag after all the tags properties have been initialized.
45       *
46       */
47      public void doTag(XMLOutput output) throws JellyTagException {
48          Object basenameInput = null;
49          if (this.basename != null) {
50              basenameInput = this.basename.evaluate(context);
51          }
52  
53          LocalizationContext locCtxt = BundleTag.getLocalizationContext(
54              context, (String) basenameInput);
55  
56          String varname = (var != null) ? var : Config.FMT_LOCALIZATION_CONTEXT;
57  
58          if (scope != null) {
59              context.setVariable(varname, scope, locCtxt);
60          }
61          else {
62              context.setVariable(varname, locCtxt);
63          }
64      }
65  
66      public void setVar(String var) {
67          this.var = var;
68      }
69  
70      public void setBasename(Expression basename) {
71          this.basename = basename;
72      }
73  
74      public void setScope(String scope) {
75          this.scope = scope;
76      }
77  }