Top Description Fields Constructors Methods
org.apache.commons.lang3.text

public Class ExtendedMessageFormat

extends MessageFormat
Class Inheritance
Annotations
@Deprecated
Imports
java.text.Format, .MessageFormat, .ParsePosition, java.util.ArrayList, .Collection, .Locale, .Map, .Objects, org.apache.commons.lang3.LocaleUtils, .StringUtils, .Validate

Deprecated

As of 3.6, use Apache Commons Text ExtendedMessageFormat.

Extends java.text.MessageFormat to allow pluggable/additional formatting options for embedded format elements. Client code should specify a registry of FormatFactory instances associated with String format names. This registry will be consulted when the format elements are parsed from the message pattern. In this way custom patterns can be specified, and the formats supported by java.text.MessageFormat can be overridden at the format and/or format style level (see MessageFormat). A "format element" embedded in the message pattern is specified (()? signifies optionality):
{argument-number(,format-name (,format-style)?)?}

format-name and format-style values are trimmed of surrounding whitespace in the manner of java.text.MessageFormat. If format-name denotes FormatFactory formatFactoryInstance in registry, a Format matching format-name and format-style is requested from formatFactoryInstance. If this is successful, the Format found is used for this format element.

NOTICE: The various subformat mutator methods are considered unnecessary; they exist on the parent class to allow the type of customization which it is the job of this class to provide in a configurable fashion. These methods have thus been disabled and will throw UnsupportedOperationException if called.

Limitations inherited from java.text.MessageFormat:

Since
2.4

Field Summary

Modifier and TypeField and Description
private static final String
private static final char
private static final char
private final Map<String, ? extends FormatFactory>
registry

Our registry of FormatFactory.

private static final long
private static final char
private static final char
private String
toPattern

To pattern string.

Constructor Summary

AccessConstructor and Description
public
ExtendedMessageFormat(final String
the pattern to use, not null
pattern
)

Create a new ExtendedMessageFormat for the default locale.

public
ExtendedMessageFormat(final String
the pattern to use, not null
pattern
,
final Locale
the locale to use, not null
locale
)

Create a new ExtendedMessageFormat.

public
ExtendedMessageFormat(final String
the pattern to use, not null.
pattern
,
final Locale
the locale to use.
locale
,
final Map<String, ? extends FormatFactory>
the registry of format factories, may be null.
registry
)

Create a new ExtendedMessageFormat.

public
ExtendedMessageFormat(final String
the pattern to use, not null
pattern
,
final Map<String, ? extends FormatFactory>
the registry of format factories, may be null
registry
)

Create a new ExtendedMessageFormat for the default locale.

Method Summary

Modifier and TypeMethod and Description
private StringBuilder

Returns:

appendTo
appendQuotedString
(final String
pattern to parse
pattern
,
final ParsePosition
current parse position
pos
,
final StringBuilder
optional StringBuilder to append
appendTo
)

Consume a quoted string, adding it to appendTo if specified.

public final void
applyPattern(final String
String
pattern
)

Overrides java.text.MessageFormat.applyPattern.

Apply the specified pattern.

private boolean

Returns:

true if some Object was found, false otherwise.
containsElements
(final Collection<?>
to check
coll
)

Learn whether the specified Collection contains non-null elements.

public boolean
equals(final Object obj)

Overrides java.text.MessageFormat.equals.

Compares the specified object with this MessageFormat for equality.

private Format

Returns:

Format
getFormat
(final String
String
desc
)

Gets a custom format from a format description.

private void
getQuotedString(final String
pattern to parse
pattern
,
final ParsePosition
current parse position
pos
)

Consume quoted string only

public int
hashCode()

Overrides java.text.MessageFormat.hashCode.

Returns the hash code value for this MessageFormat.

private String

Returns:

full pattern
insertFormats
(final String
source
pattern
,
final ArrayList<String>
The custom patterns to re-insert, if any
customPatterns
)

Insert formats back into the pattern for toPattern() support.

private ParsePosition

Returns:

pos
next
(final ParsePosition
ParsePosition
pos
)

Convenience method to advance parse position by 1

private String

Returns:

Format description String
parseFormatDescription
(final String
string to parse
pattern
,
final ParsePosition
current parse position
pos
)

Parse the format component of a format element.

private int

Returns:

