Skip navigation links

Oracle Fusion Middleware Java API Reference for Oracle Extension SDK Reference
11g Release 1 (11.1.1.7.2)

E13403-10


oracle.javatools.resourcebundle
Class NamedMessageFormat

java.lang.Object
  extended by oracle.javatools.resourcebundle.NamedMessageFormat


public class NamedMessageFormat
extends java.lang.Object

The NamedMessageFormat class is a greatly reduced version of the java.text.MessageFormat class, supporting named-parameter replacement instead of index-based replacement.

The only syntax supported by this class is simple name-based replacement, namely:

     some{first}text{second}here{more-complicated}andthere
 

as well as escaping using single quotes. However, unlike MessageFormat, the contents of the text between two single quotes is not interpreted only if the first single quote is followed by a left bracket. That is, the following pattern

     some'{text'more
 

will be interpred as:

     some{textmore
 

Otherwise, a standalone single quote will be interpreted as a single quote. Followings are some examples:

Parameters: first = seven, second = ten Unformatted message: They've {first} java tests and we've {second} java tests. Formatted message: They've seven java tests and we've ten java tests.

Parameters: null Unformatted message: Use '''{amount}''' to indicate negative amount Formatted message: Use '{amount}' to indicate negative amount

Parameters: diskname = Mydisk Unformatted message: ''{diskname}'' is full Formatted message: 'Mydisk' is full

The names of the parameters can contain any characters other than single quotes and right braces. Single-quote escaping is also not permitted within keys, so the following is illegal:

     some text{fir'{'st}
 

Constructor Summary
NamedMessageFormat(java.lang.String formatString)
          Creates a NamedMessageFormat based on the given format string.

 

Method Summary
 java.lang.String format(java.util.Map<java.lang.String,java.lang.String> parameters)
          Formats the given Map of strings based on the initial pattern.
 java.lang.String format(java.util.Map<java.lang.String,java.lang.String> parameters, int parameterSize)
          Formats the given Map of strings based on the initial pattern.
static java.lang.String formatMsg(java.lang.String message, java.util.Map<java.lang.String,java.lang.Object> parameters)
          Takes the given message and replaces any named tokens in the message with the value from the tokens map.
static java.lang.String formatMsgMixed(java.lang.String message, java.util.Map<java.lang.String,java.lang.Object> formatValues, java.util.Map<java.lang.String,java.lang.Object> noformatValues)
          /** Takes the given message and replaces any named tokens in the message that are included in the parameters map and replaces them with the value in the parameter map.
static java.lang.String formatMsgPlain(java.lang.String message, java.util.Map<java.lang.String,java.lang.Object> parameters)
          Takes the given message and replaces any named tokens in the message that are included in the parameters map and replaces them with the value in the parameter map.

 

Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

 

Constructor Detail

NamedMessageFormat

public NamedMessageFormat(java.lang.String formatString)
Creates a NamedMessageFormat based on the given format string.

Method Detail

format

public java.lang.String format(java.util.Map<java.lang.String,java.lang.String> parameters)
Formats the given Map of strings based on the initial pattern. It is legal for this Map to contain keys not supported by the pattern, or to omit keys looked for in the pattern.
Parameters:
parameters - a Map of key/value String pairs

format

public java.lang.String format(java.util.Map<java.lang.String,java.lang.String> parameters,
                               int parameterSize)
Formats the given Map of strings based on the initial pattern. It is legal for this Map to contain keys not supported by the pattern, or to omit keys looked for in the pattern.
Parameters:
parameters - a Map of key/value String pairs
parameterSize - no longer used, still here for api compatibility

formatMsg

public static java.lang.String formatMsg(java.lang.String message,
                                         java.util.Map<java.lang.String,java.lang.Object> parameters)
Takes the given message and replaces any named tokens in the message with the value from the tokens map. This method uses MessageFormat so parameters whose object is not a string already will be formatted according to the default locale (eg, a number like 1000 may become 1,000)
Parameters:
message - the message string with tokens in place
parameters - parameters map of tokens to objects
Returns:
formatted message with named tokens replaced with data from the parameters map

formatMsgPlain

public static java.lang.String formatMsgPlain(java.lang.String message,
                                              java.util.Map<java.lang.String,java.lang.Object> parameters)
Takes the given message and replaces any named tokens in the message that are included in the parameters map and replaces them with the value in the parameter map. The object put into the parameters map for the token must either be a String or support toString().
Parameters:
message - the message string with tokens in place
parameters - map of tokens to objects
Returns:
formatted message with named tokens replaced with data from the parameters map

formatMsgMixed

public static java.lang.String formatMsgMixed(java.lang.String message,
                                              java.util.Map<java.lang.String,java.lang.Object> formatValues,
                                              java.util.Map<java.lang.String,java.lang.Object> noformatValues)
/** Takes the given message and replaces any named tokens in the message that are included in the parameters map and replaces them with the value in the parameter map. This method allows some parameter objects to be substituted directly and some to be formatted in the default locale. For example, if a message were something like: {PO_NUMBER} is greater than {MAX_VALUE} you probably want the po_number to be unformatted but let the max_value be formatted.
Parameters:
message - the message string with tokens in place
formatValues - map of tokens to objects that should be formatted
noformatValues - map of tokens to objects that should not be formatted
Returns:
formatted message with named tokens replaced with data from the parameters map

Skip navigation links

Oracle Fusion Middleware Java API Reference for Oracle Extension SDK Reference
11g Release 1 (11.1.1.7.2)

E13403-10


Copyright © 1997, 2013, Oracle. All rights reserved.