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