com.gargoylesoftware.htmlunit
Class DefaultPageCreator

java.lang.Object
  extended by com.gargoylesoftware.htmlunit.DefaultPageCreator
All Implemented Interfaces:
PageCreator, Serializable

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 HtmlPage
text/xml
application/xml
text/vnd.wap.wml
*+xml
XmlPage, or an XHtmlPage if an XHTML namespace is used
text/javascript
application/x-javascript
JavaScriptPage
text/* TextPage
Anything else UnexpectedPage

Version:
$Revision: 5834 $
Author:
Mike Bowler, Christian Sell, Brad Clarke, Marc Guillemot, Ahmed Ashour, Daniel Gredler
See Also:
Serialized Form

Constructor Summary
DefaultPageCreator()
          Creates an instance.
 
Method Summary
protected  HtmlPage createHtmlPage(WebResponse webResponse, WebWindow webWindow)
          Creates an HtmlPage for this WebResponse.
protected  JavaScriptPage createJavaScriptPage(WebResponse webResponse, WebWindow webWindow)
          Creates a JavaScriptPage 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  XmlPage createXmlPage(WebResponse webResponse, WebWindow webWindow)
          Creates an XmlPage for this WebResponse.
protected  String determineContentType(String contentType, InputStream contentAsStream)
          Tries to determine the content type.
protected  String determinePageType(String contentType)
          Determines the kind of page to create from the content type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultPageCreator

public DefaultPageCreator()
Creates an instance.

Method Detail

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

determineContentType

protected String determineContentType(String contentType,
                                      InputStream contentAsStream)
                               throws IOException
Tries to determine the content type. TODO: implement a content type sniffer based on the Content-Type Processing Model

Parameters:
contentType - the contentType header if any
contentAsStream - stream allowing to read the downloaded content
Returns:
the sniffed mime type
Throws:
IOException - if an IO problem occurs

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

createJavaScriptPage

protected JavaScriptPage createJavaScriptPage(WebResponse webResponse,
                                              WebWindow webWindow)
Creates a JavaScriptPage for this WebResponse.

Parameters:
webResponse - the page's source
webWindow - the WebWindow to place the JavaScriptPage in
Returns:
the newly created JavaScriptPage

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 XmlPage createXmlPage(WebResponse webResponse,
                                WebWindow webWindow)
                         throws IOException
Creates an XmlPage 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

determinePageType

protected String 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"


Copyright © 2002-2010 Gargoyle Software Inc.. All Rights Reserved.