|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| package org.apache.tapestry.web; |
|
16 |
| |
|
17 |
| import java.util.Locale; |
|
18 |
| |
|
19 |
| import org.apache.hivemind.util.LocalizedNameGenerator; |
|
20 |
| import org.apache.hivemind.util.LocalizedResource; |
|
21 |
| |
|
22 |
| |
|
23 |
| |
|
24 |
| |
|
25 |
| |
|
26 |
| |
|
27 |
| |
|
28 |
| |
|
29 |
| public class LocalizedWebContextResourceFinder |
|
30 |
| { |
|
31 |
| private WebContext _context; |
|
32 |
| |
|
33 |
210
| public LocalizedWebContextResourceFinder(WebContext context)
|
|
34 |
| { |
|
35 |
210
| _context = context;
|
|
36 |
| } |
|
37 |
| |
|
38 |
| |
|
39 |
| |
|
40 |
| |
|
41 |
| |
|
42 |
| |
|
43 |
| |
|
44 |
| |
|
45 |
| |
|
46 |
210
| public LocalizedResource resolve(String contextPath, Locale locale)
|
|
47 |
| { |
|
48 |
210
| int dotx = contextPath.lastIndexOf('.');
|
|
49 |
210
| String basePath;
|
|
50 |
210
| String suffix;
|
|
51 |
210
| if (dotx >= 0) {
|
|
52 |
207
| basePath = contextPath.substring(0, dotx);
|
|
53 |
207
| suffix = contextPath.substring(dotx);
|
|
54 |
| } |
|
55 |
| else |
|
56 |
| { |
|
57 |
| |
|
58 |
3
| basePath = contextPath;
|
|
59 |
3
| suffix = "";
|
|
60 |
| } |
|
61 |
| |
|
62 |
210
| LocalizedNameGenerator generator = new LocalizedNameGenerator(basePath, locale, suffix);
|
|
63 |
| |
|
64 |
210
| while (generator.more())
|
|
65 |
| { |
|
66 |
417
| String candidatePath = generator.next();
|
|
67 |
| |
|
68 |
417
| if (isExistingResource(candidatePath))
|
|
69 |
204
| return new LocalizedResource(candidatePath, generator.getCurrentLocale());
|
|
70 |
| } |
|
71 |
| |
|
72 |
6
| return null;
|
|
73 |
| } |
|
74 |
| |
|
75 |
417
| private boolean isExistingResource(String path)
|
|
76 |
| { |
|
77 |
417
| return _context.getResource(path) != null;
|
|
78 |
| } |
|
79 |
| } |