1 /*
2 * Copyright 2023 Web-Legacy
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.apache.tiles.request.jakarta.servlet;
17
18 import java.io.PrintWriter;
19
20 import jakarta.servlet.http.HttpServletResponse;
21 import jakarta.servlet.http.HttpServletResponseWrapper;
22
23 /**
24 * Wraps an HTTP response and overrides its print writer.
25 *
26 * <p>Copied from Apache tiles-request-servlet 1.0.7 and adapted for
27 * Jakarta EE 9.</p>
28 */
29 public class ExternalWriterHttpServletResponse extends
30 HttpServletResponseWrapper {
31
32 /**
33 * The print writer to use, instead of the response's one.
34 */
35 private PrintWriter writer;
36
37 /**
38 * Constructor.
39 *
40 * @param response The response to wrap.
41 * @param writer The print writer to use, instead of the response's one.
42 */
43 public ExternalWriterHttpServletResponse(HttpServletResponse response,
44 PrintWriter writer) {
45
46 super(response);
47
48 this.writer = writer;
49 }
50
51 /**
52 * Returns the print writer to use, instead of the response's one.
53 *
54 * @return the {@code PrintWriter} object that is set within the
55 * constructor
56 */
57 @Override
58 public PrintWriter getWriter() {
59 return writer;
60 }
61 }