2 * Created on 14 juil. 2003
3 * (c)2003 Jérôme Nègre - http://www.jnegre.org/
6 package net.sourceforge.phpeclipse.news.pref;
8 import java.io.UnsupportedEncodingException;
9 import java.net.URLDecoder;
10 import java.net.URLEncoder;
11 import java.util.StringTokenizer;
13 import net.sourceforge.phpeclipse.news.Plugin;
19 public class ListEncoder {
21 public static String[] decode(String stringList) {
22 StringTokenizer tokenizer = new StringTokenizer(stringList, " ");
23 int countTokens = tokenizer.countTokens();
24 String[] result = new String[countTokens];
26 for (int i = 0; i < countTokens; i++) {
27 result[i] = URLDecoder.decode(tokenizer.nextToken(), "UTF-8");
29 } catch (UnsupportedEncodingException e) {
30 Plugin.logError("Internal Error", e);
35 public static String encode(String[] items) {
36 StringBuffer result = new StringBuffer();
38 for (int i = 0; i < items.length; i++) {
39 result.append(URLEncoder.encode(items[i], "UTF-8")).append(' ');
41 } catch (UnsupportedEncodingException e) {
42 Plugin.logError("Internal Error", e);
44 return result.toString();