java.text

Class MessageFormat

Implemented Interfaces:
Cloneable, Serializable

public class MessageFormat
extends Format

See Also:
Serialized Form

Nested Class Summary

static class
MessageFormat.Field

Nested classes/interfaces inherited from class java.text.Format

Format.Field

Constructor Summary

MessageFormat(String pattern)
Creates a new MessageFormat object with the specified pattern
MessageFormat(String pattern, Locale locale)
Creates a new MessageFormat object with the specified pattern

Method Summary

void
applyPattern(String newPattern)
Applies the specified pattern to this MessageFormat.
Object
clone()
Overrides Format.clone()
boolean
equals(Object obj)
Overrides Format.equals(Object obj)
StringBuffer
format(arguments[] , StringBuffer appendBuf, FieldPosition fp)
Returns the pattern with the formatted objects.
StringBuffer
format(Object objectArray, StringBuffer appendBuf, FieldPosition fpos)
Returns the pattern with the formatted objects.
static String
format(String pattern, java.lang.Object... arguments)
A convinience method to format patterns.
AttributedCharacterIterator
formatToCharacterIterator(Object arguments)
A convinience method to format patterns.
Format[]
getFormats()
Returns an array with the Formats for the arguments.
Format[]
getFormatsByArgumentIndex()
Return the formatters used sorted by argument index.
Locale
getLocale()
Returns the locale.
int
hashCode()
Overrides Format.hashCode()
Object[]
parse(String sourceStr)
Object[]
parse(String sourceStr, ParsePosition pos)
Parse a string sourceStr against the pattern specified to the MessageFormat constructor.
Object
parseObject(String sourceStr, ParsePosition pos)
void
setFormat(int variableNum, Format newFormat)
Sets the format for the argument at an specified index.
void
setFormatByArgumentIndex(int argumentIndex, Format newFormat)
Set the format to used using the argument index number.
void
setFormats(Format[] newFormats)
Sets the formats for the arguments.
void
setFormatsByArgumentIndex(Format[] newFormats)
Set the format for argument using a specified array of formatters which is sorted according to the argument index.
void
setLocale(Locale loc)
Sets the locale.
String
toPattern()
Returns the pattern.

Methods inherited from class java.text.Format

clone, format, format, formatToCharacterIterator, parseObject, parseObject

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Details

MessageFormat

public MessageFormat(String pattern)
Creates a new MessageFormat object with the specified pattern
Parameters:
pattern - The Pattern

MessageFormat

public MessageFormat(String pattern,
                     Locale locale)
Creates a new MessageFormat object with the specified pattern
Parameters:
pattern - The Pattern
locale - The Locale to use
Since:
1.4

Method Details

applyPattern

public void applyPattern(String newPattern)
Applies the specified pattern to this MessageFormat.
Parameters:
newPattern - The Pattern

clone

public Object clone()
Overrides Format.clone()
Overrides:
clone in interface Format

equals

public boolean equals(Object obj)
Overrides Format.equals(Object obj)
Overrides:
equals in interface Object

format

public final StringBuffer format(arguments[] ,
                                 StringBuffer appendBuf,
                                 FieldPosition fp)
Returns the pattern with the formatted objects.
Parameters:
appendBuf - The StringBuffer where the text is appened.
fp - A FieldPosition object (it is ignored).

format

public final StringBuffer format(Object objectArray,
                                 StringBuffer appendBuf,
                                 FieldPosition fpos)
Returns the pattern with the formatted objects. The first argument must be a array of Objects. This is equivalent to format((Object[]) objectArray, appendBuf, fpos)
Overrides:
format in interface Format
Parameters:
objectArray - The object array to be formatted.
appendBuf - The StringBuffer where the text is appened.
fpos - A FieldPosition object (it is ignored).

format

public static String format(String pattern,
                            java.lang.Object... arguments)
A convinience method to format patterns.
Parameters:
pattern - The pattern used when formatting.
arguments - The array containing the objects to be formatted.

formatToCharacterIterator

public AttributedCharacterIterator formatToCharacterIterator(Object arguments)
A convinience method to format patterns.
Overrides:
formatToCharacterIterator in interface Format
Parameters:
arguments - The array containing the objects to be formatted.

getFormats

public Format[] getFormats()
Returns an array with the Formats for the arguments.

getFormatsByArgumentIndex

public Format[] getFormatsByArgumentIndex()
Return the formatters used sorted by argument index. It uses the internal table to fill in this array: if a format has been set using setFormat or setFormatByArgumentIndex then it returns it at the right index. If not it uses the detected formatters during a format call. If nothing is known about that argument index it just puts null at that position. To get useful informations you may have to call format at least once.
Returns:
an array of formatters sorted by argument index.

getLocale

public Locale getLocale()
Returns the locale.

hashCode

public int hashCode()
Overrides Format.hashCode()
Overrides:
hashCode in interface Object

parse

public Object[] parse(String sourceStr)
            throws ParseException

parse

public Object[] parse(String sourceStr,
                      ParsePosition pos)
Parse a string sourceStr against the pattern specified to the MessageFormat constructor.
Parameters:
sourceStr - the string to be parsed.
pos - the current parse position (and eventually the error position).
Returns:
the array of parsed objects sorted according to their argument number in the pattern.

parseObject

public Object parseObject(String sourceStr,
                          ParsePosition pos)
Overrides:
parseObject in interface Format

setFormat

public void setFormat(int variableNum,
                      Format newFormat)
Sets the format for the argument at an specified index.
Parameters:
variableNum - The index.
newFormat - The Format object.

setFormatByArgumentIndex

public void setFormatByArgumentIndex(int argumentIndex,
                                     Format newFormat)
Set the format to used using the argument index number.
Parameters:
argumentIndex - the argument index.
newFormat - the format to use for this argument.

setFormats

public void setFormats(Format[] newFormats)
Sets the formats for the arguments.
Parameters:
newFormats - An array of Format objects.

setFormatsByArgumentIndex

public void setFormatsByArgumentIndex(Format[] newFormats)
Set the format for argument using a specified array of formatters which is sorted according to the argument index. If the number of elements in the array is fewer than the number of arguments only the arguments specified by the array are touched.
Parameters:
newFormats - array containing the new formats to set.
Throws:
NullPointerException - if newFormats is null

setLocale

public void setLocale(Locale loc)
Sets the locale.
Parameters:
loc - A Locale

toPattern

public String toPattern()
Returns the pattern.

MessageFormat.java - Localized message formatting. Copyright (C) 1999, 2001, 2002, 2004, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.