KickJava   Java API By Example, From Geeks To Geeks.

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


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  * Splits the provided text into an array, separators specified.
23  * The separator is not included in the returned String array and adjacent separators are treated
24  * as one separator.
25  *
26  * <dl>
27  * <dt>separator</dt><dd>
28  * Separator string to be used.
29  * </dd>
30  * </dl>
31  *
32  * @author Felipe Leme (felipeal at apache dot org)
33  */

34 public class SplitTag extends StringTagSupport {
35
36   private String JavaDoc separator;
37
38   public SplitTag() {
39     super();
40   }
41
42   /**
43    * Set the separator to be used.
44    *
45    * @param separator separator to be used
46    */

47   public void setSeparator(String JavaDoc separator) {
48     this.separator = separator;
49   }
50
51   public String JavaDoc changeString(String JavaDoc text) throws JspException JavaDoc {
52     throw new JspException JavaDoc( "INTERNAL ERROR: operation not supported" );
53   }
54
55   public Object JavaDoc evaluateString(String JavaDoc text) throws JspException JavaDoc {
56     return StringUtils.split( text, this.separator );
57   }
58
59   public void initAttributes() {
60     this.separator = null;
61   }
62
63 }
64
Popular Tags