|
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.engine.ServiceEncoder; |
|
19 |
| import org.apache.tapestry.engine.ServiceEncoding; |
|
20 |
| import org.apache.tapestry.services.ServiceConstants; |
|
21 |
| |
|
22 |
| |
|
23 |
| |
|
24 |
| |
|
25 |
| |
|
26 |
| |
|
27 |
| |
|
28 |
| |
|
29 |
| |
|
30 |
| |
|
31 |
| public class PageServiceEncoder implements ServiceEncoder |
|
32 |
| { |
|
33 |
| private String _extension; |
|
34 |
| |
|
35 |
| private String _serviceName; |
|
36 |
| |
|
37 |
15
| public void encode(ServiceEncoding encoding)
|
|
38 |
| { |
|
39 |
15
| String service = encoding.getParameterValue(ServiceConstants.SERVICE);
|
|
40 |
| |
|
41 |
15
| if (!service.equals(_serviceName))
|
|
42 |
3
| return;
|
|
43 |
| |
|
44 |
12
| String pageName = encoding.getParameterValue(ServiceConstants.PAGE);
|
|
45 |
| |
|
46 |
| |
|
47 |
| |
|
48 |
12
| if (pageName.indexOf(INamespace.SEPARATOR) >= 0)
|
|
49 |
3
| return;
|
|
50 |
| |
|
51 |
9
| StringBuffer buffer = new StringBuffer("/");
|
|
52 |
9
| buffer.append(pageName);
|
|
53 |
9
| buffer.append('.');
|
|
54 |
9
| buffer.append(_extension);
|
|
55 |
| |
|
56 |
9
| encoding.setServletPath(buffer.toString());
|
|
57 |
| |
|
58 |
9
| encoding.setParameterValue(ServiceConstants.SERVICE, null);
|
|
59 |
9
| encoding.setParameterValue(ServiceConstants.PAGE, null);
|
|
60 |
| } |
|
61 |
| |
|
62 |
12
| public void decode(ServiceEncoding encoding)
|
|
63 |
| { |
|
64 |
12
| String servletPath = encoding.getServletPath();
|
|
65 |
| |
|
66 |
12
| int dotx = servletPath.lastIndexOf('.');
|
|
67 |
12
| if (dotx < 0)
|
|
68 |
3
| return;
|
|
69 |
| |
|
70 |
9
| String extension = servletPath.substring(dotx + 1);
|
|
71 |
| |
|
72 |
9
| if (!extension.equals(_extension))
|
|
73 |
6
| return;
|
|
74 |
| |
|
75 |
| |
|
76 |
| |
|
77 |
3
| String page = servletPath.substring(1, dotx);
|
|
78 |
| |
|
79 |
3
| encoding.setParameterValue(ServiceConstants.SERVICE, _serviceName);
|
|
80 |
3
| encoding.setParameterValue(ServiceConstants.PAGE, page);
|
|
81 |
| } |
|
82 |
| |
|
83 |
12
| public void setExtension(String extension)
|
|
84 |
| { |
|
85 |
12
| _extension = extension;
|
|
86 |
| } |
|
87 |
| |
|
88 |
18
| public void setServiceName(String serviceName)
|
|
89 |
| { |
|
90 |
18
| _serviceName = serviceName;
|
|
91 |
| } |
|
92 |
| } |