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