|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| package org.apache.tapestry.asset; |
|
16 |
| |
|
17 |
| import java.util.Locale; |
|
18 |
| |
|
19 |
| import org.apache.hivemind.ApplicationRuntimeException; |
|
20 |
| import org.apache.hivemind.Location; |
|
21 |
| import org.apache.hivemind.Resource; |
|
22 |
| import org.apache.tapestry.IAsset; |
|
23 |
| import org.apache.tapestry.IRequestCycle; |
|
24 |
| import org.apache.tapestry.l10n.ResourceLocalizer; |
|
25 |
| import org.apache.tapestry.web.WebContext; |
|
26 |
| import org.apache.tapestry.web.WebContextResource; |
|
27 |
| |
|
28 |
| |
|
29 |
| |
|
30 |
| |
|
31 |
| |
|
32 |
| |
|
33 |
| |
|
34 |
| |
|
35 |
| public class ContextAssetFactory implements AssetFactory |
|
36 |
| { |
|
37 |
| private String _contextPath; |
|
38 |
| |
|
39 |
| private AssetFactory _classpathAssetFactory; |
|
40 |
| |
|
41 |
| private WebContext _webContext; |
|
42 |
| |
|
43 |
| private ResourceLocalizer _localizer; |
|
44 |
| |
|
45 |
| private IRequestCycle _requestCycle; |
|
46 |
| |
|
47 |
27
| public void setWebContext(WebContext webContext)
|
|
48 |
| { |
|
49 |
27
| _webContext = webContext;
|
|
50 |
| } |
|
51 |
| |
|
52 |
12
| public IAsset createAsset(Resource baseResource, String path, Locale locale, Location location)
|
|
53 |
| { |
|
54 |
| |
|
55 |
| |
|
56 |
| |
|
57 |
| |
|
58 |
12
| Resource assetResource = baseResource.getRelativeResource(path);
|
|
59 |
| |
|
60 |
| |
|
61 |
| |
|
62 |
| |
|
63 |
| |
|
64 |
| |
|
65 |
12
| if (assetResource.getResourceURL() == null && path.startsWith("/"))
|
|
66 |
6
| return _classpathAssetFactory.createAbsoluteAsset(path, locale, location);
|
|
67 |
| |
|
68 |
6
| Resource localized = _localizer.findLocalization(assetResource, locale);
|
|
69 |
| |
|
70 |
6
| if (localized == null)
|
|
71 |
3
| throw new ApplicationRuntimeException(AssetMessages.missingAsset(path, baseResource),
|
|
72 |
| location, null); |
|
73 |
| |
|
74 |
3
| return createAsset(localized, location);
|
|
75 |
| } |
|
76 |
| |
|
77 |
27
| public IAsset createAbsoluteAsset(String path, Locale locale, Location location)
|
|
78 |
| { |
|
79 |
27
| Resource base = new WebContextResource(_webContext, path);
|
|
80 |
27
| Resource localized = _localizer.findLocalization(base, locale);
|
|
81 |
| |
|
82 |
27
| if (localized == null)
|
|
83 |
3
| throw new ApplicationRuntimeException(AssetMessages.missingContextResource(path),
|
|
84 |
| location, null); |
|
85 |
| |
|
86 |
24
| return createAsset(localized, location);
|
|
87 |
| } |
|
88 |
| |
|
89 |
27
| public IAsset createAsset(Resource resource, Location location)
|
|
90 |
| { |
|
91 |
27
| return new ContextAsset(_contextPath, resource, location, _requestCycle);
|
|
92 |
| } |
|
93 |
| |
|
94 |
36
| public void setContextPath(String contextPath)
|
|
95 |
| { |
|
96 |
36
| _contextPath = contextPath;
|
|
97 |
| } |
|
98 |
| |
|
99 |
21
| public void setClasspathAssetFactory(AssetFactory classpathAssetFactory)
|
|
100 |
| { |
|
101 |
21
| _classpathAssetFactory = classpathAssetFactory;
|
|
102 |
| } |
|
103 |
| |
|
104 |
33
| public void setLocalizer(ResourceLocalizer localizer)
|
|
105 |
| { |
|
106 |
33
| _localizer = localizer;
|
|
107 |
| } |
|
108 |
| |
|
109 |
21
| public void setRequestCycle(IRequestCycle cycle)
|
|
110 |
| { |
|
111 |
21
| _requestCycle = cycle;
|
|
112 |
| } |
|
113 |
| } |