com.artima.place.attribute
Class Text

java.lang.Object
  |
  +--com.artima.place.attribute.Text
All Implemented Interfaces:
java.lang.Cloneable, java.io.Serializable

public class Text
extends java.lang.Object
implements java.io.Serializable, java.lang.Cloneable

A chunk of localizable text, suitable for indexing by search engines.

See Also:
Serialized Form

Inner Class Summary
static class Text.Cache
          Contains a String cached text and its Locale, the cache for a Text object.
 
Constructor Summary
Text(java.util.Locale cachedLocale, java.lang.String cachedText)
          Constructs a new Text with passed cached text for the passed locale, and no text key and resource bundle loader.
Text(ResourceBundleLoader loader, java.lang.String textKey)
          Constructs a new Text with passed resource bundle loader, text key, and no cached text.
Text(ResourceBundleLoader loader, java.lang.String textKey, java.util.Locale cachedLocale, java.lang.String cachedText)
          Constructs a new Text with passed resource bundle loader, text key, and cached text (for the passed locale).
 
Method Summary
 java.lang.Object clone()
          Clones this Text.
 boolean equals(java.lang.Object o)
          Compares this Text to the passed object for equality.
 Text.Cache getCache()
          Returns this Text's Cache, or null if none exists.
 ResourceBundleLoader getResourceBundleLoader()
          Returns the ResourceBundleLoader contained in this Text, or null if none exists.
 java.lang.String getText()
          Returns a String text, suitable for presentation to users, appropriate to the default locale.
 java.lang.String getText(java.util.Locale desiredLocale)
          Returns a String text, suitable for presentation to users, which represents the best-fit text for the specified locale.
 java.lang.String getTextKey()
          Returns the String text key contained in this Text, or null if none exists.
 boolean hasCache()
          Indicates whether this Text object has a String cached text and its Locale.
 int hashCode()
          Returns a hash code for this object.
 boolean hasResources()
          Indicates whether this Text object has a ResourceBundleLoader and String text key.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Text

public Text(ResourceBundleLoader loader,
            java.lang.String textKey)
Constructs a new Text with passed resource bundle loader, text key, and no cached text.
Parameters:
loader - the ResourceBundleLoader which can load ResourceBundles for this Text.
textKey - the String key with which the String resource can be retrieved from a ResourceBundle provided by the ResourceBundleLoader
Throws:
NullPointerException - if either of the passed loader or textKey references are null

Text

public Text(ResourceBundleLoader loader,
            java.lang.String textKey,
            java.util.Locale cachedLocale,
            java.lang.String cachedText)
Constructs a new Text with passed resource bundle loader, text key, and cached text (for the passed locale).
Parameters:
loader - the ResourceBundleLoader which can load ResourceBundles for this Text.
textKey - the String key with which the String resource can be retrieved from a ResourceBundle provided by the ResourceBundleLoader
cachedLocale - the Locale of the text passed as cachedText.
cachedText - the text whose locale is passed as cachedLocale that should be cached by this Text.
Throws:
NullPointerException - if any of passed loader, textKey, cachedLocale, or cachedText references are null

Text

public Text(java.util.Locale cachedLocale,
            java.lang.String cachedText)
Constructs a new Text with passed cached text for the passed locale, and no text key and resource bundle loader. (Because this Text info object contains no resource bundle loader, it also requires no key with which to look up a text resource in a resource bundle.
Parameters:
cachedLocale - the Locale of the text passed as cachedText.
cachedText - the text whose locale is passed as cachedLocale that should be cached by this Text.
Throws:
NullPointerException - if any of passed cachedLocale, or cachedText references are null
Method Detail

getText

public java.lang.String getText()
Returns a String text, suitable for presentation to users, appropriate to the default locale.
Returns:
a String text, suitable for presentation to users, appropriate to the default locale.
Throws:
MissingResourceException - if a codebase URL is found to be unusable. (Because URLString enforces well-formedness of all URLs used by this method, this exception probably indicates the protocol was unknown.), or if a ResourceBundle is not found at the expected codebase

getText

public java.lang.String getText(java.util.Locale desiredLocale)
Returns a String text, suitable for presentation to users, which represents the best-fit text for the specified locale.
Returns:
a String text, suitable for presentation to users, which represents the best-fit text for the specified locale.
Throws:
NullPointerException - if passed desiredLocale is null
MissingResourceException - if a codebase URL is found to be unusable. (Because URLString enforces well-formedness of all URLs used by this method, this exception probably indicates the protocol was unknown.), or if a ResourceBundle is not found at the expected codebase

equals

public boolean equals(java.lang.Object o)
Compares this Text to the passed object for equality. To be semantically equal, the class of the passed object must be Text, the passed object's cached text must be semantically equal to this object's cached text, the passed object's text key must be semantically to this object's text key, and the equals method of Text's superclass must return true.
Overrides:
equals in class java.lang.Object
Parameters:
An - object to compare to this Text
Returns:
true if this Text is semantically equal to the passed Text

hashCode

public int hashCode()
Returns a hash code for this object.
Overrides:
hashCode in class java.lang.Object
Returns:
the hash code

clone

public java.lang.Object clone()
Clones this Text.
Overrides:
clone in class java.lang.Object
Returns:
a clone of this object

getCache

public Text.Cache getCache()
Returns this Text's Cache, or null if none exists. This method will return null only if this Text object contains no cached String text. Otherwise, this method will return a Text.Cache object containing this object's cached String text and the Locale of that cached text (the "cached locale").
Returns:
a reference to the Text.Cache, which contains this object's cached text and locale, or null if this object contains no cache

hasResources

public boolean hasResources()
Indicates whether this Text object has a ResourceBundleLoader and String text key.
Returns:
true if this Text object has a ResourceBundleLoader and String text key.

hasCache

public boolean hasCache()
Indicates whether this Text object has a String cached text and its Locale.
Returns:
true if this Text object has a String cached text and its Locale.

getResourceBundleLoader

public ResourceBundleLoader getResourceBundleLoader()
Returns the ResourceBundleLoader contained in this Text, or null if none exists.
Returns:
a ResourceBundleLoader, or null if this object contains no ResourceBundleLoader.

getTextKey

public java.lang.String getTextKey()
Returns the String text key contained in this Text, or null if none exists.
Returns:
a String text key, or null if this object contains no text key.