View Javadoc
1   /* 
2    * Licensed under the Apache License, Version 2.0 (the "License");
3    * you may not use this file except in compliance with the License.
4    * You may obtain a copy of the License at
5    *
6    * http://www.apache.org/licenses/LICENSE-2.0
7    *
8    * Unless required by applicable law or agreed to in writing, software
9    * distributed under the License is distributed on an "AS IS" BASIS,
10   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11   * See the License for the specific language governing permissions and
12   * limitations under the License.
13   *
14   */
15  
16  package org.esigate.http;
17  
18  import java.util.Date;
19  import java.util.List;
20  
21  import org.apache.http.client.CookieStore;
22  import org.apache.http.cookie.Cookie;
23  import org.esigate.cookie.CookieManager;
24  import org.esigate.impl.DriverRequest;
25  
26  /**
27   * A CookieStore that delegates to the CookieManager instance associated with this Driver instance. The CookieManager
28   * will decide what to do with each cookie like forwarding it to the browser, storing it to session or just ignoring it.
29   * 
30   * @see CookieStore
31   * 
32   * @author Nicolas Richeton
33   * 
34   */
35  public class RequestCookieStore implements CookieStore {
36  
37      private final DriverRequest originalRequest;
38      private final CookieManager cookieManager;
39  
40      public RequestCookieStore(CookieManager cookieManager, DriverRequest originalRequest) {
41          this.originalRequest = originalRequest;
42          this.cookieManager = cookieManager;
43      }
44  
45      @Override
46      public void addCookie(Cookie cookie) {
47          this.cookieManager.addCookie(cookie, this.originalRequest);
48      }
49  
50      @Override
51      public List<Cookie> getCookies() {
52          return this.cookieManager.getCookies(this.originalRequest);
53      }
54  
55      @Override
56      public boolean clearExpired(Date date) {
57          return this.cookieManager.clearExpired(date, this.originalRequest);
58      }
59  
60      @Override
61      public void clear() {
62          this.cookieManager.clear(this.originalRequest);
63      }
64  
65  }