Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||||||
HomeService |
|
| 1.2857142857142858;1.286 |
1 | // Copyright 2004, 2005 The Apache Software Foundation |
|
2 | // |
|
3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
|
4 | // you may not use this file except in compliance with the License. |
|
5 | // You may obtain a copy of the License at |
|
6 | // |
|
7 | // http://www.apache.org/licenses/LICENSE-2.0 |
|
8 | // |
|
9 | // Unless required by applicable law or agreed to in writing, software |
|
10 | // distributed under the License is distributed on an "AS IS" BASIS, |
|
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
12 | // See the License for the specific language governing permissions and |
|
13 | // limitations under the License. |
|
14 | ||
15 | package org.apache.tapestry.engine; |
|
16 | ||
17 | import java.io.IOException; |
|
18 | import java.util.HashMap; |
|
19 | import java.util.Map; |
|
20 | ||
21 | import org.apache.tapestry.IRequestCycle; |
|
22 | import org.apache.tapestry.Tapestry; |
|
23 | import org.apache.tapestry.services.LinkFactory; |
|
24 | import org.apache.tapestry.services.ResponseRenderer; |
|
25 | import org.apache.tapestry.services.ServiceConstants; |
|
26 | ||
27 | /** |
|
28 | * An implementation of the home service that renders the Home page. This is the |
|
29 | * most likely candidate for overriding ... for example, to select the page to |
|
30 | * render based on known information about the user (stored as a cookie). |
|
31 | * |
|
32 | * @author Howard Lewis Ship |
|
33 | * @since 1.0.9 |
|
34 | */ |
|
35 | ||
36 | 1 | public class HomeService implements IEngineService |
37 | { |
|
38 | ||
39 | /** @since 4.0 */ |
|
40 | private ResponseRenderer _responseRenderer; |
|
41 | ||
42 | /** @since 4.0 */ |
|
43 | ||
44 | private LinkFactory _linkFactory; |
|
45 | ||
46 | /** @since 4.0 */ |
|
47 | ||
48 | private String _pageName; |
|
49 | ||
50 | public ILink getLink(boolean post, Object parameter) |
|
51 | { |
|
52 | 0 | if (parameter != null) |
53 | 0 | throw new IllegalArgumentException(EngineMessages |
54 | .serviceNoParameter(this)); |
|
55 | ||
56 | 0 | Map parameters = new HashMap(); |
57 | ||
58 | 0 | parameters.put(ServiceConstants.SERVICE, getName()); |
59 | ||
60 | 0 | return _linkFactory.constructLink(this, post, parameters, true); |
61 | } |
|
62 | ||
63 | public void service(IRequestCycle cycle) |
|
64 | throws IOException |
|
65 | { |
|
66 | 0 | cycle.activate(_pageName); |
67 | ||
68 | 0 | _responseRenderer.renderResponse(cycle); |
69 | 0 | } |
70 | ||
71 | public String getName() |
|
72 | { |
|
73 | 0 | return Tapestry.HOME_SERVICE; |
74 | } |
|
75 | ||
76 | /** @since 4.0 */ |
|
77 | public void setResponseRenderer(ResponseRenderer responseRenderer) |
|
78 | { |
|
79 | 0 | _responseRenderer = responseRenderer; |
80 | 0 | } |
81 | ||
82 | /** @since 4.0 */ |
|
83 | public void setLinkFactory(LinkFactory linkFactory) |
|
84 | { |
|
85 | 0 | _linkFactory = linkFactory; |
86 | 0 | } |
87 | ||
88 | /** @since 4.0 */ |
|
89 | public void setPageName(String pageName) |
|
90 | { |
|
91 | 0 | _pageName = pageName; |
92 | 0 | } |
93 | ||
94 | /** @since 4.0 */ |
|
95 | public String getPageName() |
|
96 | { |
|
97 | 0 | return _pageName; |
98 | } |
|
99 | } |