com.go.tea.runtime
Interface Context

All Superinterfaces:
OutputReceiver
All Known Subinterfaces:
AdminHttpContext, HttpContext, UtilityContext

public interface Context
extends OutputReceiver

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

Version:
41 , 01/04/19
Author:
Brian S O'Neill
See Also:
Compiler.getRuntimeContext(), DefaultContext

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

Method Detail

print

public void print(java.lang.Object obj)
           throws java.lang.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
See Also:
Compiler.getRuntimeReceiver()

print

public void print(java.util.Date date)
           throws java.lang.Exception

print

public void print(java.lang.Number n)
           throws java.lang.Exception

print

public void print(int n)
           throws java.lang.Exception

print

public void print(float n)
           throws java.lang.Exception

print

public void print(long n)
           throws java.lang.Exception

print

public void print(double n)
           throws java.lang.Exception

toString

public java.lang.String toString(java.lang.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

public java.lang.String toString(java.lang.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

public java.lang.String toString(java.util.Date date)
A function that converts a date to a string, using the current date format.
See Also:
Compiler.getRuntimeStringConverter()

toString

public java.lang.String toString(java.lang.Number n)
A function that converts a number to a string, using the current number format.
See Also:
Compiler.getRuntimeStringConverter()

toString

public java.lang.String toString(int n)
A function that converts a number to a string, using the current number format.
See Also:
Compiler.getRuntimeStringConverter()

toString

public java.lang.String toString(float n)
A function that converts a number to a string, using the current number format.
See Also:
Compiler.getRuntimeStringConverter()

toString

public java.lang.String toString(long n)
A function that converts a number to a string, using the current number format.
See Also:
Compiler.getRuntimeStringConverter()

toString

public java.lang.String toString(double n)
A function that converts a number to a string, using the current number format.
See Also:
Compiler.getRuntimeStringConverter()

setLocale

public void setLocale(java.util.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

public void setLocale(java.lang.String language,
                      java.lang.String country)
Setting the locale resets date and number formats to the default for that locale.
Parameters:
language - language code
country - country code

setLocale

public void setLocale(java.lang.String language,
                      java.lang.String country,
                      java.lang.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

public java.util.Locale getLocale()
Returns the current locale setting.

getAvailableLocales

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

nullFormat

public void nullFormat(java.lang.String format)
A function that sets the formatted value of null object references.
Parameters:
format - string to print in place of "null".

getNullFormat

public java.lang.String getNullFormat()
Returns the current null format specification.

dateFormat

public void dateFormat(java.lang.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

public void dateFormat(java.lang.String format,
                       java.lang.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

public java.lang.String getDateFormat()
Returns the current date format specification.

getDateFormatTimeZone

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

getAvailableTimeZones

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

numberFormat

public void numberFormat(java.lang.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

public void numberFormat(java.lang.String format,
                         java.lang.String infinity,
                         java.lang.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

public java.lang.String getNumberFormat()
Returns the current number format specification.

getNumberFormatInfinity

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

getNumberFormatNaN

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