|
|||||||||||||||||||
30 day Evaluation License registered to hlship@comcast.net Your 30 day evaluation period has expired. Please visit http://www.cenqua.com to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
ResponseRendererImpl.java | 50% | 100% | 100% | 95% |
|
1 | // Copyright 2004, 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.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 | /** | |
30 | * Responsible for rendering a response to the client. | |
31 | * | |
32 | * @author Howard M. Lewis Ship | |
33 | * @since 4.0 | |
34 | */ | |
35 | public class ResponseRendererImpl implements ResponseRenderer | |
36 | { | |
37 | private RequestLocaleManager _localeManager; | |
38 | ||
39 | private MarkupWriterSource _markupWriterSource; | |
40 | ||
41 | private WebResponse _webResponse; | |
42 | ||
43 | /** | |
44 | * Inside a {@link org.apache.tapestry.util.ContentType}, the output encoding is called | |
45 | * "charset". | |
46 | */ | |
47 | ||
48 | public static final String ENCODING_KEY = "charset"; | |
49 | ||
50 | 141 | public void renderResponse(IRequestCycle cycle) throws IOException |
51 | { | |
52 | 141 | _localeManager.persistLocale(); |
53 | ||
54 | 141 | IPage page = cycle.getPage(); |
55 | ||
56 | 141 | ContentType contentType = page.getResponseContentType(); |
57 | ||
58 | 141 | String encoding = contentType.getParameter(ENCODING_KEY); |
59 | ||
60 | 141 | if (encoding == null) |
61 | { | |
62 | 141 | encoding = cycle.getEngine().getOutputEncoding(); |
63 | ||
64 | 141 | contentType.setParameter(ENCODING_KEY, encoding); |
65 | } | |
66 | ||
67 | 141 | PrintWriter printWriter = _webResponse.getPrintWriter(contentType); |
68 | ||
69 | 141 | IMarkupWriter writer = _markupWriterSource.newMarkupWriter(printWriter, contentType); |
70 | ||
71 | 141 | cycle.renderPage(writer); |
72 | ||
73 | 131 | writer.close(); |
74 | } | |
75 | ||
76 | 41 | public void setLocaleManager(RequestLocaleManager localeManager) |
77 | { | |
78 | 41 | _localeManager = localeManager; |
79 | } | |
80 | ||
81 | 41 | public void setMarkupWriterSource(MarkupWriterSource markupWriterSource) |
82 | { | |
83 | 41 | _markupWriterSource = markupWriterSource; |
84 | } | |
85 | ||
86 | 41 | public void setWebResponse(WebResponse webResponse) |
87 | { | |
88 | 41 | _webResponse = webResponse; |
89 | } | |
90 | } |
|