42 |
42 |
|
43 |
43 |
private static Logger logMetacat = Logger.getLogger(SystemUtil.class);
|
44 |
44 |
private static String METACAT_SERVLET = "metacat";
|
45 |
|
|
|
45 |
private static int OS_CLASS = 0;
|
|
46 |
|
|
47 |
// Class of OS. If we need more granularity, we should create a version
|
|
48 |
// list and access it separately.
|
|
49 |
public static int WIN_OS = 1;
|
|
50 |
public static int LINUX_OS = 2;
|
|
51 |
public static int MAC_OS = 3;
|
|
52 |
public static int OTHER_OS = 4;
|
|
53 |
|
46 |
54 |
/**
|
47 |
55 |
* private constructor - all methods are static so there is no no need to
|
48 |
56 |
* instantiate.
|
... | ... | |
50 |
58 |
private SystemUtil() {}
|
51 |
59 |
|
52 |
60 |
/**
|
|
61 |
* Get the OS for this system.
|
|
62 |
* @return an integer representing the class of OS. Possibilities are:
|
|
63 |
* WIN_OS = 1;
|
|
64 |
* LINUX_OS = 2;
|
|
65 |
* MAC_OS = 3;
|
|
66 |
* OTHER_OS = 4;
|
|
67 |
*/
|
|
68 |
public static int getOsClass() {
|
|
69 |
if (OS_CLASS > 0) {
|
|
70 |
return OS_CLASS;
|
|
71 |
}
|
|
72 |
|
|
73 |
String osName = System.getProperty("os.name");
|
|
74 |
if (osName.startsWith("Windows")) {
|
|
75 |
OS_CLASS = WIN_OS;
|
|
76 |
} else if (osName.startsWith("Linux")) {
|
|
77 |
OS_CLASS = LINUX_OS;
|
|
78 |
} else if (osName.startsWith("Mac")) {
|
|
79 |
OS_CLASS = MAC_OS;
|
|
80 |
} else if (osName.startsWith("Mac")) {
|
|
81 |
OS_CLASS = OTHER_OS;
|
|
82 |
}
|
|
83 |
|
|
84 |
return OS_CLASS;
|
|
85 |
}
|
|
86 |
|
|
87 |
/**
|
53 |
88 |
* Attempt to discover the server name. The name is retrieved from the http
|
54 |
89 |
* servlet request. This is used by configuration routines before the port
|
55 |
90 |
* has been populated in metacat.properties. it is possible the port that
|
... | ... | |
168 |
203 |
* @return string holding the server URL with context
|
169 |
204 |
*/
|
170 |
205 |
public static String getContextURL() throws PropertyNotFoundException {
|
171 |
|
return getServerURL() + FileUtil.getFS()
|
|
206 |
return getServerURL() + "/"
|
172 |
207 |
+ PropertyService.getProperty("application.context");
|
173 |
208 |
}
|
174 |
209 |
|
... | ... | |
179 |
214 |
* @return string holding the servlet URL
|
180 |
215 |
*/
|
181 |
216 |
public static String getServletURL() throws PropertyNotFoundException {
|
182 |
|
return getContextURL() + FileUtil.getFS() + METACAT_SERVLET;
|
|
217 |
return getContextURL() + "/" + METACAT_SERVLET;
|
183 |
218 |
}
|
184 |
219 |
|
185 |
220 |
/**
|
... | ... | |
189 |
224 |
* @return string holding the style skins URL
|
190 |
225 |
*/
|
191 |
226 |
public static String getStyleSkinsURL() throws PropertyNotFoundException {
|
192 |
|
return getContextURL() + FileUtil.getFS() + "style" + FileUtil.getFS()
|
193 |
|
+ "skins";
|
|
227 |
return getContextURL() + "/" + "style" + "/" + "skins";
|
194 |
228 |
}
|
195 |
229 |
|
196 |
230 |
/**
|
... | ... | |
200 |
234 |
* @return string holding the style common URL
|
201 |
235 |
*/
|
202 |
236 |
public static String getStyleCommonURL() throws PropertyNotFoundException {
|
203 |
|
return getContextURL() + FileUtil.getFS() + "style" + FileUtil.getFS()
|
204 |
|
+ "common";
|
|
237 |
return getContextURL() + "/" + "style" + "/" + "common";
|
205 |
238 |
}
|
206 |
239 |
|
207 |
240 |
/**
|
... | ... | |
263 |
296 |
|
264 |
297 |
return contextPath;
|
265 |
298 |
}
|
|
299 |
|
|
300 |
/**
|
|
301 |
* Attempt to discover the external (to the metacat installation)
|
|
302 |
* directory where metacat will hold backup files. This functionality
|
|
303 |
* is used to populate the configuration utility initially. The user
|
|
304 |
* can change the directory manually, so you can't rely on this method
|
|
305 |
* to give you the actual directory.
|
|
306 |
*
|
|
307 |
* @return a string holding the backup directory path
|
|
308 |
*/
|
|
309 |
public static String discoverExternalDir() {
|
|
310 |
if (getOsClass() == WIN_OS) {
|
|
311 |
return "C:\\Program Files\\metacat";
|
|
312 |
}
|
|
313 |
|
|
314 |
return "/var/metacat";
|
|
315 |
}
|
266 |
316 |
|
267 |
317 |
/**
|
268 |
318 |
* Get the style skins directory. This is made up of the tomcat directory
|
... | ... | |
291 |
341 |
* @return string holding the default style URL
|
292 |
342 |
*/
|
293 |
343 |
public static String getDefaultStyleURL() throws PropertyNotFoundException {
|
294 |
|
return getStyleCommonURL() + FileUtil.getFS()
|
|
344 |
return getStyleCommonURL() + "/"
|
295 |
345 |
+ PropertyService.getProperty("application.default-style");
|
296 |
346 |
}
|
297 |
347 |
|
Discover the external (backup) directory based on OS