|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.io.Writer
org.teatrove.tea.runtime.DefaultContext
public abstract class 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.
| Nested Class Summary | |
|---|---|
static class |
DefaultContext.GenericComparator
|
static class |
DefaultContext.StringComparator
|
| Field Summary |
|---|
| Fields inherited from class java.io.Writer |
|---|
lock |
| Constructor Summary | |
|---|---|
DefaultContext()
|
|
| Method Summary | ||
|---|---|---|
void |
append(StringBuilder buffer,
Object value)
A function to append a value to an existing buffer. |
|
String |
cardinal(long n)
A function that converts an integer to a cardinal value. |
|
String |
cardinal(Long n)
A function that converts an integer to a cardinal value. |
|
void |
close()
|
|
StringBuilder |
createStringBuilder()
A function that creates a string builder to allow programs to perform concatenation and pass around strings. |
|
StringBuilder |
createStringBuilder(int size)
A function that creates a string builder to allow programs to perform concatenation and pass around strings. |
|
Date |
currentDate()
Returns a standard Java Date object with the current date and time. |
|
org.joda.time.DateTime |
currentDateTime()
Returns a Joda DateTime object with the current date and time. |
|
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. |
|
boolean |
endsWith(String str,
String suffix)
Tests if the given string ends with the given suffix. |
|
int[] |
find(String str,
String search)
Finds the indices for each occurrence of the given search string in the source string. |
|
int[] |
find(String str,
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(String str,
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(String str,
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(String str,
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(String str,
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. |
|
void |
flush()
|
|
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 |
insert(StringBuilder buffer,
Object value,
int index)
A function to insert a value into an existing buffer. |
|
boolean |
isArray(Object o)
A function that checks if an object is an Array |
|
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. |
|
String |
ordinal(long n)
A function that converts an integer to an ordinal value. |
|
String |
ordinal(Long n)
A function that converts an integer to an ordinal value. |
|
void |
prepend(StringBuilder buffer,
Object value)
A function to prepend a value to an existing buffer. |
|
void |
print(Date date)
|
|
void |
print(double n)
|
|
void |
print(float n)
|
|
void |
print(int n)
|
|
void |
print(long n)
|
|
void |
print(Number n)
|
|
abstract void |
print(Object obj)
Method that is the runtime receiver. |
|
void |
print(org.joda.time.ReadableInstant instant)
|
|
|
replace(String source,
Map<K,V> patternReplacements)
Applies string replacements using the pattern-replacement pairs provided by the given map (associative array). |
|
String |
replace(String source,
String pattern,
String replacement)
Replaces all exact matches of the given pattern in the source string with the provided replacement. |
|
String |
replace(String source,
String pattern,
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. |
|
String |
replaceFirst(String source,
String pattern,
String replacement)
Replaces the first exact match of the given pattern in the source string with the provided replacement. |
|
String |
replaceFirst(String source,
String pattern,
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. |
|
String |
replaceLast(String source,
String pattern,
String replacement)
Replaces the last exact match of the given pattern in the source string with the provided replacement. |
|
String |
replaceLast(String source,
String pattern,
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(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 |
shortOrdinal(long n)
A function that converts an integer to a short ordinal value. |
|
String |
shortOrdinal(Long n)
A function that converts an integer to a short ordinal value. |
|
void |
sort(Object[] array,
boolean sortAscending)
|
|
void |
sort(Object[] array,
String[] onColumns,
boolean[] reverse)
|
|
void |
sort(Object[] array,
String onColumn,
boolean reverse)
|
|
void |
sort(String[] array,
boolean reverse,
boolean ignoreCase)
|
|
void |
sortAscending(byte[] array)
|
|
void |
sortAscending(double[] array)
|
|
void |
sortAscending(float[] array)
|
|
void |
sortAscending(int[] array)
|
|
void |
sortAscending(long[] array)
|
|
void |
sortAscending(Object[] array)
|
|
void |
sortAscending(short[] array)
|
|
String[] |
split(String str,
String regex)
|
|
boolean |
startsWith(String str,
String prefix)
Tests if the given string starts with the given prefix. |
|
String |
substring(String str,
int startIndex)
Returns the trailing end of the given string, starting from the given index. |
|
String |
substring(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. |
|
String |
toLowerCase(String str)
Converts all the characters in the given string to lowercase. |
|
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. |
|
String |
toString(StringBuilder buffer)
A function to convert the buffer into a standard string. |
|
String |
toUpperCase(String str)
Converts all the characters in the given string to uppercase. |
|
String |
trim(String str)
Trims all leading and trailing whitespace characters from the given string. |
|
String |
trimLeading(String str)
Trims all leading whitespace characters from the given string. |
|
String |
trimTrailing(String str)
Trims all trailing whitespace characters from the given string. |
|
void |
write(char[] cbuf,
int off,
int len)
|
|
void |
write(int c)
|
|
| Methods inherited from class java.io.Writer |
|---|
append, append, append, write, write, write |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Methods inherited from interface org.teatrove.tea.runtime.OutputReceiver |
|---|
write, write, write |
| Constructor Detail |
|---|
public DefaultContext()
| Method Detail |
|---|
public void write(int c)
throws IOException
write in interface OutputReceiverwrite in class WriterIOException
public void write(char[] cbuf,
int off,
int len)
throws IOException
write in interface OutputReceiverwrite in class WriterIOException
public void flush()
throws IOException
flush in interface Flushableflush in class WriterIOException
public void close()
throws IOException
close in interface Closeableclose in class WriterIOException
public abstract void print(Object obj)
throws Exception
NOTE: This method should not be called directly within a template.
print in interface Contextprint in interface OutputReceiverExceptionCompiler.getRuntimeReceiver()
public void print(Date date)
throws Exception
print in interface ContextException
public void print(org.joda.time.ReadableInstant instant)
throws Exception
print in interface ContextException
public void print(Number n)
throws Exception
print in interface ContextException
public void print(int n)
throws Exception
print in interface ContextException
public void print(float n)
throws Exception
print in interface ContextException
public void print(long n)
throws Exception
print in interface ContextException
public void print(double n)
throws Exception
print in interface ContextExceptionpublic String toString(Object obj)
Context
toString in interface ContextCompiler.getRuntimeStringConverter()public String toString(String str)
Context
toString in interface ContextCompiler.getRuntimeStringConverter()public String toString(Date date)
Context
toString in interface ContextCompiler.getRuntimeStringConverter()public String toString(org.joda.time.ReadableInstant instant)
Context
toString in interface ContextCompiler.getRuntimeStringConverter()public String toString(Number n)
Context
toString in interface ContextCompiler.getRuntimeStringConverter()public String toString(int n)
Context
toString in interface ContextCompiler.getRuntimeStringConverter()public String toString(float n)
Context
toString in interface ContextCompiler.getRuntimeStringConverter()public String toString(long n)
Context
toString in interface ContextCompiler.getRuntimeStringConverter()public String toString(double n)
Context
toString in interface ContextCompiler.getRuntimeStringConverter()public void setLocale(Locale locale)
ContextSee getAvailableLocales to get all the available language, country and variant codes.
setLocale in interface Contextlocale - pre-constructed locale object
public void setLocale(String language,
String country)
Context
setLocale in interface Contextlanguage - language codecountry - country code
public void setLocale(String language,
String country,
String variant)
Context
setLocale in interface Contextlanguage - language codecountry - country codevariant - optional variant codepublic Locale getLocale()
Context
getLocale in interface Contextpublic Locale[] getAvailableLocales()
Context
getAvailableLocales in interface Contextpublic void nullFormat(String format)
Context
nullFormat in interface Contextformat - string to print in place of "null".public String getNullFormat()
Context
getNullFormat in interface Contextpublic void dateFormat(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 Contextformat - date format specification string
public void dateFormat(String format,
String timeZoneID)
Context
dateFormat in interface Contextformat - date format specification stringtimeZoneID - time zone ID, i.e. "PST"public String getDateFormat()
Context
getDateFormat in interface Contextpublic String getDateFormatTimeZone()
Context
getDateFormatTimeZone in interface Contextpublic TimeZone[] getAvailableTimeZones()
Context
getAvailableTimeZones in interface Contextpublic void numberFormat(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 Contextformat - number format specification string
public void numberFormat(String format,
String infinity,
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 Contextformat - number format specification stringinfinity - display string for infinityNaN - display string for not-a-number, resulting from zero divided
by zero.public String getNumberFormat()
Context
getNumberFormat in interface Contextpublic String getNumberFormatInfinity()
Context
getNumberFormatInfinity in interface Contextpublic String getNumberFormatNaN()
Context
getNumberFormatNaN in interface Contextpublic Date currentDate()
UtilityContext
currentDate in interface UtilityContextpublic org.joda.time.DateTime currentDateTime()
UtilityContext
currentDateTime in interface UtilityContext
public boolean startsWith(String str,
String prefix)
UtilityContext
startsWith in interface UtilityContextstr - the source stringprefix - the prefix to test for
public boolean endsWith(String str,
String suffix)
UtilityContext
endsWith in interface UtilityContextstr - the source stringsuffix - the suffix to test for
public int[] find(String str,
String search)
UtilityContext
find in interface UtilityContextstr - the source stringsearch - the string to search for
public int[] find(String str,
String search,
int fromIndex)
UtilityContext
find in interface UtilityContextstr - the source stringsearch - the string to search forfromIndex - index to start the find
public int findFirst(String str,
String search)
UtilityContext
findFirst in interface UtilityContextstr - the source stringsearch - the string to search for
public int findFirst(String str,
String search,
int fromIndex)
UtilityContext
findFirst in interface UtilityContextstr - the source stringsearch - the string to search forfromIndex - index to start the find
public int findLast(String str,
String search)
UtilityContext
findLast in interface UtilityContextstr - the source stringsearch - the string to search for
public int findLast(String str,
String search,
int fromIndex)
UtilityContext
findLast in interface UtilityContextstr - the source stringsearch - the string to search forfromIndex - optional index to start the find
public String substring(String str,
int startIndex)
UtilityContext
substring in interface UtilityContextstr - the source stringstartIndex - the start index, inclusive
public String substring(String str,
int startIndex,
int endIndex)
UtilityContext
substring in interface UtilityContextstr - the source stringstartIndex - the start index, inclusiveendIndex - the ending index, exclusive
public String toLowerCase(String str)
UtilityContext
toLowerCase in interface UtilityContextstr - the string to convert
public String toUpperCase(String str)
UtilityContext
toUpperCase in interface UtilityContextstr - the string to convert
public String trim(String str)
UtilityContext
trim in interface UtilityContextstr - the string to trim
public String trimLeading(String str)
UtilityContext
trimLeading in interface UtilityContextstr - the string to trim
public String trimTrailing(String str)
UtilityContext
trimTrailing in interface UtilityContextstr - the string to trim
public String shortOrdinal(Long n)
UtilityContext
shortOrdinal in interface UtilityContextn - the number to convert
public String shortOrdinal(long n)
UtilityContext
shortOrdinal in interface UtilityContextn - the number to convert
public String ordinal(Long n)
UtilityContext
ordinal in interface UtilityContextn - the number to convert
public String ordinal(long n)
UtilityContext
ordinal in interface UtilityContextn - the number to convert
public String cardinal(Long n)
UtilityContext
cardinal in interface UtilityContextn - the number to convert
public String cardinal(long n)
UtilityContext
cardinal in interface UtilityContextn - the number to convert
public String replace(String source,
String pattern,
String replacement)
UtilityContext
replace in interface UtilityContextsource - the source stringpattern - the simple string pattern to search forreplacement - the string to use for replacing matched patterns.
public String replace(String source,
String pattern,
String replacement,
int fromIndex)
UtilityContext
replace in interface 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 <K,V> String replace(String source,
Map<K,V> patternReplacements)
UtilityContext
replace in interface UtilityContextsource - the source stringpatternReplacements - pattern-replacement pairs
public String replaceFirst(String source,
String pattern,
String replacement)
UtilityContext
replaceFirst in interface UtilityContextsource - the source stringpattern - the simple string pattern to search forreplacement - the string to use for replacing matched patterns
public String replaceFirst(String source,
String pattern,
String replacement,
int fromIndex)
UtilityContext
replaceFirst in interface 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 String replaceLast(String source,
String pattern,
String replacement)
UtilityContext
replaceLast in interface UtilityContextsource - the source stringpattern - the simple string pattern to search forreplacement - the string to use for replacing matched patterns
public String replaceLast(String source,
String pattern,
String replacement,
int fromIndex)
UtilityContext
replaceLast in interface 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 boolean isArray(Object o)
UtilityContext
isArray in interface UtilityContexto - the Object to check
public void sort(Object[] array,
String onColumn,
boolean reverse)
sort in interface UtilityContext
public void sort(Object[] array,
String[] onColumns,
boolean[] reverse)
sort in interface UtilityContext
public void sort(String[] array,
boolean reverse,
boolean ignoreCase)
sort in interface UtilityContext
public void sort(Object[] array,
boolean sortAscending)
sort in interface UtilityContextpublic void sortAscending(Object[] array)
sortAscending in interface UtilityContextpublic void sortAscending(int[] array)
sortAscending in interface UtilityContextpublic void sortAscending(double[] array)
sortAscending in interface UtilityContextpublic void sortAscending(float[] array)
sortAscending in interface UtilityContextpublic void sortAscending(byte[] array)
sortAscending in interface UtilityContextpublic void sortAscending(short[] array)
sortAscending in interface UtilityContextpublic void sortAscending(long[] array)
sortAscending in interface UtilityContext
public String[] split(String str,
String regex)
split in interface UtilityContextpublic StringBuilder createStringBuilder()
UtilityContext
createStringBuilder in interface UtilityContextpublic StringBuilder createStringBuilder(int size)
UtilityContext
createStringBuilder in interface UtilityContextsize - the initial size of the buffer
public void append(StringBuilder buffer,
Object value)
UtilityContext
append in interface UtilityContextbuffer - the buffer to append tovalue - the value to append
public void prepend(StringBuilder buffer,
Object value)
UtilityContext
prepend in interface UtilityContextbuffer - the buffer to prepend tovalue - the value to prepend
public void insert(StringBuilder buffer,
Object value,
int index)
UtilityContext
insert in interface UtilityContextbuffer - the buffer to insert intovalue - the value to insertindex - the index of the position to insert atpublic String toString(StringBuilder buffer)
UtilityContext
toString in interface UtilityContextbuffer - the buffer to convert
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||