View Javadoc

1   /*
2    * $Id: ELBaseTag.java 376779 2006-02-10 18:08:58Z husted $
3    *
4    * Copyright 1999-2004 The Apache Software Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.strutsel.taglib.html;
19  
20  import org.apache.struts.taglib.html.BaseTag;
21  import org.apache.strutsel.taglib.utils.EvalHelper;
22  
23  import javax.servlet.jsp.JspException;
24  
25  /***
26   * Renders an HTML <base> element with an href attribute pointing to the
27   * absolute location of the enclosing JSP page. This tag is only valid when
28   * nested inside a head tag body. The presence of this tag allows the browser
29   * to resolve relative URL's to images, CSS stylesheets  and other resources
30   * in a manner independent of the URL used to call the ActionServlet. <p> This
31   * class is a subclass of the class <code>org.apache.struts.taglib.html.BaseTag</code>
32   * which provides most of the described functionality.  This subclass allows
33   * all attribute values to be specified as expressions utilizing the
34   * JavaServer Pages Standard Library expression language.
35   *
36   * @version $Rev: 376779 $
37   */
38  public class ELBaseTag extends BaseTag {
39      /***
40       * Instance variable mapped to "target" tag attribute. (Mapping set in
41       * associated BeanInfo class.)
42       */
43      private String targetExpr;
44  
45      /***
46       * Instance variable mapped to "server" tag attribute. (Mapping set in
47       * associated BeanInfo class.)
48       */
49      private String serverExpr;
50  
51      /***
52       * Instance variable mapped to "ref" tag attribute. (Mapping set in
53       * associated BeanInfo class.)
54       */
55      private String refExpr;
56  
57      /***
58       * Getter method for "target" tag attribute. (Mapping set in associated
59       * BeanInfo class.)
60       */
61      public String getTargetExpr() {
62          return (targetExpr);
63      }
64  
65      /***
66       * Getter method for "server" tag attribute. (Mapping set in associated
67       * BeanInfo class.)
68       */
69      public String getServerExpr() {
70          return (serverExpr);
71      }
72  
73      /***
74       * Getter method for "ref" tag attribute. (Mapping set in associated
75       * BeanInfo class.)
76       */
77      public String getRefExpr() {
78          return (refExpr);
79      }
80  
81      /***
82       * Setter method for "target" tag attribute. (Mapping set in associated
83       * BeanInfo class.)
84       */
85      public void setTargetExpr(String targetExpr) {
86          this.targetExpr = targetExpr;
87      }
88  
89      /***
90       * Setter method for "server" tag attribute. (Mapping set in associated
91       * BeanInfo class.)
92       */
93      public void setServerExpr(String serverExpr) {
94          this.serverExpr = serverExpr;
95      }
96  
97      /***
98       * Setter method for "ref" tag attribute. (Mapping set in associated
99       * BeanInfo class.)
100      */
101     public void setRefExpr(String refExpr) {
102         this.refExpr = refExpr;
103     }
104 
105     /***
106      * Resets attribute values for tag reuse.
107      */
108     public void release() {
109         super.release();
110         setTargetExpr(null);
111         setServerExpr(null);
112         setRefExpr(null);
113     }
114 
115     /***
116      * Process the start tag.
117      *
118      * @throws JspException if a JSP exception has occurred
119      */
120     public int doStartTag() throws JspException {
121         evaluateExpressions();
122 
123         return (super.doStartTag());
124     }
125 
126     /***
127      * Processes all attribute values which use the JSTL expression evaluation
128      * engine to determine their values.
129      *
130      * @throws JspException if a JSP exception has occurred
131      */
132     private void evaluateExpressions()
133         throws JspException {
134         String string = null;
135 
136         if ((string =
137                 EvalHelper.evalString("target", getTargetExpr(), this,
138                     pageContext)) != null) {
139             setTarget(string);
140         }
141 
142         if ((string =
143                 EvalHelper.evalString("server", getServerExpr(), this,
144                     pageContext)) != null) {
145             setServer(string);
146         }
147 
148         if ((string =
149                 EvalHelper.evalString("ref", getRefExpr(), this, pageContext)) != null) {
150             setRef(string);
151         }
152     }
153 }