Fix OPENDJ-142: Message.raw() with treats first arg as format string even when there are no format arguments
| | |
| | | * |
| | | * |
| | | * Copyright 2008-2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2011 ForgeRock AS |
| | | */ |
| | | |
| | | package org.opends.messages; |
| | |
| | | * null if <code>formatString</code> is null |
| | | */ |
| | | static public Message raw(CharSequence formatString, Object... args) { |
| | | Message message = null; |
| | | if (formatString != null) { |
| | | message = new MessageDescriptor.Raw(formatString).get(args); |
| | | } |
| | | return message; |
| | | return raw(Category.USER_DEFINED, Severity.INFORMATION, formatString, args); |
| | | } |
| | | |
| | | /** |
| | |
| | | CharSequence formatString, Object... args) { |
| | | Message message = null; |
| | | if (formatString != null) { |
| | | MessageDescriptor.Raw md = |
| | | new MessageDescriptor.Raw(formatString, |
| | | category, |
| | | severity); |
| | | message = md.get(args); |
| | | if (args == null || args.length == 0) |
| | | { |
| | | MessageDescriptor.Raw md = new MessageDescriptor.Raw( |
| | | "%s", category, severity); |
| | | message = md.get(formatString); |
| | | } |
| | | else |
| | | { |
| | | MessageDescriptor.Raw md = new MessageDescriptor.Raw( |
| | | formatString, category, severity); |
| | | message = md.get(args); |
| | | } |
| | | } |
| | | return message; |
| | | } |
| | |
| | | * will cause this message to render without argument substitution. |
| | | * |
| | | * @param object from which the message will be created |
| | | * @param arguments for message |
| | | * @param args for message |
| | | * @return a message object that will render the same in all locales; |
| | | * null if <code>object</code> is null |
| | | */ |
| | | static public Message fromObject(Object object, Object... arguments) { |
| | | Message message = null; |
| | | if (object != null) { |
| | | CharSequence cs = object.toString(); |
| | | message = raw(cs, arguments); |
| | | } |
| | | return message; |
| | | static public Message fromObject(Object object, Object... args) { |
| | | return (object != null) ? raw(object.toString(), args) : null; |
| | | } |
| | | |
| | | /** |
| | |
| | | * |
| | | * |
| | | * Copyright 2008 Sun Microsystems, Inc. |
| | | * Portions copyright 2011 ForgeRock AS |
| | | */ |
| | | |
| | | package org.opends.messages; |
| | |
| | | /** |
| | | * Creates a parameterized instance. |
| | | * @param formatString for created messages |
| | | */ |
| | | Raw(CharSequence formatString) { |
| | | this(formatString, Category.USER_DEFINED, Severity.INFORMATION); |
| | | } |
| | | |
| | | /** |
| | | * Creates a parameterized instance. |
| | | * @param formatString for created messages |
| | | * @param category for created messages |
| | | * @param severity for created messages |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Creates a parameterized instance. Created messages will |
| | | * have a category of <code>Category.USER_DEFINED</code>. |
| | | * @param formatString for created messages |
| | | * @param mask for created messages |
| | | * @param severity for created messages |
| | | */ |
| | | Raw(CharSequence formatString, int mask, Severity severity) { |
| | | super(null, null, mask, severity, null, null); |
| | | this.formatString = formatString != null ? formatString.toString() : ""; |
| | | this.requiresFormatter = this.formatString.matches(".*%.*"); |
| | | } |
| | | |
| | | /** |
| | | * Creates a message with arguments that will replace format |
| | | * specifiers in the assocated format string when the message |
| | | * is rendered to string representation. |
| | |
| | | * |
| | | * |
| | | * Copyright 2006-2008 Sun Microsystems, Inc. |
| | | * Portions copyright 2011 ForgeRock AS |
| | | */ |
| | | |
| | | package org.opends.messages; |
| | |
| | | {"Hello %s", "Hello World", new Object[]{"World"}}, |
| | | {"Hel%nlo %s", "Hel" + EOL + "lo World", new Object[]{"World"}}, |
| | | {"Hel%%lo %s", "Hel%lo World", new Object[]{"World"}}, |
| | | {"Hel%%lo", "Hel%lo", new Object[]{}}, |
| | | {"Hel%nlo", "Hel" + EOL + "lo", new Object[]{}}, |
| | | {"Hel%%lo", "Hel%%lo", new Object[]{}}, |
| | | {"Hel%nlo", "Hel%nlo", new Object[]{}}, |
| | | {"Hel%Dlo", "Hel%Dlo", new Object[]{}}, |
| | | {"Hel%Dlo", "Hel%Dlo", new Object[]{ "abc"}}, |
| | | |