01: package scioworks.imap.presentation.imapWeb;
02:
03: import java.text.SimpleDateFormat;
04: import java.io.IOException;
05: import java.io.BufferedReader;
06: import java.io.StringReader;
07: import java.util.Date;
08: import java.util.Vector;
09:
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: // Constants
19: String INDENT = " ";
20:
21: // Format date and time
22: 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
32: .getString("ImapWeb.Util.DateFormat");
33: df = new SimpleDateFormat(dateFormat);
34:
35: } catch (ConfigException e) {
36: e.printStackTrace();
37: }
38: }
39:
40: public static synchronized TextUtil singleton() {
41: if (fSingleton == null) {
42: fSingleton = new TextUtil();
43: }
44: return fSingleton;
45: }
46:
47: public String dateFormat(Date date) {
48: return df.format(date);
49: }
50:
51: public String textToHtml(String str) {
52: StringBuffer buf = new StringBuffer();
53: try {
54: BufferedReader in = new BufferedReader(
55: new StringReader(str));
56: String line;
57: while ((line = in.readLine()) != null) {
58: buf.append(line).append("<br>");
59: }
60: in.close();
61: } catch (IOException e) {
62: buf.append("<p><b>Error: </b>" + e.getMessage());
63: }
64: return buf.toString();
65: }
66:
67: public String verboseFilesize(int size) {
68: if (size > 1000000) {
69: return Long.toString(Math.round(size / 1000000.0)) + "mb";
70: } else if (size > 1000) {
71: return Long.toString(Math.round(size / 1000.0)) + "k";
72: } else {
73: return size + "b";
74: }
75: }
76:
77: public String initCap(String str) {
78: StringBuffer buf = new StringBuffer();
79: buf.append(Character.toUpperCase(str.charAt(0)));
80: buf.append(str.substring(1));
81: return buf.toString();
82: }
83: }
|