List of usage examples for org.springframework.context.support DefaultMessageSourceResolvable DefaultMessageSourceResolvable
public DefaultMessageSourceResolvable(String[] codes, Object[] arguments)
From source file:org.openmrs.web.taglib.OpenmrsMessageTagTest.java
/** * @see OpenmrsMessageTag#doEndTag()//from ww w . j a va 2 s . c o m */ @Test @Verifies(value = "javaScript escaping works when activated", method = "doEndTag()") public void doEndTag_javaScriptEscapingWorks() throws Exception { final String unescapedText = "'Eensy Weensy' spider"; openmrsMessageTag.setJavaScriptEscape("true"); final DefaultMessageSourceResolvable message = new DefaultMessageSourceResolvable(new String[] { "test" }, unescapedText); openmrsMessageTag.setMessage(message); checkDoEndTagEvaluation("\\'Eensy Weensy\\' spider"); }
From source file:com.company.simple.util.validator.GlobeValidator.java
protected Object[] getArgumentsForConstraint(String objectName, String field, ConstraintDescriptor<?> descriptor) { List<Object> arguments = new LinkedList<Object>(); String[] codes = new String[] { objectName + Errors.NESTED_PATH_SEPARATOR + field, field }; arguments.add(new DefaultMessageSourceResolvable(codes, field)); // Using a TreeMap for alphabetical ordering of attribute names Map<String, Object> attributesToExpose = new TreeMap<String, Object>(); for (Map.Entry<String, Object> entry : descriptor.getAttributes().entrySet()) { String attributeName = entry.getKey(); Object attributeValue = entry.getValue(); if (!internalAnnotationAttributes.contains(attributeName)) { attributesToExpose.put(attributeName, attributeValue); }// w ww . jav a 2 s .c o m } arguments.addAll(attributesToExpose.values()); return arguments.toArray(new Object[arguments.size()]); }
From source file:org.openmrs.web.taglib.OpenmrsMessageTagTest.java
/** * @see OpenmrsMessageTag#doEndTag()/* ww w. ja v a 2 s . c o m*/ */ @Test @Verifies(value = "javaScript escaping is not performed when not activated", method = "doEndTag()") public void doEndTag_messageIsNotEscapedWhenEscapingIsOff() throws Exception { final String unescapedText = "'Eensy Weensy' spider"; openmrsMessageTag.setJavaScriptEscape("false"); final DefaultMessageSourceResolvable message = new DefaultMessageSourceResolvable(new String[] { "test" }, unescapedText); openmrsMessageTag.setMessage(message); checkDoEndTagEvaluation(unescapedText); }
From source file:org.obiba.onyx.engine.state.AbstractStageState.java
public MessageSourceResolvable getMessage() { // Codes are: <fullname>, State.<name>, <name> return new DefaultMessageSourceResolvable(new String[] { getFullName(), "State." + getName(), getName() }, getName());/*from ww w . jav a 2s .c om*/ }
From source file:org.obiba.onyx.engine.state.AbstractStageState.java
public MessageSourceResolvable getReasonMessage() { String eventReason = (getReason() != null) ? getReason().getEventReason() : null; if (eventReason != null) { return new DefaultMessageSourceResolvable(new String[] { getName() + "." + eventReason, eventReason }, eventReason);// w ww.ja v a 2 s . co m } return null; }
From source file:org.springjutsu.validation.ValidationManager.java
/** * In the event that a validation rule fails, this method is responsible * for recording an error message on the affected path of the Errors object. * The error message is gathered in three parts: * First the base message, if not provided is based on the rule executor class. * This is a message like "\{0} should be longer than \{1} chars." * Next, the first argument \{0} is the model descriptor. This will resolve to a * label for the path that failed, based on second to last path subBean and the * field that failed. So, if "account.accountOwner.username" had an error, * it would look for a message based on the class name of accountOwner, and the * field username: like "user.username". If the message files contained a * "user.username=User name", then the message would now read something like * "User name should be longer than \{1} chars." * Finally, the argument is resolved. /* w w w. ja v a 2 s .com*/ * If the argument is just a flat string, like "16", then you would get * "User name should be longer than 16 chars." * If the argument contained EL that resolved on the model, it would perform * the same model lookup detailed above, so you could potentially have something * like "User name should be longer than First name", which is a bit weird, but * has its uses. * For either the model or argument lookup, if EL is used in the path * which resolves off the model, the literal value of the evaluated * EL expression is used. * @param rule the rule which failed * @param rootModel the root model (not failed bean) * @param errors standard Errors object to record error on. */ protected void logError(ValidationRule rule, Object rootModel, Errors errors) { String errorMessageKey = rule.getMessage(); if (errorMessageKey == null || errorMessageKey.isEmpty()) { errorMessageKey = errorMessagePrefix + rule.getType(); } String defaultError = rule.getPath() + " " + rule.getType(); String modelMessageKey = getMessageResolver(rootModel, rule.getPath(), true); String ruleArg = getMessageResolver(rootModel, rule.getValue(), false); MessageSourceResolvable modelMessageResolvable = new DefaultMessageSourceResolvable( new String[] { modelMessageKey }, modelMessageKey); MessageSourceResolvable argumentMessageResolvable = new DefaultMessageSourceResolvable( new String[] { ruleArg }, ruleArg); // get the local path to error, in case errors object is on nested path. String errorMessagePath = rule.getErrorPath(); if (errorMessagePath == null || errorMessagePath.isEmpty()) { errorMessagePath = rule.getPath(); } if (!errors.getNestedPath().isEmpty() && errorMessagePath.startsWith(errors.getNestedPath())) { errorMessagePath = appendPath(errorMessagePath.substring(errors.getNestedPath().length()), ""); } errors.rejectValue(errorMessagePath, errorMessageKey, new Object[] { modelMessageResolvable, argumentMessageResolvable }, defaultError); }