1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portal.servlet;
16  
17  import com.liferay.portal.kernel.util.StringPool;
18  import com.liferay.portal.kernel.util.Validator;
19  import com.liferay.portal.util.CookieKeys;
20  import com.liferay.portal.util.PortalUtil;
21  
22  import java.io.IOException;
23  
24  import javax.servlet.http.HttpServletRequest;
25  import javax.servlet.http.HttpServletResponse;
26  import javax.servlet.http.HttpServletResponseWrapper;
27  
28  /**
29   * <a href="AbsoluteRedirectsResponse.java.html"><b><i>View Source</i></b></a>
30   *
31   * @author Jorge Ferrer
32   */
33  public class AbsoluteRedirectsResponse extends HttpServletResponseWrapper {
34  
35      public AbsoluteRedirectsResponse(
36          HttpServletRequest request, HttpServletResponse response) {
37  
38          super(response);
39  
40          _request = request;
41      }
42  
43      public void sendRedirect(String redirect) throws IOException {
44          String portalURL = getPortalURL();
45  
46          if (Validator.isNotNull(portalURL) &&
47              redirect.startsWith(StringPool.SLASH)) {
48  
49              redirect = portalURL + redirect;
50          }
51  
52          if (!CookieKeys.hasSessionId(_request)) {
53              redirect = PortalUtil.getURLWithSessionId(
54                  redirect, _request.getSession().getId());
55          }
56  
57          _request.setAttribute(
58              AbsoluteRedirectsResponse.class.getName(), redirect);
59  
60          super.sendRedirect(redirect);
61      }
62  
63      protected String getPortalURL() {
64          return PortalUtil.getPortalURL(_request);
65      }
66  
67      private HttpServletRequest _request;
68  
69  }