Fix #200: remove string switch and use ugly if ... else 😢 to be compatible with Java target 6

This commit is contained in:
Sefa Ilkimen
2019-04-05 16:48:18 +02:00
parent d977392a49
commit a1b6ea94f0
5 changed files with 30 additions and 47 deletions
@@ -40,18 +40,13 @@ class CordovaClientAuth implements Runnable, KeyChainAliasCallback {
@Override
public void run() {
switch (this.mode) {
case "systemstore":
if ("systemstore".equals(this.mode)) {
KeyChain.choosePrivateKeyAlias(this.activity, this, null, null, null, -1, null);
break;
case "file":
// @todo use pfx in bundle
} else if ("file".equals(this.mode)) {
this.callbackContext.error("Not implemented, yet");
break;
default:
} else {
this.tlsConfiguration.setKeyManagers(null);
this.callbackContext.success();
break;
}
}
@@ -131,16 +131,12 @@ abstract class CordovaHttpBase implements Runnable {
}
protected void setContentType(HttpRequest request) {
switch (this.serializer) {
case "json":
if ("json".equals(this.serializer)) {
request.contentType("application/json", "UTF-8");
break;
case "utf8":
} else if ("utf8".equals(this.serializer)) {
request.contentType("text/plain", "UTF-8");
break;
case "urlencoded":
} else if ("urlencoded".equals(this.serializer)) {
// intentionally left blank, because content type is set in HttpRequest.form()
break;
}
}
@@ -149,16 +145,12 @@ abstract class CordovaHttpBase implements Runnable {
return;
}
switch (this.serializer) {
case "json":
if ("json".equals(this.serializer)) {
request.send(this.data.toString());
break;
case "utf8":
} else if ("utf8".equals(this.serializer)) {
request.send(((JSONObject) this.data).getString("text"));
break;
case "urlencoded":
} else if ("urlencoded".equals(this.serializer)) {
request.form(JsonUtils.getObjectMap((JSONObject) this.data));
break;
}
}
@@ -51,30 +51,29 @@ public class CordovaHttpPlugin extends CordovaPlugin {
return false;
}
switch (action) {
case "get":
if ("get".equals(action)) {
return this.executeHttpRequestWithoutData(action, args, callbackContext);
case "post":
return this.executeHttpRequestWithData(action, args, callbackContext);
case "put":
return this.executeHttpRequestWithData(action, args, callbackContext);
case "patch":
return this.executeHttpRequestWithData(action, args, callbackContext);
case "head":
} else if ("head".equals(action)) {
return this.executeHttpRequestWithoutData(action, args, callbackContext);
case "delete":
} else if ("delete".equals(action)) {
return this.executeHttpRequestWithoutData(action, args, callbackContext);
case "uploadFile":
} else if ("post".equals(action)) {
return this.executeHttpRequestWithData(action, args, callbackContext);
} else if ("put".equals(action)) {
return this.executeHttpRequestWithData(action, args, callbackContext);
} else if ("patch".equals(action)) {
return this.executeHttpRequestWithData(action, args, callbackContext);
} else if ("uploadFile".equals(action)) {
return this.uploadFile(args, callbackContext);
case "downloadFile":
} else if ("downloadFile".equals(action)) {
return this.downloadFile(args, callbackContext);
case "setServerTrustMode":
} else if ("setServerTrustMode".equals(action)) {
return this.setServerTrustMode(args, callbackContext);
case "setClientAuthMode":
} else if ("setClientAuthMode".equals(action)) {
return this.setClientAuthMode(args, callbackContext);
case "disableRedirect":
} else if ("disableRedirect".equals(action)) {
return this.disableRedirect(args, callbackContext);
default:
} else {
return false;
}
}
@@ -63,23 +63,18 @@ class CordovaServerTrust implements Runnable {
@Override
public void run() {
try {
switch (this.mode) {
case "legacy":
if ("legacy".equals(this.mode)) {
this.tlsConfiguration.setHostnameVerifier(null);
this.tlsConfiguration.setTrustManagers(null);
break;
case "nocheck":
} else if ("nocheck".equals(this.mode)) {
this.tlsConfiguration.setHostnameVerifier(this.noOpVerifier);
this.tlsConfiguration.setTrustManagers(this.noOpTrustManagers);
break;
case "pinned":
} else if ("pinned".equals(this.mode)) {
this.tlsConfiguration.setHostnameVerifier(null);
this.tlsConfiguration.setTrustManagers(this.getTrustManagers(this.getCertsFromBundle("www/certificates")));
break;
default:
} else {
this.tlsConfiguration.setHostnameVerifier(null);
this.tlsConfiguration.setTrustManagers(this.getTrustManagers(this.getCertsFromKeyStore("AndroidCAStore")));
break;
}
callbackContext.success();