View Javadoc
1 /* 2 * Copyright (c) 2003 3 * Information Desire GmbH 4 * All rights reserved. 5 */ 6 package com.infodesire.infobit.util; 7 8 import java.text.DateFormat; 9 import java.text.SimpleDateFormat; 10 import java.text.NumberFormat; 11 12 import java.util.Date; 13 14 import org.apache.commons.logging.Log; 15 import org.apache.commons.logging.LogFactory; 16 17 /*** 18 * tool to perform formatting of various data 19 * 20 * @author konstantin 21 * @created August 30, 2003 22 * @version $Revision: 1.2 $ 23 */ 24 public class FormatTool { 25 26 static DateFormat _medium = DateFormat.getDateInstance(DateFormat.MEDIUM); 27 static NumberFormat _percent = NumberFormat.getPercentInstance(); 28 private static Log _log = LogFactory.getLog(FormatTool.class); 29 30 31 /*** 32 * Constructor for the FormatTool object 33 */ 34 public FormatTool() { 35 } 36 37 38 /*** 39 * format long milliseconds as medium date 40 * 41 * @param date Description of Parameter 42 * @return Description of the Returned Value 43 */ 44 public String mediumDate(long date) { 45 if (_log.isDebugEnabled()) { 46 _log.debug("formatting " + date + " as medium date"); 47 } 48 return _medium.format(new Date(date)); 49 } 50 51 52 /*** 53 * format date string coming out of attribute to date 54 * 55 * @param date Description of Parameter 56 * @return Description of the Returned Value 57 */ 58 public String mediumDate(String date) { 59 try { 60 return mediumDate(Long.parseLong(date)); 61 } catch (Exception ex) { 62 _log.warn("tried to format string: '" + date + "' as medium date"); 63 } 64 return null; 65 } 66 67 68 /*** 69 * format float as percent value 70 * 71 * @param value Description of Parameter 72 * @return Description of the Returned Value 73 */ 74 public String percent(float value) { 75 return _percent.format(value); 76 } 77 78 79 /*** 80 * format double as percent. 81 * 82 * @param value Description of Parameter 83 * @return Description of the Returned Value 84 */ 85 public String percent(double value) { 86 return _percent.format(value); 87 } 88 }

This page was automatically generated by Maven