argument index
readArgumentIndex
(final String
pattern to parse
pattern
,
final ParsePosition
current parse position
pos
)

Reads the argument index from the current format element

private void
seekNonWs(final String
String to read
pattern
,
final ParsePosition
current position
pos
)

Consume whitespace from the current parse position.

public void
setFormat(final int
format element index
formatElementIndex
,
final Format
the new format
newFormat
)

Overrides java.text.MessageFormat.setFormat.

Throws UnsupportedOperationException - see class Javadoc for details.

public void
setFormatByArgumentIndex(final int
argument index
argumentIndex
,
final Format
the new format
newFormat
)

Overrides java.text.MessageFormat.setFormatByArgumentIndex.

Throws UnsupportedOperationException - see class Javadoc for details.

public void
setFormats(final Format[]
new formats
newFormats
)

Overrides java.text.MessageFormat.setFormats.

Throws UnsupportedOperationException - see class Javadoc for details.

public void
setFormatsByArgumentIndex(final Format[]
new formats
newFormats
)

Overrides java.text.MessageFormat.setFormatsByArgumentIndex.

Throws UnsupportedOperationException - see class Javadoc for details.

public String
toPattern()

Overrides java.text.MessageFormat.toPattern.

Returns a String pattern adhering to the patterns section that represents the current state of this MessageFormat.

Inherited from java.text.MessageFormat:
cloneformatformatformatformatToCharacterIteratorgetFormatsgetFormatsByArgumentIndexgetLocaleparseparseparseObjectsetLocaletoString

Field Detail

EMPTY_PATTERNback to summary
private static final String EMPTY_PATTERN
END_FEback to summary
private static final char END_FE
QUOTEback to summary
private static final char QUOTE
registryback to summary
private final Map<String, ? extends FormatFactory> registry

Our registry of FormatFactory.

serialVersionUIDback to summary
private static final long serialVersionUID

Hides java.text.MessageFormat.serialVersionUID.

START_FEback to summary
private static final char START_FE
START_FMTback to summary
private static final char START_FMT
toPatternback to summary
private String toPattern

To pattern string.

Constructor Detail

ExtendedMessageFormatback to summary
public ExtendedMessageFormat(final String pattern)

Create a new ExtendedMessageFormat for the default locale.

Parameters
pattern:String

the pattern to use, not null

Exceptions
IllegalArgumentException:
in case of a bad pattern.
ExtendedMessageFormatback to summary
public ExtendedMessageFormat(final String pattern, final Locale locale)

Create a new ExtendedMessageFormat.

Parameters
pattern:String

the pattern to use, not null

locale:Locale

the locale to use, not null

Exceptions
IllegalArgumentException:
in case of a bad pattern.
ExtendedMessageFormatback to summary
public ExtendedMessageFormat(final String pattern, final Locale locale, final Map<String, ? extends FormatFactory> registry)

Create a new ExtendedMessageFormat.

Parameters
pattern:String

the pattern to use, not null.

locale:Locale

the locale to use.

registry:Map<String, ? extends FormatFactory>

the registry of format factories, may be null.

Exceptions
IllegalArgumentException:
in case of a bad pattern.
ExtendedMessageFormatback to summary
public ExtendedMessageFormat(final String pattern, final Map<String, ? extends FormatFactory> registry)

Create a new ExtendedMessageFormat for the default locale.

Parameters
pattern:String

the pattern to use, not null

registry:Map<String, ? extends FormatFactory>

the registry of format factories, may be null

Exceptions
IllegalArgumentException:
in case of a bad pattern.

Method Detail

appendQuotedStringback to summary
private StringBuilder appendQuotedString(final String pattern, final ParsePosition pos, final StringBuilder appendTo)

Consume a quoted string, adding it to appendTo if specified.

Parameters
pattern:String

pattern to parse

pos:ParsePosition

current parse position

appendTo:StringBuilder

optional StringBuilder to append

Returns:StringBuilder

appendTo

applyPatternback to summary
public final void applyPattern(final String pattern)

Overrides java.text.MessageFormat.applyPattern.

Apply the specified pattern.

Parameters
pattern:String

String

Annotations
@Override
containsElementsback to summary
private boolean containsElements(final Collection<?> coll)

Learn whether the specified Collection contains non-null elements.

