1   /**
2    * Copyright (c) 2000-2009 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 2009 Sun Microsystems Inc. All rights reserved.
40   */
41  
42  package com.liferay.portal.portletcontainer;
43  
44  import com.liferay.portal.kernel.log.Log;
45  import com.liferay.portal.kernel.log.LogFactoryUtil;
46  import com.liferay.portal.kernel.util.StringPool;
47  import com.liferay.portal.model.Portlet;
48  import com.liferay.portlet.PortletURLImpl;
49  
50  import com.sun.portal.container.ChannelMode;
51  import com.sun.portal.container.ChannelState;
52  import com.sun.portal.container.ChannelURL;
53  import com.sun.portal.container.ChannelURLType;
54  import com.sun.portal.portletcontainer.appengine.PortletAppEngineUtils;
55  
56  import java.io.Serializable;
57  
58  import java.util.Collections;
59  import java.util.List;
60  import java.util.Map;
61  
62  import javax.portlet.PortletModeException;
63  import javax.portlet.PortletRequest;
64  import javax.portlet.WindowStateException;
65  
66  import javax.servlet.http.HttpServletRequest;
67  
68  /**
69   * <a href="PortletWindowURL.java.html"><b><i>View Source</i></b></a>
70   *
71   * @author Deepak Gothe
72   * @author Brian Wing Shun Chan
73   *
74   */
75  public class PortletWindowURL implements ChannelURL, Serializable {
76  
77      public PortletWindowURL(
78          HttpServletRequest request, Portlet portlet, ChannelState windowState,
79          ChannelMode portletMode, long plid) {
80  
81          _portletURLImpl = new PortletURLImpl(
82              request, portlet.getPortletId(), plid, PortletRequest.RENDER_PHASE);
83  
84          setWindowState(windowState);
85          setChannelMode(portletMode);
86      }
87  
88      public void addProperty(String name, String value) {
89          if (name == null) {
90              return;
91          }
92  
93          _portletURLImpl.addProperty(name, value);
94      }
95  
96      public String getCacheLevel() {
97          return _portletURLImpl.getCacheability();
98      }
99  
100     public ChannelMode getChannelMode() {
101         return PortletAppEngineUtils.getChannelMode(
102             _portletURLImpl.getPortletMode());
103     }
104 
105     public Map<String, String[]> getParameters() {
106         return _portletURLImpl.getParameterMap();
107     }
108 
109     public Map<String, List<String>> getProperties() {
110         return Collections.EMPTY_MAP;
111     }
112 
113     public ChannelURLType getURLType() {
114         return _urlType;
115     }
116 
117     public ChannelState getWindowState() {
118         return PortletAppEngineUtils.getChannelState(
119             _portletURLImpl.getWindowState());
120     }
121 
122     public boolean isSecure() {
123         return _portletURLImpl.isSecure();
124     }
125 
126     public void setCacheLevel(String cacheLevel) {
127         _portletURLImpl.setCacheability(cacheLevel);
128     }
129 
130     public void setChannelMode(ChannelMode portletMode) {
131         try {
132             _portletURLImpl.setPortletMode(
133                 PortletAppEngineUtils.getPortletMode(portletMode));
134         }
135         catch (PortletModeException pme) {
136             _log.error(pme);
137         }
138     }
139 
140     public void setParameter(String name, String value) {
141         if (value == null) {
142             value = StringPool.NULL;
143         }
144 
145         _portletURLImpl.setParameter(name, value);
146     }
147 
148     public void setParameter(String name, String[] values) {
149         _portletURLImpl.setParameter(name, values);
150     }
151 
152     public void setParameters(Map<String, String[]> parametersMap) {
153         _portletURLImpl.setParameters(parametersMap);
154     }
155 
156     public void setProperty(String name, String value) {
157         if (name == null) {
158             return;
159         }
160 
161         _portletURLImpl.setProperty(name, value);
162     }
163 
164     public void setResourceID(String resourceID) {
165         _portletURLImpl.setResourceID(resourceID);
166     }
167 
168     public void setSecure(boolean secure) {
169         _portletURLImpl.setSecure(secure);
170     }
171 
172     public void setURLType(ChannelURLType urlType) {
173         _urlType = urlType;
174 
175         _portletURLImpl.setLifecycle(getLifecycle());
176         _portletURLImpl.setURLType(getURLType());
177     }
178 
179     public void setWindowState(ChannelState windowState) {
180         try {
181             _portletURLImpl.setWindowState(
182                 PortletAppEngineUtils.getWindowState(windowState));
183         }
184         catch (WindowStateException wse) {
185             _log.error(wse);
186         }
187     }
188     public String toString() {
189         return _portletURLImpl.toString();
190     }
191 
192     protected String getLifecycle() {
193         if (ChannelURLType.ACTION.equals(getURLType())) {
194             return PortletRequest.ACTION_PHASE;
195         }
196         else if (ChannelURLType.RENDER.equals(getURLType())) {
197 
198             // Force the portal to call executeAction
199 
200             return PortletRequest.ACTION_PHASE;
201         }
202         else if (ChannelURLType.RESOURCE.equals(getURLType())) {
203             return PortletRequest.RESOURCE_PHASE;
204         }
205         else {
206             return PortletRequest.RENDER_PHASE;
207         }
208     }
209 
210     private static Log _log = LogFactoryUtil.getLog(PortletWindowURL.class);
211 
212     private PortletURLImpl _portletURLImpl;
213     private ChannelURLType _urlType;
214 
215 }