Class Formatter

java.lang.Object
io.milton.common.Formatter

public class Formatter extends Object
Handy functions exposes to rendering logic for formatting.
  • Field Details

  • Constructor Details

    • Formatter

      public Formatter()
  • Method Details

    • toString

      public String toString(Object o)
      Null safe method, returns empty string if the value is null
      Parameters:
      o -
      Returns:
    • toBool

      public Boolean toBool(Object o)
    • toDecimal

      public BigDecimal toDecimal(Object o, int places)
    • toDouble

      public Double toDouble(Object o)
    • toLong

      public Long toLong(Object oLimit)
    • toLong

      public Long toLong(Object oVal, boolean withNulls)
    • getYear

      public int getYear(Object o)
    • getMonth

      public int getMonth(Object o)
    • getDayOfMonth

      public int getDayOfMonth(Object o)
    • formatMinsAsDuration

      public String formatMinsAsDuration(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)
    • padWith

      public String padWith(String padChar, 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 numerator
      div - - 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 value
      withBlanks - - 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:
    • lt

      public boolean lt(Object val1, Object val2)
    • eq

      public boolean eq(Object val1, Object val2)
    • percentDecode

      public String percentDecode(String s)
      Decode percentage encoded paths. Eg a%20b -> a b
      Parameters:
      s -
      Returns:
    • percentEncode

      public String percentEncode(String s)
    • toDate

      public Date toDate(Object oVal)
    • toSqlDate

      public Date toSqlDate(Object oVal)
    • toSqlTimestamp

      public Timestamp toSqlTimestamp(Object oVal)
    • toPlain

      public String toPlain(String html)
    • getMonthName

      public String getMonthName(int i)
    • ifEqual

      public String ifEqual(String ifEqual, String ifNoteEqual, Object o1, Object o2)
    • 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)
    • checkbox

      public String checkbox(String name, Object oChecked)
    • checkbox

      public String checkbox(String id, String name, Object oChecked)
    • checkbox

      public String checkbox(String id, String name, Object oChecked, String value)
    • radio

      public String radio(String id, String name, Object oChecked, String value)
    • option

      public String option(Object value, String text, Object currentValue)
      Generate an option element
      Returns:
    • toCsv

      public String toCsv(Iterable list)
    • toCsv

      public String toCsv(String[] list)
    • addDays

      public Date addDays(Date now, int days)
      Return a date which has the given number of days added (or subtracted if negative) to the given date
      Parameters:
      now -
      i -
      Returns: