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