001/* 002 * Copyright 2023 Web-Legacy 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.apache.tiles.request.jakarta.servlet; 017 018import java.io.PrintWriter; 019 020import jakarta.servlet.http.HttpServletResponse; 021import jakarta.servlet.http.HttpServletResponseWrapper; 022 023/** 024 * Wraps an HTTP response and overrides its print writer. 025 * 026 * <p>Copied from Apache tiles-request-servlet 1.0.7 and adapted for 027 * Jakarta EE 9.</p> 028 */ 029public class ExternalWriterHttpServletResponse extends 030 HttpServletResponseWrapper { 031 032 /** 033 * The print writer to use, instead of the response's one. 034 */ 035 private PrintWriter writer; 036 037 /** 038 * Constructor. 039 * 040 * @param response The response to wrap. 041 * @param writer The print writer to use, instead of the response's one. 042 */ 043 public ExternalWriterHttpServletResponse(HttpServletResponse response, 044 PrintWriter writer) { 045 046 super(response); 047 048 this.writer = writer; 049 } 050 051 /** 052 * Returns the print writer to use, instead of the response's one. 053 * 054 * @return the {@code PrintWriter} object that is set within the 055 * constructor 056 */ 057 @Override 058 public PrintWriter getWriter() { 059 return writer; 060 } 061}