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