1 15 package org.apache.tapestry.portlet; 16 17 import java.io.IOException ; 18 import java.io.PrintWriter ; 19 import java.util.Date ; 20 21 import org.apache.tapestry.IMarkupWriter; 22 import org.apache.tapestry.IPage; 23 import org.apache.tapestry.IRequestCycle; 24 import org.apache.tapestry.Tapestry; 25 import org.apache.tapestry.TapestryUtils; 26 import org.apache.tapestry.asset.AssetFactory; 27 import org.apache.tapestry.engine.IEngineService; 28 import org.apache.tapestry.markup.MarkupWriterSource; 29 import org.apache.tapestry.util.ContentType; 30 import org.apache.tapestry.util.PageRenderSupportImpl; 31 import org.apache.tapestry.web.WebResponse; 32 33 41 public class PortletRendererImpl implements PortletRenderer 42 { 43 private WebResponse _response; 44 45 private MarkupWriterSource _markupWriterSource; 46 47 private AssetFactory _assetFactory; 48 49 private String _applicationId; 50 51 public void renderPage(IRequestCycle cycle, String pageName) throws IOException 52 { 53 cycle.activate(pageName); 54 55 IPage page = cycle.getPage(); 56 57 ContentType contentType = page.getResponseContentType(); 58 59 PrintWriter printWriter = _response.getPrintWriter(contentType); 60 61 IMarkupWriter writer = _markupWriterSource.newMarkupWriter(printWriter, contentType); 62 63 String namespace = _response.getNamespace(); 64 65 PageRenderSupportImpl support = new PageRenderSupportImpl(_assetFactory, namespace, null); 66 67 TapestryUtils.storePageRenderSupport(cycle, support); 68 69 IMarkupWriter nested = writer.getNestedWriter(); 70 71 cycle.renderPage(nested); 72 73 String id = "Tapestry Portlet " + _applicationId + " " + namespace; 74 75 writer.comment("BEGIN " + id); 76 writer.comment("Page: " + page.getPageName()); 77 writer.comment("Generated: " + new Date ()); 78 writer.comment("Framework version: " + Tapestry.VERSION); 79 80 support.writeBodyScript(writer, cycle); 81 82 nested.close(); 83 84 support.writeInitializationScript(writer); 85 86 writer.comment("END " + id); 87 88 writer.close(); 89 90 } 92 93 public void setMarkupWriterSource(MarkupWriterSource markupWriterSource) 94 { 95 _markupWriterSource = markupWriterSource; 96 } 97 98 public void setResponse(WebResponse response) 99 { 100 _response = response; 101 } 102 103 public void setAssetFactory(AssetFactory assetFactory) 104 { 105 _assetFactory = assetFactory; 106 } 107 108 public void setApplicationId(String applicationId) 109 { 110 _applicationId = applicationId; 111 } 112 } | Popular Tags |