KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > myfaces > portlet > PortletUtil


1 /*
2  * Copyright 2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.myfaces.portlet;
18
19 import javax.faces.context.FacesContext;
20 import javax.portlet.RenderResponse;
21
22 /**
23  * Static utility class for portlet-related operations.
24  *
25  * @author Stan Silvert
26  */

27 public class PortletUtil {
28     
29         /** This flag is imbedded in the request.
30          * It signifies to MyFaces that the request is coming from a portlet.
31          */

32         public static final String JavaDoc PORTLET_REQUEST_FLAG =
33            PortletUtil.class.getName() + ".PORTLET_REQUEST_FLAG";
34     
35         /** Don't allow a new instance of PortletUtil */
36         private PortletUtil() {
37         }
38         
39         /**
40          * Determine if we are processing a portlet RenderResponse.
41          *
42          * @param facesContext The current FacesContext.
43          * @return <code>true</code> if we are processing a RenderResponse,
44          * <code>false</code> otherwise.
45          */

46         public static boolean isRenderResponse(FacesContext facesContext) {
47             if (!isPortletRequest(facesContext)) return false;
48             
49             return facesContext.getExternalContext().getResponse() instanceof RenderResponse;
50         }
51         
52         /**
53          * Determine if we are running as a portlet.
54          *
55          * @param facesContext The current FacesContext.
56          * @return <code>true</code> if we are running as a portlet,
57          * <code>false</code> otherwise.
58          */

59         public static boolean isPortletRequest(FacesContext facesContext) {
60             return facesContext.getExternalContext()
61                                .getSessionMap()
62                                .get(PORTLET_REQUEST_FLAG) != null;
63         }
64     }
Popular Tags