|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
ResponseRendererImpl.java | 100% | 100% | 100% | 100% |
|
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 |
|
|
19 |
import javax.servlet.ServletException;
|
|
20 |
|
|
21 |
import org.apache.tapestry.IMarkupWriter;
|
|
22 |
import org.apache.tapestry.IPage;
|
|
23 |
import org.apache.tapestry.IRequestCycle;
|
|
24 |
import org.apache.tapestry.request.ResponseOutputStream;
|
|
25 |
import org.apache.tapestry.services.RequestLocaleManager;
|
|
26 |
import org.apache.tapestry.services.ResponseRenderer;
|
|
27 |
|
|
28 |
/**
|
|
29 |
* Responsible for rendering a response to the client.
|
|
30 |
*
|
|
31 |
* @author Howard M. Lewis Ship
|
|
32 |
* @since 3.1
|
|
33 |
*/
|
|
34 |
public class ResponseRendererImpl implements ResponseRenderer |
|
35 |
{ |
|
36 |
private RequestLocaleManager _localeManager;
|
|
37 |
|
|
38 | 195 |
public void renderResponse(IRequestCycle cycle, ResponseOutputStream output) |
39 |
throws ServletException, IOException
|
|
40 |
{ |
|
41 | 195 |
_localeManager.persistLocale(cycle.getEngine().getLocale()); |
42 |
|
|
43 | 195 |
IPage page = cycle.getPage(); |
44 |
|
|
45 | 195 |
IMarkupWriter writer = page.getResponseWriter(output); |
46 |
|
|
47 | 195 |
output.setContentType(writer.getContentType()); |
48 |
|
|
49 | 195 |
boolean discard = true; |
50 |
|
|
51 | 195 |
try
|
52 |
{ |
|
53 | 195 |
cycle.renderPage(writer); |
54 |
|
|
55 | 180 |
discard = false;
|
56 |
} |
|
57 |
finally
|
|
58 |
{ |
|
59 |
// Closing the writer closes its PrintWriter and a whole stack of
|
|
60 |
// java.io objects,
|
|
61 |
// which tend to stream a lot of output that eventually hits the
|
|
62 |
// ResponseOutputStream. If we are discarding output anyway (due to
|
|
63 |
// an exception
|
|
64 |
// getting thrown during the render), we can save ourselves some
|
|
65 |
// trouble
|
|
66 |
// by ignoring it.
|
|
67 |
|
|
68 | 195 |
if (discard)
|
69 | 15 |
output.setDiscard(true);
|
70 |
|
|
71 | 195 |
writer.close(); |
72 |
|
|
73 | 195 |
if (discard)
|
74 | 15 |
output.setDiscard(false);
|
75 |
} |
|
76 |
} |
|
77 |
|
|
78 | 52 |
public void setLocaleManager(RequestLocaleManager localeManager) |
79 |
{ |
|
80 | 52 |
_localeManager = localeManager; |
81 |
} |
|
82 |
} |
|