org.teatrove.tea.runtime
Interface Context

All Superinterfaces:
OutputReceiver
All Known Subinterfaces:
UtilityContext
All Known Implementing Classes:
DefaultContext, TestCompiler.Context

public interface Context
extends OutputReceiver

Interface establishes basic printing and formatting functions for a template runtime context.

Author:
Brian S O'Neill
See Also:
Compiler.getRuntimeContext(), DefaultContext

Method Summary
 void dateFormat(String format)
          Defines a format to use when printing dates from templates.
 void dateFormat(String format, String timeZoneID)
          A function that sets the formatted value of dates.
 Locale[] getAvailableLocales()
          Returns a list of all the available locales.
 TimeZone[] getAvailableTimeZones()
          Returns a list of all the available time zones.
 String getDateFormat()
          Returns the current date format specification.
 String getDateFormatTimeZone()
          Returns the current date format time zone.
 Locale getLocale()
          Returns the current locale setting.
 String getNullFormat()
          Returns the current null format specification.
 String getNumberFormat()
          Returns the current number format specification.
 String getNumberFormatInfinity()
          Returns the current number format for infinity.
 String getNumberFormatNaN()
          Returns the current number format for NaN.
 void nullFormat(String format)
          A function that sets the formatted value of null object references.
 void numberFormat(String format)
          A function that sets the formatted value of numbers.
 void numberFormat(String format, String infinity, String NaN)
          A function that sets the formatted value of numbers.
 void print(Date date)
           
 void print(double n)
           
 void print(float n)
           
 void print(int n)
           
 void print(long n)
           
 void print(Number n)
           
 void print(Object obj)
          Method that is the runtime receiver.
 void print(org.joda.time.ReadableInstant instant)
           
 void setLocale(Locale locale)
          Setting the locale resets date and number formats to the default for that locale.
 void setLocale(String language, String country)
          Setting the locale resets date and number formats to the default for that locale.
 void setLocale(String language, String country, String variant)
          Setting the locale resets date and number formats to the default for that locale.
 String toString(Date date)
          A function that converts a date to a string, using the current datetime format.
 String toString(double n)
          A function that converts a number to a string, using the current number format.
 String toString(float n)
          A function that converts a number to a string, using the current number format.
 String toString(int n)
          A function that converts a number to a string, using the current number format.
 String toString(long n)
          A function that converts a number to a string, using the current number format.
 String toString(Number n)
          A function that converts a number to a string, using the current number format.
 String toString(Object obj)
          A function that converts an object to a string, applying any applicable formatting settings.
 String toString(org.joda.time.ReadableInstant instant)
          A function that converts an instant in time to a string, using the current datetime format.
 String toString(String str)
          A function that converts a string to the null format string if it is null.
 
Methods inherited from interface org.teatrove.tea.runtime.OutputReceiver
write, write, write, write, write
 

Method Detail

print

void print(Object obj)
           throws Exception
Method that is the runtime receiver. Implementations should call one of the toString methods when converting this object to a string.

NOTE: This method should not be called directly within a template.

Specified by:
print in interface OutputReceiver
Throws:
Exception
See Also:
Compiler.getRuntimeReceiver()

print

void print(Date date)
           throws Exception
Throws:
Exception

print

void print(org.joda.time.ReadableInstant instant)
           throws Exception
Throws:
Exception

print

void print(Number n)
           throws Exception
Throws:
Exception

print

void print(int n)
           throws Exception
Throws:
Exception

print

void print(float n)
           throws Exception
Throws:
Exception

print

void print(long n)
           throws Exception
Throws:
Exception

print

void print(double n)
           throws Exception
Throws:
Exception

toString

String toString(Object obj)
A function that converts an object to a string, applying any applicable formatting settings. The returned String is never null.

See Also:
Compiler.getRuntimeStringConverter()

toString

String toString(String str)
A function that converts a string to the null format string if it is null. Otherwise, it is returned unchanged.

See Also:
Compiler.getRuntimeStringConverter()

toString

String toString(Date date)
A function that converts a date to a string, using the current datetime format.

See Also:
Compiler.getRuntimeStringConverter()

toString

String toString(org.joda.time.ReadableInstant instant)
A function that converts an instant in time to a string, using the current datetime format.

See Also:
Compiler.getRuntimeStringConverter()

toString

String toString(Number n)
A function that converts a number to a string, using the current number format.

See Also:
Compiler.getRuntimeStringConverter()

toString

String toString(int n)
A function that converts a number to a string, using the current number format.

See Also:
Compiler.getRuntimeStringConverter()

toString

String toString(float n)
A function that converts a number to a string, using the current number format.

See Also:
Compiler.getRuntimeStringConverter()

toString

String toString(long n)
A function that converts a number to a string, using the current number format.

See Also:
Compiler.getRuntimeStringConverter()

toString

String toString(double n)
A function that converts a number to a string, using the current number format.

See Also:
Compiler.getRuntimeStringConverter()

setLocale

void setLocale(Locale locale)
Setting the locale resets date and number formats to the default for that locale. Setting a locale of null resets date and number formats to the system defaults.

See getAvailableLocales to get all the available language, country and variant codes.

Parameters:
locale - pre-constructed locale object

setLocale

void setLocale(String language,
               String country)
Setting the locale resets date and number formats to the default for that locale.

Parameters:
language - language code
country - country code

setLocale

void setLocale(String language,
               String country,
               String variant)
Setting the locale resets date and number formats to the default for that locale.

Parameters:
language - language code
country - country code
variant - optional variant code

getLocale

Locale getLocale()
Returns the current locale setting.


getAvailableLocales

Locale[] getAvailableLocales()
Returns a list of all the available locales.


nullFormat

void nullFormat(String format)
A function that sets the formatted value of null object references.

