1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.jdiagnose.library.db;
17
18 import javax.servlet.ServletContext;
19
20 import org.springframework.web.context.ServletContextAware;
21
22
23 /***
24 * @author JMcCrindle
25 */
26 public class HsqlDbUrlFactory implements ServletContextAware {
27
28 private String filename = null;
29 private String path = null;
30 private ServletContext context = null;
31
32 public String getUrl() {
33 String filePath = path;
34 if(path.startsWith("context:")) {
35 filePath = context.getRealPath(path.substring("context:".length()));
36 }
37 return "jdbc:hsqldb:file:" + safeAppendSlash(filePath) + filename;
38 }
39
40 protected String safeAppendSlash(String path) {
41 String fileSeparator = System.getProperty("file.separator");
42 return path.endsWith(fileSeparator) ? path : path + fileSeparator;
43 }
44
45 public void setFilename(String filename) {
46 this.filename = filename;
47 }
48
49 public void setPath(String path) {
50 this.path = path;
51 }
52
53
54
55
56 public void setServletContext(ServletContext context) {
57 this.context = context;
58 }
59 }