aboutsummaryrefslogtreecommitdiffstats
path: root/netx/net/sourceforge/jnlp/security
diff options
context:
space:
mode:
authorAndrew Azores <[email protected]>2013-09-04 12:18:40 -0400
committerAndrew Azores <[email protected]>2013-09-04 12:18:40 -0400
commit3a58ec9fc80fe436c774c2579e683dcb62dde19c (patch)
tree54c4a89fabeabee83623bd9d0a4a84eec1667d5d /netx/net/sourceforge/jnlp/security
parent6fbf033b59cff6cedf9d31411835ab01938e048e (diff)
Extracted integer response casting/handling logic in SecurityDialogs to new method, added test for this method
Diffstat (limited to 'netx/net/sourceforge/jnlp/security')
-rw-r--r--netx/net/sourceforge/jnlp/security/SecurityDialogs.java61
1 files changed, 22 insertions, 39 deletions
diff --git a/netx/net/sourceforge/jnlp/security/SecurityDialogs.java b/netx/net/sourceforge/jnlp/security/SecurityDialogs.java
index a2dc6eb..da70d79 100644
--- a/netx/net/sourceforge/jnlp/security/SecurityDialogs.java
+++ b/netx/net/sourceforge/jnlp/security/SecurityDialogs.java
@@ -132,16 +132,7 @@ public class SecurityDialogs {
Object selectedValue = getUserResponse(message);
- if (selectedValue == null) {
- return false;
- } else if (selectedValue instanceof Integer) {
- if (((Integer) selectedValue).intValue() == 0)
- return true;
- else
- return false;
- } else {
- return false;
- }
+ return getIntegerResponseAsBoolean(selectedValue);
}
/**
@@ -164,17 +155,7 @@ public class SecurityDialogs {
Object selectedValue = getUserResponse(message);
- if (selectedValue == null) {
- return false;
- } else if (selectedValue instanceof Integer) {
- if (((Integer) selectedValue).intValue() == 0) {
- return true;
- } else {
- return false;
- }
- } else {
- return false;
- }
+ return getIntegerResponseAsBoolean(selectedValue);
}
/**
@@ -224,16 +205,7 @@ public class SecurityDialogs {
Object selectedValue = getUserResponse(message);
- if (selectedValue == null) {
- return false;
- } else if (selectedValue instanceof Integer) {
- if (((Integer) selectedValue).intValue() == 0)
- return true;
- else
- return false;
- } else {
- return false;
- }
+ return getIntegerResponseAsBoolean(selectedValue);
}
/**
@@ -263,11 +235,7 @@ public class SecurityDialogs {
message.extras = new Object[] { host, port, prompt, type };
Object response = getUserResponse(message);
- if (response == null) {
- return null;
- } else {
- return (Object[]) response;
- }
+ return (Object[]) response;
}
/**
@@ -286,11 +254,11 @@ public class SecurityDialogs {
Object selectedValue = getUserResponse(message);
// result 0 = Yes, 1 = No, 2 = Cancel
- if (selectedValue == null) {
- return 2;
- } else if (selectedValue instanceof Integer) {
+ if (selectedValue instanceof Integer) {
+ // If the selected value can be cast to Integer, use that value
return ((Integer) selectedValue).intValue();
} else {
+ // Otherwise default to "cancel"
return 2;
}
}
@@ -376,6 +344,21 @@ public class SecurityDialogs {
}
/**
+ * Returns true iff the given Object reference can be cast to Integer and that Integer's
+ * intValue is 0.
+ * @param ref the Integer (hopefully) reference
+ * @return whether the given reference is both an Integer type and has intValue of 0
+ */
+ public static boolean getIntegerResponseAsBoolean(Object ref) {
+ boolean isInteger = ref instanceof Integer;
+ if (isInteger) {
+ Integer i = (Integer) ref;
+ return i.intValue() == 0;
+ }
+ return false;
+ }
+
+ /**
* Returns whether the current runtime configuration allows prompting user
* for security warnings.
*