KickJava   Java API By Example, From Geeks To Geeks.

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


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.NullAttributeException;
22 import org.apache.taglibs.standard.tag.common.core.SetSupport;
23
24 /**
25  * <p>A handler for &lt;set&gt;, which redirects the browser to a
26  * new URL.
27  *
28  * @author Shawn Bayern
29  */

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

36     private String JavaDoc value_; // stores EL-based property
37
private String JavaDoc target_; // stores EL-based property
38
private String JavaDoc property_; // stores EL-based property
39

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

44     public SetTag() {
45         super();
46         init();
47     }
48
49
50     //*********************************************************************
51
// Tag logic
52

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

74     public void setValue(String JavaDoc value_) {
75         this.value_ = value_;
76     this.valueSpecified = true;
77     }
78
79     public void setTarget(String JavaDoc target_) {
80         this.target_ = target_;
81     }
82
83     public void setProperty(String JavaDoc property_) {
84         this.property_ = property_;
85     }
86
87
88     //*********************************************************************
89
// Private (utility) methods
90

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

106
107     // 'value'
108
try {
109         value = ExpressionUtil.evalNotNull(
110             "set", "value", value_, Object JavaDoc.class, this, pageContext);
111     } catch (NullAttributeException ex) {
112         // explicitly let 'value' be null
113
value = null;
114     }
115
116     // 'target'
117
target = ExpressionUtil.evalNotNull(
118         "set", "target", target_, Object JavaDoc.class, this, pageContext);
119
120     // 'property'
121
try {
122         property = (String JavaDoc) ExpressionUtil.evalNotNull(
123              "set", "property", property_, String JavaDoc.class, this, pageContext);
124         } catch (NullAttributeException ex) {
125             // explicitly let 'property' be null
126
property = null;
127         }
128     }
129 }
130
Popular Tags