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.orchestra.lib.jsf;
    20
    21  /**
    22   * TODO: This class is a copy of
    23   * org.apache.myfaces.commons.util.RequestType
    24   *
    25   * Since orchestra should be compatible with 1.1, this is placed
    26   * here and there is not a dependency for myfaces-commons-utils, because
    27   * this stuff only works for 1.2 (this class is also compatible
    28   * with jdk 1.4)
    29   *
    30   * Represents the type of request currently in the ExternalContext.
    31   * All servlet requests will be of the SERVLET requestType whereas
    32   * all of the other RequestTypes will be portlet type requests.  There
    33   * are a number of convenience methods on the RequestType enumeration
    34   * which can be used to determine the capabilities of the current request.
    35   *
    36   * @since 1.4
    37   */
    38  public class RequestType
    39  {
    40      /**
    41       * The type for all servlet requests.  SERVLET request types are
    42       * both client requests and response writable.
    43       */
    44      final public static RequestType SERVLET = new RequestType(true, true, false);
    45
    46      /**
    47       * The type for a portlet RenderRequest.  RENDER request types are
    48       * for portlets and are response writable but are NOT client
    49       * requests.
    50       */
    51      final public static RequestType RENDER = new RequestType(false, true, true);
    52
    53      /**
    54       * The type for a portlet ActionRequest.  ACTION request types are
    55       * for portlets and are client requests but are NOT response
    56       * writable.
    57       */
    58      final public static RequestType ACTION = new RequestType(true, false, true);
    59
    60      /**
    61       * The type for a portlet ResourceRequest.  RESOURCE request types
    62       * are for portlets and are both client requests and response
    63       * writable.  RESOURCE request types will only be returned in a
    64       * Portlet 2.0 portlet container.
    65       */
    66      final public static RequestType RESOURCE = new RequestType(true, true, true);
    67
    68      /**
    69       * The type for a portlet EventRequest.  EVENT request types
    70       * are for portlets and are neither client requests nor response
    71       * writable.  EVENT request types will only be returned in a
    72       * Portlet 2.0 portlet container.
    73       */
    74      final public static RequestType EVENT  = new RequestType(false, false, true);
    75
    76      private boolean _client;
    77      private boolean _writable;
    78      private boolean _portlet;
    79
    80      RequestType(boolean client, boolean writable, boolean portlet)
    81      {
    82          _client = client;
    83          _writable  = writable;
    84          _portlet    = portlet;
    85      }
    86
    87      /**
    88       * Returns <code>true</code> if this request was a direct
    89       * result of a call from the client.  This implies that
    90       * the current application is the "owner" of the current
    91       * request and that it has access to the inputStream, can
    92       * get and set character encodings, etc.  Currently all
    93       * SERVLET, ACTION, and RESOURCE RequestTypes are client
    94       * requests.
    95       *
    96       * @return <code>true</code> if the current request is a
    97       *         client data type request and <code>false</code>
    98       *         if it is not.
    99       */
    100     public boolean isRequestFromClient()
    101     {
    102         return _client;
    103     }
    104
    105     /**
    106      * Returns <code>true</code> if the response for this
    107      * RequestType is intended to produce output to the client.
    108      * Currently the SERVLET, RENDER, and RESOURCE request are
    109      * response writable.
    110      *
    111      * @return <code>true</code> if the current request is
    112      *         intended to produce output and <code>false</code>
    113      *         if it is not.
    114      */
    115     public boolean isResponseWritable()
    116     {
    117         return _writable;
    118     }
    119
    120     /**
    121      * Returns <code>true</code> if the response for this
    122      * RequestType originated from a JSR-168 or JSR-286
    123      * portlet container.  Currently RENDER, ACTION,
    124      * RESOURCE, and EVENT RequestTypes are all portlet
    125      * requests.
    126      *
    127      * @return <code>true</code> if the current request
    128      *         originated inside of a JSR-168 or JSR-286
    129      *         Portlet Container or <code>false</code> if
    130      *         it did not.
    131      */
    132     public boolean isPortlet()
    133     {
    134         return _portlet;
    135     }
    136 }