KickJava   Java API By Example, From Geeks To Geeks.

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


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  * Overlay a String on top of another String. The length
24  * of the String to overlay does not have to be the same as
25  * the size of substring it replaces.
26  *
27  * <dl>
28  * <dt>with</dt><dd>
29  * String to overlay onto the body.
30  * Required.
31  * </dd>
32  * <dt>start</dt><dd>
33  * Start index.
34  * Required.
35  * </dd>
36  * <dt>end</dt><dd>
37  * Index to end before.
38  * Required.
39  * </dd>
40  * </dl>
41  *
42  * @author bayard@generationjava.com
43  */

44 public class OverlayTag extends StringTagSupport {
45
46     private String JavaDoc start;
47     private String JavaDoc with;
48     private String JavaDoc end;
49
50     public OverlayTag() {
51         super();
52     }
53
54     /**
55      * Get the with property
56      *
57      * @return String property
58      */

59     public String JavaDoc getWith() {
60         return this.with;
61     }
62
63     /**
64      * Set the with property
65      *
66      * @param with String property
67      */

68     public void setWith(String JavaDoc with) {
69         this.with = with;
70     }
71
72
73     /**
74      * Get the start property
75      *
76      * @return String property
77      */

78     public String JavaDoc getStart() {
79         return this.start;
80     }
81
82     /**
83      * Set the start property
84      *
85      * @param start String property
86      */

87     public void setStart(String JavaDoc start) {
88         this.start = start;
89     }
90
91
92     /**
93      * Get the end property
94      *
95      * @return String property
96      */

97     public String JavaDoc getEnd() {
98         return this.end;
99     }
100
101     /**
102      * Set the end property
103      *
104      * @param end String property
105      */

106     public void setEnd(String JavaDoc end) {
107         this.end = end;
108     }
109
110
111
112     public String JavaDoc changeString(String JavaDoc text) throws JspException JavaDoc {
113         return StringUtils.overlay(text, with, NumberUtils.stringToInt(start), NumberUtils.stringToInt(end));
114     }
115
116     public void initAttributes() {
117
118         this.with = null;
119
120         this.start = "0";
121
122         this.end = "0";
123
124     }
125
126 }
127
Popular Tags