FileDocCategorySizeDatePackage
LocalizedMessage.javaAPI DocAndroid 1.5 API5922Wed May 06 22:41:06 BST 2009org.bouncycastle.i18n

LocalizedMessage

public class LocalizedMessage extends Object

Fields Summary
protected final String
id
protected final String
resource
protected Object[]
arguments
protected Object[]
filteredArguments
protected org.bouncycastle.i18n.filter.Filter
filter
Constructors Summary
public LocalizedMessage(String resource, String id)
Constructs a new LocalizedMessage using resource as the base name for the RessourceBundle and id as the message bundle id the resource file.

param
resource base name of the resource file
param
id the id of the corresponding bundle in the resource file
throws
NullPointerException if resource or id is null

    
                                                               
         
    
        if (resource == null || id == null)
        {
            throw new NullPointerException();
        }
        this.id = id;
        this.resource = resource;
        this.arguments = new Object[0];
        this.filteredArguments = arguments;
    
public LocalizedMessage(String resource, String id, Object[] arguments)
Constructs a new LocalizedMessage using resource as the base name for the RessourceBundle and id as the message bundle id the resource file.

param
resource base name of the resource file
param
id the id of the corresponding bundle in the resource file
param
arguments an array containing the arguments for the message
throws
NullPointerException if resource or id is null

        if (resource == null || id == null || arguments == null)
        {
            throw new NullPointerException();
        }
        this.id = id;
        this.resource = resource;
        this.arguments = arguments;
        this.filteredArguments = arguments;
    
Methods Summary
protected java.lang.StringformatWithTimeZone(java.lang.String template, java.lang.Object[] arguments, java.util.Locale locale, java.util.TimeZone timezone)

        MessageFormat mf = new MessageFormat(" ");
        mf.setLocale(locale);
        mf.applyPattern(template);
        if (!timezone.equals(TimeZone.getDefault())) 
        {
            Format[] formats = mf.getFormats();
            for (int i = 0; i < formats.length; i++) 
            {
                if (formats[i] instanceof DateFormat) 
                {
                    DateFormat temp = (DateFormat) formats[i];
                    temp.setTimeZone(timezone);
                    mf.setFormat(i,temp);
                }
            }
        }
        return mf.format(arguments);
    
public java.lang.Object[]getArguments()
Returns an Object[] containing the message arguments.

return
the message arguments

        return arguments;
    
public java.lang.StringgetEntry(java.lang.String key, java.util.Locale loc, java.util.TimeZone timezone)
Reads the entry id + "." + key from the resource file and returns a formated message for the given Locale and TimeZone.

param
key second part of the entry id
param
loc the used {@link Locale}
param
timezone the used {@link TimeZone}
return
a Strng containing the localized message
throws
MissingEntryException if the resource file is not available or the entry does not exist.

        String entry = id + "." + key;
        
        try
        {
            ResourceBundle bundle = ResourceBundle.getBundle(resource,loc);
            String template = bundle.getString(entry);
            if (arguments == null || arguments.length == 0)
            {
                return template;
            }
            else
            {
                return formatWithTimeZone(template,filteredArguments,loc,timezone);
            }
        }
        catch (MissingResourceException mre)
        {
            throw new MissingEntryException("Can't find entry " + entry + " in resource file " + resource + ".",
                    resource,
                    entry); 
        }
    
public org.bouncycastle.i18n.filter.FiltergetFilter()
Returns the current filter.

return
the current filter

        return filter;
    
public java.lang.StringgetId()
Returns the id of the message in the resource bundle.

return
the id of the message

        return id;
    
public java.lang.StringgetResource()
Returns the name of the resource bundle for this message

return
name of the resource file

        return resource;
    
public voidsetFilter(org.bouncycastle.i18n.filter.Filter filter)
Sets the {@link Filter} that is used to filter the arguments of this message

param
filter the {@link Filter} to use. null to disable filtering.

        if (filter == null)
        {
            filteredArguments = arguments;
        }
        else if (!filter.equals(this.filter))
        {
            filteredArguments = new Object[arguments.length];
            for (int i = 0; i < arguments.length; i++)
            {
                if (arguments[i] instanceof UntrustedInput) 
                {
                    filteredArguments[i] = filter.doFilter(((UntrustedInput) arguments[i]).getString());
                }
                else
                {
                    filteredArguments[i] = arguments[i];
                }
            }
        }
        this.filter = filter;