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.portlet.configuration.icon;
016    
017    import com.liferay.portal.kernel.log.Log;
018    import com.liferay.portal.kernel.log.LogFactoryUtil;
019    import com.liferay.portal.kernel.util.Validator;
020    
021    import java.io.IOException;
022    
023    import javax.servlet.RequestDispatcher;
024    import javax.servlet.ServletContext;
025    import javax.servlet.ServletException;
026    import javax.servlet.http.HttpServletRequest;
027    import javax.servlet.http.HttpServletResponse;
028    
029    /**
030     * @author Eduardo Garcia
031     */
032    public abstract class BaseJSPPortletConfigurationIcon
033            extends BasePortletConfigurationIcon {
034    
035            public abstract String getJspPath();
036    
037            public ServletContext getServletContext() {
038                    return _servletContext;
039            }
040    
041            @Override
042            public boolean include(
043                            HttpServletRequest request, HttpServletResponse response)
044                    throws IOException {
045    
046                    String jspPath = getJspPath();
047    
048                    if (Validator.isNull(jspPath)) {
049                            return false;
050                    }
051    
052                    RequestDispatcher requestDispatcher =
053                            _servletContext.getRequestDispatcher(jspPath);
054    
055                    try {
056                            requestDispatcher.include(request, response);
057                    }
058                    catch (ServletException se) {
059                            _log.error("Unable to include JSP " + jspPath, se);
060    
061                            return false;
062                    }
063    
064                    return true;
065            }
066    
067            public void setServletContext(ServletContext servletContext) {
068                    _servletContext = servletContext;
069            }
070    
071            private static final Log _log = LogFactoryUtil.getLog(
072                    BaseJSPPortletConfigurationIcon.class);
073    
074            private ServletContext _servletContext;
075    
076    }