KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > engine > PageService


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 JavaDoc;
18 import java.util.HashMap JavaDoc;
19 import java.util.Map JavaDoc;
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 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(IRequestCycle cycle, Object JavaDoc parameter)
44     {
45         Defense.isAssignable(parameter, String JavaDoc.class, "parameter");
46
47         Map JavaDoc parameters = new HashMap JavaDoc();
48
49         parameters.put(ServiceConstants.SERVICE, Tapestry.PAGE_SERVICE);
50         parameters.put(ServiceConstants.PAGE, parameter);
51
52         return _linkFactory.constructLink(cycle, parameters, true);
53
54     }
55
56     public void service(IRequestCycle cycle) throws IOException JavaDoc
57     {
58         String JavaDoc pageName = cycle.getParameter(ServiceConstants.PAGE);
59
60         // At one time, the page service required a session, but that is no longer necessary.
61
// Users can now bookmark pages within a Tapestry application. Pages
62
// can implement validate() and throw a PageRedirectException if they don't
63
// want to be accessed this way. For example, most applications have a concept
64
// of a "login" and have a few pages that don't require the user to be logged in,
65
// and other pages that do. The protected pages should redirect to a login page.
66

67         cycle.activate(pageName);
68
69         _responseRenderer.renderResponse(cycle);
70     }
71
72     public String JavaDoc getName()
73     {
74         return Tapestry.PAGE_SERVICE;
75     }
76
77     /** @since 4.0 */
78     public void setResponseRenderer(ResponseRenderer responseRenderer)
79     {
80         _responseRenderer = responseRenderer;
81     }
82
83     /** @since 4.0 */
84     public void setLinkFactory(LinkFactory linkFactory)
85     {
86         _linkFactory = linkFactory;
87     }
88 }
Popular Tags