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 javax.servlet.ServletContext; |
21 |
| |
22 |
| import org.apache.commons.logging.Log; |
23 |
| import org.apache.commons.logging.LogFactory; |
24 |
| import org.apache.hivemind.Resource; |
25 |
| import org.apache.hivemind.util.AbstractResource; |
26 |
| import org.apache.hivemind.util.LocalizedResource; |
27 |
| |
28 |
| |
29 |
| |
30 |
| |
31 |
| |
32 |
| |
33 |
| |
34 |
| |
35 |
| |
36 |
| public class WebContextResource extends AbstractResource |
37 |
| { |
38 |
| private static final Log LOG = LogFactory.getLog(WebContextResource.class); |
39 |
| |
40 |
| private WebContext _context; |
41 |
| |
42 |
1016
| public WebContextResource(WebContext context, String path)
|
43 |
| { |
44 |
1016
| this(context, path, null);
|
45 |
| } |
46 |
| |
47 |
1019
| public WebContextResource(WebContext context, String path, Locale locale)
|
48 |
| { |
49 |
1019
| super(path, locale);
|
50 |
| |
51 |
1019
| _context = context;
|
52 |
| } |
53 |
| |
54 |
| |
55 |
| |
56 |
| |
57 |
| |
58 |
| |
59 |
70
| public Resource getLocalization(Locale locale)
|
60 |
| { |
61 |
70
| LocalizedWebContextResourceFinder finder = new LocalizedWebContextResourceFinder(
|
62 |
| _context); |
63 |
| |
64 |
70
| String path = getPath();
|
65 |
70
| LocalizedResource localizedResource = finder.resolve(path, locale);
|
66 |
| |
67 |
70
| if (localizedResource == null)
|
68 |
1
| return null;
|
69 |
| |
70 |
69
| String localizedPath = localizedResource.getResourcePath();
|
71 |
69
| Locale pathLocale = localizedResource.getResourceLocale();
|
72 |
| |
73 |
69
| if (localizedPath == null)
|
74 |
0
| return null;
|
75 |
| |
76 |
69
| if (path.equals(localizedPath))
|
77 |
67
| return this;
|
78 |
| |
79 |
2
| return new WebContextResource(_context, localizedPath, pathLocale);
|
80 |
| } |
81 |
| |
82 |
574
| public URL getResourceURL()
|
83 |
| { |
84 |
574
| return _context.getResource(getPath());
|
85 |
| } |
86 |
| |
87 |
42
| public String toString()
|
88 |
| { |
89 |
42
| return "context:" + getPath();
|
90 |
| } |
91 |
| |
92 |
237
| public int hashCode()
|
93 |
| { |
94 |
237
| return 2387 & getPath().hashCode();
|
95 |
| } |
96 |
| |
97 |
967
| protected Resource newResource(String path)
|
98 |
| { |
99 |
967
| return new WebContextResource(_context, path);
|
100 |
| } |
101 |
| |
102 |
| } |