1 package org.apache.fulcrum.parser;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 import java.net.URLDecoder;
25 import java.util.StringTokenizer;
26
27
28
29
30
31
32
33 public class StringValueParser
34 extends BaseValueParser
35 {
36
37
38
39
40
41
42
43
44 public void parse(String s, char delim, boolean urlDecode)
45 throws Exception
46 {
47 String delimChar = String.valueOf(delim);
48 StringTokenizer st = new StringTokenizer(s, delimChar);
49 boolean isNameTok = true;
50 String pathPart = null;
51 String key = null;
52 while (st.hasMoreTokens())
53 {
54 String tok = st.nextToken();
55 if ( urlDecode )
56 {
57 tok = URLDecoder.decode(tok, getCharacterEncoding());
58 }
59
60 if (isNameTok)
61 {
62 key = tok;
63 isNameTok = false;
64 }
65 else
66 {
67 pathPart = tok;
68 if (key != null && key.length() > 0)
69 {
70 add (convert(key), pathPart);
71 }
72 isNameTok = true;
73 }
74 }
75 }
76
77 public void parse(String s, char paramDelim, char pairDelim,
78 boolean urlDecode)
79 throws Exception
80 {
81 if ( paramDelim == pairDelim )
82 {
83 parse(s, paramDelim, urlDecode);
84 }
85 else
86 {
87 String delimChar = String.valueOf(paramDelim);
88 StringTokenizer st = new StringTokenizer(s, delimChar);
89
90 while (st.hasMoreTokens())
91 {
92 String pair = st.nextToken();
93 int pos = pair.indexOf(pairDelim);
94 String name = pair.substring(0, pos);
95 String value = pair.substring(pos+1);
96
97 if ( urlDecode )
98 {
99 name = URLDecoder.decode(name, getCharacterEncoding());
100 value = URLDecoder.decode(value, getCharacterEncoding());
101 }
102
103 if (name.length() > 0)
104 {
105 add (convert(name), value);
106 }
107 }
108 }
109 }
110 }