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 String _contextPath; |
36 |
| |
37 |
| private AssetFactory _classpathAssetFactory; |
38 |
| |
39 |
| private WebContext _webContext; |
40 |
| |
41 |
8
| public void setWebContext(WebContext webContext)
|
42 |
| { |
43 |
8
| _webContext = webContext;
|
44 |
| } |
45 |
| |
46 |
4
| public IAsset createAsset(Resource baseResource, String path, Locale locale, Location location)
|
47 |
| { |
48 |
| |
49 |
| |
50 |
| |
51 |
| |
52 |
4
| Resource assetResource = baseResource.getRelativeResource(path);
|
53 |
| |
54 |
| |
55 |
| |
56 |
| |
57 |
| |
58 |
| |
59 |
4
| if (assetResource.getResourceURL() == null && path.startsWith("/"))
|
60 |
2
| return _classpathAssetFactory.createAbsoluteAsset(path, locale, location);
|
61 |
| |
62 |
2
| Resource localized = assetResource.getLocalization(locale);
|
63 |
| |
64 |
2
| if (localized == null)
|
65 |
1
| throw new ApplicationRuntimeException(AssetMessages.missingAsset(path, baseResource),
|
66 |
| location, null); |
67 |
| |
68 |
1
| return createAsset(localized, location);
|
69 |
| } |
70 |
| |
71 |
8
| public IAsset createAbsoluteAsset(String path, Locale locale, Location location)
|
72 |
| { |
73 |
8
| Resource base = new WebContextResource(_webContext, path);
|
74 |
8
| Resource localized = base.getLocalization(locale);
|
75 |
| |
76 |
8
| if (localized == null)
|
77 |
1
| throw new ApplicationRuntimeException(AssetMessages.missingContextResource(path),
|
78 |
| location, null); |
79 |
| |
80 |
7
| return createAsset(localized, location);
|
81 |
| } |
82 |
| |
83 |
8
| public IAsset createAsset(Resource resource, Location location)
|
84 |
| { |
85 |
8
| return new ContextAsset(_contextPath, resource, location);
|
86 |
| } |
87 |
| |
88 |
11
| public void setContextPath(String contextPath)
|
89 |
| { |
90 |
11
| _contextPath = contextPath;
|
91 |
| } |
92 |
| |
93 |
7
| public void setClasspathAssetFactory(AssetFactory classpathAssetFactory)
|
94 |
| { |
95 |
7
| _classpathAssetFactory = classpathAssetFactory;
|
96 |
| } |
97 |
| } |