1
2
3
4
5
6
7 package org.astrogrid.tableserver.out;
8 import java.text.DateFormat;
9 import java.text.SimpleDateFormat;
10 import org.astrogrid.cfg.ConfigFactory;
11
12 /***
13 * Provides some methods for writing tables in ASCII text. Mostly help for
14 * dates.
15 *
16 * @author M Hill
17 */
18
19 public abstract class AsciiTableSupport implements TableWriter {
20
21 /*** Key used to configure date formats */
22 public static final String DATE_FORMAT_KEY = "default.date.pattern";
23
24 protected static final String defaultDatePattern = "yyyy-MM-dd'T'HH:mm:ss";
25 protected DateFormat dateFormat = null;
26
27 protected AsciiTableSupport() {
28 dateFormat = new SimpleDateFormat(ConfigFactory.getCommonConfig().getString(DATE_FORMAT_KEY, defaultDatePattern));
29
30 }
31
32 /*** Returns an empty string if the given string is null, otherwise returns
33 * the string. Prevents annoying 'null' turning up if there is no entry. In
34 * general, use it for header info; for cell values, it's best to use something
35 * to distinguish between 'no value' and 'empty value'
36 */
37 public String emptyIfNull(String s) {
38 if (s==null) return ""; else return s;
39 }
40
41
42
43 }
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68