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