KickJava   Java API By Example, From Geeks To Geeks.

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


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.StringUtils;
20 import org.apache.commons.lang.math.NumberUtils;
21
22 /**
23  * Gets the leftmost 'n' characters from a string.
24  *
25  * <dl>
26  * <dt>count</dt><dd>
27  * Size of characters to get.
28  * Required.
29  * </dd>
30  * </dl>
31  *
32  * @author bayard@generationjava.com
33  */

34 public class LeftTag extends StringTagSupport {
35
36     private String JavaDoc count;
37
38     public LeftTag() {
39         super();
40     }
41
42     /**
43      * Get the count property
44      *
45      * @return String property
46      */

47     public String JavaDoc getCount() {
48         return this.count;
49     }
50
51     /**
52      * Set the count property
53      *
54      * @param count String property
55      */

56     public void setCount(String JavaDoc count) {
57         this.count = count;
58     }
59
60
61
62     public String JavaDoc changeString(String JavaDoc text) throws JspException JavaDoc {
63         return StringUtils.left(text, NumberUtils.stringToInt(count));
64     }
65
66     public void initAttributes() {
67
68         this.count = "0";
69
70     }
71
72 }
73
Popular Tags