1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| package org.apache.tapestry.engine.encoders; |
16 |
| |
17 |
| import org.apache.tapestry.Tapestry; |
18 |
| import org.apache.tapestry.asset.AssetService; |
19 |
| import org.apache.tapestry.engine.ServiceEncoder; |
20 |
| import org.apache.tapestry.engine.ServiceEncoding; |
21 |
| import org.apache.tapestry.services.ServiceConstants; |
22 |
| |
23 |
| |
24 |
| |
25 |
| |
26 |
| |
27 |
| |
28 |
| |
29 |
| |
30 |
| public class AssetEncoder implements ServiceEncoder |
31 |
| { |
32 |
| private String _path; |
33 |
| |
34 |
6
| public void setPath(String path)
|
35 |
| { |
36 |
6
| _path = path;
|
37 |
| } |
38 |
| |
39 |
4
| public void encode(ServiceEncoding encoding)
|
40 |
| { |
41 |
4
| if (!encoding.getParameterValue(ServiceConstants.SERVICE).equals(Tapestry.ASSET_SERVICE))
|
42 |
2
| return;
|
43 |
| |
44 |
2
| String path = encoding.getParameterValue(AssetService.PATH);
|
45 |
2
| String digest = encoding.getParameterValue(AssetService.DIGEST);
|
46 |
| |
47 |
| |
48 |
| |
49 |
2
| String fullPath = _path + "/" + digest + path;
|
50 |
| |
51 |
2
| encoding.setServletPath(fullPath);
|
52 |
2
| encoding.setParameterValue(AssetService.PATH, null);
|
53 |
2
| encoding.setParameterValue(AssetService.DIGEST, null);
|
54 |
2
| encoding.setParameterValue(ServiceConstants.SERVICE, null);
|
55 |
| } |
56 |
| |
57 |
4
| public void decode(ServiceEncoding encoding)
|
58 |
| { |
59 |
4
| if (!encoding.getServletPath().equals(_path))
|
60 |
2
| return;
|
61 |
| |
62 |
2
| String pathInfo = encoding.getPathInfo();
|
63 |
| |
64 |
| |
65 |
| |
66 |
2
| int slashx = pathInfo.indexOf('/', 1);
|
67 |
| |
68 |
2
| encoding.setParameterValue(ServiceConstants.SERVICE, Tapestry.ASSET_SERVICE);
|
69 |
2
| encoding.setParameterValue(AssetService.DIGEST, pathInfo.substring(1, slashx));
|
70 |
2
| encoding.setParameterValue(AssetService.PATH, pathInfo.substring(slashx));
|
71 |
| } |
72 |
| |
73 |
| } |