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