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 |
7 |
public class AssetEncoder implements ServiceEncoder |
31 |
|
{ |
32 |
|
public static final String DIGEST_STATIC = "static"; |
33 |
|
|
34 |
|
private static final String PATH_SEPARATOR = "/"; |
35 |
|
|
36 |
|
private String _path; |
37 |
|
|
38 |
|
public void setPath(String path) |
39 |
|
{ |
40 |
6 |
_path = path; |
41 |
6 |
} |
42 |
|
|
43 |
|
public void encode(ServiceEncoding encoding) |
44 |
|
{ |
45 |
4 |
if (!encoding.getParameterValue(ServiceConstants.SERVICE).equals(Tapestry.ASSET_SERVICE)) |
46 |
1 |
return; |
47 |
|
|
48 |
3 |
String path = encoding.getParameterValue(AssetService.PATH); |
49 |
3 |
String digest = encoding.getParameterValue(AssetService.DIGEST); |
50 |
|
|
51 |
|
|
52 |
|
|
53 |
3 |
if (!path.startsWith(PATH_SEPARATOR)) |
54 |
1 |
path = PATH_SEPARATOR + path; |
55 |
|
|
56 |
|
|
57 |
|
|
58 |
3 |
String fullPath = _path + ((digest != null) ? "/" + digest : "/" + DIGEST_STATIC) + path; |
59 |
|
|
60 |
3 |
encoding.setServletPath(fullPath); |
61 |
3 |
encoding.setParameterValue(AssetService.PATH, null); |
62 |
3 |
encoding.setParameterValue(AssetService.DIGEST, null); |
63 |
3 |
encoding.setParameterValue(ServiceConstants.SERVICE, null); |
64 |
3 |
} |
65 |
|
|
66 |
|
public void decode(ServiceEncoding encoding) |
67 |
|
{ |
68 |
3 |
if (!encoding.getServletPath().equals(_path)) |
69 |
1 |
return; |
70 |
|
|
71 |
2 |
String pathInfo = encoding.getPathInfo(); |
72 |
|
|
73 |
|
|
74 |
|
|
75 |
2 |
int slashx = pathInfo.indexOf('/', 1); |
76 |
|
|
77 |
2 |
encoding.setParameterValue(ServiceConstants.SERVICE, Tapestry.ASSET_SERVICE); |
78 |
2 |
encoding.setParameterValue(AssetService.DIGEST, pathInfo.substring(1, slashx)); |
79 |
2 |
encoding.setParameterValue(AssetService.PATH, pathInfo.substring(slashx)); |
80 |
2 |
} |
81 |
|
|
82 |
|
} |