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