org.archive.wayback.util
Class StringFormatter

java.lang.Object
  extended by org.archive.wayback.util.StringFormatter

public class StringFormatter
extends Object

An class which assists in UI generation, primarily through Locale-aware String formatting, and also helps in escaping (hopefully properly) Strings for use in HTML. Note that date formatting done through this class forces all times to the UTC timezone - at the moment it appears too confusing to attempt to localize times in any other way..

Version:
$Date: 2010-09-29 05:28:38 +0700 (Wed, 29 Sep 2010) $, $Revision: 3262 $
Author:
brad

Constructor Summary
StringFormatter(ResourceBundle bundle, Locale locale)
          Construct a StringFormatter...
 
Method Summary
 String escapeHtml(String raw)
          handy shortcut to the apache StringEscapeUtils
 String escapeJavaScript(String raw)
          handy shortcut to the apache StringEscapeUtils
 String format(String key)
          Localize a string key from the UI.properties file
 String format(String key, Object o1)
           
 String format(String key, Object o1, Object o2)
           
 String format(String key, Object o1, Object o2, Object o3)
           
 String format(String key, Object o1, Object o2, Object o3, Object o4)
           
 String getLocalized(String key)
          Access a localized string associated with key from the ResourceBundle, likely the UI.properties file.
 String spaceToNBSP(String input)
          Convert...
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringFormatter

public StringFormatter(ResourceBundle bundle,
                       Locale locale)
Construct a StringFormatter...

Parameters:
bundle - ResourceBundle to lookup patterns for MessageFormat objects.
locale - to use, where applicable with MessageFormat objects
Method Detail

getLocalized

public String getLocalized(String key)
Access a localized string associated with key from the ResourceBundle, likely the UI.properties file.

Parameters:
key - to lookup in the ResourceBundle
Returns:
localized String version of key argument, or key itself if something goes wrong...

format

public String format(String key)
Localize a string key from the UI.properties file

Parameters:
key - String property name in UI.properties file to use as the pattern for the MessageFormat
Returns:
Localized String for key

format

public String format(String key,
                     Object o1)
Parameters:
key - String property name in UI.properties file to use as the pattern for interpolation
o1 - thing1 to interpolate within the MessageFormat described by the pattern in UI.properties for key key
Returns:
Localized Formatted String for key, interpolated with argument objects

format

public String format(String key,
                     Object o1,
                     Object o2)
Parameters:
key - String property name in UI.properties file to use as the pattern for interpolation
o1 - thing1 to interpolate within the MessageFormat described by the pattern in UI.properties for key key
o2 - thing2 to interpolate within the MessageFormat described by the pattern in UI.properties for key key
Returns:
Localized Formatted String for key, interpolated with argument objects

format

public String format(String key,
                     Object o1,
                     Object o2,
                     Object o3)
Parameters:
key - String property name in UI.properties file to use as the pattern for interpolation
o1 - thing1 to interpolate within the MessageFormat described by the pattern in UI.properties for key key
o2 - thing2 to interpolate within the MessageFormat described by the pattern in UI.properties for key key
o3 - thing3 to interpolate within the MessageFormat described by the pattern in UI.properties for key key
Returns:
Localized Formatted String for key, interpolated with argument objects

format

public String format(String key,
                     Object o1,
                     Object o2,
                     Object o3,
                     Object o4)
Parameters:
key - String property name in UI.properties file to use as the pattern for interpolation
o1 - thing1 to interpolate within the MessageFormat described by the pattern in UI.properties for key key
o2 - thing2 to interpolate within the MessageFormat described by the pattern in UI.properties for key key
o3 - thing3 to interpolate within the MessageFormat described by the pattern in UI.properties for key key
o4 - thing4 to interpolate within the MessageFormat described by the pattern in UI.properties for key key
Returns:
Localized Formatted String for key, interpolated with argument objects

escapeHtml

public String escapeHtml(String raw)
handy shortcut to the apache StringEscapeUtils

Parameters:
raw - string to be escaped
Returns:
the string escaped so it's safe for insertion in HTML

escapeJavaScript

public String escapeJavaScript(String raw)
handy shortcut to the apache StringEscapeUtils

Parameters:
raw - string to be escaped
Returns:
the string escaped so it's safe for insertion in Javascript

spaceToNBSP

public String spaceToNBSP(String input)
Convert... spaces to  

Parameters:
input - to replace
Returns:
with spaces replaced


Copyright © 2005-2011 Internet Archive. All Rights Reserved.