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.requestParameterProvider;
20  
21  import javax.servlet.http.HttpServletResponse;
22  import javax.servlet.http.HttpServletResponseWrapper;
23  
24  /**
25   * This wrapper intercepts encodeURL and pass it to the {@link RequestParameterProviderManager}
26   * which attaches the url parameters
27   */
28  public class RequestParameterResponseWrapper extends HttpServletResponseWrapper
29  {
30      public RequestParameterResponseWrapper(HttpServletResponse httpServletResponse)
31      {
32          super(httpServletResponse);
33      }
34  
35      /**
36       * Override the inherited behaviour to add to the url any query parameters that have
37       * been registered with the RequestParameterProviderManager.
38       * <p>
39       * Method ExternalContext.encodeActionURL will call this method. All JSF implementations
40       * should invoke that method in the NavigationHandler implementation (on redirect), the
41       * Form renderer and the commandLink renderer. This ensures that all the normal places
42       * that send urls back to the client browser will insert the appropriate query-params.
43       * <p>
44       * Note however that ExternalContext.redirect does *not* call this method. And neither does
45       * ViewHandler.getActionUrl(). Therefore custom code that uses redirect or emits "action urls"
46       * itself should call ExternalContext.encodeActionURL (which in turn invokes this method).
47       */
48      public String encodeURL(String url)
49      {
50          if (url != null)
51          {
52              url = RequestParameterProviderManager.getInstance().encodeAndAttachParameters(url);
53          }
54  
55          return super.encodeURL(url);
56      }
57  
58      /**
59       * Override deprecated form of this method, in case users call it.
60       * <p>
61       * The inherited implementation of this method calls super.encodeUrl(url)
62       * directly, which would bypass our custom code.
63       * 
64       * @since 1.1
65       * @deprecated
66       */
67      public String encodeUrl(String url)
68      {
69          return encodeURL(url);
70      }
71  }