Parameters
coll:Collection<?>

to check

Returns:boolean

true if some Object was found, false otherwise.

equalsback to summary
public boolean equals(final Object obj)

Overrides java.text.MessageFormat.equals.

Doc from java.text.MessageFormat.equals.

Compares the specified object with this MessageFormat for equality. Returns true if the object is also a MessageFormat and the two formats would format any value the same.

Annotations
@Override
getFormatback to summary
private Format getFormat(final String desc)

Gets a custom format from a format description.

Parameters
desc:String

String

Returns:Format

Format

getQuotedStringback to summary
private void getQuotedString(final String pattern, final ParsePosition pos)

Consume quoted string only

Parameters
pattern:String

pattern to parse

pos:ParsePosition

current parse position

hashCodeback to summary
public int hashCode()

Overrides java.text.MessageFormat.hashCode.

Doc from java.text.MessageFormat.hashCode.

Returns the hash code value for this MessageFormat.

Annotations
@Override
insertFormatsback to summary
private String insertFormats(final String pattern, final ArrayList<String> customPatterns)

Insert formats back into the pattern for toPattern() support.

Parameters
pattern:String

source

customPatterns:ArrayList<String>

The custom patterns to re-insert, if any

Returns:String

full pattern

nextback to summary
private ParsePosition next(final ParsePosition pos)

Convenience method to advance parse position by 1

Parameters
pos:ParsePosition

ParsePosition

Returns:ParsePosition

pos

parseFormatDescriptionback to summary
private String parseFormatDescription(final String pattern, final ParsePosition pos)

Parse the format component of a format element.

Parameters
pattern:String

string to parse

pos:ParsePosition

current parse position

Returns:String

Format description String

readArgumentIndexback to summary
private int readArgumentIndex(final String pattern, final ParsePosition pos)

Reads the argument index from the current format element

Parameters
pattern:String

pattern to parse

pos:ParsePosition

current parse position

Returns:int

argument index

seekNonWsback to summary
private void seekNonWs(final String pattern, final ParsePosition pos)

Consume whitespace from the current parse position.

Parameters
pattern:String

String to read

pos:ParsePosition

current position

setFormatback to summary
public void setFormat(final int formatElementIndex, final Format newFormat)

Overrides java.text.MessageFormat.setFormat.

Throws UnsupportedOperationException - see class Javadoc for details.

Parameters
formatElementIndex:int

format element index

newFormat:Format

the new format

Annotations
@Override
Exceptions
UnsupportedOperationException:
always thrown since this isn't supported by ExtendMessageFormat
setFormatByArgumentIndexback to summary
public void setFormatByArgumentIndex(final int argumentIndex, final Format newFormat)

Overrides java.text.MessageFormat.setFormatByArgumentIndex.

Throws UnsupportedOperationException - see class Javadoc for details.

Parameters
argumentIndex:int

argument index

newFormat:Format

the new format

Annotations
@Override
Exceptions
UnsupportedOperationException:
always thrown since this isn't supported by ExtendMessageFormat
setFormatsback to summary
public void setFormats(final Format[] newFormats)

Overrides java.text.MessageFormat.setFormats.

Throws UnsupportedOperationException - see class Javadoc for details.

Parameters
newFormats:Format[]

new formats

Annotations
@Override
Exceptions
UnsupportedOperationException:
always thrown since this isn't supported by ExtendMessageFormat
setFormatsByArgumentIndexback to summary
public void setFormatsByArgumentIndex(final Format[] newFormats)

Overrides java.text.MessageFormat.setFormatsByArgumentIndex.

Throws UnsupportedOperationException - see class Javadoc for details.

Parameters
newFormats:Format[]

new formats

Annotations
@Override
Exceptions
UnsupportedOperationException:
always thrown since this isn't supported by ExtendMessageFormat
toPatternback to summary
public String toPattern()

Overrides java.text.MessageFormat.toPattern.

Doc from java.text.MessageFormat.toPattern.

Returns a String pattern adhering to the patterns section that represents the current state of this MessageFormat. The string is constructed from internal information and therefore does not necessarily equal the previously applied pattern. The order of FormatStyle matching is not guaranteed. That is, a FormatStyle produced may not be equivalent to the corresponding style passed, in the instance that multiple styles are equivalent.

Annotations
@Override