1 15 package org.apache.tapestry.services.impl; 16 17 import java.io.IOException ; 18 import java.io.PrintWriter ; 19 20 import org.apache.tapestry.IMarkupWriter; 21 import org.apache.tapestry.IPage; 22 import org.apache.tapestry.IRequestCycle; 23 import org.apache.tapestry.markup.MarkupWriterSource; 24 import org.apache.tapestry.services.RequestLocaleManager; 25 import org.apache.tapestry.services.ResponseRenderer; 26 import org.apache.tapestry.util.ContentType; 27 import org.apache.tapestry.web.WebResponse; 28 29 35 public class ResponseRendererImpl implements ResponseRenderer 36 { 37 private RequestLocaleManager _localeManager; 38 39 private MarkupWriterSource _markupWriterSource; 40 41 private WebResponse _webResponse; 42 43 47 48 public static final String ENCODING_KEY = "charset"; 49 50 public void renderResponse(IRequestCycle cycle) throws IOException 51 { 52 _localeManager.persistLocale(); 53 54 IPage page = cycle.getPage(); 55 56 ContentType contentType = page.getResponseContentType(); 57 58 String encoding = contentType.getParameter(ENCODING_KEY); 59 60 if (encoding == null) 61 { 62 encoding = cycle.getEngine().getOutputEncoding(); 63 64 contentType.setParameter(ENCODING_KEY, encoding); 65 } 66 67 PrintWriter printWriter = _webResponse.getPrintWriter(contentType); 68 69 IMarkupWriter writer = _markupWriterSource.newMarkupWriter(printWriter, contentType); 70 71 cycle.renderPage(writer); 72 73 writer.close(); 74 } 75 76 public void setLocaleManager(RequestLocaleManager localeManager) 77 { 78 _localeManager = localeManager; 79 } 80 81 public void setMarkupWriterSource(MarkupWriterSource markupWriterSource) 82 { 83 _markupWriterSource = markupWriterSource; 84 } 85 86 public void setWebResponse(WebResponse webResponse) 87 { 88 _webResponse = webResponse; 89 } 90 } | Popular Tags |