|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object | +--com.go.tea.runtime.DefaultContext
The default runtime context class that Tea templates get compiled to use. All functions callable from a template are defined in the context. To add more or override existing ones, do so when extending this class.
| Constructor Summary | |
DefaultContext()
|
|
| Method Summary | |
java.lang.String |
cardinal(long n)
A function that converts an integer to a cardinal value. |
java.lang.String |
cardinal(java.lang.Long n)
A function that converts an integer to a cardinal value. |
java.util.Date |
currentDate()
Returns a Date object with the current date and time. |
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. |
boolean |
endsWith(java.lang.String str,
java.lang.String suffix)
Tests if the given string ends with the given suffix. |
int[] |
find(java.lang.String str,
java.lang.String search)
Finds the indices for each occurrence of the given search string in the source string. |
int[] |
find(java.lang.String str,
java.lang.String search,
int fromIndex)
Finds the indices for each occurrence of the given search string in the source string, starting from the given index. |
int |
findFirst(java.lang.String str,
java.lang.String search)
Finds the index of the first occurrence of the given search string in the source string, or -1 if not found. |
int |
findFirst(java.lang.String str,
java.lang.String search,
int fromIndex)
Finds the index of the first occurrence of the given search string in the source string, starting from the given index, or -1 if not found. |
int |
findLast(java.lang.String str,
java.lang.String search)
Finds the index of the last occurrence of the given search string in the source string, or -1 if not found. |
int |
findLast(java.lang.String str,
java.lang.String search,
int fromIndex)
Finds the index of the last occurrence of the given search string in the source string, starting from the given index, or -1 if not found. |
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. |
java.lang.String |
ordinal(long n)
A function that converts an integer to an ordinal value. |
java.lang.String |
ordinal(java.lang.Long n)
A function that converts an integer to an ordinal value. |
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)
|
abstract void |
print(java.lang.Object obj)
Method that is the runtime receiver. |
java.lang.String |
replace(java.lang.String source,
java.util.Map patternReplacements)
Applies string replacements using the pattern-replacement pairs provided by the given map (associative array). |
java.lang.String |
replace(java.lang.String source,
java.lang.String pattern,
java.lang.String replacement)
Replaces all exact matches of the given pattern in the source string with the provided replacement. |
java.lang.String |
replace(java.lang.String source,
java.lang.String pattern,
java.lang.String replacement,
int fromIndex)
Replaces all exact matches of the given pattern in the source string with the provided replacement, starting from the given index. |
java.lang.String |
replaceFirst(java.lang.String source,
java.lang.String pattern,
java.lang.String replacement)
Replaces the first exact match of the given pattern in the source string with the provided replacement. |
java.lang.String |
replaceFirst(java.lang.String source,
java.lang.String pattern,
java.lang.String replacement,
int fromIndex)
Replaces the first exact match of the given pattern in the source string with the provided replacement, starting from the given index. |
java.lang.String |
replaceLast(java.lang.String source,
java.lang.String pattern,
java.lang.String replacement)
Replaces the last exact match of the given pattern in the source string with the provided replacement. |
java.lang.String |
replaceLast(java.lang.String source,
java.lang.String pattern,
java.lang.String replacement,
int fromIndex)
Replaces the last exact match of the given pattern in the source string with the provided replacement, starting from the given index. |
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 |
shortOrdinal(long n)
A function that converts an integer to a short ordinal value. |
java.lang.String |
shortOrdinal(java.lang.Long n)
A function that converts an integer to a short ordinal value. |
boolean |
startsWith(java.lang.String str,
java.lang.String prefix)
Tests if the given string starts with the given prefix. |
java.lang.String |
substring(java.lang.String str,
int startIndex)
Returns the trailing end of the given string, starting from the given index. |
java.lang.String |
substring(java.lang.String str,
int startIndex,
int endIndex)
Returns a sub-portion of the given string for the characters that are at or after the starting index, and are before the end index. |
java.lang.String |
toLowerCase(java.lang.String str)
Converts all the characters in the given string to lowercase. |
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. |
java.lang.String |
toUpperCase(java.lang.String str)
Converts all the characters in the given string to uppercase. |
java.lang.String |
trim(java.lang.String str)
Trims all leading and trailing whitespace characters from the given string. |
java.lang.String |
trimLeading(java.lang.String str)
Trims all leading whitespace characters from the given string. |
java.lang.String |
trimTrailing(java.lang.String str)
Trims all trailing whitespace characters from the given string. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
public DefaultContext()
| Method Detail |
public abstract void print(java.lang.Object obj)
throws java.lang.Exception
NOTE: This method should not be called directly within a template.
print in interface ContextCompiler.getRuntimeReceiver()
public void print(java.util.Date date)
throws java.lang.Exception
print in interface Context
public void print(java.lang.Number n)
throws java.lang.Exception
print in interface Context
public void print(int n)
throws java.lang.Exception
print in interface Context
public void print(float n)
throws java.lang.Exception
print in interface Context
public void print(long n)
throws java.lang.Exception
print in interface Context
public void print(double n)
throws java.lang.Exception
print in interface Contextpublic java.lang.String toString(java.lang.Object obj)
ContexttoString in interface Contextcom.go.tea.runtime.ContextCompiler.getRuntimeStringConverter()public java.lang.String toString(java.lang.String str)
ContexttoString in interface Contextcom.go.tea.runtime.ContextCompiler.getRuntimeStringConverter()public java.lang.String toString(java.util.Date date)
ContexttoString in interface Contextcom.go.tea.runtime.ContextCompiler.getRuntimeStringConverter()public java.lang.String toString(java.lang.Number n)
ContexttoString in interface Contextcom.go.tea.runtime.ContextCompiler.getRuntimeStringConverter()public java.lang.String toString(int n)
ContexttoString in interface Contextcom.go.tea.runtime.ContextCompiler.getRuntimeStringConverter()public java.lang.String toString(float n)
ContexttoString in interface Contextcom.go.tea.runtime.ContextCompiler.getRuntimeStringConverter()public java.lang.String toString(long n)
ContexttoString in interface Contextcom.go.tea.runtime.ContextCompiler.getRuntimeStringConverter()public java.lang.String toString(double n)
ContexttoString in interface Contextcom.go.tea.runtime.ContextCompiler.getRuntimeStringConverter()public void setLocale(java.util.Locale locale)
ContextSee getAvailableLocales to get all the available language, country and variant codes.
setLocale in interface Contextcom.go.tea.runtime.Contextlocale - pre-constructed locale object
public void setLocale(java.lang.String language,
java.lang.String country)
ContextsetLocale in interface Contextcom.go.tea.runtime.Contextlanguage - language codecountry - country code
public void setLocale(java.lang.String language,
java.lang.String country,
java.lang.String variant)
ContextsetLocale in interface Contextcom.go.tea.runtime.Contextlanguage - language codecountry - country codevariant - optional variant codepublic java.util.Locale getLocale()
ContextgetLocale in interface Contextpublic java.util.Locale[] getAvailableLocales()
ContextgetAvailableLocales in interface Contextpublic void nullFormat(java.lang.String format)
ContextnullFormat in interface Contextcom.go.tea.runtime.Contextformat - string to print in place of "null".public java.lang.String getNullFormat()
ContextgetNullFormat in interface Contextpublic void dateFormat(java.lang.String format)
ContextTime 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:
The count of pattern letters determine the format.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) '
(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
dateFormat in interface Contextcom.go.tea.runtime.Contextformat - date format specification string
public void dateFormat(java.lang.String format,
java.lang.String timeZoneID)
ContextdateFormat in interface Contextcom.go.tea.runtime.Contextformat - date format specification stringtimeZoneID - time zone ID, i.e. "PST"public java.lang.String getDateFormat()
ContextgetDateFormat in interface Contextpublic java.lang.String getDateFormatTimeZone()
ContextgetDateFormatTimeZone in interface Contextpublic java.util.TimeZone[] getAvailableTimeZones()
ContextgetAvailableTimeZones in interface Contextpublic void numberFormat(java.lang.String format)
ContextHere 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.
numberFormat in interface Contextcom.go.tea.runtime.Contextformat - number format specification string
public void numberFormat(java.lang.String format,
java.lang.String infinity,
java.lang.String NaN)
ContextHere 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.
numberFormat in interface Contextcom.go.tea.runtime.Contextformat - number format specification stringinfinity - display string for infinityNaN - display string for not-a-number, resulting from zero divided
by zero.public java.lang.String getNumberFormat()
ContextgetNumberFormat in interface Contextpublic java.lang.String getNumberFormatInfinity()
ContextgetNumberFormatInfinity in interface Contextpublic java.lang.String getNumberFormatNaN()
ContextgetNumberFormatNaN in interface Contextpublic java.util.Date currentDate()
UtilityContextcurrentDate in interface UtilityContext
public boolean startsWith(java.lang.String str,
java.lang.String prefix)
UtilityContextstartsWith in interface UtilityContextcom.go.tea.runtime.UtilityContextstr - the source stringprefix - the prefix to test for
public boolean endsWith(java.lang.String str,
java.lang.String suffix)
UtilityContextendsWith in interface UtilityContextcom.go.tea.runtime.UtilityContextstr - the source stringsuffix - the suffix to test for
public int[] find(java.lang.String str,
java.lang.String search)
UtilityContextfind in interface UtilityContextcom.go.tea.runtime.UtilityContextstr - the source stringsearch - the string to search for
public int[] find(java.lang.String str,
java.lang.String search,
int fromIndex)
UtilityContextfind in interface UtilityContextcom.go.tea.runtime.UtilityContextstr - the source stringsearch - the string to search forfromIndex - index to start the find
public int findFirst(java.lang.String str,
java.lang.String search)
UtilityContextfindFirst in interface UtilityContextcom.go.tea.runtime.UtilityContextstr - the source stringsearch - the string to search for
public int findFirst(java.lang.String str,
java.lang.String search,
int fromIndex)
UtilityContextfindFirst in interface UtilityContextcom.go.tea.runtime.UtilityContextstr - the source stringsearch - the string to search forfromIndex - index to start the find
public int findLast(java.lang.String str,
java.lang.String search)
UtilityContextfindLast in interface UtilityContextcom.go.tea.runtime.UtilityContextstr - the source stringsearch - the string to search for
public int findLast(java.lang.String str,
java.lang.String search,
int fromIndex)
UtilityContextfindLast in interface UtilityContextcom.go.tea.runtime.UtilityContextstr - the source stringsearch - the string to search forfromIndex - optional index to start the find
public java.lang.String substring(java.lang.String str,
int startIndex)
UtilityContextsubstring in interface UtilityContextcom.go.tea.runtime.UtilityContextstr - the source stringstartIndex - the start index, inclusive
public java.lang.String substring(java.lang.String str,
int startIndex,
int endIndex)
UtilityContextsubstring in interface UtilityContextcom.go.tea.runtime.UtilityContextstr - the source stringstartIndex - the start index, inclusiveendIndex - the ending index, exclusivepublic java.lang.String toLowerCase(java.lang.String str)
UtilityContexttoLowerCase in interface UtilityContextcom.go.tea.runtime.UtilityContextstr - the string to convertpublic java.lang.String toUpperCase(java.lang.String str)
UtilityContexttoUpperCase in interface UtilityContextcom.go.tea.runtime.UtilityContextstr - the string to convertpublic java.lang.String trim(java.lang.String str)
UtilityContexttrim in interface UtilityContextcom.go.tea.runtime.UtilityContextstr - the string to trimpublic java.lang.String trimLeading(java.lang.String str)
UtilityContexttrimLeading in interface UtilityContextcom.go.tea.runtime.UtilityContextstr - the string to trimpublic java.lang.String trimTrailing(java.lang.String str)
UtilityContexttrimTrailing in interface UtilityContextcom.go.tea.runtime.UtilityContextstr - the string to trim
public java.lang.String replace(java.lang.String source,
java.lang.String pattern,
java.lang.String replacement)
UtilityContextreplace in interface UtilityContextcom.go.tea.runtime.UtilityContextsource - the source stringpattern - the simple string pattern to search forreplacement - the string to use for replacing matched patterns.
public java.lang.String replace(java.lang.String source,
java.lang.String pattern,
java.lang.String replacement,
int fromIndex)
UtilityContextreplace in interface UtilityContextcom.go.tea.runtime.UtilityContextsource - the source stringpattern - the simple string pattern to search forreplacement - the string to use for replacing matched patterns.fromIndex - index to start the replace
public java.lang.String replace(java.lang.String source,
java.util.Map patternReplacements)
UtilityContextreplace in interface UtilityContextcom.go.tea.runtime.UtilityContextsource - the source stringpatternReplacements - pattern-replacement pairs
public java.lang.String replaceFirst(java.lang.String source,
java.lang.String pattern,
java.lang.String replacement)
UtilityContextreplaceFirst in interface UtilityContextcom.go.tea.runtime.UtilityContextsource - the source stringpattern - the simple string pattern to search forreplacement - the string to use for replacing matched patterns
public java.lang.String replaceFirst(java.lang.String source,
java.lang.String pattern,
java.lang.String replacement,
int fromIndex)
UtilityContextreplaceFirst in interface UtilityContextcom.go.tea.runtime.UtilityContextsource - the source stringpattern - the simple string pattern to search forreplacement - the string to use for replacing matched patternsfromIndex - index to start the replace
public java.lang.String replaceLast(java.lang.String source,
java.lang.String pattern,
java.lang.String replacement)
UtilityContextreplaceLast in interface UtilityContextcom.go.tea.runtime.UtilityContextsource - the source stringpattern - the simple string pattern to search forreplacement - the string to use for replacing matched patterns
public java.lang.String replaceLast(java.lang.String source,
java.lang.String pattern,
java.lang.String replacement,
int fromIndex)
UtilityContextreplaceLast in interface UtilityContextcom.go.tea.runtime.UtilityContextsource - the source stringpattern - the simple string pattern to search forreplacement - the string to use for replacing matched patternsfromIndex - index to start the replacepublic java.lang.String shortOrdinal(java.lang.Long n)
UtilityContextshortOrdinal in interface UtilityContextcom.go.tea.runtime.UtilityContextn - the number to convertpublic java.lang.String shortOrdinal(long n)
UtilityContextshortOrdinal in interface UtilityContextcom.go.tea.runtime.UtilityContextn - the number to convertpublic java.lang.String ordinal(java.lang.Long n)
UtilityContextordinal in interface UtilityContextcom.go.tea.runtime.UtilityContextn - the number to convertpublic java.lang.String ordinal(long n)
UtilityContextordinal in interface UtilityContextcom.go.tea.runtime.UtilityContextn - the number to convertpublic java.lang.String cardinal(java.lang.Long n)
UtilityContextcardinal in interface UtilityContextcom.go.tea.runtime.UtilityContextn - the number to convertpublic java.lang.String cardinal(long n)
UtilityContextcardinal in interface UtilityContextcom.go.tea.runtime.UtilityContextn - the number to convert
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||