*/
private static boolean ignoreNonStringValues = false;
+ /**
+ * flag to say whether to allow the string "false" to be interpreted as a
+ * boolean negation, e.g., --wrap=false to mean --nowrap
+ *
+ * Requires ignoreNonStringValues to be true. Default is false, but set to
+ * true for JalviewJS so a radio-box could send e.g. wrap=true or wrap=false
+ */
+ private static boolean allowFalseStringValue = false;
+
+ /**
+ * flag to say whether to always prioritise a positive boolean value (e.g.
+ * --wrap) when both positive and negative (e.g. --wrap --nowrap) are present.
+ * This could be useful for JalviewJS if a form sends both a hidden nowrap=x
+ * and a checkbox wrap=true.
+ */
+ private static boolean prioritisePositiveBooleanValue = false;
+
protected static final Map<String, Arg> argMap;
protected Map<String, ArgValuesMap> linkedArgs = new HashMap<>();
{
if (getIgnoreNonStringValues())
{
+ // if we're allowing booleanarg=false, check it's not nobooleanarg
+ // and the val is "false"
+ if (getAllowFalseStringValue() && !negated && val != null
+ && val.equalsIgnoreCase("false"))
+ {
+ negated = true;
+ }
// delete equals sign and value
val = null;
arg = arg.substring(0, equalPos);
else if (a.hasOption(Opt.BOOLEAN))
{
setBoolean(linkedId, type, avs, !negated, argIndex);
- setNegated(linkedId, avs, negated);
}
else if (a.hasOption(Opt.UNARY))
{
b, argIndex, false);
}
- private void setNegated(String linkedId, ArgValues avs, boolean b)
- {
- this.argValueOperation(Op.SETNEGATED, linkedId, null, avs, null, null,
- b, 0, false);
- }
-
private void incrementCount(String linkedId, ArgValues avs)
{
this.argValueOperation(Op.INCREMENTCOUNT, linkedId, null, avs, null,
private enum Op
{
- ADDVALUE, SETBOOLEAN, SETNEGATED, INCREMENTCOUNT
+ ADDVALUE, SETBOOLEAN, INCREMENTCOUNT
}
private void argValueOperation(Op op, String linkedId, Type type,
break;
case SETBOOLEAN:
- tavs.setBoolean(type, b, argIndex, true);
- finaliseStoringArgValue(id, tavs);
- break;
-
- case SETNEGATED:
- tavs.setNegated(b, true);
- break;
-
- case INCREMENTCOUNT:
- tavs.incrementCount();
- break;
-
- default:
+ if (getPrioritisePositiveBooleanValue() && tavs.getCount() > 0
+ && tavs.getBoolean())
+ {
+ Console.debug("Not setting due to prioritisePositiveValue and '"
+ + a.argString() + "' has already been set to true");
+ }
+ else
+ {
+ tavs.setBoolean(type, b, argIndex, true);
+ if (a.hasOption(Opt.BOOLEAN))
+ {
+ tavs.setNegated(!b, true);
+ }
+ finaliseStoringArgValue(id, tavs);
+ }
break;
-
}
}
break;
case SETBOOLEAN:
- avs.setBoolean(type, b, argIndex, false);
- finaliseStoringArgValue(linkedId, avs);
- break;
-
- case SETNEGATED:
- avs.setNegated(b, false);
+ if (getPrioritisePositiveBooleanValue() && avs.getCount() > 0
+ && avs.getBoolean())
+ {
+ Console.debug("Not setting due to prioritisePositiveValue and '"
+ + a.argString() + "' has already been set to true");
+ }
+ else
+ {
+ avs.setBoolean(type, b, argIndex, false);
+ if (a.hasOption(Opt.BOOLEAN))
+ {
+ avs.setNegated(!b, true);
+ }
+ finaliseStoringArgValue(linkedId, avs);
+ }
break;
case INCREMENTCOUNT:
{
ignoreNonStringValues = b;
}
+
+ public static boolean getAllowFalseStringValue()
+ {
+ return allowFalseStringValue;
+ }
+
+ public static void setAllowFalseStringValue(boolean b)
+ {
+ allowFalseStringValue = b;
+ }
+
+ public static boolean getPrioritisePositiveBooleanValue()
+ {
+ return prioritisePositiveBooleanValue;
+ }
+
+ public static void setPrioritisePositiveBooleanValue(boolean b)
+ {
+ prioritisePositiveBooleanValue = b;
+ }
}
\ No newline at end of file