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.portlet;
016    
017    import com.liferay.portal.kernel.model.Portlet;
018    import com.liferay.portal.kernel.portlet.InvokerPortlet;
019    import com.liferay.portal.kernel.util.ParamUtil;
020    import com.liferay.portal.kernel.util.PortalUtil;
021    import com.liferay.portal.kernel.util.StringPool;
022    import com.liferay.portal.kernel.util.Validator;
023    
024    import java.util.Map;
025    
026    import javax.portlet.PortletContext;
027    import javax.portlet.PortletMode;
028    import javax.portlet.PortletPreferences;
029    import javax.portlet.PortletRequest;
030    import javax.portlet.ResourceRequest;
031    import javax.portlet.ResourceURL;
032    import javax.portlet.WindowState;
033    
034    import javax.servlet.http.HttpServletRequest;
035    
036    /**
037     * @author Brian Wing Shun Chan
038     */
039    public class ResourceRequestImpl
040            extends ClientDataRequestImpl implements ResourceRequest {
041    
042            @Override
043            public String getCacheability() {
044                    return _cacheablity;
045            }
046    
047            @Override
048            public String getETag() {
049                    return null;
050            }
051    
052            @Override
053            public String getLifecycle() {
054                    return PortletRequest.RESOURCE_PHASE;
055            }
056    
057            @Override
058            public Map<String, String[]> getPrivateRenderParameterMap() {
059                    return null;
060            }
061    
062            @Override
063            public String getResourceID() {
064                    return _resourceID;
065            }
066    
067            @Override
068            protected void init(
069                    HttpServletRequest request, Portlet portlet,
070                    InvokerPortlet invokerPortlet, PortletContext portletContext,
071                    WindowState windowState, PortletMode portletMode,
072                    PortletPreferences preferences, long plid) {
073    
074                    if (Validator.isNull(windowState.toString())) {
075                            windowState = WindowState.NORMAL;
076                    }
077    
078                    if (Validator.isNull(portletMode.toString())) {
079                            portletMode = PortletMode.VIEW;
080                    }
081    
082                    super.init(
083                            request, portlet, invokerPortlet, portletContext, windowState,
084                            portletMode, preferences, plid);
085    
086                    _cacheablity = ParamUtil.getString(
087                            request, "p_p_cacheability", ResourceURL.PAGE);
088    
089                    _resourceID = request.getParameter("p_p_resource_id");
090    
091                    if (!PortalUtil.isValidResourceId(_resourceID)) {
092                            _resourceID = StringPool.BLANK;
093                    }
094            }
095    
096            private String _cacheablity;
097            private String _resourceID;
098    
099    }