Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||||||
PageService |
|
| 1.0;1 |
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.hivemind.util.Defense; |
|
22 | import org.apache.tapestry.IRequestCycle; |
|
23 | import org.apache.tapestry.Tapestry; |
|
24 | import org.apache.tapestry.services.LinkFactory; |
|
25 | import org.apache.tapestry.services.ResponseRenderer; |
|
26 | import org.apache.tapestry.services.ServiceConstants; |
|
27 | ||
28 | /** |
|
29 | * Basic server for creating a link to another page in the application. |
|
30 | * |
|
31 | * @author Howard Lewis Ship |
|
32 | * @since 1.0.9 |
|
33 | */ |
|
34 | ||
35 | 2 | public class PageService implements IEngineService |
36 | { |
|
37 | /** @since 4.0 */ |
|
38 | private ResponseRenderer _responseRenderer; |
|
39 | ||
40 | /** @since 4.0 */ |
|
41 | private LinkFactory _linkFactory; |
|
42 | ||
43 | public ILink getLink(boolean post, Object parameter) |
|
44 | { |
|
45 | 2 | Defense.isAssignable(parameter, String.class, "parameter"); |
46 | ||
47 | 1 | Map parameters = new HashMap(); |
48 | ||
49 | 1 | parameters.put(ServiceConstants.PAGE, parameter); |
50 | ||
51 | 1 | return _linkFactory.constructLink(this, post, parameters, true); |
52 | ||
53 | } |
|
54 | ||
55 | public void service(IRequestCycle cycle) throws IOException |
|
56 | { |
|
57 | 1 | String pageName = cycle.getParameter(ServiceConstants.PAGE); |
58 | ||
59 | // At one time, the page service required a session, but that is no longer necessary. |
|
60 | // Users can now bookmark pages within a Tapestry application. Pages |
|
61 | // can implement validate() and throw a PageRedirectException if they don't |
|
62 | // want to be accessed this way. For example, most applications have a concept |
|
63 | // of a "login" and have a few pages that don't require the user to be logged in, |
|
64 | // and other pages that do. The protected pages should redirect to a login page. |
|
65 | ||
66 | 1 | cycle.activate(pageName); |
67 | ||
68 | 1 | _responseRenderer.renderResponse(cycle); |
69 | 1 | } |
70 | ||
71 | public String getName() |
|
72 | { |
|
73 | 0 | return Tapestry.PAGE_SERVICE; |
74 | } |
|
75 | ||
76 | /** @since 4.0 */ |
|
77 | public void setResponseRenderer(ResponseRenderer responseRenderer) |
|
78 | { |
|
79 | 1 | _responseRenderer = responseRenderer; |
80 | 1 | } |
81 | ||
82 | /** @since 4.0 */ |
|
83 | public void setLinkFactory(LinkFactory linkFactory) |
|
84 | { |
|
85 | 1 | _linkFactory = linkFactory; |
86 | 1 | } |
87 | } |