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 |
1052
| public WebContextResource(WebContext context, String path)
|
37 |
| { |
38 |
1052
| this(context, path, null);
|
39 |
| } |
40 |
| |
41 |
1056
| public WebContextResource(WebContext context, String path, Locale locale)
|
42 |
| { |
43 |
1056
| super(path, locale);
|
44 |
| |
45 |
1056
| _context = context;
|
46 |
| } |
47 |
| |
48 |
| |
49 |
| |
50 |
| |
51 |
| |
52 |
| |
53 |
73
| public Resource getLocalization(Locale locale)
|
54 |
| { |
55 |
73
| LocalizedWebContextResourceFinder finder = new LocalizedWebContextResourceFinder(_context);
|
56 |
| |
57 |
73
| String path = getPath();
|
58 |
73
| LocalizedResource localizedResource = finder.resolve(path, locale);
|
59 |
| |
60 |
73
| if (localizedResource == null)
|
61 |
2
| return null;
|
62 |
| |
63 |
71
| String localizedPath = localizedResource.getResourcePath();
|
64 |
71
| Locale pathLocale = localizedResource.getResourceLocale();
|
65 |
| |
66 |
71
| if (localizedPath == null)
|
67 |
0
| return null;
|
68 |
| |
69 |
71
| if (path.equals(localizedPath))
|
70 |
68
| return this;
|
71 |
| |
72 |
3
| return new WebContextResource(_context, localizedPath, pathLocale);
|
73 |
| } |
74 |
| |
75 |
591
| public URL getResourceURL()
|
76 |
| { |
77 |
591
| return _context.getResource(getPath());
|
78 |
| } |
79 |
| |
80 |
30
| public String toString()
|
81 |
| { |
82 |
30
| return "context:" + getPath();
|
83 |
| } |
84 |
| |
85 |
113
| public int hashCode()
|
86 |
| { |
87 |
113
| return 2387 & getPath().hashCode();
|
88 |
| } |
89 |
| |
90 |
999
| protected Resource newResource(String path)
|
91 |
| { |
92 |
999
| return new WebContextResource(_context, path);
|
93 |
| } |
94 |
| |
95 |
| } |