org.norther.tammi.spray.engine.tool
Class FormatTool

java.lang.Object
  extended by org.norther.tammi.core.converter.Formatter
      extended by org.norther.tammi.spray.engine.tool.FormatTool
All Implemented Interfaces:
Serializable, EventListener, Poolable, Recyclable, ContextBindingListener

public class FormatTool
extends Formatter
implements Poolable, ContextBindingListener

A request context tool for localized resources.

Author:
Ilkka Priha
See Also:
Serialized Form

Constructor Summary
FormatTool()
          Constructs a tool.
 
Method Summary
 void dispose()
          Disposes the object after use.
 void disposed()
          A call back indicating that this instance is not needed any more and can be disposed.
 String formatCurrency(Number number)
          Formats currency.
 String formatDate(Object date, String style, String timezone)
          Formats the specified with style and time zone.
 String formatDateTime(Object date, String dstyle, String tstyle, String timezone)
          Formats the specified date and time with style and time zone.
 String formatError(Throwable error)
          Formats an error.
 String formatString(String string, List arguments)
          Formats a string with arguments.
 String formatTime(Object time, String style, String timezone)
          Formats the specified time with style and time zone.
 Calendar getCalendar()
          Gets a calendar.
protected  TemplateContext getContext()
          Gets the target context.
protected  ContextToolFilter getContextToolFilter()
          Gets the context tool filter if available.
 Locale getDefaultLocale()
          Gets the default locale.
protected  Filter getFilter(Class clazz)
          Gets the first specific filter from the filter chain.
protected  HttpFilterChain getFilterChain()
          Gets the current filter chain if available.
protected  String getFilterKey(Class clazz)
          Gets the key of the first specific key filter from the filter chain.
 int getFirstDayOfWeek()
          Gets the first day of a week.
protected  String getName()
          Gets the bound name.
protected  ServletRequest getRequest()
          Gets the current request if available.
protected  ResourceFilter getResourceFilter()
          Gets the resource filter from the filter stack.
protected  ResourceMap getResourceMap()
          Gets the referent of the resource map MBean.
protected  ServletResponse getResponse()
          Gets the current response if available.
protected  boolean isBound()
          Gets the bound state.
 boolean isDisposed()
          Checks whether the recyclable has been disposed.
protected  boolean isFilterChanged()
          Checks whether the current filter has changed since the previous check.
 void recycle()
          Recycles the object for a new client.
 void recycled(MBeanReference instance)
          A callback specifying the pool, from which this instance was recycled.
 void valueBound(ContextBindingEvent event)
          Notifies the object that it is being bound to a context.
 void valueUnbound(ContextBindingEvent event)
          Notifies the object that it is being unbound from a context.
 
Methods inherited from class org.norther.tammi.core.converter.Formatter
clearFormats, format, format, formatDate, formatDate, formatDate, formatDate, formatDate, formatDateTime, formatDateTime, formatDateTime, formatDateTime, formatDateTime, formatNumber, formatNumber, formatPercent, formatString, formatTime, formatTime, formatTime, formatTime, formatTime, getDateFormat, getLocale, getMBeanServer, getNumberFormat, getObject, getObject, getString, getString, parseDate, parseDate, parseDateTime, parseDateTime, parseDouble, parseDouble, parseInt, parseInt, parseLong, parseLong, parseTime, parseTime, resolve, resolve, resolve, resolve, resolve, resolve, resolve, setLocale, toLowerCase, toUpperCase
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FormatTool

public FormatTool()
Constructs a tool.

Method Detail

recycle

public void recycle()
Description copied from interface: Recyclable
Recycles the object for a new client. Recycle methods with parameters must be added to implementing object and they will be automatically called by pool implementations when the object is taken from the pool for a new client. The parameters must correspond to the parameters of the constructors of the object. For new objects, constructors can call their corresponding recycle methods whenever applicable. The recycle methods must call their super.

Specified by:
recycle in interface Recyclable

dispose

public void dispose()
Description copied from interface: Recyclable
Disposes the object after use. The method is called when the object is returned to its pool. The dispose method must call its super.

Specified by:
dispose in interface Recyclable

isDisposed

public boolean isDisposed()
Description copied from interface: Recyclable
Checks whether the recyclable has been disposed.

Specified by:
isDisposed in interface Recyclable
Returns:
true, if the recyclable is disposed.

recycled

public void recycled(MBeanReference instance)
Description copied from interface: Poolable
A callback specifying the pool, from which this instance was recycled.

Specified by:
recycled in interface Poolable
Parameters:
instance - the pool MBean reference.

disposed

