if (param != null && param.length() > 0) {
String nonQuotedPart = param;
boolean addQuotes = true;
if (param.charAt(0) == '\"' && param.charAt(param.length() - 1) == '\"') {
if (param.length() < 2)
throw new BadParam("Passed in parameter is incorrectly quoted: " + param);
addQuotes = false;
nonQuotedPart = param.substring(1, param.length() - 1);
}
// If we have any quotes other then the outside quotes, throw
if (nonQuotedPart.contains("\"")) {
throw new BadParam("Passed in parameter is incorrectly quoted: " + param);
}
if (addQuotes) {
param = '\"' + param + '\"';
}