a83e409826ca73736fc6b8385da640397701c43d
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.news / src / net / sourceforge / phpeclipse / news / pref / ListEncoder.java
1 /*
2  * Created on 14 juil. 2003
3  * (c)2003 Jérôme Nègre - http://www.jnegre.org/
4  *
5  */
6 package net.sourceforge.phpeclipse.news.pref;
7
8 import java.io.UnsupportedEncodingException;
9 import java.net.URLDecoder;
10 import java.net.URLEncoder;
11 import java.util.StringTokenizer;
12
13 import net.sourceforge.phpeclipse.news.Plugin;
14
15 /**
16  * @author jerome
17  *
18  */
19 public class ListEncoder {
20
21     public static String[] decode(String stringList) {
22         StringTokenizer tokenizer = new StringTokenizer(stringList, " ");
23         int countTokens = tokenizer.countTokens();
24         String[] result = new String[countTokens];
25         try {
26             for (int i = 0; i < countTokens; i++) {
27                 result[i] = URLDecoder.decode(tokenizer.nextToken(), "UTF-8");
28             }
29         } catch (UnsupportedEncodingException e) {
30             Plugin.logError("Internal Error", e);
31         }
32         return result;
33     }
34
35     public static String encode(String[] items) {
36         StringBuffer result = new StringBuffer();
37         try {
38             for (int i = 0; i < items.length; i++) {
39                 result.append(URLEncoder.encode(items[i], "UTF-8")).append(' ');
40             }
41         } catch (UnsupportedEncodingException e) {
42             Plugin.logError("Internal Error", e);
43         }
44         return result.toString();
45     }
46
47 }