View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.myfaces.trinidad.util;
20  
21  /**
22   * Represents the type of request currently in the ExternalContext.
23   * All servlet requests will be of the SERVLET requestType whereas
24   * all of the other RequestTypes will be portlet type requests.  There
25   * are a number of convenience methods on the RequestType enumeration
26   * which can be used to determine the capabilities of the current request.
27   */
28  public enum RequestType
29  {
30      /**
31       * The type for all servlet requests.  SERVLET request types are
32       * both client requests and response writable.
33       */
34      SERVLET(true, true, false),
35      
36      /**
37       * The type for a portlet RenderRequest.  RENDER request types are
38       * for portlets and are response writable but are NOT client
39       * requests.
40       */
41      RENDER(false, true, true),
42      
43      /**
44       * The type for a portlet ActionRequest.  ACTION request types are
45       * for portlets and are client requests but are NOT response 
46       * writable.
47       */
48      ACTION(true, false, true),
49      
50      /**
51       * The type for a portlet ResourceRequest.  RESOURCE request types
52       * are for portlets and are both client requests and response 
53       * writable.  RESOURCE request types will only be returned in a
54       * Portlet 2.0 portlet container.
55       */
56      RESOURCE(true, true, true),
57      
58      /**
59       * The type for a portlet EventRequest.  EVENT request types
60       * are for portlets and are neither client requests nor response 
61       * writable.  EVENT request types will only be returned in a
62       * Portlet 2.0 portlet container.
63       */        
64      EVENT(false, false, true);
65      
66      private boolean _client;
67      private boolean _writable;
68      private boolean _portlet;
69      
70      RequestType(boolean client, boolean writable, boolean portlet)
71      {
72          _client = client;
73          _writable  = writable;
74          _portlet    = portlet;
75      }
76      
77      /**
78       * Returns <code>true</code> if this request was a direct
79       * result of a call from the client.  This implies that
80       * the current application is the "owner" of the current
81       * request and that it has access to the inputStream, can
82       * get and set character encodings, etc.  Currently all
83       * SERVLET, ACTION, and RESOURCE RequestTypes are client
84       * requests.
85       * 
86       * @return <code>true</code> if the current request is a
87       *         client data type request and <code>false</code>
88       *         if it is not.
89       */
90      public boolean isRequestFromClient()
91      {
92          return _client;
93      }
94      
95      /**
96       * Returns <code>true</code> if the response for this
97       * RequestType is intended to produce output to the client.
98       * Currently the SERVLET, RENDER, and RESOURCE request are
99       * response writable.
100      *  
101      * @return <code>true</code> if the current request is 
102      *         intended to produce output and <code>false</code>
103      *         if it is not.
104      */
105     public boolean isResponseWritable()
106     {
107         return _writable;
108     }
109     
110     /**
111      * Returns <code>true</code> if the response for this
112      * RequestType originated from a JSR-168 or JSR-286 
113      * portlet container.  Currently RENDER, ACTION,
114      * RESOURCE, and EVENT RequestTypes are all portlet
115      * requests.
116      * 
117      * @return <code>true</code> if the current request
118      *         originated inside of a JSR-168 or JSR-286
119      *         Portlet Container or <code>false</code> if
120      *         it did not.
121      */
122     public boolean isPortlet()
123     {
124         return _portlet;
125     }
126 }