1 38 package com.gargoylesoftware.htmlunit; 39 40 import java.io.IOException ; 41 42 import com.gargoylesoftware.htmlunit.html.HTMLParser; 43 import com.gargoylesoftware.htmlunit.html.HtmlPage; 44 import com.gargoylesoftware.htmlunit.xml.XmlPage; 45 46 59 public class DefaultPageCreator implements PageCreator { 60 61 64 public DefaultPageCreator() { 65 } 66 67 75 public Page createPage( 76 final WebResponse webResponse, 77 final WebWindow webWindow ) 78 throws 79 IOException { 80 final String contentType = webResponse.getContentType(); 81 final Page newPage; 82 83 if( contentType.equals( "text/html" ) || contentType.equals( "text/xhtml" ) ) { 84 newPage = createHtmlPage(webResponse, webWindow); 85 } 86 else if( contentType.equals("application/xhtml+xml") ) { 87 newPage = createHtmlPage(webResponse, webWindow); 89 } 90 else if( contentType.equals("text/javascript") || contentType.equals("application/x-javascript") ) { 91 newPage = createJavaScriptPage(webResponse, webWindow); 92 } 93 else if (contentType.equals("text/xml") || contentType.equals("application/xml")) { 94 newPage = createXmlPage(webResponse, webWindow); 95 } 96 else if( contentType.startsWith( "text/" ) ) { 97 newPage = createTextPage(webResponse, webWindow); 98 } 99 else { 100 newPage = createUnexpectedPage(webResponse, webWindow); 101 } 102 return newPage; 103 104 } 105 113 protected HtmlPage createHtmlPage(final WebResponse webResponse, final WebWindow webWindow) throws IOException { 114 final HtmlPage newPage; 115 newPage = HTMLParser.parse(webResponse, webWindow); 116 return newPage; 117 } 118 125 protected JavaScriptPage createJavaScriptPage(final WebResponse webResponse, final WebWindow webWindow) { 126 final JavaScriptPage newPage; 127 newPage = new JavaScriptPage( webResponse, webWindow ); 128 webWindow.setEnclosedPage(newPage); 129 return newPage; 130 } 131 132 139 protected TextPage createTextPage(final WebResponse webResponse, final WebWindow webWindow) { 140 final TextPage newPage; 141 newPage = new TextPage( webResponse, webWindow ); 142 webWindow.setEnclosedPage(newPage); 143 return newPage; 144 } 145 146 153 protected UnexpectedPage createUnexpectedPage(final WebResponse webResponse, final WebWindow webWindow) { 154 final UnexpectedPage newPage; 155 newPage = new UnexpectedPage( webResponse, webWindow ); 156 webWindow.setEnclosedPage(newPage); 157 return newPage; 158 } 159 160 168 protected XmlPage createXmlPage(final WebResponse webResponse, final WebWindow webWindow) throws IOException { 169 final XmlPage newPage = new XmlPage( webResponse, webWindow ); 170 webWindow.setEnclosedPage(newPage); 171 return newPage; 172 } 173 } 174 | Popular Tags |