1   /**
2    * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  /**
24   * The contents of this file are subject to the terms of the Common Development
25   * and Distribution License (the License). You may not use this file except in
26   * compliance with the License.
27   *
28   * You can obtain a copy of the License at http://www.sun.com/cddl/cddl.html and
29   * legal/CDDLv1.0.txt. See the License for the specific language governing
30   * permission and limitations under the License.
31   *
32   * When distributing Covered Code, include this CDDL Header Notice in each file
33   * and include the License file at legal/CDDLv1.0.txt.
34   *
35   * If applicable, add the following below the CDDL Header, with the fields
36   * enclosed by brackets [] replaced by your own identifying information:
37   * "Portions Copyrighted [year] [name of copyright owner]"
38   *
39   * Copyright 2008 Sun Microsystems Inc. All rights reserved.
40   */
41  
42  package com.liferay.portal.portletcontainer;
43  
44  import com.liferay.portlet.PortletURLImpl;
45  
46  import com.sun.portal.container.ChannelURLType;
47  
48  import javax.portlet.PortletMode;
49  import javax.portlet.PortletModeException;
50  import javax.portlet.PortletRequest;
51  import javax.portlet.WindowState;
52  import javax.portlet.WindowStateException;
53  
54  import javax.servlet.http.HttpServletRequest;
55  
56  import org.apache.commons.logging.Log;
57  import org.apache.commons.logging.LogFactory;
58  
59  /**
60   * <a href="LiferayPortletURLImpl.java.html"><b><i>View Source</i></b></a>
61   *
62   * @author Deepak Gothe
63   *
64   */
65  public class LiferayPortletURLImpl extends PortletURLImpl {
66  
67      public LiferayPortletURLImpl(
68          HttpServletRequest request, String portletId, WindowState windowState,
69          PortletMode portletMode, long plid, String lifecycle) {
70  
71          super(request, portletId, plid, lifecycle);
72  
73          setLifecycle(getLifecyclePhase(lifecycle));
74          setURLType(getChannelURlType(lifecycle));
75  
76          try {
77              setWindowState(windowState);
78          }
79          catch (WindowStateException wse1) {
80              if (_log.isWarnEnabled()) {
81                  _log.warn(
82                      "Exception while setting window state for " + portletId,
83                          wse1);
84              }
85              try {
86                  setWindowState(WindowState.NORMAL);
87              }
88              catch (WindowStateException wse2) {
89              }
90          }
91  
92          try {
93              setPortletMode(portletMode);
94          }
95          catch (PortletModeException pme1) {
96              if (_log.isWarnEnabled()) {
97                  _log.warn(
98                      "Exception while setting portlet mode for " + portletId,
99                          pme1);
100             }
101             try {
102                 setPortletMode(PortletMode.VIEW);
103             }
104             catch (PortletModeException pme2) {
105             }
106         }
107     }
108 
109     protected ChannelURLType getChannelURlType(String lifecycle) {
110         if (PortletRequest.ACTION_PHASE.equals(lifecycle)) {
111             return ChannelURLType.ACTION;
112         }
113         else if (PortletRequest.RENDER_PHASE.equals(lifecycle)) {
114             return ChannelURLType.RENDER;
115         }
116         else if (PortletRequest.RESOURCE_PHASE.equals(lifecycle)) {
117             return ChannelURLType.RESOURCE;
118         }
119         else {
120             return ChannelURLType.RENDER;
121         }
122     }
123 
124     protected String getLifecyclePhase(String lifecycle) {
125         if (PortletRequest.RENDER_PHASE.equals(lifecycle)) {
126 
127             // Force the portal to call executeAction
128 
129             return PortletRequest.ACTION_PHASE;
130         }
131 
132         return lifecycle;
133     }
134 
135     private static Log _log = LogFactory.getLog(LiferayPortletURLImpl.class);
136 
137 }