|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectplay.templates.JavaExtensions
public class JavaExtensions
Java extensions in templates
| Constructor Summary | |
|---|---|
JavaExtensions()
|
|
| Method Summary | |
|---|---|
static String[] |
add(String[] array,
String o)
Adds the String to the end of the array. |
static String |
addSlashes(Object o)
Backslash-escapes Java-escaped single and double quotes in the object’s String representation. |
static Template.ExecutableTemplate.RawData |
asAttr(Map attributes)
Formats the map’s keys and values as HTML attributes. |
static Template.ExecutableTemplate.RawData |
asAttr(Map attributes,
Object condition)
Formats the map’s keys and values as HTML attributes, if the condition is true. |
static String |
asdate(Long timestamp,
String pattern)
Formats a time stamp as a date. |
static String |
asdate(Long timestamp,
String pattern,
String lang)
Formats a time stamp as a date, in the given language. |
static groovy.util.slurpersupport.GPathResult |
asXml(String xml)
Parses the given XML string. |
static String |
camelCase(String string)
Formats the string in camel case, as if for a Java class name. |
static String |
capAll(Object o)
Capitalises every word in the object’s String representation. |
static String |
capFirst(Object o)
Capitalises the first word in the object’s String representation. |
static String |
capitalizeWords(String source)
Capitalises every word in the string. |
static boolean |
contains(String[] array,
String value)
Returns true if the array contains the given string. |
static String |
cut(Object o,
String pattern)
Removes occurrences of the given sub-string. |
static boolean |
divisibleBy(Number n,
int by)
Returns true if the number is divisible by the given number – the divisor. |
static String |
escape(Object o)
Escapes reserved HTML characters in the object’s String representation. |
static String |
escapeHtml(String htmlToEscape)
Escapes reserved HTML characters. |
static String |
escapeJavaScript(String str)
Escapes reserved JavaScript characters. |
static String |
escapeXml(String str)
Escapes reserved XML characters. |
protected static boolean |
eval(Object condition)
|
static String |
format(Date date,
String pattern)
Formats the date using the given date format pattern. |
static String |
format(Date date,
String pattern,
String lang)
Formats the date using the given date format pattern, in the given language. |
static String |
format(Number number,
String pattern)
Formats the number using the given number format pattern. |
static String |
formatCurrency(Number number,
String currencyCode)
Formats the number as a currency for the given currency code. |
static String |
formatSize(Long bytes)
Formats a number of bytes as a file size, with units. |
static String |
join(Collection items,
String separator)
Concatenate items of a collection as a string separated with separator items toString() method should be implemented to provide a string representation |
static Object |
last(List<?> items)
Return the last item of a list or null if the List is null |
static Template.ExecutableTemplate.RawData |
nl2br(Object data)
Replaces new-line characters with HTML br tags. |
static String |
noAccents(String string)
Removes accents from the letters in the string. |
static String |
pad(String str,
Integer size)
Pads the string with up to the given length. |
static Integer |
page(Number number,
Integer pageSize)
Returns the page number, for the given page size, from interpreting the number as an index. |
static String |
pluralize(Collection n)
Returns an ‘s’ when the collection’s size is not 1. |
static String |
pluralize(Collection n,
String plural)
Returns the given plural when the collection’s size is not 1. |
static String |
pluralize(Collection n,
String[] forms)
Returns the given plural form when the collection’s size is not 1; returns the given singular form when it is 1. |
static String |
pluralize(Number n)
Returns an ‘s’ when the number is not 1. |
static String |
pluralize(Number n,
String plural)
Returns the given plural when the number is not 1. |
static String |
pluralize(Number n,
String[] forms)
Returns the given plural form when the number is not 1; returns the given singular form when it is 1. |
static Template.ExecutableTemplate.RawData |
raw(Object val)
Returns the object without template escaping. |
static Template.ExecutableTemplate.RawData |
raw(Object val,
Object condition)
Returns the object without template escaping, if the condition is true. |
static String[] |
remove(String[] array,
String s)
Returns the array, with the given string removed. |
static String |
since(Date date)
Formats the date as a relative time, compared to now, e.g. |
static String |
since(Date date,
Boolean stopAtMonth)
Formats the date as a relative time, compared to now, e.g. |
static String |
slugify(String string)
Formats the string as a ‘slug’ for use in URLs, that avoids reserved URL path characters |
static String |
toString(groovy.lang.Closure closure)
|
static String |
urlEncode(String entity)
Escapes reserved URL query string characters. |
static String |
yesno(Object o,
String[] values)
Returns the first parameter (‘yes’) if the object evaluates to true, or the second parameter (‘no’) otherwise. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public JavaExtensions()
| Method Detail |
|---|
public static String[] add(String[] array,
String o)
public static String addSlashes(Object o)
public static Template.ExecutableTemplate.RawData asAttr(Map attributes)
public static Template.ExecutableTemplate.RawData asAttr(Map attributes,
Object condition)
public static String asdate(Long timestamp,
String pattern)
public static String asdate(Long timestamp,
String pattern,
String lang)
public static groovy.util.slurpersupport.GPathResult asXml(String xml)
public static String camelCase(String string)
public static String capAll(Object o)
public static String capFirst(Object o)
public static String capitalizeWords(String source)
public static boolean contains(String[] array,
String value)
public static String cut(Object o,
String pattern)
public static boolean divisibleBy(Number n,
int by)
public static String escape(Object o)
public static String escapeHtml(String htmlToEscape)
public static String escapeJavaScript(String str)
public static String escapeXml(String str)
protected static boolean eval(Object condition)
public static String format(Date date,
String pattern)
public static String format(Date date,
String pattern,
String lang)
public static String format(Number number,
String pattern)
public static String formatCurrency(Number number,
String currencyCode)
currencyCode - An ISO 4217 currency code, e.g. EUR.public static String formatSize(Long bytes)
public static String join(Collection items,
String separator)
public static Object last(List<?> items)
public static Template.ExecutableTemplate.RawData nl2br(Object data)
public static String noAccents(String string)
public static String pad(String str,
Integer size)
public static Integer page(Number number,
Integer pageSize)
public static String pluralize(Collection n)
public static String pluralize(Collection n,
String plural)
public static String pluralize(Collection n,
String[] forms)
forms - A two-element array containing the singular form, then the plural form.public static String pluralize(Number n)
public static String pluralize(Number n,
String plural)
public static String pluralize(Number n,
String[] forms)
public static Template.ExecutableTemplate.RawData raw(Object val)
public static Template.ExecutableTemplate.RawData raw(Object val,
Object condition)
public static String[] remove(String[] array,
String s)
public static String since(Date date)
public static String since(Date date,
Boolean stopAtMonth)
stopAtMonth - If true, then dates more than a month ago are formatted as a date string, e.g. Jan 1, 2010.public static String slugify(String string)
public static String toString(groovy.lang.Closure closure)
public static String urlEncode(String entity)
public static String yesno(Object o,
String[] values)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||