KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > taglibs > string > DefaultTag


1 /*
2  * Copyright 1999,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.taglibs.string;
17
18 import javax.servlet.jsp.JspException JavaDoc;
19
20 /**
21  * If the body String is a particular value, then output
22  * a default value, else output the body String.
23  * The major use of this is to convert 'null' into an
24  * empty String.
25  *
26  * <dl>
27  * <dt>value</dt><dd>
28  * Value to be equal to.
29  * Default is the string: "null".
30  * </dd>
31  * <dt>default</dt><dd>
32  * Value to place if body is equal to value field.
33  * Default is an empty String.
34  * </dd>
35  * </dl>
36  *
37  * @author bayard@generationjava.com
38  */

39 public class DefaultTag extends StringTagSupport {
40
41     private String JavaDoc defaultValue;
42     private String JavaDoc value;
43
44     public DefaultTag() {
45         super();
46     }
47
48     /**
49      * Get the value property
50      *
51      * @return String property
52      */

53     public String JavaDoc getValue() {
54         return this.value;
55     }
56
57     /**
58      * Set the value property
59      *
60      * @param value String property
61      */

62     public void setValue(String JavaDoc value) {
63         this.value = value;
64     }
65
66
67     /**
68      * Get the default property
69      *
70      * @return String property
71      */

72     public String JavaDoc getDefault() {
73         return this.defaultValue;
74     }
75
76     /**
77      * Set the default property
78      *
79      * @param default String property
80      */

81     public void setDefault(String JavaDoc defaultValue) {
82         this.defaultValue = defaultValue;
83     }
84
85
86
87     public String JavaDoc changeString(String JavaDoc text) throws JspException JavaDoc {
88         if( (""+text).equals(this.value) ) {
89             return this.defaultValue;
90         } else {
91             return text;
92         }
93     }
94
95     public void initAttributes() {
96
97         this.value = "null";
98
99         this.defaultValue = "";
100
101     }
102
103 }
104
Popular Tags