1 /*
2 * Copyright (c) 2002-2025 Gargoyle Software Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 * https://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 package org.htmlunit.httpclient;
16
17 import java.io.Serializable;
18 import java.util.Date;
19 import java.util.List;
20
21 import org.apache.http.client.CookieStore;
22 import org.apache.http.cookie.ClientCookie;
23 import org.apache.http.cookie.Cookie;
24 import org.htmlunit.CookieManager;
25
26 /**
27 * Implementation of {@link CookieStore} like {@link org.apache.http.impl.client.BasicCookieStore}
28 * BUT using our own {@link CookieManager} as back end.
29 *
30 * @author Marc Guillemot
31 * @author Ronald Brill
32 */
33 public final class HtmlUnitCookieStore implements CookieStore, Serializable {
34 private final CookieManager manager_;
35
36 /**
37 * Constructor.
38 *
39 * @param manager the CookieManager
40 */
41 public HtmlUnitCookieStore(final CookieManager manager) {
42 manager_ = manager;
43 }
44
45 /**
46 * {@inheritDoc}
47 */
48 @Override
49 public synchronized void addCookie(final Cookie cookie) {
50 manager_.addCookie(new org.htmlunit.util.Cookie((ClientCookie) cookie));
51 }
52
53 /**
54 * {@inheritDoc}
55 */
56 @Override
57 public synchronized List<Cookie> getCookies() {
58 return HttpClientConverter.toHttpClient(manager_.getCookies());
59 }
60
61 /**
62 * {@inheritDoc}
63 */
64 @Override
65 public synchronized boolean clearExpired(final Date date) {
66 return manager_.clearExpired(date);
67 }
68
69 /**
70 * {@inheritDoc}
71 */
72 @Override
73 public synchronized void clear() {
74 manager_.clearCookies();
75 }
76 }