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.

Version:
$Id: FormatTool.java,v 1.22 2009/10/28 10:52:06 cvsimp Exp $
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(Date date, String... style)
          Formats the specified date.
 String formatDateTime(Date date, String... style)
          Formats the specified date and time.
 String formatError(Throwable error)
          Formats an error.
 String formatObject(Object object, String... pattern)
          Formats an object.
 String formatString(String string, List<?> arguments)
          Formats a string with arguments.
 String formatTime(Date time, String... style)
          Formats the specified time.
 Calendar getCalendar()
          Gets a calendar.
protected  TemplateContext getContext()
          Gets the target context.
protected  ContextToolFilter getContextToolFilter()
          Gets the context tool filter if available.
 String getDefaultDatePattern(String className, String pattern)
          Gets a class specific default date format pattern.
 Locale getDefaultLocale()
          Gets the default locale.
protected  int getEncodingSize()
          Gets the encoding size.
 String getExcelDatePattern(String className, String pattern)
          Gets a class specific Excel date format pattern.
protected
<F extends Filter>
F
getFilter(Class<F> clazz)
          Gets the first specific filter from the filter chain.
protected  HttpFilterChain getFilterChain()
          Gets the current filter chain if available.
protected
<F extends KeyFilter>
String
getFilterKey(Class<F> clazz)
          Gets the key of the first specific key filter from the filter chain.
 int getFirstDayOfWeek()
          Gets the first day of a week.
 String getLocalizedDatePattern(String className, String pattern)
          Gets a class specific localized date format pattern.
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.
 long getTime()
          Gets the current time in msecs.
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<? extends Pool> 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, formatDateTime, formatDateTime, formatNumber, formatPercent, formatString, formatTime, formatTime, getCurrencyFormat, getDateFormat, getDateFormat, getLocale, getMBeanServer, getNumberFormat, getNumberFormat, getObject, getObject, getPercentFormat, getString, getString, parseDate, parseDateTime, parseDouble, parseDouble, parseInt, parseInt, parseLong, parseLong, parseTime, 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<? extends Pool> 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(Date date,
                         String... style)
Description copied from class: Formatter
Formats the specified date.

Overrides:
formatDate in class Formatter
Parameters:
date - the date.
style - the style and timezone.
Returns:
the formatted date.

formatTime

public String formatTime(Date time,
                         String... style)
Description copied from class: Formatter
Formats the specified time.

Overrides:
formatTime in class Formatter
Parameters:
time - the time.
style - the style and timezone.
Returns:
the formatted time.

formatDateTime

public String formatDateTime(Date date,
                             String... style)
Description copied from class: Formatter
Formats the specified date and time.

Overrides:
formatDateTime in class Formatter
Parameters:
date - the date and time.
style - date style, time style and 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.

formatObject

public String formatObject(Object object,
                           String... pattern)
Description copied from class: Formatter
Formats an object.

Overrides:
formatObject in class Formatter
Parameters:
object - the object to format.
pattern - the format pattern and a base name.
Returns:
the formatted object.

getDefaultLocale

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

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

getDefaultDatePattern

public String getDefaultDatePattern(String className,
                                    String pattern)
Gets a class specific default date format pattern.

Parameters:
className - the date class name.
pattern - the conversion pattern.
Returns:
the default format pattern.

getLocalizedDatePattern

public String getLocalizedDatePattern(String className,
                                      String pattern)
Gets a class specific localized date format pattern.

Parameters:
className - the date class name.
pattern - the conversion pattern.
Returns:
the localized format pattern.

getExcelDatePattern

public String getExcelDatePattern(String className,
                                  String pattern)
Gets a class specific Excel date format pattern.

Parameters:
className - the date class name.
pattern - the conversion pattern.
Returns:
the Excel format pattern.

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.

getTime

public long getTime()
Gets the current time in msecs.

Returns:
the msecs.

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 <F extends Filter> F getFilter(Class<F> clazz)
Gets the first specific filter from the filter chain.

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

getFilterKey

protected <F extends KeyFilter> String getFilterKey(Class<F> clazz)
Gets the key of the first specific key filter from the filter chain.

Type Parameters:
F - the filter type.
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.

getEncodingSize

protected int getEncodingSize()
Gets the encoding size.

Returns:
the size or -1.

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.