public void disposed()
Description copied from interface: Poolable
A call back indicating that this instance is not needed any more and can be disposed.

Specified by:
disposed in interface Poolable

formatString

public String formatString(String string,
                           List arguments)
Description copied from class: Formatter
Formats a string with arguments.

Overrides:
formatString in class Formatter
Parameters:
string - the string to format.
arguments - the source objects of the format.
Returns:
the formatted string.

formatError

public String formatError(Throwable error)
Description copied from class: Formatter
Formats an error. The result is encoded as an XML string.

Overrides:
formatError in class Formatter
Parameters:
error - the error to format.
Returns:
the formatted error.

formatDate

public String formatDate(Object date,
                         String style,
                         String timezone)
Description copied from class: Formatter
Formats the specified with style and time zone.

Overrides:
formatDate in class Formatter
Parameters:
date - the date or milliseconds.
style - default, short, medium, long or full.
timezone - the timezone.
Returns:
the formatted date.

formatTime

public String formatTime(Object time,
                         String style,
                         String timezone)
Description copied from class: Formatter
Formats the specified time with style and time zone.

Overrides:
formatTime in class Formatter
Parameters:
time - the time or milliseconds.
style - default, short, medium, long or full.
timezone - the timezone.
Returns:
the formatted time.

formatDateTime

public String formatDateTime(Object date,
                             String dstyle,
                             String tstyle,
                             String timezone)
Description copied from class: Formatter
Formats the specified date and time with style and time zone.

Overrides:
formatDateTime in class Formatter
Parameters:
date - the date and time or milliseconds.
dstyle - default, short, medium, long or full for date.
tstyle - default, short, medium, long or full for time.
timezone - the timezone.
Returns:
the formatted date and time.

formatCurrency

public String formatCurrency(Number number)
Description copied from class: Formatter
Formats currency.

Overrides:
formatCurrency in class Formatter
Parameters:
number - the amount to format.
Returns:
the formatted currency.

getDefaultLocale

public Locale getDefaultLocale()
Description copied from class: Formatter
Gets the default locale.

Overrides:
getDefaultLocale in class Formatter
Returns:
the default locale.

getCalendar

public Calendar getCalendar()
Gets a calendar.

Returns:
a calendar.

getFirstDayOfWeek

public int getFirstDayOfWeek()
Gets the first day of a week.

Returns:
the index of the day starting from 0.

valueBound

public void valueBound(ContextBindingEvent event)
Description copied from interface: ContextBindingListener
Notifies the object that it is being bound to a context.

Specified by:
valueBound in interface ContextBindingListener
Parameters:
event - the binding event.

valueUnbound

public void valueUnbound(ContextBindingEvent event)
Description copied from interface: ContextBindingListener
Notifies the object that it is being unbound from a context.

Specified by:
valueUnbound in interface ContextBindingListener
Parameters:
event - the binding event.

getResourceMap

protected ResourceMap getResourceMap()
Description copied from class: Formatter
Gets the referent of the resource map MBean.

Overrides:
getResourceMap in class Formatter
Returns:
the referent of the resource map MBean or null.

getResourceFilter

protected ResourceFilter getResourceFilter()
Gets the resource filter from the filter stack.

Returns:
the resource filter or null.

getRequest

protected ServletRequest getRequest()
Gets the current request if available.

Returns:
the request or null.

getResponse

protected ServletResponse getResponse()
Gets the current response if available.

Returns:
the response or null.

getFilterChain

protected HttpFilterChain getFilterChain()
Gets the current filter chain if available.

Returns:
the filter chain or null.

getFilter

protected Filter getFilter(Class clazz)
Gets the first specific filter from the filter chain.

Parameters:
clazz - the class or interface of the filter.
Returns:
the found filter.
Throws:
IllegalStateException - if not found.

getFilterKey

protected String getFilterKey(Class clazz)
Gets the key of the first specific key filter from the filter chain.

Parameters:
clazz - the class or interface of the key filter.
Returns:
the found key.
Throws:
IllegalStateException - if not found.

isFilterChanged

protected boolean isFilterChanged()
Checks whether the current filter has changed since the previous check.

Returns:
true if changed, false otherwise.

getContext

protected TemplateContext getContext()
Gets the target context.

Returns:
the context.

getName

protected String getName()
Gets the bound name.

Returns:
the bound name.

isBound

protected boolean isBound()
Gets the bound state.

Returns:
true if bound, otherwise false.

getContextToolFilter

protected ContextToolFilter getContextToolFilter()
Gets the context tool filter if available.

Returns:
the context tool filter or null.


Copyright © 2004 The Norther Organization. All rights reserved.