KickJava   Java API By Example, From Geeks To Geeks.

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


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
21 /**
22  * Get a String that is nested between an open and closing
23  * substring.
24  *
25  * <dl>
26  * <dt>open</dt><dd>
27  * Index to start substring at.
28  * Required.
29  * </dd>
30  * <dt>close</dt><dd>
31  * Index to stop substring before.
32  * Default is to be the last index.
33  * </dd>
34  * </dl>
35  *
36  * @author bayard@generationjava.com
37  */

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

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

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

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

80     public void setClose(String JavaDoc close) {
81         this.close = close;
82     }
83
84
85
86     public String JavaDoc changeString(String JavaDoc text) throws JspException JavaDoc {
87         if(close == null) {
88             close = open;
89         }
90         return StringUtils.substringBetween(text, open, close);
91     }
92
93     public void initAttributes() {
94
95         this.open = null;
96
97         this.close = null;
98
99     }
100
101 }
102
Popular Tags