001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.kernel.servlet;
016    
017    import com.liferay.portal.kernel.util.GetterUtil;
018    import com.liferay.portal.kernel.util.PropsKeys;
019    import com.liferay.portal.kernel.util.PropsUtil;
020    
021    import javax.servlet.Servlet;
022    import javax.servlet.ServletContext;
023    import javax.servlet.ServletRequest;
024    import javax.servlet.ServletResponse;
025    import javax.servlet.jsp.JspApplicationContext;
026    import javax.servlet.jsp.JspEngineInfo;
027    import javax.servlet.jsp.JspFactory;
028    import javax.servlet.jsp.PageContext;
029    
030    /**
031     * @author Shuyang Zhou
032     */
033    public class JspFactoryWrapper extends JspFactory {
034    
035            public JspFactoryWrapper(JspFactory jspFactory) {
036                    _jspFactory = jspFactory;
037            }
038    
039            public JspEngineInfo getEngineInfo() {
040                    return _jspFactory.getEngineInfo();
041            }
042    
043            public JspApplicationContext getJspApplicationContext(
044                    ServletContext servletContext) {
045    
046                    return _jspFactory.getJspApplicationContext(servletContext);
047            }
048    
049            public PageContext getPageContext(
050                    Servlet servlet, ServletRequest servletRequest,
051                    ServletResponse servletResponse, String errorPageURL,
052                    boolean needsSession, int buffer, boolean autoflush) {
053    
054                    PageContext pageContext = _jspFactory.getPageContext(
055                            servlet, servletRequest, servletResponse, errorPageURL,
056                            needsSession, _JSP_WRITER_BUFFER_SIZE, autoflush);
057    
058                    return new PageContextWrapper(pageContext);
059            }
060    
061            public void releasePageContext(PageContext pageContext) {
062                    if (pageContext instanceof PageContextWrapper) {
063                            PageContextWrapper pageContextWrapper =
064                                    (PageContextWrapper)pageContext;
065    
066                            pageContext = pageContextWrapper.getWrappedPageContext();
067                    }
068    
069                    _jspFactory.releasePageContext(pageContext);
070            }
071    
072            private static final int _JSP_WRITER_BUFFER_SIZE = GetterUtil.getInteger(
073                    PropsUtil.get(PropsKeys.JSP_WRITER_BUFFER_SIZE));
074    
075            private JspFactory _jspFactory;
076    
077    }