Parameters:
format - string to print in place of "null".

getNullFormat

String getNullFormat()
Returns the current null format specification.


dateFormat

void dateFormat(String format)
Defines a format to use when printing dates from templates. Passing null sets the format back to the default.

Time Format Syntax:

To specify the time format use a time pattern string. In this pattern, all ASCII letters are reserved as pattern letters, which are defined as the following:

 
 Symbol   Meaning                 Presentation        Example 
 ------   -------                 ------------        ------- 
 G        era designator          (Text)              AD 
 y        year                    (Number)            1996 
 M        month in year           (Text & Number)     July & 07 
 d        day in month            (Number)            10 
 h        hour in am/pm (1~12)    (Number)            12 
 H        hour in day (0~23)      (Number)            0 
 m        minute in hour          (Number)            30 
 s        second in minute        (Number)            55 
 S        millisecond             (Number)            978 
 E        day in week             (Text)              Tuesday 
 D        day in year             (Number)            189 
 F        day of week in month    (Number)            2 (2nd Wed in July)
 w        week in year            (Number)            27 
 W        week in month           (Number)            2 
 a        am/pm marker            (Text)              PM 
 k        hour in day (1~24)      (Number)            24 
 K        hour in am/pm (0~11)    (Number)            0 
 z        time zone               (Text)              Pacific Standard Time 
 '        escape for text         (Delimiter) 
 ''       single quote            (Literal)           ' 
 
The count of pattern letters determine the format.

(Text): 4 or more pattern letters--use full form, less than 4--use short or abbreviated form if one exists.

(Number): the minimum number of digits. Shorter numbers are zero-padded to this amount. Year is handled specially; that is, if the count of 'y' is 2, the Year will be truncated to 2 digits.

(Text & Number): 3 or over, use text, otherwise use number.

Any characters in the pattern that are not in the ranges of ['a'..'z'] and ['A'..'Z'] will be treated as quoted text. For instance, characters like ':', '.', ' ', '#' and '@' will appear in the resulting time text even they are not embraced within single quotes.

A pattern containing any invalid pattern letter will result in a thrown exception during formatting or parsing.

Examples:

 
 Format Pattern                         Result 
 --------------                         ------- 
 "yyyy.MM.dd G 'at' hh:mm:ss z"    ->>  1996.07.10 AD at 15:08:56 PDT 
 "EEE, MMM d, ''yy"                ->>  Wed, July 10, '96 
 "h:mm a"                          ->>  12:08 PM 
 "hh 'o''clock' a, zzzz"           ->>  12 o'clock PM, Pacific Daylight Time 
 "K:mm a, z"                       ->>  0:00 PM, PST 
 "yyyyy.MMMMM.dd GGG hh:mm aaa"    ->>  1996.July.10 AD 12:08 PM 
 

Parameters:
format - date format specification string

dateFormat

void dateFormat(String format,
                String timeZoneID)
A function that sets the formatted value of dates.

Parameters:
format - date format specification string
timeZoneID - time zone ID, i.e. "PST"

getDateFormat

String getDateFormat()
Returns the current date format specification.


getDateFormatTimeZone

String getDateFormatTimeZone()
Returns the current date format time zone.


getAvailableTimeZones

TimeZone[] getAvailableTimeZones()
Returns a list of all the available time zones.


numberFormat

void numberFormat(String format)
A function that sets the formatted value of numbers. Defines a format to use when printing numbers from templates. Passing null sets the format back to the default. The format string is of the form "#.#".

Here are the special characters used in the parts of the format string, with notes on their usage.

 
 Symbol   Meaning 
 ------   ------- 
 0        a digit 
 #        a digit, zero shows as absent 
 .        placeholder for decimal separator. 
 ,        placeholder for grouping separator. 
 ;        separates formats. 
 -        default negative prefix. 
 %        multiply by 100 and show as percentage 
 ?        multiply by 1000 and show as per mille 
 ¤        currency sign; replaced by currency symbol;
          if doubled, replaced by international currency 
          symbol. If present in a pattern, the monetary
          decimal separator is used instead of the decimal 
          separator. (Unicode escape is \\u00a4) 
 X        any other characters can be used in the prefix or suffix 
 '        used to quote special characters in a prefix or suffix. 
 

Parameters:
format - number format specification string

numberFormat

void numberFormat(String format,
                  String infinity,
                  String NaN)
A function that sets the formatted value of numbers. Defines a format to use when printing numbers from templates. Passing null sets the format back to the default. The format string is of the form "#.#".

Here are the special characters used in the parts of the format string, with notes on their usage.

 
 Symbol   Meaning 
 ------   ------- 
 0        a digit 
 #        a digit, zero shows as absent 
 .        placeholder for decimal separator. 
 ,        placeholder for grouping separator. 
 ;        separates formats. 
 -        default negative prefix. 
 %        multiply by 100 and show as percentage 
 ?        multiply by 1000 and show as per mille 
 ¤        currency sign; replaced by currency symbol;
          if doubled, replaced by international currency 
          symbol. If present in a pattern, the monetary
          decimal separator is used instead of the decimal 
          separator. (Unicode escape is \\u00a4) 
 X        any other characters can be used in the prefix or suffix 
 '        used to quote special characters in a prefix or suffix. 
 

Parameters:
format - number format specification string
infinity - display string for infinity
NaN - display string for not-a-number, resulting from zero divided by zero.

getNumberFormat

String getNumberFormat()
Returns the current number format specification.


getNumberFormatInfinity

String getNumberFormatInfinity()
Returns the current number format for infinity.


getNumberFormatNaN

String getNumberFormatNaN()
Returns the current number format for NaN.



Copyright © 1997-2012 TeaTrove.org. All Rights Reserved.