001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.taglib.servlet;
016    
017    import java.io.IOException;
018    import java.io.PrintWriter;
019    
020    import javax.servlet.ServletOutputStream;
021    import javax.servlet.http.HttpServletResponse;
022    import javax.servlet.http.HttpServletResponseWrapper;
023    import javax.servlet.jsp.JspWriter;
024    import javax.servlet.jsp.PageContext;
025    
026    /**
027     * @author Carlos Sierra Andr??s
028     */
029    public class JspWriterHttpServletResponse extends HttpServletResponseWrapper {
030    
031            public JspWriterHttpServletResponse(PageContext pageContext) {
032                    super((HttpServletResponse)pageContext.getResponse());
033    
034                    _pageContext = pageContext;
035            }
036    
037            @Override
038            public ServletOutputStream getOutputStream() {
039                    return new ServletOutputStream() {
040    
041                            @Override
042                            public void write(int b) throws IOException {
043                                    JspWriter jspWriter = _pageContext.getOut();
044    
045                                    jspWriter.write(b);
046                            }
047    
048                    };
049            }
050    
051            @Override
052            public PrintWriter getWriter() {
053                    return new PrintWriter(_pageContext.getOut(), true);
054            }
055    
056            private final PageContext _pageContext;
057    
058    }