List of usage examples for org.json JSONArray join
public String join(String separator) throws JSONException
From source file:org.chromium.ChromeProxy.java
private void set(final CordovaArgs args, final CallbackContext callbackContext) { cordova.getThreadPool().execute(new Runnable() { @Override/*from w w w .j a v a2 s .c o m*/ public void run() { // Ignoring scope. JSONObject details; try { details = args.getJSONObject(0); } catch (JSONException e) { callbackContext.error("Failed to parse details as JSON"); return; } try { if (details.has("value")) { config = details.getJSONObject("value"); String mode = config.getString("mode"); if (!"fixed_servers".equals(mode) && !"direct".equals(mode)) { callbackContext.error("Mode must be fixed_servers or direct"); return; } if ("direct".equals(mode)) { clear(args, callbackContext); return; } } else { callbackContext.error("Missing value"); } } catch (JSONException e) { callbackContext.error("Failed to parse value as JSON"); } try { JSONObject rules = config.getJSONObject("rules"); String nonProxyHosts = null; if (rules.has("bypassList")) { JSONArray bypassList = rules.getJSONArray("bypassList"); nonProxyHosts = bypassList.join("|"); } if (rules.has("singleProxy")) { JSONObject rule = rules.getJSONObject("singleProxy"); String scheme = rule.getString("scheme"); if ("socks5".equals(scheme)) { if (nonProxyHosts != null) { callbackContext.error("nonProxyHosts not supported with socks"); return; } String host = rule.getString("host"); int port = rule.has("port") ? rule.getInt("port") : 1080; String portString = Integer.toString(port); System.setProperty("socksProxyHost", host); System.setProperty("socksProxyPort", portString); } else if ("http".equals(scheme)) { setHttpProxy(rule, "http", nonProxyHosts); setHttpProxy(rule, "https", nonProxyHosts); setHttpProxy(rule, "ftp", nonProxyHosts); } else { callbackContext.error("Scheme must be socks5 or http"); return; } } else { if (rules.has("proxyForHttp")) { JSONObject rule = rules.getJSONObject("httpProxy"); setHttpProxy(rule, "http", nonProxyHosts); } if (rules.has("proxyForHttps")) { JSONObject rule = rules.getJSONObject("proxyForHttps"); setHttpProxy(rule, "https", nonProxyHosts); } if (rules.has("proxyForFtp")) { JSONObject rule = rules.getJSONObject("proxyForFtp"); setHttpProxy(rule, "ftp", nonProxyHosts); } } onSettingsChanged(); callbackContext.success(); } catch (JSONException e) { callbackContext.error("Failed to parse rule(s) as JSON"); } catch (Exception e) { callbackContext.error("Other error"); } } }); }