1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.jelly.tags.util;
18
19 import java.util.ArrayList;
20 import java.util.List;
21 import java.util.StringTokenizer;
22
23 import org.apache.commons.jelly.JellyTagException;
24 import org.apache.commons.jelly.MissingAttributeException;
25 import org.apache.commons.jelly.TagSupport;
26 import org.apache.commons.jelly.XMLOutput;
27
28 public class TokenizeTag extends TagSupport
29 {
30 private String var;
31 private String delim;
32
33 public TokenizeTag()
34 {
35 }
36
37
38
39
40
41 public void doTag(final XMLOutput output) throws MissingAttributeException, JellyTagException {
42 if ( this.var == null )
43 {
44 throw new MissingAttributeException( "var" );
45 }
46
47 if ( this.delim == null )
48 {
49 throw new MissingAttributeException( "delim" );
50 }
51
52 StringTokenizer tokenizer = new StringTokenizer( getBodyText(),
53 this.delim );
54
55 List tokens = new ArrayList();
56
57 while ( tokenizer.hasMoreTokens() )
58 {
59 tokens.add( tokenizer.nextToken() );
60 }
61
62 getContext().setVariable( this.var,
63 tokens );
64 }
65
66 /*** The variable name to hold the list of tokens */
67 public void setVar(String var)
68 {
69 this.var = var;
70 }
71
72 /*** the delimiter that separates the tokens */
73 public void setDelim(String delim)
74 {
75 this.delim = delim;
76 }
77
78 }