KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > portlet > PortletHomeService


1 // Copyright 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.portlet;
16
17 import java.io.IOException JavaDoc;
18 import java.util.HashMap JavaDoc;
19 import java.util.Map JavaDoc;
20
21 import org.apache.tapestry.IRequestCycle;
22 import org.apache.tapestry.Tapestry;
23 import org.apache.tapestry.engine.EngineMessages;
24 import org.apache.tapestry.engine.IEngineService;
25 import org.apache.tapestry.engine.ILink;
26 import org.apache.tapestry.services.LinkFactory;
27 import org.apache.tapestry.services.ResponseRenderer;
28 import org.apache.tapestry.services.ServiceConstants;
29
30 /**
31  * Replacement for the standard home service, used by Portlets. This exists to handle the special
32  * case where a Portlet render request arrives when there is not a Portlet action request prior ...
33  * this can happen when a Portlet is first added to a Portal page.
34  *
35  * @author Howard M. Lewis Ship
36  * @since 4.0
37  */

38 public class PortletHomeService implements IEngineService
39 {
40     private PortletRenderer _portletRenderer;
41
42     private PortletRequestGlobals _requestGlobals;
43
44     private ResponseRenderer _responseRenderer;
45
46     private LinkFactory _linkFactory;
47
48     private PortletPageResolver _pageResolver;
49
50     public String JavaDoc getName()
51     {
52         return Tapestry.HOME_SERVICE;
53     }
54
55     public ILink getLink(IRequestCycle cycle, Object JavaDoc parameter)
56     {
57         if (parameter != null)
58             throw new IllegalArgumentException JavaDoc(EngineMessages.serviceNoParameter(this));
59
60         Map JavaDoc parameters = new HashMap JavaDoc();
61
62         parameters.put(ServiceConstants.SERVICE, Tapestry.HOME_SERVICE);
63
64         return _linkFactory.constructLink(cycle, parameters, true);
65     }
66
67     public void setLinkFactory(LinkFactory linkFactory)
68     {
69         _linkFactory = linkFactory;
70     }
71
72     public void setResponseRenderer(ResponseRenderer responseRenderer)
73     {
74         _responseRenderer = responseRenderer;
75     }
76
77     public void service(IRequestCycle cycle) throws IOException JavaDoc
78     {
79         String JavaDoc pageName = _pageResolver.getPageNameForRequest(cycle);
80
81         if (_requestGlobals.isRenderRequest())
82         {
83             _portletRenderer.renderPage(cycle, pageName);
84             return;
85         }
86
87         cycle.activate(pageName);
88
89         _responseRenderer.renderResponse(cycle);
90     }
91
92     public void setPortletRenderer(PortletRenderer portletRenderer)
93     {
94         _portletRenderer = portletRenderer;
95     }
96
97     public void setRequestGlobals(PortletRequestGlobals requestGlobals)
98     {
99         _requestGlobals = requestGlobals;
100     }
101
102     public void setPageResolver(PortletPageResolver pageResolver)
103     {
104         _pageResolver = pageResolver;
105     }
106 }
Popular Tags