All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.sf.mmm.util.nls.api.NlsArgument Maven / Gradle / Ivy

/* Copyright (c) The m-m-m Team, Licensed under the Apache License, Version 2.0
 * http://www.apache.org/licenses/LICENSE-2.0 */
package net.sf.mmm.util.nls.api;

import java.util.Locale;

import net.sf.mmm.util.nls.impl.formatter.NlsFormatterDefault;
import net.sf.mmm.util.text.api.Justification;

/**
 * This class represents an argument of an {@link NlsMessage}. An argument is a place-holder for a dynamic parameter
 * filled into the message. It is resolved when the message is finally
 * {@link NlsMessage#getLocalizedMessage(java.util.Locale) localized} as {@link String} for a specific
 * {@link java.util.Locale}. The {@link #getKey() key} is used to {@link NlsMessage#getArgument(String) lookup} the
 * argument value to fill in. If that value itself implements {@link NlsObject} it will be also translated using the
 * same {@link Locale}.
* The syntax for an {@link NlsArgument} in an {@link NlsMessage#getInternationalizedMessage() i18n message} is * specified as following: * *
 * '{' key [ ',' type [ ',' style ] ] [ '{' justification '}' ] '}'
 * 
* * The literals are explained in this table. * * * * * * * * * * * * * * * * * * * * *
literalexplanation
keyis the key of the parameter (may be numeric for legacy support)
typea type specifying how to format the value (see below). Should fit to the {@link Object#getClass() type} of the * {@link NlsMessage#getArgument(String) argument value} to fill in. *
stylea style according to {@code type} (see below).
justificationa {@link net.sf.mmm.util.text.api.JustificationBuilder justification}
* *
* The following table shows the supported variants of {@code type} and {@code style}: * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
typestyleExampleComment
--value as stringdefault string representation of the value
{@link NlsFormatterManager#TYPE_NUMBER number}-123,456.78Numeric representation
{@link NlsFormatterManager#TYPE_NUMBER number}{@link NlsFormatterManager#STYLE_PERCENT percent}12,345,678%Number in percent
{@link NlsFormatterManager#TYPE_NUMBER number}{@link NlsFormatterManager#STYLE_CURRENCY currency}123,456.78 ¤Number as currency
{@link NlsFormatterManager#TYPE_NUMBER number}'#'##.###123456.78Any other style is treated as pattern for {@link java.text.DecimalFormat}
{@link NlsFormatterManager#TYPE_DATE date}-31-Dec-1999Date default representation
{@link NlsFormatterManager#TYPE_DATE date}{@link NlsFormatterManager#STYLE_SHORT short}31/12/99Date short representation
{@link NlsFormatterManager#TYPE_DATE date}{@link NlsFormatterManager#STYLE_MEDIUM medium}31-Dec-1999Date medium representation
{@link NlsFormatterManager#TYPE_DATE date}{@link NlsFormatterManager#STYLE_LONG long}31 December 1999Date long representation
{@link NlsFormatterManager#TYPE_DATE date}{@link NlsFormatterManager#STYLE_FULL full}Friday, 31 December 1999Date full representation
{@link NlsFormatterManager#TYPE_DATE date}{@link NlsFormatterManager#STYLE_ISO_8601 iso8601}1999-12-31Date ISO-8601 representation
{@link NlsFormatterManager#TYPE_DATE date}yyyy.MM.dd2010.01.01Any other style is treated as pattern for {@link java.text.SimpleDateFormat}
{@link NlsFormatterManager#TYPE_TIME time}-23:59:59Time default representation
{@link NlsFormatterManager#TYPE_TIME time}{@link NlsFormatterManager#STYLE_SHORT short}23:59Time short representation
{@link NlsFormatterManager#TYPE_TIME time}{@link NlsFormatterManager#STYLE_MEDIUM medium}23:59:59Time medium representation
{@link NlsFormatterManager#TYPE_TIME time}{@link NlsFormatterManager#STYLE_LONG long}23:59:59 GMT+01:00Time long representation
{@link NlsFormatterManager#TYPE_TIME time}{@link NlsFormatterManager#STYLE_FULL full}23:59:59 o'clock GMT+01:00Time full representation
{@link NlsFormatterManager#TYPE_TIME time}{@link NlsFormatterManager#STYLE_ISO_8601 iso8601}23:59:59+01:00Time ISO-8601 representation
{@link NlsFormatterManager#TYPE_TIME time}HH:mm:ss23:59:59Any other style is treated as pattern for {@link java.text.SimpleDateFormat}
{@link NlsFormatterManager#TYPE_DATETIME datetime}-31-Dec-1999 23:59:59Date+time default representation
{@link NlsFormatterManager#TYPE_DATETIME datetime}{@link NlsFormatterManager#STYLE_SHORT short}31/12/99 23:59Date+time short representation
{@link NlsFormatterManager#TYPE_DATETIME datetime}{@link NlsFormatterManager#STYLE_MEDIUM medium}31-Dec-1999 23:59:59Date+time medium representation
{@link NlsFormatterManager#TYPE_DATETIME datetime}{@link NlsFormatterManager#STYLE_LONG long}31 December 1999 23:59:59 GMT+01:00Date+time long representation
{@link NlsFormatterManager#TYPE_DATETIME datetime}{@link NlsFormatterManager#STYLE_FULL full}Friday, 31 December 1999 23:59:59 o'clock GMT+01:00Date+time full representation
{@link NlsFormatterManager#TYPE_DATETIME datetime}{@link NlsFormatterManager#STYLE_ISO_8601 iso8601}1999-12-31T23:59:59+01:00Date+time ISO-8601 representation
{@link NlsFormatterManager#TYPE_DATE date}yyyy.MM.dd-HH:mm:ss2010.01.01-23:59:59Any other style is treated as pattern for {@link java.text.SimpleDateFormat}
{@link NlsFormatterManager#TYPE_TYPE type}-java.util.List{@link java.lang.reflect.Type} medium representation (omit {@code java.lang})
{@link NlsFormatterManager#TYPE_TYPE type}{@link NlsFormatterManager#STYLE_SHORT short}List{@link java.lang.reflect.Type} short representation
{@link NlsFormatterManager#TYPE_TYPE type}{@link NlsFormatterManager#STYLE_MEDIUM medium}java.util.List{@link java.lang.reflect.Type} medium representation (omit {@code java.lang})
{@link NlsFormatterManager#TYPE_TYPE type}{@link NlsFormatterManager#STYLE_LONG long}java.util.List<String>{@link java.lang.reflect.Type} long representation
{@link NlsFormatterManager#TYPE_TYPE type}{@link NlsFormatterManager#STYLE_FULL full}java.util.List<java.lang.String>{@link java.lang.reflect.Type} full representation
{@link NlsFormatterManager#TYPE_CHOICE choice}(?==1)'error'(else)'errors'errorA choice to distinguish singular/plural forms.
{@link NlsFormatterManager#TYPE_CHOICE choice}(?>=5){key,choice,(?==true)'a'(else){key2}}(else)'c'aA choice that results to 'c' if the value is NOT greater or equal to 5. Otherwise it results to 'a' if the value * of the argument "key" is {@link Boolean#TRUE}. Otherwise it results to the value of the argument "key2". - This is a * wired example. It shows the power of the choice format as well as how things turn out unmaintainable if the power is * missused.
* * @author Joerg Hohwiller (hohwille at users.sourceforge.net) * @since 2.0.0 */ public class NlsArgument { private final String key; private final NlsFormatterPlugin formatter; private final Justification justification; /** * The constructor. * * @param key is the {@link #getKey() key}. * @param formatter is the {@link #getFormatter() formatter}. * @param justification is the {@link #getJustification() justification}. */ public NlsArgument(String key, NlsFormatterPlugin formatter, Justification justification) { super(); this.key = key; this.formatter = formatter; this.justification = justification; } /** * This method gets the key of the argument to format. * * @return the key */ public String getKey() { return this.key; } /** * Is the formatter used to format the {@link #getKey() argument}. * * @return the formatter */ public NlsFormatterPlugin getFormatter() { return this.formatter; } /** * This method gets the optional {@link Justification}. * * @return the justification or {@code null} for none. */ public Justification getJustification() { return this.justification; } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append(NlsArgumentParser.START_EXPRESSION); sb.append(this.key); if (!(this.formatter instanceof NlsFormatterDefault)) { sb.append(NlsArgumentParser.FORMAT_SEPARATOR); sb.append(this.formatter); } if (this.justification != null) { sb.append(NlsArgumentParser.START_EXPRESSION); sb.append(this.justification); sb.append(NlsArgumentParser.END_EXPRESSION); } sb.append(NlsArgumentParser.END_EXPRESSION); return sb.toString(); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy