1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| package org.apache.hivemind.util; |
16 |
| |
17 |
| import java.io.File; |
18 |
| import java.net.MalformedURLException; |
19 |
| import java.net.URL; |
20 |
| import java.util.Locale; |
21 |
| |
22 |
| import org.apache.commons.logging.Log; |
23 |
| import org.apache.commons.logging.LogFactory; |
24 |
| import org.apache.hivemind.Resource; |
25 |
| |
26 |
| |
27 |
| |
28 |
| |
29 |
| |
30 |
| |
31 |
| |
32 |
| public class FileResource extends AbstractResource |
33 |
| { |
34 |
| private static final Log LOG = LogFactory.getLog(FileResource.class); |
35 |
| |
36 |
14
| public FileResource(String path)
|
37 |
| { |
38 |
14
| super(path);
|
39 |
| } |
40 |
| |
41 |
1
| public FileResource(String path, Locale locale)
|
42 |
| { |
43 |
1
| super(path, locale);
|
44 |
| } |
45 |
| |
46 |
1
| protected Resource newResource(String path)
|
47 |
| { |
48 |
1
| return new FileResource(path);
|
49 |
| } |
50 |
| |
51 |
9
| private File getFile()
|
52 |
| { |
53 |
9
| return new File(getPath());
|
54 |
| } |
55 |
| |
56 |
9
| public URL getResourceURL()
|
57 |
| { |
58 |
9
| File file = getFile();
|
59 |
| |
60 |
9
| try
|
61 |
| { |
62 |
9
| if (file == null || !file.exists())
|
63 |
2
| return null;
|
64 |
| |
65 |
7
| return file.toURL();
|
66 |
| } |
67 |
| catch (MalformedURLException ex) |
68 |
| { |
69 |
0
| LOG.error(UtilMessages.badFileURL(getPath(), ex), ex);
|
70 |
0
| return null;
|
71 |
| } |
72 |
| } |
73 |
| |
74 |
3
| public Resource getLocalization(Locale locale)
|
75 |
| { |
76 |
3
| LocalizedFileResourceFinder f = new LocalizedFileResourceFinder();
|
77 |
| |
78 |
3
| String path = getPath();
|
79 |
| |
80 |
3
| String finalPath = f.findLocalizedPath(path, locale);
|
81 |
| |
82 |
3
| if (finalPath.equals(path))
|
83 |
2
| return this;
|
84 |
| |
85 |
1
| return newResource(finalPath);
|
86 |
| } |
87 |
| |
88 |
3
| public String toString()
|
89 |
| { |
90 |
3
| return getPath();
|
91 |
| } |
92 |
| |
93 |
| } |