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.web.WebContext; |
24 |
| import org.apache.tapestry.web.WebContextResource; |
25 |
| |
26 |
| |
27 |
| |
28 |
| |
29 |
| |
30 |
| |
31 |
| |
32 |
| |
33 |
| public class ContextAssetFactory implements AssetFactory |
34 |
| { |
35 |
| private WebContext _context; |
36 |
| |
37 |
| private String _contextPath; |
38 |
| |
39 |
| private Resource _servletRoot; |
40 |
| |
41 |
5
| public void initializeService()
|
42 |
| { |
43 |
5
| _servletRoot = new WebContextResource(_context, "/");
|
44 |
| } |
45 |
| |
46 |
6
| public IAsset createAsset(Resource baseResource, String path, Locale locale, Location location)
|
47 |
| { |
48 |
6
| Resource assetResource = _servletRoot.getRelativeResource(path);
|
49 |
6
| Resource localized = assetResource.getLocalization(locale);
|
50 |
| |
51 |
6
| if (localized == null)
|
52 |
0
| throw new ApplicationRuntimeException(AssetMessages.missingAsset(path, _servletRoot),
|
53 |
| location, null); |
54 |
| |
55 |
6
| return new ContextAsset(_contextPath, localized, location);
|
56 |
| } |
57 |
| |
58 |
0
| public IAsset createAsset(Resource resource, Location location)
|
59 |
| { |
60 |
0
| return new ContextAsset(_contextPath, resource, location);
|
61 |
| } |
62 |
| |
63 |
5
| public void setContext(WebContext context)
|
64 |
| { |
65 |
5
| _context = context;
|
66 |
| } |
67 |
| |
68 |
5
| public void setContextPath(String contextPath)
|
69 |
| { |
70 |
5
| _contextPath = contextPath;
|
71 |
| } |
72 |
| } |