View Javadoc

1   /*
2    * $Id: ELInitDefinitionsTag.java 376781 2006-02-10 18:09:48Z 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.tiles;
19  
20  import org.apache.struts.tiles.taglib.InitDefinitionsTag;
21  import org.apache.strutsel.taglib.utils.EvalHelper;
22  
23  import javax.servlet.jsp.JspException;
24  
25  /***
26   * Init definitions factory. <p> This class is a subclass of the class
27   * <code>org.apache.struts.taglib.tiles.InitDefinitionsTag</code> which
28   * provides most of the described functionality.  This subclass allows all
29   * attribute values to be specified as expressions utilizing the JavaServer
30   * Pages Standard Library expression language.
31   *
32   * @version $Rev: 376781 $
33   */
34  public class ELInitDefinitionsTag extends InitDefinitionsTag {
35      /***
36       * Instance variable mapped to "file" tag attribute. (Mapping set in
37       * associated BeanInfo class.)
38       */
39      private String fileExpr;
40  
41      /***
42       * Instance variable mapped to "classname" tag attribute. (Mapping set in
43       * associated BeanInfo class.)
44       */
45      private String classnameExpr;
46  
47      /***
48       * Getter method for "file" tag attribute. (Mapping set in associated
49       * BeanInfo class.)
50       */
51      public String getFileExpr() {
52          return (fileExpr);
53      }
54  
55      /***
56       * Getter method for "classname" tag attribute. (Mapping set in associated
57       * BeanInfo class.)
58       */
59      public String getClassnameExpr() {
60          return (classnameExpr);
61      }
62  
63      /***
64       * Setter method for "file" tag attribute. (Mapping set in associated
65       * BeanInfo class.)
66       */
67      public void setFileExpr(String fileExpr) {
68          this.fileExpr = fileExpr;
69      }
70  
71      /***
72       * Setter method for "classname" tag attribute. (Mapping set in associated
73       * BeanInfo class.)
74       */
75      public void setClassnameExpr(String classnameExpr) {
76          this.classnameExpr = classnameExpr;
77      }
78  
79      /***
80       * Resets attribute values for tag reuse.
81       */
82      public void release() {
83          super.release();
84          setFileExpr(null);
85          setClassnameExpr(null);
86      }
87  
88      /***
89       * Process the start tag.
90       *
91       * @throws JspException if a JSP exception has occurred
92       */
93      public int doStartTag() throws JspException {
94          evaluateExpressions();
95  
96          return (super.doStartTag());
97      }
98  
99      /***
100      * Processes all attribute values which use the JSTL expression evaluation
101      * engine to determine their values.
102      *
103      * @throws JspException if a JSP exception has occurred
104      */
105     private void evaluateExpressions()
106         throws JspException {
107         String string = null;
108 
109         if ((string =
110                 EvalHelper.evalString("file", getFileExpr(), this, pageContext)) != null) {
111             setFile(string);
112         }
113 
114         if ((string =
115                 EvalHelper.evalString("classname", getClassnameExpr(), this,
116                     pageContext)) != null) {
117             setClassname(string);
118         }
119     }
120 }