1
|
/**
|
2
|
* '$RCSfile$'
|
3
|
* Purpose: A Class that implements system utility methods
|
4
|
* Copyright: 2008 Regents of the University of California and the
|
5
|
* National Center for Ecological Analysis and Synthesis
|
6
|
* Authors: Michael Daigle
|
7
|
*
|
8
|
* '$Author: daigle $'
|
9
|
* '$Date: 2009-08-24 14:34:17 -0700 (Mon, 24 Aug 2009) $'
|
10
|
* '$Revision: 5030 $'
|
11
|
*
|
12
|
* This program is free software; you can redistribute it and/or modify
|
13
|
* it under the terms of the GNU General Public License as published by
|
14
|
* the Free Software Foundation; either version 2 of the License, or
|
15
|
* (at your option) any later version.
|
16
|
*
|
17
|
* This program is distributed in the hope that it will be useful,
|
18
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
19
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
20
|
* GNU General Public License for more details.
|
21
|
*
|
22
|
* You should have received a copy of the GNU General Public License
|
23
|
* along with this program; if not, write to the Free Software
|
24
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
25
|
*/
|
26
|
|
27
|
package edu.ucsb.nceas.metacat.util;
|
28
|
|
29
|
import java.util.Vector;
|
30
|
import java.util.regex.Matcher;
|
31
|
import java.util.regex.Pattern;
|
32
|
import javax.servlet.ServletContext;
|
33
|
import javax.servlet.http.HttpServletRequest;
|
34
|
|
35
|
import org.apache.log4j.Logger;
|
36
|
|
37
|
import edu.ucsb.nceas.metacat.MetacatVersion;
|
38
|
import edu.ucsb.nceas.metacat.properties.PropertyService;
|
39
|
import edu.ucsb.nceas.metacat.service.ServiceService;
|
40
|
import edu.ucsb.nceas.metacat.shared.MetacatUtilException;
|
41
|
import edu.ucsb.nceas.metacat.shared.ServiceException;
|
42
|
import edu.ucsb.nceas.utilities.FileUtil;
|
43
|
import edu.ucsb.nceas.utilities.PropertyNotFoundException;
|
44
|
import edu.ucsb.nceas.utilities.StringUtil;
|
45
|
import edu.ucsb.nceas.utilities.UtilException;
|
46
|
|
47
|
public class SystemUtil {
|
48
|
|
49
|
private static Logger logMetacat = Logger.getLogger(SystemUtil.class);
|
50
|
private static String METACAT_SERVLET = "metacat";
|
51
|
// private static String METACAT_WEB_SERVLET = "metacatweb";
|
52
|
private static int OS_CLASS = 0;
|
53
|
|
54
|
// Class of OS. If we need more granularity, we should create a version
|
55
|
// list and access it separately.
|
56
|
public static int WIN_OS = 1;
|
57
|
public static int LINUX_OS = 2;
|
58
|
public static int MAC_OS = 3;
|
59
|
public static int OTHER_OS = 4;
|
60
|
|
61
|
/**
|
62
|
* private constructor - all methods are static so there is no no need to
|
63
|
* instantiate.
|
64
|
*/
|
65
|
private SystemUtil() {}
|
66
|
|
67
|
/**
|
68
|
* Get the OS for this system.
|
69
|
* @return an integer representing the class of OS. Possibilities are:
|
70
|
* WIN_OS = 1;
|
71
|
* LINUX_OS = 2;
|
72
|
* MAC_OS = 3;
|
73
|
* OTHER_OS = 4;
|
74
|
*/
|
75
|
public static int getOsClass() {
|
76
|
if (OS_CLASS > 0) {
|
77
|
return OS_CLASS;
|
78
|
}
|
79
|
|
80
|
String osName = System.getProperty("os.name");
|
81
|
if (osName.startsWith("Windows")) {
|
82
|
OS_CLASS = WIN_OS;
|
83
|
} else if (osName.startsWith("Linux")) {
|
84
|
OS_CLASS = LINUX_OS;
|
85
|
} else if (osName.startsWith("Mac")) {
|
86
|
OS_CLASS = MAC_OS;
|
87
|
} else if (osName.startsWith("Mac")) {
|
88
|
OS_CLASS = OTHER_OS;
|
89
|
}
|
90
|
|
91
|
return OS_CLASS;
|
92
|
}
|
93
|
|
94
|
/**
|
95
|
* Attempt to discover the server name. The name is retrieved from the http
|
96
|
* servlet request. This is used by configuration routines before the port
|
97
|
* has been populated in metacat.properties. it is possible the port that
|
98
|
* the user configures might be different than the name we get here. You
|
99
|
* should use getServerPort() instead of this method whenever possible.
|
100
|
*
|
101
|
* @param request
|
102
|
* the http servlet request we will use to find the server name
|
103
|
*
|
104
|
* @return a string holding the server name
|
105
|
*/
|
106
|
public static String discoverServerName(HttpServletRequest request) {
|
107
|
String serverName = request.getServerName();
|
108
|
|
109
|
return serverName;
|
110
|
}
|
111
|
|
112
|
/**
|
113
|
* Attempt to discover the server port. The port is retrieved from the http
|
114
|
* servlet request. This is used by configuration routines before the port
|
115
|
* has been populated in metacat.properties. it is possible the port that
|
116
|
* the user configures might be different than the port we get here. You
|
117
|
* should use getServerPort() instead of this method whenever possible.
|
118
|
*
|
119
|
* @param request
|
120
|
* the http servlet request we will use to find the server port
|
121
|
*
|
122
|
* @return a string holding the server port
|
123
|
*/
|
124
|
public static String discoverServerPort(HttpServletRequest request) {
|
125
|
return Integer.toString(request.getServerPort());
|
126
|
}
|
127
|
|
128
|
/**
|
129
|
* Attempt to discover the server ssl port. The ssl port is assumed using
|
130
|
* the standard port. This is used by configuration routines before the port
|
131
|
* has been populated in metacat.properties. it is possible the prot that
|
132
|
* the user configures might be different than the port we get here. You
|
133
|
* should use getServerSSLPort() instead of this method whenever possible.
|
134
|
*
|
135
|
* @param request
|
136
|
* the http servlet request we will use to find the server port
|
137
|
*
|
138
|
* @return a string holding the server ssl port
|
139
|
*/
|
140
|
public static String discoverServerSSLPort(HttpServletRequest request) {
|
141
|
String serverPort = discoverServerPort(request);
|
142
|
|
143
|
if (serverPort.length() == 4 && serverPort.charAt(0) == '8') {
|
144
|
return "8443";
|
145
|
}
|
146
|
|
147
|
return "443";
|
148
|
}
|
149
|
|
150
|
/**
|
151
|
* Get the server URL which is made up of the server name + : + the http
|
152
|
* port number. Note that if the port is 80, it is left off.
|
153
|
*
|
154
|
* @return string holding the server URL
|
155
|
*/
|
156
|
public static String getServerURL() throws PropertyNotFoundException {
|
157
|
String ServerURL = "http://" + PropertyService.getProperty("server.name");
|
158
|
String httpPort = PropertyService.getProperty("server.httpPort");
|
159
|
if (!httpPort.equals("80")) {
|
160
|
ServerURL += ":" + httpPort;
|
161
|
}
|
162
|
|
163
|
return ServerURL;
|
164
|
}
|
165
|
|
166
|
/**
|
167
|
* Get the secure server URL which is made up of the server name + : + the
|
168
|
* https port number. Note that if the port is 443, it is left off.
|
169
|
*
|
170
|
* @return string holding the server URL
|
171
|
*/
|
172
|
public static String getSecureServerURL() throws PropertyNotFoundException {
|
173
|
String ServerURL = "https://" + getSecureServer();
|
174
|
return ServerURL;
|
175
|
}
|
176
|
|
177
|
/**
|
178
|
* Get the secure server which is made up of the server name + : + the
|
179
|
* https port number. Note that if the port is 443, it is left off.
|
180
|
* NOTE: does NOT include "https://"
|
181
|
* @see getSecureServerURL()
|
182
|
*
|
183
|
* @return string holding the secure server
|
184
|
*/
|
185
|
public static String getSecureServer() throws PropertyNotFoundException {
|
186
|
String server = PropertyService.getProperty("server.name");
|
187
|
String httpPort = PropertyService.getProperty("server.httpSSLPort");
|
188
|
if (!httpPort.equals("443")) {
|
189
|
server = server + ":" + httpPort;
|
190
|
}
|
191
|
|
192
|
return server;
|
193
|
}
|
194
|
|
195
|
/**
|
196
|
* Get the CGI URL which is made up of the server URL + file separator + the
|
197
|
* CGI directory
|
198
|
*
|
199
|
* @return string holding the server URL
|
200
|
*/
|
201
|
public static String getCGI_URL() throws PropertyNotFoundException{
|
202
|
return getContextURL()
|
203
|
+ PropertyService.getProperty("application.cgiDir");
|
204
|
}
|
205
|
|
206
|
/**
|
207
|
* Get the server URL with the context. This is made up of the server URL +
|
208
|
* file separator + the context
|
209
|
*
|
210
|
* @return string holding the server URL with context
|
211
|
*/
|
212
|
public static String getContextURL() throws PropertyNotFoundException {
|
213
|
return getServerURL() + "/"
|
214
|
+ PropertyService.getProperty("application.context");
|
215
|
}
|
216
|
|
217
|
/**
|
218
|
* Get the servlet URL. This is made up of the server URL with context +
|
219
|
* file separator + the metacat servlet name
|
220
|
*
|
221
|
* @return string holding the servlet URL
|
222
|
*/
|
223
|
public static String getServletURL() throws PropertyNotFoundException {
|
224
|
return getContextURL() + "/" + METACAT_SERVLET;
|
225
|
}
|
226
|
|
227
|
// /**
|
228
|
// * Get the web front end servlet URL. This is made up of the server URL with
|
229
|
// * context + file separator + the metacat web servlet name
|
230
|
// *
|
231
|
// * @return string holding the web servlet URL
|
232
|
// */
|
233
|
// public static String getWebServletURL() throws PropertyNotFoundException {
|
234
|
// return getContextURL() + "/" + METACAT_WEB_SERVLET;
|
235
|
// }
|
236
|
|
237
|
/**
|
238
|
* Get the style skins URL. This is made up of the server URL with context +
|
239
|
* file separator + "style" + file separator + "skins"
|
240
|
*
|
241
|
* @return string holding the style skins URL
|
242
|
*/
|
243
|
public static String getStyleSkinsURL() throws PropertyNotFoundException {
|
244
|
return getContextURL() + "/" + "style" + "/" + "skins";
|
245
|
}
|
246
|
|
247
|
/**
|
248
|
* Get the style common URL. This is made up of the server URL with context +
|
249
|
* file separator + "style" + file separator + "common"
|
250
|
*
|
251
|
* @return string holding the style common URL
|
252
|
*/
|
253
|
public static String getStyleCommonURL() throws PropertyNotFoundException {
|
254
|
return getContextURL() + "/" + "style" + "/" + "common";
|
255
|
}
|
256
|
|
257
|
/**
|
258
|
* Get the metacat version by getting the string representation from
|
259
|
* metacat.properties and instantiating a MetacatVersion object.
|
260
|
* The info is set in build.properties and then populated into metacat.properties
|
261
|
* at build time using Ant token replacement.
|
262
|
*
|
263
|
* @return a MetacatVersion object holding metacat version information
|
264
|
*/
|
265
|
public static MetacatVersion getMetacatVersion() throws PropertyNotFoundException {
|
266
|
String metacatVersionString =
|
267
|
PropertyService.getProperty("application.metacatVersion");
|
268
|
return new MetacatVersion(metacatVersionString);
|
269
|
}
|
270
|
|
271
|
/**
|
272
|
* Gets a string that holds some description about the release. Typically this is
|
273
|
* used during release candidates for display purposes and might hold something
|
274
|
* like "Release Candidate 1". Normally it is empty for final production release.
|
275
|
* The info is set in build.properties and then populated into metacat.properties
|
276
|
* at build time using Ant token replacement.
|
277
|
*
|
278
|
* @return a MetacatVersion object holding metacat version information
|
279
|
*/
|
280
|
public static String getMetacatReleaseInfo() throws PropertyNotFoundException {
|
281
|
return PropertyService.getProperty("application.metacatReleaseInfo");
|
282
|
}
|
283
|
|
284
|
/**
|
285
|
* Get the context directory. This is made up of the deployment directory + file
|
286
|
* separator + context
|
287
|
*
|
288
|
* @return string holding the context directory
|
289
|
*/
|
290
|
public static String getContextDir() throws PropertyNotFoundException {
|
291
|
return PropertyService.getProperty("application.deployDir") + FileUtil.getFS()
|
292
|
+ PropertyService.getProperty("application.context");
|
293
|
}
|
294
|
|
295
|
/**
|
296
|
* Attempt to discover the context for this application. This is a best
|
297
|
* guess scenario. It is used by configuration routines before the context
|
298
|
* has been populated in metacat.properties. You should always use
|
299
|
* getApplicationContext() instead of this method if possible.
|
300
|
*
|
301
|
* @param servletContext
|
302
|
* the servlet context we will use to find the application context
|
303
|
*
|
304
|
* @return a string holding the context
|
305
|
*/
|
306
|
public static String discoverApplicationContext(ServletContext servletContext) {
|
307
|
String applicationContext = "";
|
308
|
String realPath = servletContext.getRealPath("/");
|
309
|
|
310
|
if (realPath.charAt(realPath.length() - 1) == '/') {
|
311
|
realPath = realPath.substring(0, realPath.length() - 1);
|
312
|
}
|
313
|
|
314
|
int lastSlashIndex = realPath.lastIndexOf('/');
|
315
|
if (lastSlashIndex != -1) {
|
316
|
applicationContext = realPath.substring(lastSlashIndex + 1);
|
317
|
}
|
318
|
|
319
|
logMetacat.debug("application context: " + applicationContext);
|
320
|
|
321
|
return applicationContext;
|
322
|
}
|
323
|
|
324
|
/**
|
325
|
* Gets the stored backup location. This location is held in a file at
|
326
|
* <user_home>/.<application_context>/backup-location
|
327
|
*
|
328
|
* @return a string holding the backup location. Null if none could be found.
|
329
|
*/
|
330
|
public static String getStoredBackupDir() throws MetacatUtilException {
|
331
|
String applicationContext = null;
|
332
|
try {
|
333
|
applicationContext = ServiceService.getRealApplicationContext();
|
334
|
// Check if there is a file at
|
335
|
// <user_home>/<application_context>/backup-location. If so, it
|
336
|
// should contain one line that is a file that points to a writable
|
337
|
// directory. If that is true, use that value as the backup dir.
|
338
|
String storedBackupFileLoc = getUserHomeDir() + FileUtil.getFS() + "."
|
339
|
+ applicationContext + FileUtil.getFS() + "backup-location";
|
340
|
if (FileUtil.getFileStatus(storedBackupFileLoc) >= FileUtil.EXISTS_READABLE) {
|
341
|
String storedBackupDirLoc = FileUtil
|
342
|
.readFileToString(storedBackupFileLoc);
|
343
|
if (FileUtil.isDirectory(storedBackupDirLoc)
|
344
|
&& FileUtil.getFileStatus(storedBackupDirLoc) > FileUtil.EXISTS_READABLE) {
|
345
|
return storedBackupDirLoc;
|
346
|
}
|
347
|
}
|
348
|
} catch (UtilException ue) {
|
349
|
logMetacat.warn("Utility problem finding backup location: " + ue.getMessage());
|
350
|
} catch (ServiceException se) {
|
351
|
logMetacat.warn("Could not get real application context: " + se.getMessage());
|
352
|
}
|
353
|
return null;
|
354
|
}
|
355
|
|
356
|
public static void writeStoredBackupFile(String backupPath) throws MetacatUtilException {
|
357
|
String applicationContext = null;
|
358
|
try {
|
359
|
applicationContext = ServiceService.getRealApplicationContext();
|
360
|
// Write the backup path to
|
361
|
// <user_home>/.<application_context>/backup-location.
|
362
|
String storedBackupFileDir = getUserHomeDir() + FileUtil.getFS() + "." + applicationContext;
|
363
|
String storedBackupFileLoc = storedBackupFileDir + FileUtil.getFS() + "backup-location";
|
364
|
if (!FileUtil.isDirectory(storedBackupFileDir)) {
|
365
|
FileUtil.createDirectory(storedBackupFileDir);
|
366
|
}
|
367
|
if (FileUtil.getFileStatus(storedBackupFileLoc) == FileUtil.DOES_NOT_EXIST) {
|
368
|
FileUtil.createFile(storedBackupFileLoc);
|
369
|
}
|
370
|
if (FileUtil.getFileStatus(storedBackupFileLoc) < FileUtil.EXISTS_READ_WRITABLE) {
|
371
|
throw new UtilException("Stored backup location file is not writable: " + storedBackupFileLoc);
|
372
|
}
|
373
|
|
374
|
FileUtil.writeFile(storedBackupFileLoc, backupPath);
|
375
|
|
376
|
} catch (UtilException ue) {
|
377
|
logMetacat.warn("Utility error writing backup file: " + ue.getMessage());
|
378
|
} catch (ServiceException se) {
|
379
|
logMetacat.warn("Service error getting real application context: " + se.getMessage());
|
380
|
}
|
381
|
}
|
382
|
|
383
|
/**
|
384
|
* Attempt to discover the external (to the metacat installation)
|
385
|
* directory where metacat will hold backup files. This functionality
|
386
|
* is used to populate the configuration utility initially. The user
|
387
|
* can change the directory manually, so you can't rely on this method
|
388
|
* to give you the actual directory. Here are the steps taken to discover
|
389
|
* the directory:
|
390
|
*
|
391
|
* -- 1) Look for an existing hidden (.<application_context>) directory in a default system directory. Get
|
392
|
* the default base directory for the OS. (See application.windowsBackupBaseDir and
|
393
|
* application.linuxBackupBaseDir in metacat.properties.) If a directory called
|
394
|
* <base_dir>/metacat/.<application_context> exists, return <base_dir>/metacat.
|
395
|
* -- 2) Otherwise, look for an existing hidden (.metacat) directory in the user directory. If a directory
|
396
|
* called <user_dir>/metacat/.<application_context> exists for the user that started tomcat,
|
397
|
* return <user_dir>/metacat.
|
398
|
* -- 3) Otherwise, look for an existing metacat directory in a default system directory. Get
|
399
|
* the default base directory for the OS. (See application.windowsBackupBaseDir and
|
400
|
* application.linuxBackupBaseDir in metacat.properties.) If a directory called
|
401
|
* <base_dir>/metacat exists, return <base_dir>/metacat.
|
402
|
* -- 4) Otherwise, look for an existing metacat directory in the user directory. If a directory
|
403
|
* called <user_dir>/metacat/ exists for the user that started tomcat, return <user_dir>/metacat.
|
404
|
* -- 5) Otherwise, is the <base_dir> writable by the user that started tomcat? If so, return
|
405
|
* <base_dir>/metacat
|
406
|
* -- 6) Does the <user_home> exist? If so, return <user_home>/metacat
|
407
|
* -- 7) Otherwise, return null
|
408
|
*
|
409
|
* @return a string holding the backup directory path
|
410
|
*/
|
411
|
public static String discoverExternalDir() throws MetacatUtilException {
|
412
|
String applicationContext = null;
|
413
|
|
414
|
try {
|
415
|
applicationContext = ServiceService.getRealApplicationContext();
|
416
|
|
417
|
// Set the default location using the os
|
418
|
String systemDir = "";
|
419
|
if (getOsClass() == WIN_OS) {
|
420
|
systemDir = "C:\\Program Files";
|
421
|
} else {
|
422
|
systemDir = "/var";
|
423
|
}
|
424
|
String systemMetacatDir = systemDir + FileUtil.getFS() + "metacat";
|
425
|
String systemBackupDir = systemMetacatDir + FileUtil.getFS() + "."
|
426
|
+ applicationContext;
|
427
|
|
428
|
String userHomeDir = getUserHomeDir();
|
429
|
String userHomeMetacatDir = userHomeDir + FileUtil.getFS() + "metacat";
|
430
|
String userHomeBackupDir = userHomeMetacatDir + FileUtil.getFS() + "." + applicationContext;
|
431
|
|
432
|
// If <system_dir>/metacat/.<application_context> exists writable,
|
433
|
// return <system_dir>/metacat
|
434
|
if ((FileUtil.getFileStatus(systemBackupDir) >= FileUtil.EXISTS_READ_WRITABLE)) {
|
435
|
return systemMetacatDir;
|
436
|
}
|
437
|
|
438
|
// Otherwise if <user_dir>/metacat/.<application_context> exists writable, return
|
439
|
// <user_dir>/metacat
|
440
|
if ((FileUtil.getFileStatus(userHomeBackupDir) >= FileUtil.EXISTS_READ_WRITABLE)) {
|
441
|
return userHomeMetacatDir;
|
442
|
}
|
443
|
|
444
|
// Otherwise if <system_dir>/metacat exists writable, create
|
445
|
// <system_dir>/metacat/.<application_context> and return <system_dir>/metacat
|
446
|
if ((FileUtil.getFileStatus(systemMetacatDir) >= FileUtil.EXISTS_READ_WRITABLE)) {
|
447
|
// go ahead and create the backup hidden dir
|
448
|
FileUtil.createDirectory(systemBackupDir);
|
449
|
return systemMetacatDir;
|
450
|
}
|
451
|
|
452
|
// Otherwise if <user_dir>/metacat exists writable, create
|
453
|
// <user_dir>/metacat/.<application_context> and return <user_dir>/metacat
|
454
|
if ((FileUtil.getFileStatus(userHomeMetacatDir) >= FileUtil.EXISTS_READ_WRITABLE)) {
|
455
|
// go ahead and create the backup hidden dir
|
456
|
FileUtil.createDirectory(userHomeBackupDir);
|
457
|
return userHomeMetacatDir;
|
458
|
}
|
459
|
|
460
|
// Otherwise if <system_dir> exists, create
|
461
|
// <system_dir>/metacat/.<application_context> and return <system_dir>/metacat
|
462
|
if ((FileUtil.getFileStatus(systemDir) >= FileUtil.EXISTS_READ_WRITABLE)) {
|
463
|
// go ahead and create the backup hidden dir
|
464
|
FileUtil.createDirectory(systemBackupDir);
|
465
|
return systemMetacatDir;
|
466
|
}
|
467
|
|
468
|
// Otherwise if <user_dir> exists, return <user_dir> create
|
469
|
// <user_dir>/metacat/.<application_context> and return <user_dir>/metacat
|
470
|
if ((FileUtil.getFileStatus(userHomeDir) >= FileUtil.EXISTS_READ_WRITABLE)) {
|
471
|
// go ahead and create the backup hidden dir
|
472
|
FileUtil.createDirectory(userHomeBackupDir);
|
473
|
return userHomeMetacatDir;
|
474
|
}
|
475
|
|
476
|
} catch (ServiceException se) {
|
477
|
logMetacat.warn("Could not get real application context: " + se.getMessage());
|
478
|
} catch (UtilException ue) {
|
479
|
logMetacat.warn("Could not create directory: " + ue.getMessage());
|
480
|
}
|
481
|
|
482
|
// Otherwise, return userHomeDir
|
483
|
return null;
|
484
|
}
|
485
|
|
486
|
/**
|
487
|
* Store the location of the backup file location into a file at
|
488
|
* <user_home>/<application_dir>/backup-location
|
489
|
*
|
490
|
* @param externalDir the backup file location.
|
491
|
*/
|
492
|
public static void storeExternalDirLocation(String externalDir) {
|
493
|
if (getUserHomeDir() != null) {
|
494
|
String applicationContext = null;
|
495
|
String storedBackupLocDir = null;
|
496
|
String storedBackupLocFile = null;
|
497
|
try {
|
498
|
applicationContext = ServiceService.getRealApplicationContext();
|
499
|
storedBackupLocDir = getUserHomeDir() + FileUtil.getFS() + "."
|
500
|
+ applicationContext;
|
501
|
storedBackupLocFile = storedBackupLocDir + FileUtil.getFS()
|
502
|
+ "backup-location";
|
503
|
|
504
|
FileUtil.createDirectory(storedBackupLocDir);
|
505
|
FileUtil.writeFile(storedBackupLocFile, externalDir);
|
506
|
} catch (ServiceException se) {
|
507
|
logMetacat.error("Could not get real application directory while trying to write "
|
508
|
+ "stored backup directory: "+ storedBackupLocFile + " : " + se.getMessage());
|
509
|
} catch (UtilException ue) {
|
510
|
logMetacat.error("Could not write backup location file into "
|
511
|
+ "stored backup directory: "+ storedBackupLocFile + " : " + ue.getMessage());
|
512
|
}
|
513
|
} else {
|
514
|
logMetacat.warn("Could not write out stored backup directory."
|
515
|
+ " User directory does not exist");
|
516
|
}
|
517
|
}
|
518
|
|
519
|
/**
|
520
|
* Get the style skins directory. This is made up of the tomcat directory
|
521
|
* with context + file separator + "style" + file separator + "skins"
|
522
|
*
|
523
|
* @return string holding the style skins directory
|
524
|
*/
|
525
|
public static String getStyleSkinsDir() throws PropertyNotFoundException {
|
526
|
return getContextDir() + FileUtil.getFS() + "style" + FileUtil.getFS()
|
527
|
+ "skins";
|
528
|
}
|
529
|
|
530
|
/**
|
531
|
* Get the SQL directory. This is made up of the context directory + file
|
532
|
* separator + sql
|
533
|
*
|
534
|
* @return string holding the sql directory
|
535
|
*/
|
536
|
public static String getSQLDir() throws PropertyNotFoundException {
|
537
|
return getContextDir() + FileUtil.getFS() + "WEB-INF" + FileUtil.getFS() + "sql";
|
538
|
}
|
539
|
|
540
|
/**
|
541
|
* Get the default style URL from metacat.properties.
|
542
|
*
|
543
|
* @return string holding the default style URL
|
544
|
*/
|
545
|
public static String getDefaultStyleURL() throws PropertyNotFoundException {
|
546
|
return getStyleCommonURL() + "/"
|
547
|
+ PropertyService.getProperty("application.default-style");
|
548
|
}
|
549
|
|
550
|
/**
|
551
|
* Attempt to discover the deployment directory for this application. This is a
|
552
|
* best guess scenario. It is used by configuration routines before the
|
553
|
* deployment directory has been populated in metacat.properties.
|
554
|
*
|
555
|
* @param request
|
556
|
* the http servlet request we will use to find the tomcat directory
|
557
|
*
|
558
|
* @return a string holding the web application directory
|
559
|
*/
|
560
|
public static String discoverDeployDir(HttpServletRequest request) {
|
561
|
ServletContext servletContext = request.getSession()
|
562
|
.getServletContext();
|
563
|
String realPath = servletContext.getRealPath(".");
|
564
|
String contextPath = request.getContextPath();
|
565
|
|
566
|
logMetacat.debug("realPath: " + realPath);
|
567
|
logMetacat.debug("contextPath: " + contextPath);
|
568
|
|
569
|
Pattern pattern = Pattern.compile(contextPath + "/\\.$");
|
570
|
Matcher matcher = pattern.matcher(realPath);
|
571
|
|
572
|
if (matcher.find()) {
|
573
|
realPath = matcher.replaceFirst("");
|
574
|
}
|
575
|
|
576
|
return realPath;
|
577
|
}
|
578
|
|
579
|
/**
|
580
|
* Get the current user's home directory
|
581
|
*
|
582
|
* @return a string holding the home directory
|
583
|
*/
|
584
|
public static String getUserHomeDir() {
|
585
|
return System.getProperty("user.home");
|
586
|
}
|
587
|
|
588
|
/**
|
589
|
* Get a list of xml paths that need to be indexed
|
590
|
*/
|
591
|
public static Vector<String> getPathsForIndexing() throws MetacatUtilException {
|
592
|
Vector <String> indexPaths = null;
|
593
|
try {
|
594
|
indexPaths =
|
595
|
StringUtil.toVector(PropertyService.getProperty("xml.indexPaths"), ',');
|
596
|
} catch (PropertyNotFoundException pnfe) {
|
597
|
throw new MetacatUtilException("could not get index paths: " + pnfe.getMessage());
|
598
|
}
|
599
|
|
600
|
return indexPaths;
|
601
|
}
|
602
|
}
|