|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| package org.apache.tapestry.asset; |
|
16 |
| |
|
17 |
| import java.io.InputStream; |
|
18 |
| import java.net.URL; |
|
19 |
| |
|
20 |
| import org.apache.hivemind.ApplicationRuntimeException; |
|
21 |
| import org.apache.hivemind.Location; |
|
22 |
| import org.apache.hivemind.Resource; |
|
23 |
| import org.apache.hivemind.util.Defense; |
|
24 |
| import org.apache.tapestry.IAsset; |
|
25 |
| import org.apache.tapestry.IRequestCycle; |
|
26 |
| import org.apache.tapestry.Tapestry; |
|
27 |
| |
|
28 |
| |
|
29 |
| |
|
30 |
| |
|
31 |
| |
|
32 |
| |
|
33 |
| |
|
34 |
| |
|
35 |
| public class ContextAsset extends AbstractAsset implements IAsset |
|
36 |
| { |
|
37 |
| private String _contextPath; |
|
38 |
| |
|
39 |
| private String _resolvedURL; |
|
40 |
| |
|
41 |
| private IRequestCycle _requestCycle; |
|
42 |
| |
|
43 |
27
| public ContextAsset(String contextPath, Resource resource, Location location, IRequestCycle cycle)
|
|
44 |
| { |
|
45 |
27
| super(resource, location);
|
|
46 |
| |
|
47 |
27
| Defense.notNull(contextPath, "contextPath");
|
|
48 |
| |
|
49 |
27
| _contextPath = contextPath;
|
|
50 |
| |
|
51 |
27
| _requestCycle = cycle;
|
|
52 |
| } |
|
53 |
| |
|
54 |
| |
|
55 |
| |
|
56 |
| |
|
57 |
| |
|
58 |
| |
|
59 |
| |
|
60 |
18
| public String buildURL()
|
|
61 |
| { |
|
62 |
18
| if (_resolvedURL == null)
|
|
63 |
18
| _resolvedURL = _contextPath + getResourceLocation().getPath();
|
|
64 |
| |
|
65 |
18
| return _requestCycle.encodeURL(_resolvedURL);
|
|
66 |
| } |
|
67 |
| |
|
68 |
3
| public InputStream getResourceAsStream()
|
|
69 |
| { |
|
70 |
3
| try
|
|
71 |
| { |
|
72 |
3
| URL url = getResourceLocation().getResourceURL();
|
|
73 |
| |
|
74 |
3
| return url.openStream();
|
|
75 |
| } |
|
76 |
| catch (Exception ex) |
|
77 |
| { |
|
78 |
0
| throw new ApplicationRuntimeException(Tapestry.format(
|
|
79 |
| "ContextAsset.resource-missing", |
|
80 |
| getResourceLocation()), ex); |
|
81 |
| } |
|
82 |
| } |
|
83 |
| } |