01: package net.sourceforge.tracelog.utils;
02:
03: import java.io.BufferedReader;
04: import java.io.InputStream;
05: import java.io.InputStreamReader;
06:
07: import org.apache.log4j.Logger;
08:
09: public class Util {
10: public static final String FILE_PROJECT_PROPERTIES = "/net/sourceforge/tracelog/resources/resource.properties";
11: public static final String LINE_BREAK = System
12: .getProperty("line.separator");
13: private static String appVersion;
14: private static long currentTimeMillis = System.currentTimeMillis();
15:
16: private static Logger log = Logger.getLogger(Util.class);
17:
18: /**
19: * Returns the latest version.
20: *
21: * @return Latest version number.
22: */
23: public static String getLatestVersion() {
24: if (appVersion == null) {
25: String line = "";
26: String version = "";
27: boolean loop = true;
28:
29: ProjectProperties projectProperties = ProjectProperties
30: .getInstance();
31:
32: try {
33: BufferedReader rd = new BufferedReader(
34: new InputStreamReader(
35: getOwnResource(projectProperties
36: .getVersionFilePath())));
37:
38: while (loop && (line = rd.readLine()) != null) {
39: if (!line.trim().equals("")) {
40: version = line.substring(line.indexOf("-") + 1,
41: line.indexOf("\t")).trim();
42: loop = false;
43: }
44: }
45:
46: rd.close();
47: } catch (Exception e) {
48: log.error(e.getMessage());
49: }
50:
51: appVersion = "v" + version;
52: }
53:
54: return appVersion;
55: }
56:
57: /**
58: * Get project resource file.
59: *
60: * @param obj
61: * @param fileName
62: * @return
63: */
64: public static InputStream getOwnResource(String fileName) {
65: return Util.class.getResourceAsStream(fileName);
66: }
67:
68: /**
69: * Generates and returns an unique id.
70: *
71: * @return Unique ID.
72: */
73: public synchronized static String getUniqueId() {
74: return "" + currentTimeMillis++;
75: }
76:
77: public static boolean isEmpty(String value) {
78: return value == null || value.trim().equals("");
79: }
80: }
|