1 package scioworks.imap.presentation.imapWeb; 2 3 import java.text.SimpleDateFormat ; 4 import java.io.IOException ; 5 import java.io.BufferedReader ; 6 import java.io.StringReader ; 7 import java.util.Date ; 8 import java.util.Vector ; 9 10 import com.lutris.util.Config; 11 import com.lutris.util.ConfigException; 12 import com.lutris.appserver.server.Enhydra; 13 14 public class TextUtil { 15 16 private static TextUtil fSingleton; 17 18 String INDENT = " "; 20 21 SimpleDateFormat df; 23 SimpleDateFormat tf; 24 SimpleDateFormat dtf; 25 26 private TextUtil() { 27 28 Config config = Enhydra.getApplication().getConfig(); 29 30 try { 31 String dateFormat = config.getString("ImapWeb.Util.DateFormat"); 32 df = new SimpleDateFormat (dateFormat); 33 34 } catch (ConfigException e) { 35 e.printStackTrace(); 36 } 37 } 38 39 public static synchronized TextUtil singleton() { 40 if (fSingleton == null) { 41 fSingleton = new TextUtil(); 42 } 43 return fSingleton; 44 } 45 46 public String dateFormat(Date date) { 47 return df.format(date); 48 } 49 50 public String textToHtml(String str) { 51 StringBuffer buf = new StringBuffer (); 52 try { 53 BufferedReader in = new BufferedReader (new StringReader (str)); 54 String line; 55 while ((line = in.readLine()) != null) { 56 buf.append(line).append("<br>"); 57 } 58 in.close(); 59 } catch (IOException e) { 60 buf.append("<p><b>Error: </b>"+e.getMessage()); 61 } 62 return buf.toString(); 63 } 64 65 public String verboseFilesize(int size) { 66 if (size > 1000000) { 67 return Long.toString(Math.round(size/1000000.0))+"mb"; 68 } else if (size > 1000) { 69 return Long.toString(Math.round(size/1000.0))+"k"; 70 } else { 71 return size + "b"; 72 } 73 } 74 75 public String initCap(String str) { 76 StringBuffer buf = new StringBuffer (); 77 buf.append(Character.toUpperCase(str.charAt(0))); 78 buf.append(str.substring(1)); 79 return buf.toString(); 80 } 81 } 82 | Popular Tags |