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