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.INamespace; |
18 |
| import org.apache.tapestry.Tapestry; |
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 |
| |
31 |
| public class DirectServiceEncoder implements ServiceEncoder |
32 |
| { |
33 |
| private String _statelessExtension; |
34 |
| |
35 |
| private String _statefulExtension; |
36 |
| |
37 |
4
| public void encode(ServiceEncoding encoding)
|
38 |
| { |
39 |
4
| String service = encoding.getParameterValue(ServiceConstants.SERVICE);
|
40 |
4
| if (!service.equals(Tapestry.DIRECT_SERVICE))
|
41 |
1
| return;
|
42 |
| |
43 |
3
| String pageName = encoding.getParameterValue(ServiceConstants.PAGE);
|
44 |
| |
45 |
| |
46 |
| |
47 |
3
| if (pageName.indexOf(INamespace.SEPARATOR) >= 0)
|
48 |
1
| return;
|
49 |
| |
50 |
2
| String stateful = encoding.getParameterValue(ServiceConstants.SESSION);
|
51 |
2
| String componentIdPath = encoding.getParameterValue(ServiceConstants.COMPONENT);
|
52 |
| |
53 |
2
| StringBuffer buffer = new StringBuffer("/");
|
54 |
2
| buffer.append(pageName);
|
55 |
| |
56 |
2
| buffer.append(",");
|
57 |
2
| buffer.append(componentIdPath);
|
58 |
| |
59 |
2
| buffer.append(".");
|
60 |
2
| buffer.append(stateful != null ? _statefulExtension : _statelessExtension);
|
61 |
| |
62 |
2
| encoding.setServletPath(buffer.toString());
|
63 |
| |
64 |
2
| encoding.setParameterValue(ServiceConstants.SERVICE, null);
|
65 |
2
| encoding.setParameterValue(ServiceConstants.PAGE, null);
|
66 |
2
| encoding.setParameterValue(ServiceConstants.SESSION, null);
|
67 |
2
| encoding.setParameterValue(ServiceConstants.COMPONENT, null);
|
68 |
| } |
69 |
| |
70 |
3
| public void decode(ServiceEncoding encoding)
|
71 |
| { |
72 |
3
| String servletPath = encoding.getServletPath();
|
73 |
| |
74 |
3
| int dotx = servletPath.lastIndexOf('.');
|
75 |
3
| if (dotx < 0)
|
76 |
0
| return;
|
77 |
| |
78 |
3
| String extension = servletPath.substring(dotx + 1);
|
79 |
| |
80 |
3
| if (!(extension.equals(_statefulExtension) || extension.equals(_statelessExtension)))
|
81 |
1
| return;
|
82 |
| |
83 |
2
| int commax = servletPath.lastIndexOf(',');
|
84 |
| |
85 |
2
| String pageName = servletPath.substring(1, commax);
|
86 |
2
| String componentIdPath = servletPath.substring(commax + 1, dotx);
|
87 |
| |
88 |
2
| encoding.setParameterValue(ServiceConstants.SERVICE, Tapestry.DIRECT_SERVICE);
|
89 |
2
| encoding.setParameterValue(ServiceConstants.PAGE, pageName);
|
90 |
2
| encoding.setParameterValue(
|
91 |
| ServiceConstants.SESSION, |
92 |
2
| extension.equals(_statefulExtension) ? "T" : null);
|
93 |
2
| encoding.setParameterValue(ServiceConstants.COMPONENT, componentIdPath);
|
94 |
| } |
95 |
| |
96 |
4
| public void setStatefulExtension(String statefulExtension)
|
97 |
| { |
98 |
4
| _statefulExtension = statefulExtension;
|
99 |
| } |
100 |
| |
101 |
4
| public void setStatelessExtension(String statelessExtension)
|
102 |
| { |
103 |
4
| _statelessExtension = statelessExtension;
|
104 |
| } |
105 |
| } |