View Javadoc

1   /* 
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    * 
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package org.apache.jetspeed.cache.impl;
19  
20  import java.util.Iterator;
21  import java.util.List;
22  
23  import org.apache.jetspeed.cache.ContentCacheKey;
24  import org.apache.jetspeed.cache.ContentCacheKeyGenerator;
25  import org.apache.jetspeed.request.RequestContext;
26  
27  /***
28   * Wrapper around actual cache implementation
29   * 
30   * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
31   * @version $Id: $
32   */
33  public class JetspeedCacheKeyGenerator implements ContentCacheKeyGenerator
34  {
35      private List segments;
36      private boolean cacheBySessionId = true;
37          
38      public JetspeedCacheKeyGenerator(List segments)
39      {
40          this.segments = segments;
41          this.cacheBySessionId = (segments.contains("sessionid"));            
42      }
43      
44      public ContentCacheKey createCacheKey(RequestContext context, String windowId)
45      {
46          ContentCacheKey key = new JetspeedContentCacheKey(segments, context, windowId);
47          return key;
48      }
49  
50      public ContentCacheKey createUserCacheKey(String username, String pipeline, String windowId)
51      {
52          ContentCacheKey key = new JetspeedContentCacheKey();
53          key.createFromUser(username, pipeline, windowId);
54          return key;
55      }
56  
57      public ContentCacheKey createSessionCacheKey(String sessionId, String pipeline, String windowId)
58      {
59          ContentCacheKey key = new JetspeedContentCacheKey();
60          key.createFromSession(sessionId, pipeline, windowId);
61          return key;
62      }
63      
64      public boolean isCacheBySessionId()
65      {
66          return cacheBySessionId;
67      }
68      
69      public boolean isCacheByUsername()
70      {
71          return !cacheBySessionId;        
72      }
73  }