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;
16
17 import java.net.URL;
18
19 /**
20 * A basic {@link Page} implementation.
21 *
22 * @author Ahmed Ashour
23 */
24 public class AbstractPage implements Page {
25
26 private final WebResponse webResponse_;
27 private final WebWindow enclosingWindow_;
28
29 /**
30 * Creates an instance.
31 *
32 * @param webResponse the response from the server
33 * @param enclosingWindow the window that holds the page
34 */
35 public AbstractPage(final WebResponse webResponse, final WebWindow enclosingWindow) {
36 webResponse_ = webResponse;
37 enclosingWindow_ = enclosingWindow;
38 }
39
40 /**
41 * Initializes this page.
42 */
43 @Override
44 public void initialize() {
45 // nothing to do
46 }
47
48 /**
49 * Cleans up this page.
50 */
51 @Override
52 public void cleanUp() {
53 if (getEnclosingWindow().getWebClient().getCache().getCachedResponse(webResponse_.getWebRequest()) == null) {
54 webResponse_.cleanUp();
55 }
56 }
57
58 /**
59 * Returns the web response that was originally used to create this page.
60 *
61 * @return the web response that was originally used to create this page
62 */
63 @Override
64 public WebResponse getWebResponse() {
65 return webResponse_;
66 }
67
68 /**
69 * Returns the window that this page is sitting inside.
70 *
71 * @return the enclosing frame or null if this page isn't inside a frame
72 */
73 @Override
74 public WebWindow getEnclosingWindow() {
75 return enclosingWindow_;
76 }
77
78 /**
79 * Returns the URL of this page.
80 * @return the URL of this page
81 */
82 @Override
83 public URL getUrl() {
84 return getWebResponse().getWebRequest().getUrl();
85 }
86
87 @Override
88 public boolean isHtmlPage() {
89 return false;
90 }
91 }