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.ClasspathResource; |
24 |
| import org.apache.tapestry.IRequestCycle; |
25 |
| import org.apache.tapestry.Tapestry; |
26 |
| import org.apache.tapestry.engine.IEngineService; |
27 |
| import org.apache.tapestry.engine.ILink; |
28 |
| |
29 |
| |
30 |
| |
31 |
| |
32 |
| |
33 |
| |
34 |
| |
35 |
| |
36 |
| |
37 |
| |
38 |
| public class PrivateAsset extends AbstractAsset |
39 |
| { |
40 |
| private IEngineService _assetService; |
41 |
| |
42 |
| |
43 |
| |
44 |
| |
45 |
| |
46 |
0
| public PrivateAsset(ClasspathResource resourceLocation, Location location)
|
47 |
| { |
48 |
0
| this(resourceLocation, null, location);
|
49 |
| } |
50 |
| |
51 |
429
| public PrivateAsset(ClasspathResource resourceLocation, IEngineService assetService,
|
52 |
| Location location) |
53 |
| { |
54 |
429
| super(resourceLocation, location);
|
55 |
| |
56 |
429
| _assetService = assetService;
|
57 |
| } |
58 |
| |
59 |
| |
60 |
| |
61 |
| |
62 |
| |
63 |
| |
64 |
| |
65 |
75
| public String buildURL(IRequestCycle cycle)
|
66 |
| { |
67 |
75
| String path = getResourceLocation().getPath();
|
68 |
| |
69 |
| |
70 |
| |
71 |
| |
72 |
| |
73 |
75
| if (_assetService == null)
|
74 |
0
| _assetService = cycle.getEngine().getService(Tapestry.ASSET_SERVICE);
|
75 |
| |
76 |
75
| ILink link = _assetService.getLink(cycle, false, path);
|
77 |
| |
78 |
75
| return link.getURL();
|
79 |
| } |
80 |
| |
81 |
1
| public InputStream getResourceAsStream(IRequestCycle cycle)
|
82 |
| { |
83 |
1
| Resource location = getResourceLocation();
|
84 |
| |
85 |
1
| try
|
86 |
| { |
87 |
1
| URL url = location.getResourceURL();
|
88 |
| |
89 |
1
| return url.openStream();
|
90 |
| } |
91 |
| catch (Exception ex) |
92 |
| { |
93 |
0
| throw new ApplicationRuntimeException(AssetMessages.noSuchResource(location.getPath()));
|
94 |
| } |
95 |
| } |
96 |
| |
97 |
| } |