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