View Javadoc

1   /*
2    * $Id: ELHtmlTag.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.HtmlTag;
21  import org.apache.strutsel.taglib.utils.EvalHelper;
22  
23  import javax.servlet.jsp.JspException;
24  
25  /***
26   * Renders an HTML <html> element with appropriate language attributes if
27   * there is a current Locale available in the user's session. <p> This class
28   * is a subclass of the class <code>org.apache.struts.taglib.html.HtmlTag</code>
29   * which provides most of the described functionality.  This subclass allows
30   * all attribute values to be specified as expressions utilizing the
31   * JavaServer Pages Standard Library expression language.
32   *
33   * @version $Rev: 376779 $
34   */
35  public class ELHtmlTag extends HtmlTag {
36      /***
37       * Instance variable mapped to "lang" tag attribute. (Mapping set in
38       * associated BeanInfo class.)
39       */
40      private String langExpr;
41  
42      /***
43       * Instance variable mapped to "xhtml" tag attribute. (Mapping set in
44       * associated BeanInfo class.)
45       */
46      private String xhtmlExpr;
47  
48      /***
49       * Getter method for "lang" tag attribute. (Mapping set in associated
50       * BeanInfo class.)
51       */
52      public String getLangExpr() {
53          return (langExpr);
54      }
55  
56      /***
57       * Getter method for "xhtml" tag attribute. (Mapping set in associated
58       * BeanInfo class.)
59       */
60      public String getXhtmlExpr() {
61          return (xhtmlExpr);
62      }
63  
64      /***
65       * Setter method for "lang" tag attribute. (Mapping set in associated
66       * BeanInfo class.)
67       */
68      public void setLangExpr(String langExpr) {
69          this.langExpr = langExpr;
70      }
71  
72      /***
73       * Setter method for "xhtml" tag attribute. (Mapping set in associated
74       * BeanInfo class.)
75       */
76      public void setXhtmlExpr(String xhtmlExpr) {
77          this.xhtmlExpr = xhtmlExpr;
78      }
79  
80      /***
81       * Resets attribute values for tag reuse.
82       */
83      public void release() {
84          super.release();
85          setLangExpr(null);
86          setXhtmlExpr(null);
87      }
88  
89      /***
90       * Process the start tag.
91       *
92       * @throws JspException if a JSP exception has occurred
93       */
94      public int doStartTag() throws JspException {
95          evaluateExpressions();
96  
97          return (super.doStartTag());
98      }
99  
100     /***
101      * Processes all attribute values which use the JSTL expression evaluation
102      * engine to determine their values.
103      *
104      * @throws JspException if a JSP exception has occurred
105      */
106     private void evaluateExpressions()
107         throws JspException {
108         Boolean bool = null;
109         String string = null;
110 
111         if ((bool =
112                 EvalHelper.evalBoolean("lang", getLangExpr(), this, pageContext)) != null) {
113             setLang(bool.booleanValue());
114         }
115 
116         if ((bool =
117                 EvalHelper.evalBoolean("xhtml", getXhtmlExpr(), this,
118                     pageContext)) != null) {
119             setXhtml(bool.booleanValue());
120         }
121     }
122 }