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):{}<em>argument-number</em><strong>(</strong>{@code ,}<em>format-name</em><b>
(</b>{@code ,}<em>format-style</em><strong>)?)?</strong>{@code }
format-name and format-style values are trimmed of surrounding whitespace
in the manner of java.. 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.
Note
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.:
Formats, including MessageFormat and thus
ExtendedMessageFormat, is not guaranteed.| Modifier and Type | Field and Description |
|---|---|
| private static final String | EMPTY_PATTERN
The empty string. |
| private static final char | END_FE
A right curly bracket. |
| private static final char | QUOTE
A properly escaped character representing a single quote. |
| private final Map | registry
Our registry of FormatFactory. |
| private static final long | serialVersionUID
Serializable Object.
|
| private static final char | START_FE
A left curly bracket. |
| private static final char | START_FMT
A comma. |
| private String | toPattern
To pattern string. |
| Access | Constructor and Description |
|---|---|
| public | ExtendedMessageFormat(final String
the pattern to use, not null. pattern)Constructs 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)Constructs a new ExtendedMessageFormat. |
| public | ExtendedMessageFormat(final String
the pattern to use, not null. pattern, final Locale the locale to use, not null. locale, final Map<String, ? extends FormatFactory> the registry of format factories, may be null. registry)Constructs 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)Constructs a new ExtendedMessageFormat for the default locale. |
| Modifier and Type | Method and Description |
|---|---|
| private void | appendQuotedString(final String
pattern to parse. pattern, final ParsePosition current parse position. pos, final StringBuilder optional StringBuilder to append. appendTo)Consumes a quoted string, adding it to |
| public final void | applyPattern(final String
String. pattern)Overrides java. Applies the specified pattern. |
| private boolean | Returns: true if some Object was found, false otherwise.to check. coll)Tests whether the specified Collection contains non-null elements. |
| public boolean | equals(final Object obj)
Overrides java. Compares the specified object with this |
| private Format | |
| private void | getQuotedString(final String
pattern to parse. pattern, final ParsePosition current parse position. pos)Consumes quoted string only. |
| public int | hashCode()
Overrides java. Returns the hash code value for this |
| private String | Returns: full pattern.source. pattern, final ArrayList<String> The custom patterns to re-insert, if any. customPatterns)Inserts formats back into the pattern for toPattern() support. |
| private ParsePosition | |
| private String | Returns: Format description String.string to parse. pattern, final ParsePosition current parse position. pos)Parses the format component of a format element. |
| private int | Returns: argument index.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)Consumes whitespace from the current parse position. |
| public void | setFormat(final int
format element index. formatElementIndex, final Format the new format. newFormat)Overrides java. Throws UnsupportedOperationException, see class Javadoc for details. |
| public void | setFormatByArgumentIndex(final int
argument index. argumentIndex, final Format the new format. newFormat)Overrides java. Throws UnsupportedOperationException, see class Javadoc for details. |
| public void | setFormats(final Format[]
new formats. newFormats)Overrides java. Throws UnsupportedOperationException - see class Javadoc for details. |
| public void | setFormatsByArgumentIndex(final Format[]
new formats newFormats)Overrides java. Throws UnsupportedOperationException - see class Javadoc for details. |
| public String | toPattern()
Overrides java. Returns a String pattern adhering to the |
| EMPTY_PATTERN | back to summary |
|---|---|
| private static final String EMPTY_PATTERN The empty string. | |
| END_FE | back to summary |
|---|---|
| private static final char END_FE A right curly bracket. | |
| QUOTE | back to summary |
|---|---|
| private static final char QUOTE A properly escaped character representing a single quote. | |
| registry | back to summary |
|---|---|
| private final Map<String, ? extends FormatFactory> registry Our registry of FormatFactory. | |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID Hides java. Serializable Object. | |
| START_FE | back to summary |
|---|---|
| private static final char START_FE A left curly bracket. | |
| START_FMT | back to summary |
|---|---|
| private static final char START_FMT A comma. | |
| toPattern | back to summary |
|---|---|
| private String toPattern To pattern string. | |
| ExtendedMessageFormat | back to summary |
|---|---|
| public ExtendedMessageFormat(final String pattern) Constructs a new ExtendedMessageFormat for the default locale.
| |
| ExtendedMessageFormat | back to summary |
|---|---|
| public ExtendedMessageFormat(final String pattern, final Locale locale) Constructs a new ExtendedMessageFormat.
| |
| ExtendedMessageFormat | back to summary |
|---|---|
| public ExtendedMessageFormat(final String pattern, final Locale locale, final Map<String, ? extends FormatFactory> registry) Constructs a new ExtendedMessageFormat.
| |
| ExtendedMessageFormat | back to summary |
|---|---|
| public ExtendedMessageFormat(final String pattern, final Map<String, ? extends FormatFactory> registry) Constructs a new ExtendedMessageFormat for the default locale.
| |
| appendQuotedString | back to summary |
|---|---|
| private void appendQuotedString(final String pattern, final ParsePosition pos, final StringBuilder appendTo) Consumes a quoted string, adding it to
| |
| applyPattern | back to summary |
|---|---|
| public final void applyPattern(final String pattern) Overrides java. Applies the specified pattern. | |
| containsElements | back to summary |
|---|---|
| private boolean containsElements(final Collection<?> coll) Tests whether the specified Collection contains non-null elements.
| |
| equals | back to summary |
|---|---|
| public boolean equals(final Object obj) Overrides java. Doc from java. Compares the specified object with this
| |
| getFormat | back to summary |
|---|---|
| private Format getFormat(final String desc) Gets a custom format from a format description. | |
| getQuotedString | back to summary |
|---|---|
| private void getQuotedString(final String pattern, final ParsePosition pos) Consumes quoted string only.
| |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. Doc from java. Returns the hash code value for this
| |
| insertFormats | back to summary |
|---|---|
| private String insertFormats(final String pattern, final ArrayList<String> customPatterns) Inserts formats back into the pattern for toPattern() support. | |
| next | back to summary |
|---|---|
| private ParsePosition next(final ParsePosition pos) Advances parse position by 1.
| |
| parseFormatDescription | back to summary |
|---|---|
| private String parseFormatDescription(final String pattern, final ParsePosition pos) Parses the format component of a format element.
| |
| readArgumentIndex | back to summary |
|---|---|
| private int readArgumentIndex(final String pattern, final ParsePosition pos) Reads the argument index from the current format element.
| |
| seekNonWs | back to summary |
|---|---|
| private void seekNonWs(final String pattern, final ParsePosition pos) Consumes whitespace from the current parse position.
| |
| setFormat | back to summary |
|---|---|
| public void setFormat(final int formatElementIndex, final Format newFormat) Overrides java. Throws UnsupportedOperationException, see class Javadoc for details.
| |
| setFormatByArgumentIndex | back to summary |
|---|---|
| public void setFormatByArgumentIndex(final int argumentIndex, final Format newFormat) Overrides java. Throws UnsupportedOperationException, see class Javadoc for details.
| |
| setFormats | back to summary |
|---|---|
| public void setFormats(final Format[] newFormats) Overrides java. Throws UnsupportedOperationException - see class Javadoc for details.
| |
| setFormatsByArgumentIndex | back to summary |
|---|---|
| public void setFormatsByArgumentIndex(final Format[] newFormats) Overrides java. Throws UnsupportedOperationException - see class Javadoc for details.
| |
| toPattern | back to summary |
|---|---|
| public String toPattern() Overrides java. Doc from java. Returns a String pattern adhering to the
| |