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  
20  package org.apache.myfaces.shared.context.flash;
21  
22  import java.io.Serializable;
23  import java.util.Map;
24  import javax.faces.FacesWrapper;
25  import javax.faces.context.FacesContext;
26  import javax.faces.context.Flash;
27  import org.apache.commons.collections.map.LRUMap;
28  
29  /**
30   *
31   */
32  class ClientWindowFlashTokenLRUMap extends LRUMap implements Serializable
33  {
34  
35      public ClientWindowFlashTokenLRUMap()
36      {
37      }
38  
39      public ClientWindowFlashTokenLRUMap(int maxSize)
40      {
41          super(maxSize);
42      }
43  
44      public ClientWindowFlashTokenLRUMap(int maxSize, boolean scanUntilRemovable)
45      {
46          super(maxSize, scanUntilRemovable);
47      }
48  
49      public ClientWindowFlashTokenLRUMap(int maxSize, float loadFactor)
50      {
51          super(maxSize, loadFactor);
52      }
53  
54      public ClientWindowFlashTokenLRUMap(int maxSize, float loadFactor, boolean scanUntilRemovable)
55      {
56          super(maxSize, loadFactor, scanUntilRemovable);
57      }
58  
59      public ClientWindowFlashTokenLRUMap(Map map)
60      {
61          super(map);
62      }
63  
64      public ClientWindowFlashTokenLRUMap(Map map, boolean scanUntilRemovable)
65      {
66          super(map, scanUntilRemovable);
67      }
68      
69      @Override
70      protected boolean removeLRU(LinkEntry entry)
71      {
72          FacesContext facesContext = FacesContext.getCurrentInstance();
73          Flash flash = facesContext.getExternalContext().getFlash();
74          if (flash != null)
75          {
76              ReleasableFlash rf = null;
77              while (flash != null)
78              {
79                  if (flash instanceof ReleasableFlash)
80                  {
81                      rf = (ReleasableFlash) flash;
82                      break;
83                  }
84                  if (flash instanceof FacesWrapper)
85                  {
86                      flash = ((FacesWrapper<? extends Flash>) flash).getWrapped();
87                  }
88                  else
89                  {
90                      flash = null;
91                  }
92              }
93              if (rf != null)
94              {
95                  rf.clearFlashMap(facesContext, (String) entry.getKey(), (String) entry.getValue());
96              }
97          }
98          return super.removeLRU(entry);
99      }
100 }