1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| package org.apache.hivemind.util; |
16 |
| |
17 |
| import java.util.Locale; |
18 |
| |
19 |
| import org.apache.hivemind.Resource; |
20 |
| |
21 |
| |
22 |
| |
23 |
| |
24 |
| |
25 |
| |
26 |
| |
27 |
| |
28 |
| |
29 |
| public abstract class AbstractResource implements Resource |
30 |
| { |
31 |
| private String _path; |
32 |
| private String _name; |
33 |
| private String _folderPath; |
34 |
| private Locale _locale; |
35 |
| |
36 |
309
| protected AbstractResource(String path)
|
37 |
| { |
38 |
309
| this(path, null);
|
39 |
| } |
40 |
| |
41 |
436
| protected AbstractResource(String path, Locale locale)
|
42 |
| { |
43 |
436
| _path = path;
|
44 |
436
| _locale = locale;
|
45 |
| } |
46 |
| |
47 |
12
| public String getName()
|
48 |
| { |
49 |
12
| if (_name == null)
|
50 |
12
| split();
|
51 |
| |
52 |
12
| return _name;
|
53 |
| } |
54 |
| |
55 |
36
| public Resource getRelativeResource(String name)
|
56 |
| { |
57 |
36
| if (name.startsWith("/"))
|
58 |
| { |
59 |
2
| if (name.equals(_path))
|
60 |
1
| return this;
|
61 |
| |
62 |
1
| return newResource(name);
|
63 |
| } |
64 |
| |
65 |
34
| if (_folderPath == null)
|
66 |
11
| split();
|
67 |
| |
68 |
34
| if (name.equals(_name))
|
69 |
1
| return this;
|
70 |
| |
71 |
33
| return newResource(_folderPath + name);
|
72 |
| } |
73 |
| |
74 |
165
| public String getPath()
|
75 |
| { |
76 |
165
| return _path;
|
77 |
| } |
78 |
| |
79 |
3
| public Locale getLocale()
|
80 |
| { |
81 |
3
| return _locale;
|
82 |
| } |
83 |
| |
84 |
| |
85 |
| protected abstract Resource newResource(String path); |
86 |
| |
87 |
23
| private void split()
|
88 |
| { |
89 |
23
| int lastSlashx = _path.lastIndexOf('/');
|
90 |
| |
91 |
23
| _folderPath = _path.substring(0, lastSlashx + 1);
|
92 |
23
| _name = _path.substring(lastSlashx + 1);
|
93 |
| } |
94 |
| |
95 |
| |
96 |
| |
97 |
| |
98 |
| |
99 |
| |
100 |
| |
101 |
| |
102 |
35
| public boolean equals(Object obj)
|
103 |
| { |
104 |
35
| if (obj == null)
|
105 |
1
| return false;
|
106 |
| |
107 |
34
| if (obj.getClass().equals(getClass()))
|
108 |
| { |
109 |
33
| AbstractResource otherLocation = (AbstractResource) obj;
|
110 |
| |
111 |
33
| return _path.equals(otherLocation._path);
|
112 |
| } |
113 |
| |
114 |
1
| return false;
|
115 |
| } |
116 |
| } |