1 package org.javabb.infra; 2 3 import java.text.DecimalFormat ; 4 import java.util.Date ; 5 6 import org.apache.commons.logging.Log; 7 import org.apache.commons.logging.LogFactory; 8 import org.javabb.bbcode.ProcessBBCode; 9 10 17 18 19 public class VelocityHelper { 20 21 protected Log log = LogFactory.getLog(VelocityHelper.class); 22 23 public String printObj(Object obj) { 24 return ("Objeto = " + obj); 25 } 26 27 35 public int isNull(Object obj) { 36 if (obj == null) { 37 return 1; 38 } else { 39 return 0; 40 } 41 } 42 43 51 public String dateFormat(Date date) { 52 try { 53 return DateUtil.dateFormat(date); 54 } catch (Exception e) { 55 return ""; 56 } 57 } 58 59 67 public String dateMinuteFormat(Date date) { 68 try { 69 return DateUtil.dateMinuteFormat(date); 70 } catch (Exception e) { 71 return ""; 72 } 73 } 74 75 83 public String dateAbrev(Date date) { 84 return DateUtil.getDataAbreviada(date); 85 } 86 87 96 public String dateNow() { 97 try { 98 return DateUtil.dateFormat(new Date ()); 99 } catch (RuntimeException e) { 100 return ""; 101 } 102 } 103 104 111 public String dateExtended() { 112 return DateUtil.getDataExtenso(new Date ()); 113 } 114 115 124 public String dateExtended(Date date) { 125 return DateUtil.getDataExtenso(date); 126 } 127 128 135 public static String getPercentage(double parcial, double total) { 136 double p = parcial; 137 double t = total; 138 double perc = ((p * 100) / t); 139 140 return new DecimalFormat ("##.##").format(perc); 141 } 142 143 public String dateRFC() { 144 return DateUtil.dateRFCFormat(new Date ()); 145 } 146 147 public String dateRFCFormat(Date date) { 148 try { 149 return DateUtil.dateRFCFormat(date); 150 } catch (Exception e) { 151 return ""; 152 } 153 } 154 155 public String removeHTML(String text) { 156 if (text.indexOf('<') < 0) 157 return text; 158 159 StringBuffer str = new StringBuffer (); 160 161 while (text.length() > 0 && text.indexOf('<') >= 0) { 162 if (text.indexOf('<') >= 0) { 163 str.append(text.substring(0, text.indexOf('<'))); 164 text = text.substring(text.indexOf('>') + 1); 165 } 166 } 167 168 str.append(text); 169 170 return str.toString(); 171 } 172 173 public String substring(String txt, int init, int max) { 174 if (txt.length() > max) { 175 return txt.substring(init, max); 176 } else { 177 return txt; 178 } 179 } 180 181 public String escapeBBcode(String str) { 182 return ProcessBBCode.escapeBBcode(str); 183 } 184 185 190 public String formatDigitValue(String param) { 191 try { 192 return DigitFormat.parserValue(param); 193 } catch (Exception e) { 194 return "Render problem"; 195 } 196 } 197 } 198 199 | Popular Tags |