001    /**
002     * Copyright (c) 2000-2012 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 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            public void sendRedirect(String location) {
032                    if ((location == null) ||
033                            (!location.startsWith("/") && (location.indexOf("://") == -1) &&
034                            (!location.startsWith("wsrp_rewrite?")))) {
035    
036                            throw new IllegalArgumentException(
037                                    location + " is not a valid redirect");
038                    }
039    
040                    // This is needed because app servers will try to prepend a host if
041                    // they see an invalid URL
042    
043                    if (location.startsWith("wsrp_rewrite?")) {
044                            location = "http://wsrp-rewrite-holder?" + location;
045                    }
046    
047                    if (isCalledSetRenderParameter()) {
048                            throw new IllegalStateException(
049                                    "Set render parameter has already been called");
050                    }
051    
052                    setRedirectLocation(location);
053            }
054    
055            public void sendRedirect(String location, String renderUrlParamName) {
056            }
057    
058    }