org.geotools.util
Class ResourceInternationalString

java.lang.Object
  extended by org.geotools.util.AbstractInternationalString
      extended by org.geotools.util.ResourceInternationalString
All Implemented Interfaces:
java.io.Serializable, java.lang.CharSequence, java.lang.Comparable<org.opengis.util.InternationalString>, org.opengis.util.InternationalString

public class ResourceInternationalString
extends AbstractInternationalString
implements java.io.Serializable

An international string backed by a resource bundle. A resource bundle can be a Java class or a properties file, one for each language. The constructor expects the fully qualified class name of the base resource bundle (the one used when no resource was found in the client's language). The right resource bundle is loaded at runtime for the client's language by looking for a class or a properties file with the right suffix ("_en" for English or "_fr" for French). This mechanism is explained in J2SE's javadoc for the getBundle static method.

Example: If a file named "MyResources.properties" exists in the package "org.geotools.mypackage" and contains a line like "MyKey = some value", then an international string for "some value" can be created using the following code:

InternationalString value = new ResourceInternationalString( "org.geotools.mypackage.MyResources", "MyKey");
The "some value" string will be localized if the required properties files exist, for example "MyResources_fr.properties" for French, "MyResources_it.properties" for Italian, etc.

Since:
2.1
Version:
$Id: ResourceInternationalString.java 30792 2008-06-23 19:19:58Z desruisseaux $
Author:
Martin Desruisseaux (IRD)
See Also:
Serialized Form

Constructor Summary
ResourceInternationalString(java.lang.String resources, java.lang.String key)
          Creates a new international string from the specified resource bundle and key.
 
Method Summary
 boolean equals(java.lang.Object object)
          Compares this international string with the specified object for equality.
 int hashCode()
          Returns a hash code value for this international text.
 java.lang.String toString(java.util.Locale locale)
          Returns a string in the specified locale.
 
Methods inherited from class org.geotools.util.AbstractInternationalString
charAt, compareTo, length, subSequence, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ResourceInternationalString

public ResourceInternationalString(java.lang.String resources,
                                   java.lang.String key)
Creates a new international string from the specified resource bundle and key.

Parameters:
resources - The name of the resource bundle, as a fully qualified class name.
key - The key for the resource to fetch.
Method Detail

toString

public java.lang.String toString(java.util.Locale locale)
                          throws java.util.MissingResourceException
Returns a string in the specified locale. If there is no string for the specified locale, then this method search for a string in an other locale as specified in the ResourceBundle class description.

Specified by:
toString in interface org.opengis.util.InternationalString
Specified by:
toString in class AbstractInternationalString
Parameters:
locale - The locale to look for, or null for an unlocalized version.
Returns:
The string in the specified locale, or in a default locale.
Throws:
java.util.MissingResourceException - is the key given to the constructor is invalid.

equals

public boolean equals(java.lang.Object object)
Compares this international string with the specified object for equality.

Overrides:
equals in class java.lang.Object
Parameters:
object - The object to compare with this international string.
Returns:
true if the given object is equals to this string.

hashCode

public int hashCode()
Returns a hash code value for this international text.

Overrides:
hashCode in class java.lang.Object


Copyright © 1996-2010 Geotools. All Rights Reserved.