001: /*
002: * $Id: ELNotMatchTag.java 471754 2006-11-06 14:55:09Z husted $
003: *
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021: package org.apache.strutsel.taglib.logic;
022:
023: import org.apache.struts.taglib.logic.NotMatchTag;
024: import org.apache.strutsel.taglib.utils.EvalHelper;
025:
026: import javax.servlet.jsp.JspException;
027:
028: /**
029: * Evalute the nested body content of this tag if the specified value is a
030: * substring of the specified variable. <p> This class is a subclass of the
031: * class <code>org.apache.struts.taglib.logic.NotMatchTag</code> which
032: * provides most of the described functionality. This subclass allows all
033: * attribute values to be specified as expressions utilizing the JavaServer
034: * Pages Standard Library expression language.
035: *
036: * @version $Rev: 471754 $
037: */
038: public class ELNotMatchTag extends NotMatchTag {
039: /**
040: * Instance variable mapped to "cookie" tag attribute. (Mapping set in
041: * associated BeanInfo class.)
042: */
043: private String cookieExpr;
044:
045: /**
046: * Instance variable mapped to "header" tag attribute. (Mapping set in
047: * associated BeanInfo class.)
048: */
049: private String headerExpr;
050:
051: /**
052: * Instance variable mapped to "location" tag attribute. (Mapping set in
053: * associated BeanInfo class.)
054: */
055: private String locationExpr;
056:
057: /**
058: * Instance variable mapped to "name" tag attribute. (Mapping set in
059: * associated BeanInfo class.)
060: */
061: private String nameExpr;
062:
063: /**
064: * Instance variable mapped to "parameter" tag attribute. (Mapping set in
065: * associated BeanInfo class.)
066: */
067: private String parameterExpr;
068:
069: /**
070: * Instance variable mapped to "property" tag attribute. (Mapping set in
071: * associated BeanInfo class.)
072: */
073: private String propertyExpr;
074:
075: /**
076: * Instance variable mapped to "scope" tag attribute. (Mapping set in
077: * associated BeanInfo class.)
078: */
079: private String scopeExpr;
080:
081: /**
082: * Instance variable mapped to "value" tag attribute. (Mapping set in
083: * associated BeanInfo class.)
084: */
085: private String valueExpr;
086:
087: /**
088: * String value of expression to be evaluated.
089: */
090: private String expr;
091:
092: /**
093: * Evaluated value of expression.
094: */
095: private String exprValue;
096:
097: /**
098: * Getter method for "cookie" tag attribute. (Mapping set in associated
099: * BeanInfo class.)
100: */
101: public String getCookieExpr() {
102: return (cookieExpr);
103: }
104:
105: /**
106: * Getter method for "header" tag attribute. (Mapping set in associated
107: * BeanInfo class.)
108: */
109: public String getHeaderExpr() {
110: return (headerExpr);
111: }
112:
113: /**
114: * Getter method for "location" tag attribute. (Mapping set in associated
115: * BeanInfo class.)
116: */
117: public String getLocationExpr() {
118: return (locationExpr);
119: }
120:
121: /**
122: * Getter method for "name" tag attribute. (Mapping set in associated
123: * BeanInfo class.)
124: */
125: public String getNameExpr() {
126: return (nameExpr);
127: }
128:
129: /**
130: * Getter method for "parameter" tag attribute. (Mapping set in associated
131: * BeanInfo class.)
132: */
133: public String getParameterExpr() {
134: return (parameterExpr);
135: }
136:
137: /**
138: * Getter method for "property" tag attribute. (Mapping set in associated
139: * BeanInfo class.)
140: */
141: public String getPropertyExpr() {
142: return (propertyExpr);
143: }
144:
145: /**
146: * Getter method for "scope" tag attribute. (Mapping set in associated
147: * BeanInfo class.)
148: */
149: public String getScopeExpr() {
150: return (scopeExpr);
151: }
152:
153: /**
154: * Getter method for "value" tag attribute. (Mapping set in associated
155: * BeanInfo class.)
156: */
157: public String getValueExpr() {
158: return (valueExpr);
159: }
160:
161: /**
162: * Setter method for "cookie" tag attribute. (Mapping set in associated
163: * BeanInfo class.)
164: */
165: public void setCookieExpr(String cookieExpr) {
166: this .cookieExpr = cookieExpr;
167: }
168:
169: /**
170: * Setter method for "header" tag attribute. (Mapping set in associated
171: * BeanInfo class.)
172: */
173: public void setHeaderExpr(String headerExpr) {
174: this .headerExpr = headerExpr;
175: }
176:
177: /**
178: * Setter method for "location" tag attribute. (Mapping set in associated
179: * BeanInfo class.)
180: */
181: public void setLocationExpr(String locationExpr) {
182: this .locationExpr = locationExpr;
183: }
184:
185: /**
186: * Setter method for "name" tag attribute. (Mapping set in associated
187: * BeanInfo class.)
188: */
189: public void setNameExpr(String nameExpr) {
190: this .nameExpr = nameExpr;
191: }
192:
193: /**
194: * Setter method for "parameter" tag attribute. (Mapping set in associated
195: * BeanInfo class.)
196: */
197: public void setParameterExpr(String parameterExpr) {
198: this .parameterExpr = parameterExpr;
199: }
200:
201: /**
202: * Setter method for "property" tag attribute. (Mapping set in associated
203: * BeanInfo class.)
204: */
205: public void setPropertyExpr(String propertyExpr) {
206: this .propertyExpr = propertyExpr;
207: }
208:
209: /**
210: * Setter method for "scope" tag attribute. (Mapping set in associated
211: * BeanInfo class.)
212: */
213: public void setScopeExpr(String scopeExpr) {
214: this .scopeExpr = scopeExpr;
215: }
216:
217: /**
218: * Setter method for "value" tag attribute. (Mapping set in associated
219: * BeanInfo class.)
220: */
221: public void setValueExpr(String valueExpr) {
222: this .valueExpr = valueExpr;
223: }
224:
225: /**
226: * Returns the string value of the expression. This value will be
227: * evaluated by the JSTL EL engine.
228: */
229: public String getExpr() {
230: return (expr);
231: }
232:
233: /**
234: * Sets the string value of the expression. This expression will be
235: * evaluated by the JSTL EL engine.
236: */
237: public void setExpr(String expr) {
238: this .expr = expr;
239: }
240:
241: /**
242: * Returns the evaluated expression.
243: */
244: public String getExprValue() {
245: return (exprValue);
246: }
247:
248: /**
249: * Sets the evaluated expression.
250: */
251: public void setExprValue(String exprValue) {
252: this .exprValue = exprValue;
253: }
254:
255: /**
256: * Releases state of custom tag so this instance can be reused.
257: */
258: public void release() {
259: super .release();
260: setCookieExpr(null);
261: setHeaderExpr(null);
262: setLocationExpr(null);
263: setNameExpr(null);
264: setParameterExpr(null);
265: setPropertyExpr(null);
266: setScopeExpr(null);
267: setValueExpr(null);
268: setExpr(null);
269: setExprValue(null);
270: }
271:
272: /**
273: * Process the start tag.
274: *
275: * @throws JspException if a JSP exception has occurred
276: */
277: public int doStartTag() throws JspException {
278: evaluateExpressions();
279:
280: return (super .doStartTag());
281: }
282:
283: /**
284: * Evaluates the condition that is being tested by this particular tag,
285: * and returns <code>true</code> if the nested body content of this tag
286: * should be evaluated, or <code>false</code> if it should be skipped.
287: *
288: * @param desired Desired value for a true result
289: * @throws JspException if a JSP exception occurs
290: */
291: protected boolean condition(boolean desired) throws JspException {
292: boolean result = false;
293:
294: if (getExprValue() != null) {
295: result = ELMatchSupport.condition(desired, getExprValue(),
296: value, location, messages, pageContext);
297: } else {
298: result = super .condition(desired);
299: }
300:
301: return (result);
302: }
303:
304: /**
305: * Processes all attribute values which use the JSTL expression evaluation
306: * engine to determine their values.
307: *
308: * @throws JspException if a JSP exception has occurred
309: */
310: private void evaluateExpressions() throws JspException {
311: String string = null;
312:
313: if ((string = EvalHelper.evalString("cookie", getCookieExpr(),
314: this , pageContext)) != null) {
315: setCookie(string);
316: }
317:
318: if ((string = EvalHelper.evalString("expr", getExpr(), this ,
319: pageContext)) != null) {
320: setExprValue(string);
321: }
322:
323: if ((string = EvalHelper.evalString("header", getHeaderExpr(),
324: this , pageContext)) != null) {
325: setHeader(string);
326: }
327:
328: if ((string = EvalHelper.evalString("location",
329: getLocationExpr(), this , pageContext)) != null) {
330: setLocation(string);
331: }
332:
333: if ((string = EvalHelper.evalString("name", getNameExpr(),
334: this , pageContext)) != null) {
335: setName(string);
336: }
337:
338: if ((string = EvalHelper.evalString("parameter",
339: getParameterExpr(), this , pageContext)) != null) {
340: setParameter(string);
341: }
342:
343: if ((string = EvalHelper.evalString("property",
344: getPropertyExpr(), this , pageContext)) != null) {
345: setProperty(string);
346: }
347:
348: if ((string = EvalHelper.evalString("scope", getScopeExpr(),
349: this , pageContext)) != null) {
350: setScope(string);
351: }
352:
353: if ((string = EvalHelper.evalString("value", getValueExpr(),
354: this, pageContext)) != null) {
355: setValue(string);
356: }
357: }
358: }
|