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                            if (_log.isErrorEnabled()) {
048                                    _log.error("Unable to include JSP", se);
049                            }
050    
051                            throw new IOException("Unable to include JSP", se);
052                    }
053            }
054    
055            public void setServletContext(ServletContext servletContext) {
056                    _servletContext = servletContext;
057            }
058    
059            private static final Log _log = LogFactoryUtil.getLog(
060                    BaseJSPAssetAddonEntry.class);
061    
062            private ServletContext _servletContext;
063    
064    }