1   /**
2    * Copyright (c) 2000-2007 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  package com.liferay.portal.kernel.util;
24  
25  import javax.portlet.ActionRequest;
26  import javax.portlet.PortletRequest;
27  import javax.portlet.PortletResponse;
28  import javax.portlet.RenderRequest;
29  
30  import javax.servlet.http.HttpServletRequest;
31  import javax.servlet.http.HttpServletResponse;
32  import javax.servlet.http.HttpSession;
33  
34  /**
35   * <a href="PortalUtil.java.html"><b><i>View Source</i></b></a>
36   *
37   * @author Brian Wing Shun Chan
38   *
39   */
40  public class PortalUtil {
41  
42      public static String getCDNHost() throws Exception {
43          Object returnObj = PortalClassInvoker.invoke(
44              _CLASS, _METHOD_GETCDNHOST, false);
45  
46          if (returnObj != null) {
47              return (String)returnObj;
48          }
49          else {
50              return null;
51          }
52      }
53  
54      public static HttpServletRequest getHttpServletRequest(PortletRequest req)
55          throws Exception {
56  
57          Object returnObj = PortalClassInvoker.invoke(
58              _CLASS, _METHOD_GETHTTPSERVLETREQUEST, req, false);
59  
60          if (returnObj != null) {
61              return (HttpServletRequest)returnObj;
62          }
63          else {
64              return null;
65          }
66      }
67  
68      public static HttpServletResponse getHttpServletResponse(
69              PortletResponse res)
70          throws Exception {
71  
72          Object returnObj = PortalClassInvoker.invoke(
73              _CLASS, _METHOD_GETHTTPSERVLETRESPONSE, res, false);
74  
75          if (returnObj != null) {
76              return (HttpServletResponse)returnObj;
77          }
78          else {
79              return null;
80          }
81      }
82  
83      public static String getPortletNamespace(String portletId)
84          throws Exception {
85  
86          Object returnObj = PortalClassInvoker.invoke(
87              _CLASS, _METHOD_GETPORTLETNAMESPACE, portletId, false);
88  
89          if (returnObj != null) {
90              return (String)returnObj;
91          }
92          else {
93              return null;
94          }
95      }
96  
97      public static String getUserPassword(HttpSession ses)
98          throws Exception {
99  
100         Object returnObj = PortalClassInvoker.invoke(
101             _CLASS, _METHOD_GETUSERPASSWORD, ses, false);
102 
103         if (returnObj != null) {
104             return (String)returnObj;
105         }
106         else {
107             return null;
108         }
109     }
110 
111     public static String getUserPassword(HttpServletRequest req)
112         throws Exception {
113 
114         Object returnObj = PortalClassInvoker.invoke(
115             _CLASS, _METHOD_GETUSERPASSWORD, req, false);
116 
117         if (returnObj != null) {
118             return (String)returnObj;
119         }
120         else {
121             return null;
122         }
123     }
124 
125     public static String getUserPassword(ActionRequest req)
126         throws Exception {
127 
128         Object returnObj = PortalClassInvoker.invoke(
129             _CLASS, _METHOD_GETUSERPASSWORD, req, false);
130 
131         if (returnObj != null) {
132             return (String)returnObj;
133         }
134         else {
135             return null;
136         }
137     }
138 
139     public static String getUserPassword(RenderRequest req)
140         throws Exception {
141 
142         Object returnObj = PortalClassInvoker.invoke(
143             _CLASS, _METHOD_GETUSERPASSWORD, req, false);
144 
145         if (returnObj != null) {
146             return (String)returnObj;
147         }
148         else {
149             return null;
150         }
151     }
152 
153     public static void setPageSubtitle(
154             String subtitle, HttpServletRequest req)
155         throws Exception {
156 
157         PortalClassInvoker.invoke(
158             _CLASS, _METHOD_SETPAGESUBTITLE, subtitle, req, false);
159     }
160 
161     public static void setPageTitle(String title, HttpServletRequest req)
162         throws Exception {
163 
164         PortalClassInvoker.invoke(
165             _CLASS, _METHOD_SETPAGETITLE, title, req, false);
166     }
167 
168     private static final String _CLASS = "com.liferay.portal.util.PortalUtil";
169 
170     private static final String _METHOD_GETCDNHOST = "getCDNHost";
171 
172     private static final String _METHOD_GETHTTPSERVLETREQUEST =
173         "getHttpServletRequest";
174 
175     private static final String _METHOD_GETHTTPSERVLETRESPONSE =
176         "getHttpServletResponse";
177 
178     private static final String _METHOD_GETPORTLETNAMESPACE =
179         "getPortletNamespace";
180 
181     private static final String _METHOD_GETUSERPASSWORD = "getUserPassword";
182 
183     private static final String _METHOD_SETPAGESUBTITLE = "setPageSubtitle";
184 
185     private static final String _METHOD_SETPAGETITLE = "setPageTitle";
186 
187 }