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