Package io.milton.common
Class Formatter
- java.lang.Object
-
- io.milton.common.Formatter
-
public class Formatter extends Object
Handy functions exposes to rendering logic for formatting.
-
-
Field Summary
Fields Modifier and Type Field Description static StringCHECKBOX_SUFFIXstatic ThreadLocal<DateFormat>sdfDateAndTimestatic ThreadLocal<DateFormat>sdfDateOnlystatic ThreadLocal<DateFormat>tlSdfUkLongstatic ThreadLocal<DateFormat>tlSdfUkShort
-
Constructor Summary
Constructors Constructor Description Formatter()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description DateaddDays(Date now, int days)Return a date which has the given number of days added (or subtracted if negative) to the given dateStringcheckbox(String name, Object oChecked)Stringcheckbox(String id, String name, Object oChecked)Stringcheckbox(String id, String name, Object oChecked, String value)booleaneq(Object val1, Object val2)StringformatMinsAsDuration(Object o)StringformatMinsAsDuration(Object o, boolean numeric)Given a value which can be parsed to a Long, return it formatted as a human readable duration such as 12:30 (12 mins, 30 seconds) or 12 mins, 3 hrs 20intgetDayOfMonth(Object o)intgetMonth(Object o)StringgetMonthName(int i)intgetYear(Object o)booleangt(Object val1, Object val2)True if val1 is greater then val2 will do string conversionsStringifEqual(String ifEqual, String ifNoteEqual, Object o1, Object o2)ObjectifTrue(Object bb, Object o1, Object o2)This just permits simple templating syntax for basic conditional values Eg: $item.textbooleanlt(Object val1, Object val2)Stringoption(Object value, String text, Object currentValue)Generate an option elementStringpad(long l, int length)Stringpad2(long l)StringpadWith(String padChar, long l, int length)StringpercentDecode(String s)Decode percentage encoded paths.StringpercentEncode(String s)Stringradio(String id, String name, Object oChecked, String value)DateFormatsdf(boolean hasTime)StringstripExt(String s)Removes the file extension if present Eg file1.swf -> file1 file1 -> file1BigDecimaltoBigDecimal(Object o, int decimals)BooleantoBool(Object o)StringtoCsv(Iterable list)StringtoCsv(String[] list)DatetoDate(Object oVal)BigDecimaltoDecimal(Object o, int places)DoubletoDouble(Object o)LongtoLong(Object oLimit)LongtoLong(Object oVal, boolean withNulls)StringtoPercent(Object num, Object div)Format as a percentage, including a percentage symbol and where blank/null values result in a blank outputStringtoPercent(Object num, Object div, boolean appendSymbol, boolean withBlanks)StringtoPlain(String html)DatetoSqlDate(Object oVal)TimestamptoSqlTimestamp(Object oVal)StringtoString(Object o)Null safe method, returns empty string if the value is null
-
-
-
Field Detail
-
CHECKBOX_SUFFIX
public static final String CHECKBOX_SUFFIX
- See Also:
- Constant Field Values
-
tlSdfUkShort
public static ThreadLocal<DateFormat> tlSdfUkShort
-
tlSdfUkLong
public static ThreadLocal<DateFormat> tlSdfUkLong
-
sdfDateOnly
public static final ThreadLocal<DateFormat> sdfDateOnly
-
sdfDateAndTime
public static final ThreadLocal<DateFormat> sdfDateAndTime
-
-
Method Detail
-
toString
public String toString(Object o)
Null safe method, returns empty string if the value is null- Parameters:
o-- Returns:
-
toDecimal
public BigDecimal toDecimal(Object o, int places)
-
getYear
public int getYear(Object o)
-
getMonth
public int getMonth(Object o)
-
getDayOfMonth
public int getDayOfMonth(Object o)
-
formatMinsAsDuration
public String formatMinsAsDuration(Object o, boolean numeric)
Given a value which can be parsed to a Long, return it formatted as a human readable duration such as 12:30 (12 mins, 30 seconds) or 12 mins, 3 hrs 20- Parameters:
o-numeric-- Returns:
-
pad2
public String pad2(long l)
-
pad
public String pad(long l, int length)
-
toPercent
public String toPercent(Object num, Object div)
Format as a percentage, including a percentage symbol and where blank/null values result in a blank output- Parameters:
num- - the numeratordiv- - the divisor- Returns:
-
toPercent
public String toPercent(Object num, Object div, boolean appendSymbol, boolean withBlanks)
- Parameters:
num-div-appendSymbol- - if true the percentage symbol is appended if a non-blank valuewithBlanks- - if true, blank numerators or divisors result in a blank value. Otherwise return zero.- Returns:
-
stripExt
public String stripExt(String s)
Removes the file extension if present Eg file1.swf -> file1 file1 -> file1- Parameters:
s-- Returns:
-
gt
public boolean gt(Object val1, Object val2)
True if val1 is greater then val2 will do string conversions- Parameters:
val1-val2-- Returns:
-
percentDecode
public String percentDecode(String s)
Decode percentage encoded paths. Eg a%20b -> a b- Parameters:
s-- Returns:
-
getMonthName
public String getMonthName(int i)
-
ifTrue
public Object ifTrue(Object bb, Object o1, Object o2)
This just permits simple templating syntax for basic conditional values Eg:- $item.text
- Parameters:
b-o1-o2-- Returns:
-
sdf
public DateFormat sdf(boolean hasTime)
-
toBigDecimal
public BigDecimal toBigDecimal(Object o, int decimals)
-
option
public String option(Object value, String text, Object currentValue)
Generate an option element- Returns:
-
-