KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > taglibs > standard > tag > common > fmt > SetBundleSupport


1 /*
2  * Copyright 1999-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
17 package org.apache.taglibs.standard.tag.common.fmt;
18
19 import javax.servlet.jsp.JspException JavaDoc;
20 import javax.servlet.jsp.PageContext JavaDoc;
21 import javax.servlet.jsp.jstl.core.Config;
22 import javax.servlet.jsp.jstl.fmt.LocalizationContext;
23 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
24
25 import org.apache.taglibs.standard.tag.common.core.Util;
26
27 /**
28  * Support for tag handlers for <setBundle>, the JSTL 1.0 tag that loads
29  * a resource bundle and stores it in a scoped variable.
30  *
31  * @author Jan Luehe
32  */

33
34 public abstract class SetBundleSupport extends TagSupport JavaDoc {
35
36     
37     //*********************************************************************
38
// Protected state
39

40     protected String JavaDoc basename; // 'basename' attribute
41

42
43     //*********************************************************************
44
// Private state
45

46     private int scope; // 'scope' attribute
47
private String JavaDoc var; // 'var' attribute
48

49
50     //*********************************************************************
51
// Constructor and initialization
52

53     public SetBundleSupport() {
54     super();
55     init();
56     }
57
58     private void init() {
59     basename = null;
60     scope = PageContext.PAGE_SCOPE;
61     }
62
63
64     //*********************************************************************
65
// Tag attributes known at translation time
66

67     public void setVar(String JavaDoc var) {
68         this.var = var;
69     }
70
71     public void setScope(String JavaDoc scope) {
72     this.scope = Util.getScope(scope);
73     }
74
75
76     //*********************************************************************
77
// Tag logic
78

79     public int doEndTag() throws JspException JavaDoc {
80     LocalizationContext locCtxt =
81         BundleSupport.getLocalizationContext(pageContext, basename);
82
83     if (var != null) {
84         pageContext.setAttribute(var, locCtxt, scope);
85     } else {
86         Config.set(pageContext, Config.FMT_LOCALIZATION_CONTEXT, locCtxt,
87                scope);
88     }
89
90     return EVAL_PAGE;
91     }
92
93     // Releases any resources we may have (or inherit)
94
public void release() {
95     init();
96     }
97 }
98
Popular Tags