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 | 0 | this(context, path, null); |
40 | 0 | } |
41 | |
|
42 | |
public WebContextResource(WebContext context, String path, Locale locale) |
43 | |
{ |
44 | 0 | super(path, locale); |
45 | |
|
46 | 0 | _context = context; |
47 | 0 | } |
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
public Resource getLocalization(Locale locale) |
55 | |
{ |
56 | 0 | LocalizedWebContextResourceFinder finder = new LocalizedWebContextResourceFinder(_context); |
57 | |
|
58 | 0 | String path = getPath(); |
59 | 0 | LocalizedResource localizedResource = finder.resolve(path, locale); |
60 | |
|
61 | 0 | if (localizedResource == null) |
62 | 0 | return null; |
63 | |
|
64 | 0 | String localizedPath = localizedResource.getResourcePath(); |
65 | 0 | Locale pathLocale = localizedResource.getResourceLocale(); |
66 | |
|
67 | 0 | if (localizedPath == null) |
68 | 0 | return null; |
69 | |
|
70 | 0 | if (path.equals(localizedPath)) |
71 | 0 | return this; |
72 | |
|
73 | 0 | return new WebContextResource(_context, localizedPath, pathLocale); |
74 | |
} |
75 | |
|
76 | |
public URL getResourceURL() |
77 | |
{ |
78 | 0 | return _context.getResource(getPath()); |
79 | |
} |
80 | |
|
81 | |
public String toString() |
82 | |
{ |
83 | 0 | 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 | 0 | return new WebContextResource(_context, path); |
94 | |
} |
95 | |
|
96 | |
} |