X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Forg%2Fjson%2FCookieList.java;h=1ae9eea5824f848e4e6b5f7104fd9299ce68298b;hb=57738a1f3c19b1c3a00bd3ac5108f8cd0af32f99;hp=c67ee3aeab88ce02bf325e431e6cb31718d98b83;hpb=e7338a61f3ce96dadf44ac80b2b32cc5ba4b94c8;p=jalview.git diff --git a/src/org/json/CookieList.java b/src/org/json/CookieList.java index c67ee3a..1ae9eea 100644 --- a/src/org/json/CookieList.java +++ b/src/org/json/CookieList.java @@ -26,61 +26,73 @@ SOFTWARE. /** * Convert a web browser cookie list string to a JSONObject and back. + * * @author JSON.org * @version 2015-12-09 */ -public class CookieList { +public class CookieList +{ - /** - * Convert a cookie list into a JSONObject. A cookie list is a sequence - * of name/value pairs. The names are separated from the values by '='. - * The pairs are separated by ';'. The names and the values - * will be unescaped, possibly converting '+' and '%' sequences. - * - * To add a cookie to a cookie list, - * cookielistJSONObject.put(cookieJSONObject.getString("name"), - * cookieJSONObject.getString("value")); - * @param string A cookie list string - * @return A JSONObject - * @throws JSONException - */ - public static JSONObject toJSONObject(String string) throws JSONException { - JSONObject jo = new JSONObject(); - JSONTokener x = new JSONTokener(string); - while (x.more()) { - String name = Cookie.unescape(x.nextTo('=')); - x.next('='); - jo.put(name, Cookie.unescape(x.nextTo(';'))); - x.next(); - } - return jo; + /** + * Convert a cookie list into a JSONObject. A cookie list is a sequence of + * name/value pairs. The names are separated from the values by '='. The pairs + * are separated by ';'. The names and the values will be unescaped, possibly + * converting '+' and '%' sequences. + * + * To add a cookie to a cookie list, + * cookielistJSONObject.put(cookieJSONObject.getString("name"), + * cookieJSONObject.getString("value")); + * + * @param string + * A cookie list string + * @return A JSONObject + * @throws JSONException + */ + public static JSONObject toJSONObject(String string) throws JSONException + { + JSONObject jo = new JSONObject(); + JSONTokener x = new JSONTokener(string); + while (x.more()) + { + String name = Cookie.unescape(x.nextTo('=')); + x.next('='); + jo.put(name, Cookie.unescape(x.nextTo(';'))); + x.next(); } + return jo; + } - /** - * Convert a JSONObject into a cookie list. A cookie list is a sequence - * of name/value pairs. The names are separated from the values by '='. - * The pairs are separated by ';'. The characters '%', '+', '=', and ';' - * in the names and values are replaced by "%hh". - * @param jo A JSONObject - * @return A cookie list string - * @throws JSONException - */ - public static String toString(JSONObject jo) throws JSONException { - boolean b = false; - final StringBuilder sb = new StringBuilder(); - // Don't use the new entrySet API to maintain Android support - for (final String key : jo.keySet()) { - final Object value = jo.opt(key); - if (!JSONObject.NULL.equals(value)) { - if (b) { - sb.append(';'); - } - sb.append(Cookie.escape(key)); - sb.append("="); - sb.append(Cookie.escape(value.toString())); - b = true; - } + /** + * Convert a JSONObject into a cookie list. A cookie list is a sequence of + * name/value pairs. The names are separated from the values by '='. The pairs + * are separated by ';'. The characters '%', '+', '=', and ';' in the names + * and values are replaced by "%hh". + * + * @param jo + * A JSONObject + * @return A cookie list string + * @throws JSONException + */ + public static String toString(JSONObject jo) throws JSONException + { + boolean b = false; + final StringBuilder sb = new StringBuilder(); + // Don't use the new entrySet API to maintain Android support + for (final String key : jo.keySet()) + { + final Object value = jo.opt(key); + if (!JSONObject.NULL.equals(value)) + { + if (b) + { + sb.append(';'); } - return sb.toString(); + sb.append(Cookie.escape(key)); + sb.append("="); + sb.append(Cookie.escape(value.toString())); + b = true; + } } + return sb.toString(); + } }