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.portal.kernel.servlet.taglib;
016    
017    import com.liferay.portal.kernel.log.Log;
018    
019    import java.io.IOException;
020    
021    import javax.servlet.RequestDispatcher;
022    import javax.servlet.ServletContext;
023    import javax.servlet.ServletException;
024    import javax.servlet.http.HttpServletRequest;
025    import javax.servlet.http.HttpServletResponse;
026    
027    /**
028     * @author Philip Jones
029     */
030    public abstract class BaseJSPDynamicInclude extends BaseDynamicInclude {
031    
032            @Override
033            public void include(
034                            HttpServletRequest request, HttpServletResponse response,
035                            String key)
036                    throws IOException {
037    
038                    RequestDispatcher requestDispatcher =
039                            _servletContext.getRequestDispatcher(getJspPath());
040    
041                    try {
042                            requestDispatcher.include(request, response);
043                    }
044                    catch (ServletException se) {
045                            Log log = getLog();
046    
047                            log.error("Unable to include JSP " + getJspPath(), se);
048    
049                            throw new IOException("Unable to include JSP " + getJspPath(), se);
050                    }
051            }
052    
053            @Override
054            public void register(
055                    DynamicInclude.DynamicIncludeRegistry dynamicIncludeRegistry) {
056            }
057    
058            protected abstract String getJspPath();
059    
060            protected abstract Log getLog();
061    
062            protected void setServletContext(ServletContext servletContext) {
063                    _servletContext = servletContext;
064            }
065    
066            private ServletContext _servletContext;
067    
068    }