/** * {@inheritDoc} */ public String format(MessageContext messageContext, Object valueToFormat) { if(valueToFormat instanceof Localizable) { return ((Localizable)valueToFormat).toString(messageContext); } return valueToFormat != null ? valueToFormat.toString() : ""; }
/** * {@inheritDoc} */ public String format(MessageContext messageContext, Object valueToFormat) { if(valueToFormat instanceof Localizable) { return ((Localizable)valueToFormat).toString(messageContext); } return valueToFormat != null ? valueToFormat.toString() : ""; }
/** * {@inheritDoc} */ public String interpolate(MessageContext messageContext, String messageText, Serializable... arguments) { NamedArgument[] namedArguments = extractNamedArguments(arguments); String name; Serializable value; for(NamedArgument namedArgument : namedArguments) { name = "{" + namedArgument.getName() + "}"; if(messageText.contains(name)) { value = namedArgument.getValue(); if(value instanceof Localizable) { value = ((Localizable)value).toString(messageContext); } else if(value == null) { value = "null"; } messageText = messageText.replace(name, value.toString()); } } return messageText; }
/** * {@inheritDoc} */ public String interpolate(MessageContext messageContext, String messageText, Serializable... arguments) { NamedArgument[] namedArguments = extractNamedArguments(arguments); String name; Serializable value; for(NamedArgument namedArgument : namedArguments) { name = "{" + namedArgument.getName() + "}"; if(messageText.contains(name)) { value = namedArgument.getValue(); if(value instanceof Localizable) { value = ((Localizable)value).toString(messageContext); } else if(value == null) { value = "null"; } messageText = messageText.replace(name, value.toString()); } } return messageText; }
result.append(((Localizable)argument).toString(this.messageContext));
/** * if the argument isn't serializable we aren't allowed to store the instance itself * -> we have to store the string instead * (if we are aware of the context and the parameter implements {@link Localizable} we use the localized value) * * @param argument current argument * @return the string value of the argument */ private String processNoneSerializableArgument(Object argument) { if(argument instanceof Localizable && this.getMessageContextConfig() != null) { return ((Localizable)argument).toString(this.getMessageContextConfig().use().create()); } else { return argument != null ? argument.toString() : "null"; } }
result.append(((Localizable)argument).toString(this.messageContext));
/** * if the argument isn't serializable we aren't allowed to store the instance itself * -> we have to store the string instead * (if we are aware of the context and the parameter implements {@link Localizable} we use the localized value) * * @param argument current argument * @return the string value of the argument */ private String processNoneSerializableArgument(Object argument) { if(argument instanceof Localizable && this.getMessageContextConfig() != null) { return ((Localizable)argument).toString(this.getMessageContextConfig().use().create()); } else { return argument != null ? argument.toString() : "null"; } }
/** * if the argument isn't serializable we aren't allowed to store the instance itself * -> we have to store the string instead * (if we are aware of the context and the parameter implements {@link Localizable} we use the localized value) * * @param argument current argument * @return the string value of the argument */ private String processNoneSerializableArgument(Object argument) { if(argument instanceof Localizable && this.getMessageContextConfig() != null) { return ((Localizable)argument).toString(this.getMessageContextConfig().use().create()); } else { return argument != null ? argument.toString() : "null"; } }
@SuppressWarnings({"unchecked"}) protected Object formatAsString(MessageContext messageContext, Object value) { if (value == null) { return null; } if (value instanceof String) { return value; } if (messageContext.config().getFormatterFactory() != null) { Formatter formatter = messageContext.config().getFormatterFactory().findFormatter(value.getClass()); if (formatter != null) { return formatter.format(messageContext, value); } } if (value instanceof Localizable) { return ((Localizable) value).toString(messageContext); } return value; } }
@SuppressWarnings({"unchecked"}) protected Object formatAsString(MessageContext messageContext, Object value) { if (value == null) { return null; } if (value instanceof String) { return value; } if (messageContext.config().getFormatterFactory() != null) { Formatter formatter = messageContext.config().getFormatterFactory().findFormatter(value.getClass()); if (formatter != null) { return formatter.format(messageContext, value); } } if (value instanceof Localizable) { return ((Localizable) value).toString(messageContext); } return value; } }