001 // Copyright 2004, 2005 The Apache Software Foundation
002 //
003 // Licensed under the Apache License, Version 2.0 (the "License");
004 // you may not use this file except in compliance with the License.
005 // You may obtain a copy of the License at
006 //
007 // http://www.apache.org/licenses/LICENSE-2.0
008 //
009 // Unless required by applicable law or agreed to in writing, software
010 // distributed under the License is distributed on an "AS IS" BASIS,
011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012 // See the License for the specific language governing permissions and
013 // limitations under the License.
014
015 package org.apache.tapestry.engine;
016
017 import java.io.IOException;
018 import java.util.HashMap;
019 import java.util.Map;
020
021 import org.apache.tapestry.IRequestCycle;
022 import org.apache.tapestry.Tapestry;
023 import org.apache.tapestry.services.LinkFactory;
024 import org.apache.tapestry.services.ResponseRenderer;
025 import org.apache.tapestry.services.ServiceConstants;
026
027 /**
028 * An implementation of the home service that renders the Home page. This is the most likely
029 * candidate for overriding ... for example, to select the page to render based on known information
030 * about the user (stored as a cookie).
031 *
032 * @author Howard Lewis Ship
033 * @since 1.0.9
034 */
035
036 public class HomeService implements IEngineService
037 {
038 /** @since 4.0 */
039 private ResponseRenderer _responseRenderer;
040
041 /** @since 4.0 */
042
043 private LinkFactory _linkFactory;
044
045 /** @since 4.0 */
046
047 private String _pageName;
048
049 public ILink getLink(boolean post, Object parameter)
050 {
051 if (parameter != null)
052 throw new IllegalArgumentException(EngineMessages.serviceNoParameter(this));
053
054 Map parameters = new HashMap();
055
056 parameters.put(ServiceConstants.SERVICE, getName());
057
058 return _linkFactory.constructLink(this, post, parameters, true);
059 }
060
061 public void service(IRequestCycle cycle) throws IOException
062 {
063 cycle.activate(_pageName);
064
065 _responseRenderer.renderResponse(cycle);
066 }
067
068 public String getName()
069 {
070 return Tapestry.HOME_SERVICE;
071 }
072
073 /** @since 4.0 */
074 public void setResponseRenderer(ResponseRenderer responseRenderer)
075 {
076 _responseRenderer = responseRenderer;
077 }
078
079 /** @since 4.0 */
080 public void setLinkFactory(LinkFactory linkFactory)
081 {
082 _linkFactory = linkFactory;
083 }
084
085 /** @since 4.0 */
086 public void setPageName(String pageName)
087 {
088 _pageName = pageName;
089 }
090
091 /** @since 4.0 */
092 public String getPageName()
093 {
094 return _pageName;
095 }
096 }