001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portlet;
016    
017    import javax.portlet.ActionResponse;
018    import javax.portlet.PortletRequest;
019    
020    /**
021     * @author Brian Wing Shun Chan
022     */
023    public class ActionResponseImpl
024            extends StateAwareResponseImpl implements ActionResponse {
025    
026            @Override
027            public String getLifecycle() {
028                    return PortletRequest.ACTION_PHASE;
029            }
030    
031            @Override
032            public void sendRedirect(String location) {
033                    if ((location == null) ||
034                            (!location.startsWith("/") && !location.contains("://") &&
035                             !location.startsWith("wsrp_rewrite?"))) {
036    
037                            throw new IllegalArgumentException(
038                                    location + " is not a valid redirect");
039                    }
040    
041                    // This is needed because app servers will try to prepend a host if they
042                    // see an invalid URL
043    
044                    if (location.startsWith("wsrp_rewrite?")) {
045                            location = "http://wsrp-rewrite-holder?" + location;
046                    }
047    
048                    if (isCalledSetRenderParameter()) {
049                            throw new IllegalStateException(
050                                    "Set render parameter has already been called");
051                    }
052    
053                    setRedirectLocation(location);
054            }
055    
056            @Override
057            public void sendRedirect(String location, String renderUrlParamName) {
058            }
059    
060    }