Class ExtendedMessageFormat
- All Implemented Interfaces:
Serializable,Cloneable
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 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 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 MessageFormat:
- When using "choice" subformats, support for nested formatting instructions is limited to that provided by the base class.
- Thread-safety of
Formats, includingMessageFormatand thusExtendedMessageFormat, is not guaranteed.
- Since:
- 2.4
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class java.text.MessageFormat
MessageFormat.Field -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final StringDeprecated.private static final charDeprecated.private static final charDeprecated.private final Map<String,? extends FormatFactory> Deprecated.Our registry of FormatFactory.private static final longDeprecated.private static final charDeprecated.private static final charDeprecated.private StringDeprecated.To pattern string. -
Constructor Summary
ConstructorsConstructorDescriptionExtendedMessageFormat(String pattern) Deprecated.Create a new ExtendedMessageFormat for the default locale.ExtendedMessageFormat(String pattern, Locale locale) Deprecated.Create a new ExtendedMessageFormat.ExtendedMessageFormat(String pattern, Locale locale, Map<String, ? extends FormatFactory> registry) Deprecated.Create a new ExtendedMessageFormat.ExtendedMessageFormat(String pattern, Map<String, ? extends FormatFactory> registry) Deprecated.Create a new ExtendedMessageFormat for the default locale. -
Method Summary
Modifier and TypeMethodDescriptionprivate StringBuilderappendQuotedString(char[] pattern, ParsePosition pos, StringBuilder appendTo) Deprecated.Consume a quoted string, adding it toappendToif specified.final voidapplyPattern(String pattern) Deprecated.Apply the specified pattern.private booleancontainsElements(Collection<?> coll) Deprecated.Learn whether the specified Collection contains non-null elements.booleanDeprecated.private FormatDeprecated.Gets a custom format from a format description.private voidgetQuotedString(char[] pattern, ParsePosition pos) Deprecated.Gets to the end of the quoted string by advancing the parse position.inthashCode()Deprecated.private StringinsertFormats(String pattern, ArrayList<String> customPatterns) Deprecated.Insert formats back into the pattern for toPattern() support.private ParsePositionnext(ParsePosition pos) Deprecated.Convenience method to advance parse position by 1private StringparseFormatDescription(String pattern, char[] chars, ParsePosition pos) Deprecated.Parse the format component of a format element.private intreadArgumentIndex(String pattern, char[] chars, ParsePosition pos) Deprecated.Reads the argument index from the current format elementprivate voidseekNonWs(char[] buffer, ParsePosition pos) Deprecated.Consume whitespace from the current parse position.voidDeprecated.Sets no format and always throwsUnsupportedOperationException.voidsetFormatByArgumentIndex(int argumentIndex, Format newFormat) Deprecated.Sets no format and always throwsUnsupportedOperationException.voidsetFormats(Format[] newFormats) Deprecated.Sets no format and always throwsUnsupportedOperationException.voidsetFormatsByArgumentIndex(Format[] newFormats) Deprecated.Sets no format and always throwsUnsupportedOperationException.Deprecated.Methods inherited from class java.text.MessageFormat
clone, format, format, format, formatToCharacterIterator, getFormats, getFormatsByArgumentIndex, getLocale, parse, parse, parseObject, setLocaleMethods inherited from class java.text.Format
format, parseObject
-
Field Details
-
serialVersionUID
private static final long serialVersionUIDDeprecated.- See Also:
-
EMPTY_PATTERN
Deprecated.- See Also:
-
START_FMT
private static final char START_FMTDeprecated.- See Also:
-
END_FE
private static final char END_FEDeprecated.- See Also:
-
START_FE
private static final char START_FEDeprecated.- See Also:
-
QUOTE
private static final char QUOTEDeprecated.- See Also:
-
toPattern
Deprecated.To pattern string. -
registry
Deprecated.Our registry of FormatFactory.
-
-
Constructor Details
-
ExtendedMessageFormat
Deprecated.Create a new ExtendedMessageFormat for the default locale.- Parameters:
pattern- The pattern to use, not null- Throws:
IllegalArgumentException- Thrown in case of a bad pattern.
-
ExtendedMessageFormat
Deprecated.Create a new ExtendedMessageFormat.- Parameters:
pattern- The pattern to use, not nulllocale- The locale to use, not null- Throws:
IllegalArgumentException- Thrown in case of a bad pattern.
-
ExtendedMessageFormat
public ExtendedMessageFormat(String pattern, Locale locale, Map<String, ? extends FormatFactory> registry) Deprecated.Create a new ExtendedMessageFormat.- Parameters:
pattern- The pattern to use, not null.locale- The locale to use.registry- The registry of format factories, may be null.- Throws:
IllegalArgumentException- Thrown in case of a bad pattern.
-
ExtendedMessageFormat
Deprecated.Create a new ExtendedMessageFormat for the default locale.- Parameters:
pattern- The pattern to use, not nullregistry- The registry of format factories, may be null- Throws:
IllegalArgumentException- Thrown in case of a bad pattern.
-
-
Method Details
-
appendQuotedString
Deprecated.Consume a quoted string, adding it toappendToif specified.- Parameters:
pattern- pattern to parse, as a char array created once by the caller (avoids copying the entire pattern for every token parsed)pos- current parse positionappendTo- optional StringBuilder to append- Returns:
appendTo
-
applyPattern
Deprecated.Apply the specified pattern.- Overrides:
applyPatternin classMessageFormat- Parameters:
pattern- String
-
containsElements
Deprecated.Learn whether the specified Collection contains non-null elements.- Parameters:
coll- to check- Returns:
trueif some Object was found,falseotherwise.
-
equals
Deprecated.- Overrides:
equalsin classMessageFormat
-
getFormat
Deprecated.Gets a custom format from a format description.- Parameters:
desc- String- Returns:
- Format
-
getQuotedString
Deprecated.Gets to the end of the quoted string by advancing the parse position.- Parameters:
pattern- pattern to parse, as a char array created once by the callerpos- current parse position
-
hashCode
public int hashCode()Deprecated.- Overrides:
hashCodein classMessageFormat
-
insertFormats
Deprecated.Insert formats back into the pattern for toPattern() support.- Parameters:
pattern- sourcecustomPatterns- The custom patterns to re-insert, if any- Returns:
- full pattern
-
next
Deprecated.Convenience method to advance parse position by 1- Parameters:
pos- ParsePosition- Returns:
pos
-
parseFormatDescription
Deprecated.Parse the format component of a format element.- Parameters:
pattern- string to parsechars- the pattern as a char array created once by the callerpos- current parse position- Returns:
- Format description String
-
readArgumentIndex
Deprecated.Reads the argument index from the current format element- Parameters:
pattern- pattern to parsechars- the pattern as a char array created once by the callerpos- current parse position- Returns:
- argument index
-
seekNonWs
Deprecated.Consume whitespace from the current parse position.- Parameters:
buffer- the pattern to read, as a char array created once by the caller (avoids copying the entire pattern on every call)pos- current position
-
setFormat
Deprecated.Sets no format and always throwsUnsupportedOperationException. See the class Javadoc for details.- Overrides:
setFormatin classMessageFormat- Parameters:
formatElementIndex- format element indexnewFormat- The new format- Throws:
UnsupportedOperationException- Thrown because this operation is not supported.
-
setFormatByArgumentIndex
Deprecated.Sets no format and always throwsUnsupportedOperationException. See the class Javadoc for details.- Overrides:
setFormatByArgumentIndexin classMessageFormat- Parameters:
argumentIndex- argument indexnewFormat- The new format- Throws:
UnsupportedOperationException- Thrown because this operation is not supported.
-
setFormats
Deprecated.Sets no format and always throwsUnsupportedOperationException. See the class Javadoc for details.- Overrides:
setFormatsin classMessageFormat- Parameters:
newFormats- new formats- Throws:
UnsupportedOperationException- Thrown because this operation is not supported.
-
setFormatsByArgumentIndex
Deprecated.Sets no format and always throwsUnsupportedOperationException. See the class Javadoc for details.- Overrides:
setFormatsByArgumentIndexin classMessageFormat- Parameters:
newFormats- new formats- Throws:
UnsupportedOperationException- Thrown because this operation is not supported.
-
toPattern
Deprecated.- Overrides:
toPatternin classMessageFormat
-