public ActionErrors validate(ActionMapping mapping, HttpServletRequest req) {
ActionErrors errors = super.validate(mapping, req);
// Validate template-placeholders
TemplateEngine templateEngine = new TemplateEngine();
List<String> allowedPlaceholders = new ArrayList<String>();
allowedPlaceholders.addAll(TemplateEngine.VALID_SMS_MESSAGE_PLACEHOLDERS);
allowedPlaceholders.addAll(TemplateEngine.VALID_REQUESTING_USER_PLACEHOLDERS);
allowedPlaceholders.addAll(TemplateEngine.VALID_CONTACT_USER_PLACEHOLDERS);
if (new Integer(6).equals(getDestinationSelection())) { // message to msisdn must not contain placeholders for (destination) user
allowedPlaceholders.removeAll(TemplateEngine.VALID_SMS_MESSAGE_PLACEHOLDERS);
}
if (!templateEngine.validateTemplate(getMessage(), allowedPlaceholders)) {
errors.add("message", new ActionMessage("smssvc.illegalPlaceholdersFound"));
} else if (templateEngine.computeMaxMessageLength(getMessage()) == Integer.MAX_VALUE) {
errors.add("message", new ActionMessage("smssvc.missingPlaceholderLengths"));
} else if (templateEngine.computeMaxMessageLength(getMessage()) > SmsInteractionEnterOrEditAction.MAX_MESSAGE_TEXT_LENGTH) {
errors.add("message", new ActionMessage("smssvc.messageLongerThan450characters"));
}
return errors;
}