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.ClassResolver; |
21 |
| import org.apache.hivemind.Location; |
22 |
| import org.apache.hivemind.Resource; |
23 |
| import org.apache.hivemind.util.ClasspathResource; |
24 |
| import org.apache.tapestry.IAsset; |
25 |
| import org.apache.tapestry.engine.IEngineService; |
26 |
| import org.apache.tapestry.web.WebContext; |
27 |
| import org.apache.tapestry.web.WebContextResource; |
28 |
| |
29 |
| |
30 |
| |
31 |
| |
32 |
| |
33 |
| |
34 |
| |
35 |
| |
36 |
| public class ContextAssetFactory implements AssetFactory |
37 |
| { |
38 |
| private WebContext _context; |
39 |
| |
40 |
| private String _contextPath; |
41 |
| |
42 |
| private Resource _servletRoot; |
43 |
| |
44 |
| private ClassResolver _classResolver; |
45 |
| |
46 |
| private IEngineService _assetService; |
47 |
| |
48 |
6
| public void initializeService()
|
49 |
| { |
50 |
6
| _servletRoot = new WebContextResource(_context, "/");
|
51 |
| } |
52 |
| |
53 |
7
| public IAsset createAsset(Resource baseResource, String path, Locale locale, Location location)
|
54 |
| { |
55 |
7
| Resource assetResource = _servletRoot.getRelativeResource(path);
|
56 |
| |
57 |
| |
58 |
| |
59 |
| |
60 |
| |
61 |
| |
62 |
7
| if (assetResource.getResourceURL() == null && path.startsWith("/"))
|
63 |
| { |
64 |
1
| ClasspathResource resource = new ClasspathResource(_classResolver, path);
|
65 |
1
| return new PrivateAsset(resource, _assetService, location);
|
66 |
| } |
67 |
| |
68 |
6
| Resource localized = assetResource.getLocalization(locale);
|
69 |
| |
70 |
6
| if (localized == null)
|
71 |
0
| throw new ApplicationRuntimeException(AssetMessages.missingAsset(path, _servletRoot),
|
72 |
| location, null); |
73 |
| |
74 |
6
| return new ContextAsset(_contextPath, localized, location);
|
75 |
| } |
76 |
| |
77 |
0
| public IAsset createAsset(Resource resource, Location location)
|
78 |
| { |
79 |
0
| return new ContextAsset(_contextPath, resource, location);
|
80 |
| } |
81 |
| |
82 |
6
| public void setContext(WebContext context)
|
83 |
| { |
84 |
6
| _context = context;
|
85 |
| } |
86 |
| |
87 |
6
| public void setContextPath(String contextPath)
|
88 |
| { |
89 |
6
| _contextPath = contextPath;
|
90 |
| } |
91 |
| |
92 |
6
| public void setAssetService(IEngineService assetService)
|
93 |
| { |
94 |
6
| _assetService = assetService;
|
95 |
| } |
96 |
| |
97 |
6
| public void setClassResolver(ClassResolver classResolver)
|
98 |
| { |
99 |
6
| _classResolver = classResolver;
|
100 |
| } |
101 |
| } |