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 Eudaldo Alonso
031     */
032    public abstract class BaseJSPPortletConfigurationIconFactory
033            extends BasePortletConfigurationIconFactory {
034    
035            public abstract String getJspPath();
036    
037            @Override
038            public boolean include(
039                            HttpServletRequest request, HttpServletResponse response)
040                    throws IOException {
041    
042                    String jspPath = getJspPath();
043    
044                    if (Validator.isNull(jspPath)) {
045                            return false;
046                    }
047    
048                    RequestDispatcher requestDispatcher =
049                            _servletContext.getRequestDispatcher(getJspPath());
050    
051                    try {
052                            requestDispatcher.include(request, response);
053                    }
054                    catch (ServletException se) {
055                            _log.error("Unable to include JSP " + getJspPath(), se);
056    
057                            return false;
058                    }
059    
060                    return true;
061            }
062    
063            public void setServletContext(ServletContext servletContext) {
064                    _servletContext = servletContext;
065            }
066    
067            private static final Log _log = LogFactoryUtil.getLog(
068                    BaseJSPPortletConfigurationIconFactory.class);
069    
070            private ServletContext _servletContext;
071    
072    }