public String getMessage(Locale locale) { if(ruleResult.getEvalException() != null) { return ruleResult.getEvalException().getMessage(); } String message = getMessage(locale, ruleName); // If no ResouceBundle was configured then use this instances toString if (message == null) { return toString(); } if (message.startsWith("ftl:")) { // TODO: Is there a way to optimize this e.g. attach the compiled template // to the bundle as an object and then get back using ResourceBundle.getObject?? // I timed it and it was able to create and apply 10000 templates in about 2500 ms // on an "average" spec machine, so it's not toooooo bad, and it's only done on demand :) FreeMarkerTemplate template = new FreeMarkerTemplate(message.substring("ftl:".length())); beanContext.put("ruleResult", ruleResult); beanContext.put("path", failFragmentPath); message = template.apply(beanContext); } return message; }
/** * Validate will lookup the configured RuleProvider and validate the text against the * rule specfied by the composite rule name. * * @param text The selected data to perform the evaluation on. * @param executionContext The Smooks {@link org.milyn.container.ExecutionContext}. * * @throws ValidationException A FATAL Validation failure has occured, or the maximum number of * allowed failures has been exceeded. */ private OnFailResultImpl _validate(final String text, final ExecutionContext executionContext) throws ValidationException { if(ruleProvider == null) { setRuleProvider(executionContext); } final RuleEvalResult result = ruleProvider.evaluate(ruleName, text, executionContext); if(logger.isDebugEnabled()) { logger.debug(result); } if (!result.matched()) { ValidationResult validationResult = getValidationResult(executionContext); OnFailResultImpl onFailResult = new OnFailResultImpl(); onFailResult.setRuleResult(result); onFailResult.setBeanContext(executionContext.getBeanContext().getBeanMap()); validationResult.addResult(onFailResult, onFail); return onFailResult; } return null; }
/** * Validate will lookup the configured RuleProvider and validate the text against the * rule specfied by the composite rule name. * * @param text The selected data to perform the evaluation on. * @param executionContext The Smooks {@link org.milyn.container.ExecutionContext}. * * @throws ValidationException A FATAL Validation failure has occured, or the maximum number of * allowed failures has been exceeded. */ private OnFailResultImpl _validate(final String text, final ExecutionContext executionContext) throws ValidationException { if(ruleProvider == null) { setRuleProvider(executionContext); } final RuleEvalResult result = ruleProvider.evaluate(ruleName, text, executionContext); if(logger.isDebugEnabled()) { logger.debug(result); } if (!result.matched()) { ValidationResult validationResult = getValidationResult(executionContext); OnFailResultImpl onFailResult = new OnFailResultImpl(); onFailResult.setRuleResult(result); onFailResult.setBeanContext(executionContext.getBeanContext().getBeanMap()); validationResult.addResult(onFailResult, onFail); return onFailResult; } return null; }
public String getMessage(Locale locale) { if(ruleResult.getEvalException() != null) { return ruleResult.getEvalException().getMessage(); } String message = getMessage(locale, ruleName); // If no ResouceBundle was configured then use this instances toString if (message == null) { return toString(); } if (message.startsWith("ftl:")) { // TODO: Is there a way to optimize this e.g. attach the compiled template // to the bundle as an object and then get back using ResourceBundle.getObject?? // I timed it and it was able to create and apply 10000 templates in about 2500 ms // on an "average" spec machine, so it's not toooooo bad, and it's only done on demand :) FreeMarkerTemplate template = new FreeMarkerTemplate(message.substring("ftl:".length())); beanContext.put("ruleResult", ruleResult); beanContext.put("path", failFragmentPath); message = template.apply(beanContext); } return message; }