|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| package org.apache.tapestry.util.io; |
|
16 |
| |
|
17 |
| import org.apache.hivemind.ApplicationRuntimeException; |
|
18 |
| import org.apache.tapestry.Tapestry; |
|
19 |
| import org.apache.tapestry.services.DataSqueezer; |
|
20 |
| import org.apache.tapestry.util.ComponentAddress; |
|
21 |
| |
|
22 |
| |
|
23 |
| |
|
24 |
| |
|
25 |
| |
|
26 |
| |
|
27 |
| |
|
28 |
| |
|
29 |
| public class ComponentAddressAdaptor implements SqueezeAdaptor |
|
30 |
| { |
|
31 |
| private static final String PREFIX = "A"; |
|
32 |
| |
|
33 |
| private static final char SEPARATOR = ','; |
|
34 |
| |
|
35 |
111
| public String getPrefix()
|
|
36 |
| { |
|
37 |
111
| return PREFIX;
|
|
38 |
| } |
|
39 |
| |
|
40 |
111
| public Class getDataClass()
|
|
41 |
| { |
|
42 |
111
| return ComponentAddress.class;
|
|
43 |
| } |
|
44 |
| |
|
45 |
6
| public String squeeze(DataSqueezer squeezer, Object data)
|
|
46 |
| { |
|
47 |
6
| ComponentAddress address = (ComponentAddress) data;
|
|
48 |
| |
|
49 |
| |
|
50 |
6
| String idPath = address.getIdPath();
|
|
51 |
6
| if (idPath == null)
|
|
52 |
3
| idPath = "";
|
|
53 |
| |
|
54 |
6
| return PREFIX + address.getPageName() + SEPARATOR + idPath;
|
|
55 |
| } |
|
56 |
| |
|
57 |
6
| public Object unsqueeze(DataSqueezer squeezer, String string)
|
|
58 |
| { |
|
59 |
6
| int separator = string.indexOf(SEPARATOR);
|
|
60 |
6
| if (separator < 0)
|
|
61 |
0
| throw new ApplicationRuntimeException(Tapestry
|
|
62 |
| .getMessage("ComponentAddressAdaptor.no-separator")); |
|
63 |
| |
|
64 |
6
| String pageName = string.substring(1, separator);
|
|
65 |
6
| String idPath = string.substring(separator + 1);
|
|
66 |
6
| if (idPath.equals(""))
|
|
67 |
3
| idPath = null;
|
|
68 |
| |
|
69 |
6
| return new ComponentAddress(pageName, idPath);
|
|
70 |
| } |
|
71 |
| |
|
72 |
| } |