play.templates
Class JavaExtensions

java.lang.Object
  extended by play.templates.JavaExtensions

public class JavaExtensions
extends Object

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

JavaExtensions

public JavaExtensions()
Method Detail

add

public static String[] add(String[] array,
                           String o)
Adds the String to the end of the array.


addSlashes

public static String addSlashes(Object o)
Backslash-escapes Java-escaped single and double quotes in the object’s String representation.


asAttr

public static Template.ExecutableTemplate.RawData asAttr(Map attributes)
Formats the map’s keys and values as HTML attributes.


asAttr

public static Template.ExecutableTemplate.RawData asAttr(Map attributes,
                                                         Object condition)
Formats the map’s keys and values as HTML attributes, if the condition is true.


asdate

public static String asdate(Long timestamp,
                            String pattern)
Formats a time stamp as a date.


asdate

public static String asdate(Long timestamp,
                            String pattern,
                            String lang)
Formats a time stamp as a date, in the given language.


asXml

public static groovy.util.slurpersupport.GPathResult asXml(String xml)
Parses the given XML string.


camelCase

public static String camelCase(String string)
Formats the string in camel case, as if for a Java class name.


capAll

public static String capAll(Object o)
Capitalises every word in the object’s String representation.


capFirst

public static String capFirst(Object o)
Capitalises the first word in the object’s String representation.


capitalizeWords

public static String capitalizeWords(String source)
Capitalises every word in the string.


contains

public static boolean contains(String[] array,
                               String value)
Returns true if the array contains the given string.


cut

public static String cut(Object o,
                         String pattern)
Removes occurrences of the given sub-string.


divisibleBy

public static boolean divisibleBy(Number n,
                                  int by)
Returns true if the number is divisible by the given number – the divisor.


escape

public static String escape(Object o)
Escapes reserved HTML characters in the object’s String representation.


escapeHtml

public static String escapeHtml(String htmlToEscape)
Escapes reserved HTML characters.


escapeJavaScript

public static String escapeJavaScript(String str)
Escapes reserved JavaScript characters.


escapeXml

public static String escapeXml(String str)
Escapes reserved XML characters.


eval

protected static boolean eval(Object condition)

format

public static String format(Date date,
                            String pattern)
Formats the date using the given date format pattern.


format

public static String format(Date date,
                            String pattern,
                            String lang)
Formats the date using the given date format pattern, in the given language.


format

public static String format(Number number,
                            String pattern)
Formats the number using the given number format pattern.


formatCurrency

public static String formatCurrency(Number number,
                                    String currencyCode)
Formats the number as a currency for the given currency code.

Parameters:
currencyCode - An ISO 4217 currency code, e.g. EUR.

formatSize

public static String formatSize(Long bytes)
Formats a number of bytes as a file size, with units.


join

public 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


last

public static Object last(List<?> items)
Return the last item of a list or null if the List is null


nl2br

public static Template.ExecutableTemplate.RawData nl2br(Object data)
Replaces new-line characters with HTML br tags.


noAccents

public static String noAccents(String string)
Removes accents from the letters in the string.


pad

public static String pad(String str,
                         Integer size)
Pads the string with   up to the given length.


page

public static Integer page(Number number,
                           Integer pageSize)
Returns the page number, for the given page size, from interpreting the number as an index.


pluralize

public static String pluralize(Collection n)
Returns an ‘s’ when the collection’s size is not 1.


pluralize

public static String pluralize(Collection n,
                               String plural)
Returns the given plural when the collection’s size is not 1.


pluralize

public 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.

Parameters:
forms - A two-element array containing the singular form, then the plural form.

pluralize

public static String pluralize(Number n)
Returns an ‘s’ when the number is not 1.


pluralize

public static String pluralize(Number n,
                               String plural)
Returns the given plural when the number is not 1.


pluralize

public 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.


raw

public static Template.ExecutableTemplate.RawData raw(Object val)
Returns the object without template escaping.


raw

public static Template.ExecutableTemplate.RawData raw(Object val,
                                                      Object condition)
Returns the object without template escaping, if the condition is true.


remove

public static String[] remove(String[] array,
                              String s)
Returns the array, with the given string removed.


since

public static String since(Date date)
Formats the date as a relative time, compared to now, e.g. 3 minutes ago.


since

public static String since(Date date,
                           Boolean stopAtMonth)
Formats the date as a relative time, compared to now, e.g. 3 minutes ago.

Parameters:
stopAtMonth - If true, then dates more than a month ago are formatted as a date string, e.g. Jan 1, 2010.

slugify

public static String slugify(String string)
Formats the string as a ‘slug’ for use in URLs, that avoids reserved URL path characters


toString

public static String toString(groovy.lang.Closure closure)

urlEncode

public static String urlEncode(String entity)
Escapes reserved URL query string characters.


yesno

public static String yesno(Object o,
                           String[] values)
Returns the first parameter (‘yes’) if the object evaluates to true, or the second parameter (‘no’) otherwise.



Guillaume Bort & zenexity - Distributed under Apache 2 licence, without any warrantly