KickJava   Java API By Example, From Geeks To Geeks.

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


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  * Center the body String in a larger String of size width.
24  *
25  * <dl>
26  * <dt>delimiter</dt><dd>
27  * String to pad the larger String with.
28  * Default is a space character.
29  * </dd>
30  * <dt>width</dt><dd>
31  * Size of larger String.
32  * Required.
33  * </dd>
34  * </dl>
35  *
36  * @author bayard@generationjava.com
37  */

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

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

61     public void setDelimiter(String JavaDoc delimiter) {
62         this.delimiter = delimiter;
63     }
64
65
66     /**
67      * Get the width property
68      *
69      * @return String property
70      */

71     public String JavaDoc getWidth() {
72         return this.width;
73     }
74
75     /**
76      * Set the width property
77      *
78      * @param width String property
79      */

80     public void setWidth(String JavaDoc width) {
81         this.width = width;
82     }
83
84
85
86     public String JavaDoc changeString(String JavaDoc text) throws JspException JavaDoc {
87         return StringUtils.center(text, NumberUtils.stringToInt(width), delimiter);
88     }
89
90     public void initAttributes() {
91
92         this.delimiter = " ";
93
94         this.width = "0";
95
96     }
97
98 }
99
Popular Tags