View Javadoc

1   /*
2    * $Id: ServletUtil.java 619574 2008-02-07 19:09:33Z apetrelli $
3    *
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   * http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  package org.apache.tiles.servlet.context;
23  
24  import javax.servlet.http.HttpServletRequest;
25  
26  
27  /***
28   * Utilities for Tiles servlet support.
29   *
30   * @version $Rev: 619574 $ $Date: 2008-02-07 20:09:33 +0100 (Thu, 07 Feb 2008) $
31   * @since 2.0.6
32   */
33  public final class ServletUtil {
34  
35      /***
36       * Name of the attribute used to store the force-include option.
37       * @since 2.0.6
38       */
39      public static final String FORCE_INCLUDE_ATTRIBUTE_NAME =
40          "org.apache.tiles.servlet.context.ServletTilesRequestContext.FORCE_INCLUDE";
41  
42      /***
43       * Private constructor to avoid instantiation.
44       */
45      private ServletUtil() {
46      }
47  
48      /***
49       * Returns true if forced include of the result is needed.
50       *
51       * @param request The HTTP request.
52       * @return If <code>true</code> the include operation must be forced.
53       * @since 2.0.6
54       */
55      public static boolean isForceInclude(HttpServletRequest request) {
56          Boolean retValue = (Boolean) request
57                  .getAttribute(ServletUtil.FORCE_INCLUDE_ATTRIBUTE_NAME);
58          return retValue != null && retValue.booleanValue();
59      }
60  
61      /***
62       * Sets the option that enables the forced include of the response.
63       *
64       * @param request The HTTP request.
65       * @param forceInclude If <code>true</code> the include operation must be
66       * forced.
67       * @since 2.0.6
68       */
69      public static void setForceInclude(HttpServletRequest request,
70              boolean forceInclude) {
71          Boolean retValue = Boolean.valueOf(forceInclude);
72          request.setAttribute(
73                  ServletUtil.FORCE_INCLUDE_ATTRIBUTE_NAME,
74                  retValue);
75      }
76  }