KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > taglibs > standard > tag > el > fmt > BundleTag


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.el.fmt;
18
19 import javax.servlet.jsp.JspException JavaDoc;
20
21 import org.apache.taglibs.standard.lang.support.ExpressionEvaluatorManager;
22 import org.apache.taglibs.standard.tag.common.fmt.BundleSupport;
23
24 /**
25  * <p>A handler for &lt;bundle&gt; that accepts attributes as Strings
26  * and evaluates them as expressions at runtime.</p>
27  *
28  * @author Shawn Bayern
29  * @author Jan Luehe
30  */

31
32 public class BundleTag extends BundleSupport {
33
34     //*********************************************************************
35
// 'Private' state (implementation details)
36

37     private String JavaDoc basename_; // stores EL-based property
38
private String JavaDoc prefix_; // stores EL-based property
39

40
41     //*********************************************************************
42
// Constructor
43

44     /**
45      * Constructs a new BundleTag. As with TagSupport, subclasses
46      * should not provide other constructors and are expected to call
47      * the superclass constructor
48      */

49     public BundleTag() {
50         super();
51         init();
52     }
53
54
55     //*********************************************************************
56
// Tag logic
57

58     // evaluates expression and chains to parent
59
public int doStartTag() throws JspException JavaDoc {
60
61         // evaluate any expressions we were passed, once per invocation
62
evaluateExpressions();
63
64     // chain to the parent implementation
65
return super.doStartTag();
66     }
67
68     // Releases any resources we may have (or inherit)
69
public void release() {
70         super.release();
71         init();
72     }
73
74
75     //*********************************************************************
76
// Accessor methods
77

78     // for EL-based attribute
79
public void setBasename(String JavaDoc basename_) {
80         this.basename_ = basename_;
81     }
82
83     // for EL-based attribute
84
public void setPrefix(String JavaDoc prefix_) {
85         this.prefix_ = prefix_;
86     }
87
88
89     //*********************************************************************
90
// Private (utility) methods
91

92     // (re)initializes state (during release() or construction)
93
private void init() {
94         // null implies "no expression"
95
basename_ = prefix_ = null;
96     }
97
98     // Evaluates expressions as necessary
99
private void evaluateExpressions() throws JspException JavaDoc {
100
101     // 'basename' attribute (mandatory)
102
basename = (String JavaDoc) ExpressionEvaluatorManager.evaluate(
103         "basename", basename_, String JavaDoc.class, this, pageContext);
104
105     // 'prefix' attribute (optional)
106
if (prefix_ != null) {
107         prefix = (String JavaDoc) ExpressionEvaluatorManager.evaluate(
108             "prefix", prefix_, String JavaDoc.class, this, pageContext);
109     }
110     }
111 }
112
Popular Tags