01: package org.apache.myfaces.portlet;
02:
03: import javax.faces.context.FacesContext;
04: import javax.portlet.RenderResponse;
05:
06: /**
07: * Static utility class for portlet-related operations.
08: *
09: * @author Stan Silvert
10: */
11: public final class PortletUtil {
12:
13: /** This flag is imbedded in the request.
14: * It signifies to MyFaces that the request is coming from a portlet.
15: */
16: public static final String PORTLET_REQUEST_FLAG = PortletUtil.class
17: .getName()
18: + ".PORTLET_REQUEST_FLAG";
19:
20: /** Don't allow a new instance of PortletUtil */
21: private PortletUtil() {
22: }
23:
24: /**
25: * Determine if we are processing a portlet RenderResponse.
26: *
27: * @param facesContext The current FacesContext.
28: * @return <code>true</code> if we are processing a RenderResponse,
29: * <code>false</code> otherwise.
30: */
31: public static boolean isRenderResponse(FacesContext facesContext) {
32: if (!isPortletRequest(facesContext))
33: return false;
34:
35: return facesContext.getExternalContext().getResponse() instanceof RenderResponse;
36: }
37:
38: /**
39: * Determine if we are running as a portlet.
40: *
41: * @param facesContext The current FacesContext.
42: * @return <code>true</code> if we are running as a portlet,
43: * <code>false</code> otherwise.
44: */
45: public static boolean isPortletRequest(FacesContext facesContext) {
46: return facesContext.getExternalContext().getSessionMap().get(
47: PORTLET_REQUEST_FLAG) != null;
48: }
49: }
|