KickJava   Java API By Example, From Geeks To Geeks.

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


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 import org.apache.commons.lang.CharSetUtils;
20
21 /**
22  * Count the number of occurences of a passed in 'Set'.
23  * A Set is a String of a particular format. It may include ranges
24  * and single characters. A Set may be negated.
25  *
26  * <ul>
27  * <li>range - "a-z"</li>
28  * <li>char - "a"</li>
29  * <li>negate - "^a"</li>
30  * </ul>
31  *
32  * <dl>
33  * <dt>set</dt><dd>
34  * Character Set to look for.
35  * Required.
36  * </dd>
37  * </dl>
38  *
39  * @author bayard@generationjava.com
40  */

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

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

63     public void setSet(String JavaDoc set) {
64         this.set = set;
65     }
66
67
68
69     public String JavaDoc changeString(String JavaDoc text) throws JspException JavaDoc {
70         return ""+CharSetUtils.count(text, set);
71     }
72
73     public void initAttributes() {
74
75         this.set = null;
76
77     }
78
79 }
80
Popular Tags