KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > taglibs > standard > tag > el > core > ImportTag


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

30
31 public class ImportTag extends ImportSupport {
32
33     //*********************************************************************
34
// 'Private' state (implementation details)
35

36     private String JavaDoc context_; // stores EL-based property
37
private String JavaDoc charEncoding_; // stores EL-based property
38
private String JavaDoc url_; // stores EL-based property
39

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

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

49     public ImportTag() {
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
69     // Releases any resources we may have (or inherit)
70
public void release() {
71         super.release();
72         init();
73     }
74
75
76     //*********************************************************************
77
// Accessor methods
78

79     // for EL-based attribute
80
public void setUrl(String JavaDoc url_) {
81         this.url_ = url_;
82     }
83
84     public void setContext(String JavaDoc context_) {
85         this.context_ = context_;
86     }
87
88     public void setCharEncoding(String JavaDoc charEncoding_) {
89         this.charEncoding_ = charEncoding_;
90     }
91
92     //*********************************************************************
93
// Private (utility) methods
94

95     // (re)initializes state (during release() or construction)
96
private void init() {
97         // null implies "no expression"
98
url_ = context_ = charEncoding_ = null;
99     }
100
101     /* Evaluates expressions as necessary */
102     private void evaluateExpressions() throws JspException JavaDoc {
103         /*
104          * Note: we don't check for type mismatches here; we assume
105          * the expression evaluator will return the expected type
106          * (by virtue of knowledge we give it about what that type is).
107          * A ClassCastException here is truly unexpected, so we let it
108          * propagate up.
109          */

110
111     url = (String JavaDoc) ExpressionUtil.evalNotNull(
112         "import", "url", url_, String JavaDoc.class, this, pageContext);
113     if (url == null || url.equals(""))
114         throw new NullAttributeException("import", "url");
115
116     context = (String JavaDoc) ExpressionUtil.evalNotNull(
117         "import", "context", context_, String JavaDoc.class, this, pageContext);
118     charEncoding = (String JavaDoc) ExpressionUtil.evalNotNull(
119         "import", "charEncoding", charEncoding_, String JavaDoc.class, this,
120         pageContext);
121     }
122 }
123
Popular Tags