1 15 package org.apache.tapestry.portlet; 16 17 import java.io.IOException ; 18 19 import javax.portlet.PortletRequest; 20 21 import org.apache.tapestry.IRequestCycle; 22 import org.apache.tapestry.engine.IEngineService; 23 import org.apache.tapestry.engine.ILink; 24 import org.apache.tapestry.services.ServiceConstants; 25 26 46 public class RenderService implements IEngineService 47 { 48 private PortletRequest _request; 49 50 private PortletRenderer _portletRenderer; 51 52 private PortletPageResolver _pageResolver; 53 54 public ILink getLink(IRequestCycle cycle, Object parameter) 55 { 56 throw new UnsupportedOperationException (PortletMessages.unsupportedMethod("getLink")); 57 } 58 59 public void service(IRequestCycle cycle) throws IOException 60 { 61 String pageName = getPageNameToRender(cycle); 62 63 _portletRenderer.renderPage(cycle, pageName); 64 } 65 66 private String getPageNameToRender(IRequestCycle cycle) 67 { 68 if (isStateChange(cycle)) 69 return _pageResolver.getPageNameForRequest(cycle); 70 71 return cycle.getParameter(ServiceConstants.PAGE); 72 } 73 74 78 79 boolean isStateChange(IRequestCycle cycle) 80 { 81 String expectedPortletMode = cycle.getParameter(PortletConstants.PORTLET_MODE); 82 String expectedWindowState = cycle.getParameter(PortletConstants.WINDOW_STATE); 83 84 return !(_request.getPortletMode().toString().equals(expectedPortletMode) && _request 85 .getWindowState().toString().equals(expectedWindowState)); 86 87 } 88 89 public String getName() 90 { 91 return PortletConstants.RENDER_SERVICE; 92 } 93 94 public void setPortletRenderer(PortletRenderer portletRenderer) 95 { 96 _portletRenderer = portletRenderer; 97 } 98 99 public void setRequest(PortletRequest request) 100 { 101 _request = request; 102 } 103 104 public void setPageResolver(PortletPageResolver pageResolver) 105 { 106 _pageResolver = pageResolver; 107 } 108 } | Popular Tags |