1   /**
2    * Copyright (c) 2000-2009 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   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   * SOFTWARE.
18   */
19  
20  package com.liferay.portlet.webproxy;
21  
22  import com.liferay.portal.kernel.servlet.StringServletResponse;
23  import com.liferay.portal.kernel.util.StringPool;
24  import com.liferay.portal.kernel.util.StringUtil;
25  import com.liferay.portal.kernel.util.Validator;
26  import com.liferay.portal.struts.StrutsUtil;
27  import com.liferay.portlet.RenderResponseImpl;
28  
29  import java.io.IOException;
30  
31  import javax.portlet.PortletException;
32  import javax.portlet.PortletPreferences;
33  import javax.portlet.PortletRequestDispatcher;
34  import javax.portlet.RenderRequest;
35  import javax.portlet.RenderResponse;
36  
37  import org.portletbridge.portlet.PortletBridgePortlet;
38  
39  /**
40   * <a href="WebProxyPortlet.java.html"><b><i>View Source</i></b></a>
41   *
42   * @author Brian Wing Shun Chan
43   *
44   */
45  public class WebProxyPortlet extends PortletBridgePortlet {
46  
47      public void doView(
48              RenderRequest renderRequest, RenderResponse renderResponse)
49          throws IOException, PortletException {
50  
51          PortletPreferences prefs = renderRequest.getPreferences();
52  
53          String initUrl = prefs.getValue("initUrl", StringPool.BLANK);
54  
55          if (Validator.isNull(initUrl)) {
56              PortletRequestDispatcher portletRequestDispatcher =
57                  getPortletContext().getRequestDispatcher(
58                      StrutsUtil.TEXT_HTML_DIR + "/portal/portlet_not_setup.jsp");
59  
60              portletRequestDispatcher.include(renderRequest, renderResponse);
61          }
62          else {
63              super.doView(renderRequest, renderResponse);
64  
65              RenderResponseImpl renderResponseImpl =
66                  (RenderResponseImpl)renderResponse;
67  
68              StringServletResponse stringResponse = (StringServletResponse)
69                  renderResponseImpl.getHttpServletResponse();
70  
71              String output = stringResponse.getString();
72  
73              output = StringUtil.replace(output, "//pbhs/", "/pbhs/");
74  
75              stringResponse.setString(output);
76          }
77      }
78  
79  }