Package org.htmlunit

# Class DefaultPageCreator

java.lang.Object
org.htmlunit.DefaultPageCreator

All Implemented Interfaces:
  `Serializable`, `PageCreator`

public class DefaultPageCreator extends Object implements PageCreator, Serializable
The default implementation of `PageCreator`. Designed to be extended for easier handling of new content types. Just check the content type in `createPage()` and call `super(createPage())` if your custom type isn't found. There are also protected `createXXXXPage()` methods for creating the `Page` types which HtmlUnit already knows about for your custom content types.

The following table shows the type of `Page` created depending on the content type:

Content type | Type of page
--- | ---
text/html text/javascript | `HtmlPage`
text/xml application/xml text/vnd.wap.wml *+xml | `XmlPage`, or an `XHtmlPage` if an XHTML namespace is used
text/* | `TextPage`
Anything else | `UnexpectedPage`

See Also:
  - Serialized Form

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static enum`
  `DefaultPageCreator.PageType`
  The different supported page types.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `DefaultPageCreator()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `protected HtmlPage`
  `createHtmlPage(WebResponse webResponse, WebWindow webWindow)`
  Creates an HtmlPage for this WebResponse.
  `Page`
  `createPage(WebResponse webResponse, WebWindow webWindow)`
  Create a Page object for the specified web response.
  `protected TextPage`
  `createTextPage(WebResponse webResponse, WebWindow webWindow)`
  Creates a TextPage for this WebResponse.
  `protected UnexpectedPage`
  `createUnexpectedPage(WebResponse webResponse, WebWindow webWindow)`
  Creates an UnexpectedPage for this WebResponse.
  `protected XHtmlPage`
  `createXHtmlPage(WebResponse webResponse, WebWindow webWindow)`
  Creates an XHtmlPage for this WebResponse.
  `protected SgmlPage`
  `createXmlPage(WebResponse webResponse, WebWindow webWindow)`
  Creates an SgmlPage for this WebResponse.
  `static DefaultPageCreator.PageType`
  `determinePageType(String contentType)`
  Determines the kind of page to create from the content type.
  `static DefaultPageCreator.PageType`
  `determinePageType(WebResponse webResponse)`
  Determines the kind of page to create from the content type.
  `org.htmlunit.html.parser.HTMLParser`
  `getHtmlParser()`
  INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### DefaultPageCreator

    public DefaultPageCreator()

- ## Method Details

  - ### determinePageType

    public static DefaultPageCreator.PageType determinePageType(String contentType)
    Determines the kind of page to create from the content type.
    Parameters:
      `contentType` - the content type to evaluate
    Returns:
      "xml", "html", "javascript", "text" or "unknown"

  - ### determinePageType

    public static DefaultPageCreator.PageType determinePageType(WebResponse webResponse) throws IOException
    Determines the kind of page to create from the content type.
    Parameters:
      `webResponse` - the response to investigate
    Returns:
      "xml", "html", "javascript", "text" or "unknown"
    Throws:
      `IOException` - if an IO problem occurs

  - ### createPage

    public Page createPage(WebResponse webResponse, WebWindow webWindow) throws IOException
    Create a Page object for the specified web response.
    Specified by:
      `createPage` in interface `PageCreator`
    Parameters:
      `webResponse` - the response from the server
      `webWindow` - the window that this page will be loaded into
    Returns:
      the new page object
    Throws:
      `IOException` - if an IO problem occurs

  - ### getHtmlParser

    public org.htmlunit.html.parser.HTMLParser getHtmlParser()
    INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
    Specified by:
      `getHtmlParser` in interface `PageCreator`
    Returns:
      the HTMLParser in use

  - ### createHtmlPage

    protected HtmlPage createHtmlPage(WebResponse webResponse, WebWindow webWindow) throws IOException
    Creates an HtmlPage for this WebResponse.
    Parameters:
      `webResponse` - the page's source
      `webWindow` - the WebWindow to place the HtmlPage in
    Returns:
      the newly created HtmlPage
    Throws:
      `IOException` - if the page could not be created

  - ### createXHtmlPage

    protected XHtmlPage createXHtmlPage(WebResponse webResponse, WebWindow webWindow) throws IOException
    Creates an XHtmlPage for this WebResponse.
    Parameters:
      `webResponse` - the page's source
      `webWindow` - the WebWindow to place the HtmlPage in
    Returns:
      the newly created XHtmlPage
    Throws:
      `IOException` - if the page could not be created

  - ### createTextPage

    protected TextPage createTextPage(WebResponse webResponse, WebWindow webWindow)
    Creates a TextPage for this WebResponse.
    Parameters:
      `webResponse` - the page's source
      `webWindow` - the WebWindow to place the TextPage in
    Returns:
      the newly created TextPage

  - ### createUnexpectedPage

    protected UnexpectedPage createUnexpectedPage(WebResponse webResponse, WebWindow webWindow)
    Creates an UnexpectedPage for this WebResponse.
    Parameters:
      `webResponse` - the page's source
      `webWindow` - the WebWindow to place the UnexpectedPage in
    Returns:
      the newly created UnexpectedPage

  - ### createXmlPage

    protected SgmlPage createXmlPage(WebResponse webResponse, WebWindow webWindow) throws IOException
    Creates an SgmlPage for this WebResponse.
    Parameters:
      `webResponse` - the page's source
      `webWindow` - the WebWindow to place the TextPage in
    Returns:
      the newly created TextPage
    Throws:
      `IOException` - if the page could not be created