001    /**
002     * Copyright (c) 2000-2010 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.portlet.LiferayPortletURL;
018    
019    import java.util.Locale;
020    
021    import javax.portlet.PortletRequest;
022    import javax.portlet.PortletURL;
023    import javax.portlet.ResourceRequest;
024    import javax.portlet.ResourceResponse;
025    import javax.portlet.ResourceURL;
026    
027    import javax.servlet.http.Cookie;
028    import javax.servlet.http.HttpServletResponse;
029    
030    /**
031     * @author Brian Wing Shun Chan
032     */
033    public class ResourceResponseImpl
034            extends MimeResponseImpl implements ResourceResponse {
035    
036            public void addDateHeader(String name, long date) {
037                    _response.addDateHeader(name, date);
038            }
039    
040            public void addHeader(String name, String value) {
041                    _response.addHeader(name, value);
042            }
043    
044            public void addIntHeader(String name, int value) {
045                    _response.addIntHeader(name, value);
046            }
047    
048            public void addProperty(Cookie cookie) {
049                    _response.addCookie(cookie);
050            }
051    
052            public PortletURL createActionURL() {
053                    return super.createActionURL();
054            }
055    
056            public LiferayPortletURL createLiferayPortletURL(
057                    String portletName, String lifecycle) {
058    
059                    ResourceRequest resourceRequest = (ResourceRequest)getPortletRequest();
060    
061                    String cacheability = resourceRequest.getCacheability();
062    
063                    if (cacheability.equals(ResourceURL.PAGE)) {
064                    }
065                    else if (lifecycle.equals(PortletRequest.ACTION_PHASE)) {
066                            throw new IllegalStateException(
067                                    "Unable to create an action URL from a resource response " +
068                                            "when the cacheability is not set to PAGE");
069                    }
070                    else if (lifecycle.equals(PortletRequest.RENDER_PHASE)) {
071                            throw new IllegalStateException(
072                                    "Unable to create a render URL from a resource response when " +
073                                            "the cacheability is not set to PAGE");
074                    }
075    
076                    return super.createLiferayPortletURL(portletName, lifecycle);
077            }
078    
079            public PortletURL createRenderURL() {
080                    return super.createRenderURL();
081            }
082    
083            public ResourceURL createResourceURL() {
084                    return super.createResourceURL();
085            }
086    
087            public String getLifecycle() {
088                    return PortletRequest.RESOURCE_PHASE;
089            }
090    
091            public void setCharacterEncoding(String charset) {
092                    _response.setCharacterEncoding(charset);
093            }
094    
095            public void setLocale(Locale locale) {
096                    _response.setLocale(locale);
097            }
098    
099            public void setContentLength(int length) {
100                    _response.setContentLength(length);
101            }
102    
103            public void setDateHeader(String name, long date) {
104                    _response.setDateHeader(name, date);
105            }
106    
107            public void setHeader(String name, String value) {
108                    _response.setHeader(name, value);
109            }
110    
111            public void setIntHeader(String name, int value) {
112                    _response.setIntHeader(name, value);
113            }
114    
115            protected void init(
116                    PortletRequestImpl portletRequestImpl, HttpServletResponse response,
117                    String portletName, long companyId, long plid) {
118    
119                    super.init(portletRequestImpl, response, portletName, companyId, plid);
120    
121                    _response = response;
122            }
123    
124            private HttpServletResponse _response;
125    
126    }