1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| package org.apache.hivemind.util; |
16 |
| |
17 |
| import java.net.URL; |
18 |
| import java.util.Locale; |
19 |
| |
20 |
| import org.apache.hivemind.ClassResolver; |
21 |
| import org.apache.hivemind.Resource; |
22 |
| |
23 |
| |
24 |
| |
25 |
| |
26 |
| |
27 |
| |
28 |
| |
29 |
| |
30 |
| |
31 |
| public class ClasspathResource extends AbstractResource |
32 |
| { |
33 |
| private ClassResolver _resolver; |
34 |
| |
35 |
112
| public ClasspathResource(ClassResolver resolver, String path)
|
36 |
| { |
37 |
112
| this(resolver, path, null);
|
38 |
| } |
39 |
| |
40 |
115
| public ClasspathResource(ClassResolver resolver, String path, Locale locale)
|
41 |
| { |
42 |
115
| super(path, locale);
|
43 |
| |
44 |
115
| _resolver = resolver;
|
45 |
| } |
46 |
| |
47 |
| |
48 |
| |
49 |
| |
50 |
| |
51 |
| |
52 |
8
| public Resource getLocalization(Locale locale)
|
53 |
| { |
54 |
8
| String path = getPath();
|
55 |
8
| LocalizedResourceFinder finder = new LocalizedResourceFinder(_resolver);
|
56 |
| |
57 |
8
| LocalizedResource localizedResource = finder.resolve(path, locale);
|
58 |
| |
59 |
8
| if (localizedResource == null)
|
60 |
2
| return null;
|
61 |
| |
62 |
6
| String localizedPath = localizedResource.getResourcePath();
|
63 |
6
| Locale pathLocale = localizedResource.getResourceLocale();
|
64 |
| |
65 |
6
| if (localizedPath == null)
|
66 |
0
| return null;
|
67 |
| |
68 |
6
| if (path.equals(localizedPath))
|
69 |
3
| return this;
|
70 |
| |
71 |
3
| return new ClasspathResource(_resolver, localizedPath, pathLocale);
|
72 |
| } |
73 |
| |
74 |
| |
75 |
| |
76 |
| |
77 |
| |
78 |
6
| public URL getResourceURL()
|
79 |
| { |
80 |
6
| return _resolver.getResource(getPath());
|
81 |
| } |
82 |
| |
83 |
30
| public String toString()
|
84 |
| { |
85 |
30
| return "classpath:" + getPath();
|
86 |
| } |
87 |
| |
88 |
8
| public int hashCode()
|
89 |
| { |
90 |
8
| return 4783 & getPath().hashCode();
|
91 |
| } |
92 |
| |
93 |
16
| protected Resource newResource(String path)
|
94 |
| { |
95 |
16
| return new ClasspathResource(_resolver, path);
|
96 |
| } |
97 |
| |
98 |
| } |