KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > finalist > jag > taglib > EqualTag


1 /* Copyright (C) 2003 Finalist IT Group
2  *
3  * This file is part of JAG - the Java J2EE Application Generator
4  *
5  * JAG is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  * JAG is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  * You should have received a copy of the GNU General Public License
14  * along with JAG; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  */

17
18 package com.finalist.jag.taglib;
19
20
21 import com.finalist.jag.*;
22 import com.finalist.jag.taglib.util.RequestUtil;
23
24 import java.util.*;
25
26
27 /**
28  * Class EqualTag
29  *
30  *
31  * @author Wendel D. de Witte
32  * @version %I%, %G%
33  */

34 public class EqualTag extends TagBodySupport {
35
36    /** Field name */
37    private String JavaDoc name = null;
38
39    /** Field property */
40    private String JavaDoc property = null;
41
42    /** Field parameter */
43    protected String JavaDoc parameter = null;
44
45    /** Field sensitive */
46    private String JavaDoc sensitive = null;
47
48    /** Field equal */
49    protected boolean equal = false;
50
51    /** Field sensitive */
52    protected int counter = 0;
53
54    protected String JavaDoc variable;
55
56    /////////////////////////////////////
57

58    /**
59     * Method getName
60     *
61     *
62     * @return
63     *
64     */

65    public String JavaDoc getName() {
66       return (this.name);
67    }
68
69    /**
70     * Method setName
71     *
72     *
73     * @param name
74     *
75     */

76    public void setName(String JavaDoc name) {
77       this.name = name;
78    }
79
80    /**
81     * Method getValue
82     *
83     *
84     * @return
85     *
86     */

87    public String JavaDoc getProperty() {
88       return (this.property);
89    }
90
91    /**
92     * Method setValue
93     *
94     *
95     * @param property
96     *
97     */

98    public void setProperty(String JavaDoc property) {
99       this.property = property;
100    }
101
102    /**
103     * Method getParameter
104     *
105     *
106     * @return
107     *
108     */

109    public String JavaDoc getParameter() {
110       return (this.parameter);
111    }
112
113    /**
114     * Method setParameter
115     *
116     *
117     * @param parameter
118     *
119     */

120    public void setParameter(String JavaDoc parameter) {
121       this.parameter = parameter;
122    }
123
124
125    public String JavaDoc getSensitive() {
126       return (this.sensitive);
127    }
128
129    public void setSensitive(String JavaDoc sensitive) {
130       this.sensitive = sensitive;
131    }
132
133    public String JavaDoc getVariable() {
134       return variable;
135    }
136
137    public void setVariable(String JavaDoc variable) {
138       this.variable = variable;
139    }
140
141
142    /**
143     * Method doStartTag
144     *
145     *
146     * @return
147     *
148     * @throws JagException
149     *
150     */

151    public int doStartTag() throws JagException {
152
153       String JavaDoc value = RequestUtil.lookupString(getPageContext(), name, property);
154       if (value == null) {
155          value = (String JavaDoc) getPageContext().getAttribute(name);
156       }
157
158       if (value == null) {
159          value = "";
160       }
161
162       if (sensitive != null && sensitive.equals("true")) {
163          value = value.toLowerCase();
164          parameter = parameter.toLowerCase();
165       }
166
167       if (variable != null) {
168          Object JavaDoc variableValue = getPageContext().getAttribute(variable);
169
170         if (variableValue == null) {
171             equal = false;
172          } else {
173             equal = (variableValue instanceof String JavaDoc) ?
174                   value.equals(((String JavaDoc) variableValue)) :
175                   ((Set) variableValue).contains(value);
176          }
177
178       } else {
179          StringTokenizer tokens = new StringTokenizer(parameter, ", ");
180          while (tokens.hasMoreTokens()) {
181             String JavaDoc token = tokens.nextToken().trim();
182             equal = token.equals(value);
183             if (equal) {
184                break;
185             }
186          }
187       }
188       return (EVAL_PAGE);
189    }
190
191    /**
192     * Method doAfterBodyTag
193     *
194     *
195     * @return
196     *
197     * @throws JagException
198     *
199     */

200    public int doAfterBodyTag() throws JagException {
201       return (equal && (counter++ < 1)) ? (EVAL_BODY_TAG) : (SKIP_BODY);
202    }
203 }
204
205
206
Popular Tags