View Javadoc

1   package org.starobjects.restful.applib;
2   
3   import java.io.UnsupportedEncodingException;
4   import java.net.URLEncoder;
5   import java.util.HashMap;
6   import java.util.Map;
7   import java.util.Set;
8   import java.util.Map.Entry;
9   
10  import javax.ws.rs.WebApplicationException;
11  
12  
13  /**
14   * Not API, so intentionally not visible outside this package.
15   */
16  final class UrlEncodeUtils {
17  	
18  	private UrlEncodeUtils() {}
19  
20  	static String encode(String value) {
21  		try {
22  			return URLEncoder.encode(value, Constants.URL_ENCODING_CHAR_SET);
23  		} catch (UnsupportedEncodingException e) {
24  			throw new WebApplicationException(e);
25  		}
26  	}
27  
28  	static Map<String, String> urlEncode(Map<String, String> asMap) {
29  		Map<String,String> encodedMap = new HashMap<String, String>();
30  		Set<Entry<String, String>> entrySet = asMap.entrySet();
31  		for (Entry<String, String> entry : entrySet) {
32  			String value = entry.getValue();
33  			encodedMap.put(entry.getKey(), encode(value));
34  		}
35  		return encodedMap;
36  	}
37  
38  }