htmlunit-2.7

 -4420355214574495577L;
  
  public Page createPage(WebResponse webResponse, WebWindow webWindow)
    throws IOException
  {
    String contentType = webResponse.getContentType().toLowerCase();
    
    String pageType = determinePageType(contentType);
    Page newPage;
    Page newPage;
    if (pageType.equals("html"))
    {
      newPage = createHtmlPage(webResponse, webWindow);
    }
    else
    {
      Page newPage;
      if (pageType.equals("javascript"))
      {
        newPage = createJavaScriptPage(webResponse, webWindow);
      }
      else
      {
        Page newPage;
        if (pageType.equals("xml"))
        {
          XmlPage xml = createXmlPage(webResponse, webWindow);
          DomElement doc = xml.getDocumentElement();
          Page newPage;
          if ((doc != null) && ("http://www.w3.org/1999/xhtml".equals(doc.getNamespaceURI()))) {
            newPage = createXHtmlPage(webResponse, webWindow);
          } else {
            newPage = xml;
          }
        }
        else
        {
          Page newPage;
          if (pageType.equals("text")) {
            newPage = createTextPage(webResponse, webWindow);
          } else {
            newPage = createUnexpectedPage(webResponse, webWindow);
          }
        }
      }
    }
    return newPage;
  }
  
  protected HtmlPage createHtmlPage(WebResponse webResponse, WebWindow webWindow)
    throws IOException
  {
    return HTMLParser.parseHtml(webResponse, webWindow);
  }
  
  protected XHtmlPage createXHtmlPage(WebResponse webResponse, WebWindow webWindow)
    throws IOException
  {
    return HTMLParser.parseXHtml(webResponse, webWindow);
  }
  
  protected JavaScriptPage createJavaScriptPage(WebResponse webResponse, WebWindow webWindow)
  {
    JavaScriptPage newPage = new JavaScriptPage(webResponse, webWindow);
    webWindow.setEnclosedPage(newPage);
    return newPage;
  }
  
  protected TextPage createTextPage(WebResponse webResponse, WebWindow webWindow)
  {
    TextPage newPage = new TextPage(webResponse, webWindow);
    webWindow.setEnclosedPage(newPage);
    return newPage;
  }
  
  protected UnexpectedPage createUnexpectedPage(WebResponse webResponse, WebWindow webWindow)
  {
    UnexpectedPage newPage = new UnexpectedPage(webResponse, webWindow);
    webWindow.setEnclosedPage(newPage);
    return newPage;
  }
  
  protected XmlPage createXmlPage(WebResponse webResponse, WebWindow webWindow)
    throws IOException
  {
    XmlPage newPage = new XmlPage(webResponse, webWindow);
    webWindow.setEnclosedPage(newPage);
    return newPage;
  }
  
  protected String determinePageType(String contentType)
  {
    if ((contentType.equals("text/html")) || (contentType.equals(""))) {
      return "html";
    }
    if ((contentType.equals("text/javascript")) || (contentType.equals("application/x-javascript"))) {
      return "javascript";
    }
    if ((contentType.equals("text/xml")) || (contentType.equals("application/xml")) || (contentType.equals("text/vnd.wap.wml")) || (contentType.matches(".*\\+xml"))) {
      return "xml";
    }
    if (contentType.startsWith("text/")) {
      return "text";
    }
    return "unknown";
  }
}

/* Location:
 * Qualified Name:     com.gargoylesoftware.htmlunit.DefaultPageCreator
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.gargoylesoftware.htmlunit;

public class JavaScriptPage
  implements Page
{
  private static final long serialVersionUID = 3284635330718131118L;
  private final WebResponse webResponse_;
  private final String content_;
  private WebWindow enclosingWindow_;
  
  public JavaScriptPage(WebResponse webResponse, WebWindow enclosingWindow)
  {
    webResponse_ = webResponse;
    content_ = webResponse.getContentAsString();
    enclosingWindow_ = enclosingWindow;
  }
  
  public void initialize() {}
  
  public void cleanUp() {}
  
  public String getContent()
  {
    return content_;
  }
  
  public WebResponse getWebResponse()
  {
    return webResponse_;
  }
  
  public WebWindow getEnclosingWindow()
  {
    return enclosingWindow_;
  }
}

/* Location:
 * Qualified Name:     com.gargoylesoftware.htmlunit.JavaScriptPage
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.gargoylesoftware.htmlunit;

import com.gargoylesoftware.htmlunit.util.NameValuePair;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class MockWebConnection
  implements WebConnection
{
  private static final Log LOG = LogFactory.getLog(MockWebConnection.class);
  private final Map<String, WebResponseData> responseMap_ = new HashMap(10);
  private WebResponseData defaultResponse_;
  private WebRequestSettings lastRequest_;
  private int requestCount_ = 0;
  private final List<URL> requestedUrls_ = Collections.synchronizedList(new ArrayList());
  
  public WebResponse getResponse(WebRequestSettings settings)
    throws IOException
  {
    URL url = settings.getUrl();
    
    LOG.debug("Getting response for " + url.toExternalForm());
    
    lastRequest_ = settings;
    requestCount_ += 1;
    requestedUrls_.add(url);
    
    WebResponseData response = (WebResponseData)responseMap_.get(url.toExternalForm());
    if (response == null)
    {
      response = defaultResponse_;
      if (response == null) {
        throw new IllegalStateException("No response specified that can handle URL [" + url.toExternalForm() + "]");
      }
    }
    return new WebResponseImpl(response, settings, 0L);
  }
  
  public List<String> getRequestedUrls(URL relativeTo)
  {
    String baseUrl = relativeTo.toString();
    List<String> response = new ArrayList();
    for (URL url : requestedUrls_)
    {
      String s = url.toString();
      if (s.startsWith(baseUrl)) {
        s = s.substring(baseUrl.length());
      }
      response.add(s);
    }
    return response;
  }
  
  public HttpMethod getLastMethod()
  {
    return lastRequest_.getHttpMethod();
  }
  
  public List<NameValuePair> getLastParameters()
  {
    return lastRequest_.getRequestParameters();
  }
  
  public void setResponse(URL url, String content, int statusCode, String statusMessage, String contentType, List<? extends NameValuePair> responseHeaders)
  {
    setResponse(url, TextUtil.stringToByteArray(content), statusCode, statusMessage, contentType, responseHeaders);
  }
  
  public void setResponse(URL url, String content, int statusCode, String statusMessage, String contentType, String charset, List<? extends NameValuePair> responseHeaders)
  {
    setResponse(url, TextUtil.stringToByteArray(content, charset), statusCode, statusMessage, contentType, responseHeaders);
  }
  
  public void setResponse(URL url, byte[] content, int statusCode, String statusMessage, String contentType, List<? extends NameValuePair> responseHeaders)
  {
    List<NameValuePair> compiledHeaders = new ArrayList(responseHeaders);
    if (contentType != null) {
      compiledHeaders.add(new NameValuePair("Content-Type", contentType));
    }
    WebResponseData responseEntry = new WebResponseData(content, statusCode, statusMessage, compiledHeaders);
    responseMap_.put(url.toExternalForm(), responseEntry);
  }
  
  public void setResponse(URL url, String content)
  {
    List<? extends NameValuePair> emptyList = Collections.emptyList();
    setResponse(url, content, 200, "OK", "text/html", emptyList);
  }
  
  public void setResponse(URL url, String content, String contentType)
  {
    List<? extends NameValuePair> emptyList = Collections.emptyList();
    setResponse(url, content, 200, "OK", contentType, emptyList);
  }
  
  public void setResponse(URL url, String content, String contentType, String charset)
  {
    List<? extends NameValuePair> emptyList = Collections.emptyList();
    setResponse(url, content, 200, "OK", contentType, charset, emptyList);
  }
  
  public void setResponseAsGenericHtml(URL url, String title)
  {
    String content = "<html><head><title>" + title + "</title></head><body></body></html>";
    setResponse(url, content);
  }
  
  public void setDefaultResponse(String content, int statusCode, String statusMessage, String contentType)
  {
    setDefaultResponse(TextUtil.stringToByteArray(content), statusCode, statusMessage, contentType);
  }
  
  public void setDefaultResponse(byte[] content, int statusCode, String statusMessage, String contentType)
  {
    List<NameValuePair> compiledHeaders = new ArrayList();
    compiledHeaders.add(new NameValuePair("Content-Type", contentType));
    WebResponseData responseEntry = new WebResponseData(content, statusCode, statusMessage, compiledHeaders);
    defaultResponse_ = responseEntry;
  }
  
  public void setDefaultResponse(String content)
  {
    setDefaultResponse(content, 200, "OK", "text/html");
  }
  
  public void setDefaultResponse(String content, String contentType)
  {
    List<? extends NameValuePair> emptyList = Collections.emptyList();
    setDefaultResponse(content, 200, "OK", contentType, emptyList);
  }
  
  public void setDefaultResponse(String content, String contentType, String charset)
  {
    List<? extends NameValuePair> emptyList = Collections.emptyList();
    setDefaultResponse(content, 200, "OK", contentType, charset, emptyList);
  }
  
  public void setDefaultResponse(String content, int statusCode, String statusMessage, String contentType, List<? extends NameValuePair> responseHeaders)
  {
    List<NameValuePair> compiledHeaders = new ArrayList(responseHeaders);
    compiledHeaders.add(new NameValuePair("Content-Type", contentType));
    defaultResponse_ = new WebResponseData(TextUtil.stringToByteArray(content), statusCode, statusMessage, compiledHeaders);
  }
  
  public void setDefaultResponse(String content, int statusCode, String statusMessage, String contentType, String charset, List<? extends NameValuePair> responseHeaders)
  {
    List<NameValuePair> compiledHeaders = new ArrayList(responseHeaders);
    compiledHeaders.add(new NameValuePair("Content-Type", contentType));
    defaultResponse_ = new WebResponseData(TextUtil.stringToByteArray(content, charset), statusCode, statusMessage, compiledHeaders);
  }
  
  public Map<String, String> getLastAdditionalHeaders()
  {
    return lastRequest_.getAdditionalHeaders();
  }
  
  public WebRequestSettings getLastWebRequestSettings()
  {
    return lastRequest_;
  }
  
  public int getRequestCount()
  {
    return requestCount_;
  }
  
  public boolean hasResponse(URL url)
  {
    return responseMap_.containsKey(url.toExternalForm());
  }
}

/* Location:
 * Qualified Name:     com.gargoylesoftware.htmlunit.MockWebConnection
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.gargoylesoftware.htmlunit;

import com.gargoylesoftware.htmlunit.util.KeyDataPair;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.OutputStream;
import org.apache.commons.httpclient.methods.multipart.ByteArrayPartSource;
import org.apache.commons.httpclient.methods.multipart.FilePart;
import org.apache.commons.httpclient.methods.multipart.PartSource;
import org.apache.commons.httpclient.util.EncodingUtil;

final class HttpWebConnection$FilePartPageCharSet
  extends FilePart
{
  private KeyDataPair pairWithFile_;
  private WebClient webClient_;
  private String pageCharset_;
  
  private HttpWebConnection$FilePartPageCharSet(String name, ByteArrayPartSource byteArrayPartSource, String contentType, String charset)
  {
    super(name, byteArrayPartSource, contentType, charset);
    pageCharset_ = charset;
  }
  
  private HttpWebConnection$FilePartPageCharSet(String name, String value, File file, String contentType, String charset)
    throws FileNotFoundException
  {
    super(name, value, file, contentType, charset);
    pageCharset_ = charset;
  }
  
  protected void sendDispositionHeader(OutputStream out)
    throws IOException
  {
    out.write(CONTENT_DISPOSITION_BYTES);
    out.write(QUOTE_BYTES);
    out.write(EncodingUtil.getAsciiBytes(getName()));
    out.write(QUOTE_BYTES);
    String filename = getSource().getFileName();
    if (filename != null)
    {
      out.write(EncodingUtil.getAsciiBytes("; filename="));
      out.write(QUOTE_BYTES);
      out.write(EncodingUtil.getBytes(getFileName(), pageCharset_));
      out.write(QUOTE_BYTES);
    }
  }
  
  private String getFileName()
  {
    if (pairWithFile_.getFile() == null) {
      return pairWithFile_.getValue();
    }
    if (webClient_.getBrowserVersion().isIE()) {
      return pairWithFile_.getFile().getAbsolutePath();
    }
    return pairWithFile_.getValue();
  }
}

/* Location:
 * Qualified Name:     com.gargoylesoftware.htmlunit.HttpWebConnection.FilePartPageCharSet
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.gargoylesoftware.htmlunit;

class HttpWebConnection$1 {}

/* Location:
 * Qualified Name:     com.gargoylesoftware.htmlunit.HttpWebConnection.1
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.gargoylesoftware.htmlunit;

import com.gargoylesoftware.htmlunit.util.KeyDataPair;
import com.gargoylesoftware.htmlunit.util.NameValuePair;
import com.gargoylesoftware.htmlunit.util.UrlUtils;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HostConfiguration;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpConnectionManager;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpMethodBase;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
import org.apache.commons.httpclient.URI;
import org.apache.commons.httpclient.URIException;
import org.apache.commons.httpclient.methods.DeleteMethod;
import org.apache.commons.httpclient.methods.EntityEnclosingMethod;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.HeadMethod;
import org.apache.commons.httpclient.methods.OptionsMethod;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.PutMethod;
import org.apache.commons.httpclient.methods.StringRequestEntity;
import org.apache.commons.httpclient.methods.TraceMethod;
import org.apache.commons.httpclient.methods.multipart.ByteArrayPartSource;
import org.apache.commons.httpclient.methods.multipart.FilePart;
import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity;
import org.apache.commons.httpclient.methods.multipart.Part;
import org.apache.commons.httpclient.methods.multipart.PartBase;
import org.apache.commons.httpclient.methods.multipart.PartSource;
import org.apache.commons.httpclient.methods.multipart.StringPart;
import org.apache.commons.httpclient.params.HttpClientParams;
import org.apache.commons.httpclient.params.HttpConnectionManagerParams;
import org.apache.commons.httpclient.params.HttpMethodParams;
import org.apache.commons.httpclient.util.EncodingUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.commons.logging.impl.SimpleLog;

public class HttpWebConnection
  implements WebConnection
{
  private final WebClient webClient_;
  private HttpClient httpClient_;
  private String virtualHost_;
  
  public HttpWebConnection(WebClient webClient)
  {
    webClient_ = webClient;
  }
  
  public WebResponse getResponse(WebRequestSettings settings)
    throws IOException
  {
    URL url = settings.getUrl();
    HttpClient httpClient = getHttpClient();
    webClient_.getCookieManager().updateState(httpClient.getState());
    
    HttpMethodBase httpMethod = makeHttpMethod(settings);
    try
    {
      HostConfiguration hostConfiguration = getHostConfiguration(settings);
      long startTime = System.currentTimeMillis();
      responseCode = httpClient.executeMethod(hostConfiguration, httpMethod);
      long endTime = System.currentTimeMillis();
      webClient_.getCookieManager().updateFromState(httpClient.getState());
      return makeWebResponse(responseCode, httpMethod, settings, endTime - startTime);
    }
    catch (HttpException e)
    {
      int responseCode;
      if (url.getPath().length() == 0)
      {
        StringBuilder buffer = new StringBuilder();
        buffer.append(url.getProtocol());
        buffer.append("://");
        buffer.append(url.getHost());
        buffer.append("/");
        if (url.getQuery() != null) {
          buffer.append(url.getQuery());
        }
        WebRequestSettings newRequest = new WebRequestSettings(new URL(buffer.toString()));
        newRequest.setHttpMethod(settings.getHttpMethod());
        newRequest.setRequestParameters(settings.getRequestParameters());
        newRequest.setAdditionalHeaders(settings.getAdditionalHeaders());
        return getResponse(newRequest);
      }
      throw new RuntimeException("HTTP Error: " + e.getMessage(), e);
    }
    finally
    {
      onResponseGenerated(httpMethod);
    }
  }
  
  protected void onResponseGenerated(HttpMethodBase httpMethod)
  {
    httpMethod.releaseConnection();
  }
  
  private static HostConfiguration getHostConfiguration(WebRequestSettings webRequestSettings)
    throws IOException
  {
    HostConfiguration hostConfiguration = new HostConfiguration();
    URL url = webRequestSettings.getUrl();
    URI uri;
    try
    {
      uri = new URI(url.toExternalForm(), false);
    }
    catch (URIException e)
    {
      throw new IOException("Unable to create URI from URL: " + url.toExternalForm());
    }
    hostConfiguration.setHost(uri);
    if (webRequestSettings.getProxyHost() != null)
    {
      String proxyHost = webRequestSettings.getProxyHost();
      int proxyPort = webRequestSettings.getProxyPort();
      hostConfiguration.setProxy(proxyHost, proxyPort);
    }
    return hostConfiguration;
  }
  
  private HttpMethodBase makeHttpMethod(WebRequestSettings webRequestSettings)
    throws IOException
  {
    URL url = UrlUtils.encodeUrl(webRequestSettings.getUrl(), false);
    
    String path = url.getPath();
    if (path.length() == 0) {
      path = "/";
    } else if (path.startsWith("//")) {
      path = "//" + path;
    }
    HttpMethodBase httpMethod = buildHttpMethod(webRequestSettings.getHttpMethod(), path);
    if (!(httpMethod instanceof EntityEnclosingMethod))
    {
      if (webRequestSettings.getRequestParameters().isEmpty())
      {
        String queryString = url.getQuery();
        httpMethod.setQueryString(queryString);
      }
      else
      {
        NameValuePair[] pairs = new NameValuePair[webRequestSettings.getRequestParameters().size()];
        webRequestSettings.getRequestParameters().toArray(pairs);
        httpMethod.setQueryString(NameValuePair.toHttpClient(pairs));
      }
    }
    else
    {
      EntityEnclosingMethod method = (EntityEnclosingMethod)httpMethod;
      method.getParams().setContentCharset(webRequestSettings.getCharset());
      
      String queryString = url.getQuery();
      method.setQueryString(queryString);
      if (webRequestSettings.getRequestBody() != null)
      {
        String body = webRequestSettings.getRequestBody();
        String charset = webRequestSettings.getCharset();
        method.setRequestEntity(new StringRequestEntity(body, null, charset));
      }
      PostMethod postMethod;
      if ((webRequestSettings.getEncodingType() == FormEncodingType.URL_ENCODED) && ((method instanceof PostMethod)))
      {
        postMethod = (PostMethod)httpMethod;
        for (NameValuePair pair : webRequestSettings.getRequestParameters()) {
          postMethod.removeParameter(pair.getName(), pair.getValue());
        }
        for (NameValuePair pair : webRequestSettings.getRequestParameters()) {
          postMethod.addParameter(pair.getName(), pair.getValue());
        }
      }
      else if (FormEncodingType.MULTIPART == webRequestSettings.getEncodingType())
      {
        List<PartBase> partList = new ArrayList();
        for (NameValuePair pair : webRequestSettings.getRequestParameters())
        {
          PartBase newPart;
          PartBase newPart;
          if ((pair instanceof KeyDataPair))
          {
            KeyDataPair pairWithFile = (KeyDataPair)pair;
            String charset = webRequestSettings.getCharset();
            newPart = buildFilePart(pairWithFile, charset);
          }
          else
          {
            newPart = new StringPart(pair.getName(), pair.getValue(), webRequestSettings.getCharset());
            newPart.setContentType(null);
          }
          newPart.setTransferEncoding(null);
          partList.add(newPart);
        }
        Part[] parts = new Part[partList.size()];
        parts = (Part[])partList.toArray(parts);
        method.setRequestEntity(new MultipartRequestEntity(parts, method.getParams()));
      }
      else
      {
        String body = webRequestSettings.getRequestBody();
        if (body != null)
        {
          String contentType = (String)webRequestSettings.getAdditionalHeaders().get("Content-type");
          String charset = webRequestSettings.getCharset();
          method.setRequestEntity(new StringRequestEntity(body, contentType, charset));
        }
      }
    }
    httpMethod.setRequestHeader("User-Agent", webClient_.getBrowserVersion().getUserAgent());
    
    writeRequestHeadersToHttpMethod(httpMethod, webRequestSettings.getAdditionalHeaders());
    httpMethod.setFollowRedirects(false);
    if (webRequestSettings.getCredentialsProvider() != null) {
      httpMethod.getParams().setParameter("http.authentication.credential-provider", webRequestSettings.getCredentialsProvider());
    }
    if (webClient_.getCookieManager().isCookiesEnabled())
    {
      httpMethod.getParams().setBooleanParameter("http.protocol.single-cookie-header", true);
      httpMethod.getParams().setCookiePolicy("compatibility");
    }
    else
    {
      httpMethod.getParams().setCookiePolicy("ignoreCookies");
    }
    return httpMethod;
  }
  
  FilePart buildFilePart(KeyDataPair pairWithFile, String charset)
    throws FileNotFoundException
  {
    FilePartPageCharSet part;
    FilePartPageCharSet part;
    if (pairWithFile.getData() != null) {
      part = new FilePartPageCharSet(pairWithFile.getName(), new ByteArrayPartSource(pairWithFile.getValue(), pairWithFile.getData()), pairWithFile.getContentType(), charset, null);
    } else {
      part = new FilePartPageCharSet(pairWithFile.getName(), pairWithFile.getValue(), pairWithFile.getFile(), pairWithFile.getContentType(), charset, null);
    }
    pairWithFile_ = pairWithFile;
    webClient_ = webClient_;
    
    part.setCharSet(null);
    
    return part;
  }
  
  private static HttpMethodBase buildHttpMethod(HttpMethod submitMethod, String path)
  {
    HttpMethodBase method;
    switch (submitMethod)
    {
    case GET: 
      method = new GetMethod(path);
      break;
    case POST: 
      method = new PostMethod(path);
      break;
    case PUT: 
      method = new PutMethod(path);
      break;
    case DELETE: 
      method = new DeleteMethod(path);
      break;
    case OPTIONS: 
      method = new OptionsMethod(path);
      break;
    case HEAD: 
      method = new HeadMethod(path);
      break;
    case TRACE: 
      method = new TraceMethod(path);
      break;
    default: 
      throw new IllegalStateException("Submit method not yet supported: " + submitMethod);
    }
    return method;
  }
  
  protected synchronized HttpClient getHttpClient()
  {
    if (httpClient_ == null)
    {
      httpClient_ = createHttpClient();
      
      Log log = LogFactory.getLog("httpclient.wire");
      if ((log instanceof SimpleLog)) {
        ((SimpleLog)log).setLevel(4);
      }
      httpClient_.getHttpConnectionManager().getParams().setSoTimeout(getTimeout());
      httpClient_.getHttpConnectionManager().getParams().setConnectionTimeout(getTimeout());
      if (virtualHost_ != null) {
        httpClient_.getParams().setVirtualHost(virtualHost_);
      }
    }
    httpClient_.getParams().setParameter("http.authentication.credential-provider", webClient_.getCredentialsProvider());
    
    return httpClient_;
  }
  
  protected int getTimeout()
  {
    return webClient_.getTimeout();
  }
  
  protected HttpClient createHttpClient()
  {
    MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
    return new HttpClient(connectionManager);
  }
  
  public void setVirtualHost(String virtualHost)
  {
    virtualHost_ = virtualHost;
  }
  
  public String getVirtualHost()
  {
    return virtualHost_;
  }
  
  private WebResponse makeWebResponse(int statusCode, HttpMethodBase method, WebRequestSettings requestSettings, long loadTime)
    throws IOException
  {
    String statusMessage = method.getStatusText();
    if ((statusMessage == null) || (statusMessage.length() == 0)) {
      statusMessage = HttpStatus.getStatusText(statusCode);
    }
    if (statusMessage == null) {
      statusMessage = "Unknown status code";
    }
    List<NameValuePair> headers = new ArrayList();
    for (Header header : method.getResponseHeaders()) {
      headers.add(new NameValuePair(header.getName(), header.getValue()));
    }
    WebResponseData responseData = newWebResponseDataInstance(statusMessage, headers, statusCode, method);
    return newWebResponseInstance(responseData, loadTime, requestSettings);
  }
  
  protected WebResponseData newWebResponseDataInstance(String statusMessage, List<NameValuePair> headers, int statusCode, HttpMethodBase method)
    throws IOException
  {
    return new WebResponseData(method.getResponseBodyAsStream(), statusCode, statusMessage, headers);
  }
  
  @Deprecated
  protected WebResponse newWebResponseInstance(String charset, WebResponseData responseData, long loadTime, WebRequestSettings requestSettings)
  {
    return new WebResponseImpl(responseData, charset, requestSettings, loadTime);
  }
  
  protected WebResponse newWebResponseInstance(WebResponseData responseData, long loadTime, WebRequestSettings requestSettings)
  {
    return new WebResponseImpl(responseData, requestSettings, loadTime);
  }
  
  private static void writeRequestHeadersToHttpMethod(org.apache.commons.httpclient.HttpMethod httpMethod, Map<String, String> requestHeaders)
  {
    synchronized (requestHeaders)
    {
      for (Map.Entry<String, String> entry : requestHeaders.entrySet()) {
        httpMethod.setRequestHeader((String)entry.getKey(), (String)entry.getValue());
      }
    }
  }
  
  private static final class FilePartPageCharSet
    extends FilePart
  {
    private KeyDataPair pairWithFile_;
    private WebClient webClient_;
    private String pageCharset_;
    
    private FilePartPageCharSet(String name, ByteArrayPartSource byteArrayPartSource, String contentType, String charset)
    {
      super(byteArrayPartSource, contentType, charset);
      pageCharset_ = charset;
    }
    
    private FilePartPageCharSet(String name, String value, File file, String contentType, String charset)
      throws FileNotFoundException
    {
      super(value, file, contentType, charset);
      pageCharset_ = charset;
    }
    
    protected void sendDispositionHeader(OutputStream out)
      throws IOException
    {
      out.write(CONTENT_DISPOSITION_BYTES);
      out.write(QUOTE_BYTES);
      out.write(EncodingUtil.getAsciiBytes(getName()));
      out.write(QUOTE_BYTES);
      String filename = getSource().getFileName();
      if (filename != null)
      {
        out.write(EncodingUtil.getAsciiBytes("; filename="));
        out.write(QUOTE_BYTES);
        out.write(EncodingUtil.getBytes(getFileName(), pageCharset_));
        out.write(QUOTE_BYTES);
      }
    }
    
    private String getFileName()
    {
      if (pairWithFile_.getFile() == null) {
        return pairWithFile_.getValue();
      }
      if (webClient_.getBrowserVersion().isIE()) {
        return pairWithFile_.getFile().getAbsolutePath();
      }
      return pairWithFile_.getValue();
    }
  }
}

/* Location:
 * Qualified Name:     com.gargoylesoftware.htmlunit.HttpWebConnection
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.gargoylesoftware.htmlunit;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;

public final class TextUtil
{
  public static final String DEFAULT_CHARSET = "ISO-8859-1";
  
  public static boolean startsWithIgnoreCase(String stringToCheck, String prefix)
  {
    WebAssert.notNull("stringToCheck", stringToCheck);
    WebAssert.notNull("prefix", prefix);
    if (prefix.length() == 0) {
      throw new IllegalArgumentException("Prefix may not be empty");
    }
    int prefixLength = prefix.length();
    if (stringToCheck.length() < prefixLength) {
      return false;
    }
    return stringToCheck.substring(0, prefixLength).toLowerCase().equals(prefix.toLowerCase());
  }
  
  public static InputStream toInputStream(String content)
  {
    try
    {
      return toInputStream(content, "ISO-8859-1");
    }
    catch (UnsupportedEncodingException e)
    {
      throw new IllegalStateException("ISO-8859-1 is an unsupported encoding!  You may have a corrupted installation of java.");
    }
  }
  
  public static InputStream toInputStream(String content, String encoding)
    throws UnsupportedEncodingException
  {
    try
    {
      ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(content.length() * 2);
      OutputStreamWriter writer = new OutputStreamWriter(byteArrayOutputStream, encoding);
      writer.write(content);
      writer.flush();
      
      byte[] byteArray = byteArrayOutputStream.toByteArray();
      return new ByteArrayInputStream(byteArray);
    }
    catch (UnsupportedEncodingException e)
    {
      throw e;
    }
    catch (IOException e)
    {
      e.printStackTrace();
      throw new IllegalStateException("Exception when converting a string to an input stream: " + e);
    }
  }
  
  public static byte[] stringToByteArray(String content)
  {
    return content != null ? stringToByteArray(content, "ISO-8859-1") : null;
  }
  
  public static byte[] stringToByteArray(String content, String charset)
  {
    byte[] contentBytes;
    try
    {
      contentBytes = content.getBytes(charset);
    }
    catch (UnsupportedEncodingException e)
    {
      contentBytes = new byte[0];
    }
    return contentBytes;
  }
}

/* Location:
 * Qualified Name:     com.gargoylesoftware.htmlunit.TextUtil
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.gargoylesoftware.htmlunit;

import java.net.URL;

class WebClient$1
  extends StringWebResponse
{
  private static final long serialVersionUID = 5713127877370126236L;
  
  WebClient$1(WebClient paramWebClient, String x0, String x1, URL x2, String paramString1)
  {
    super(x0, x1, x2);
  }
  
  public String getContentType()
  {
    return val$contentType;
  }
}

/* Location:
 * Qualified Name:     com.gargoylesoftware.htmlunit.WebClient.1
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.gargoylesoftware.htmlunit;

import com.gargoylesoftware.htmlunit.util.NameValuePair;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

final class WebClient$BinaryWebResponse
  extends WebResponseImpl
{
  private static final long serialVersionUID = 8000117717229261957L;
  private final byte[] data_;
  
  private static WebResponseData getWebResponseData(byte[] data, String contentType)
  {
    List<NameValuePair> compiledHeaders = new ArrayList();
    compiledHeaders.add(new NameValuePair("Content-Type", contentType));
    return new WebResponseData(data, 200, "OK", compiledHeaders);
  }
  
  private WebClient$BinaryWebResponse(byte[] data, URL originatingURL, String contentType)
  {
    super(getWebResponseData(data, contentType), originatingURL, HttpMethod.GET, 0L);
    data_ = data;
  }
  
  public InputStream getContentAsStream()
  {
    return new ByteArrayInputStream(data_);
  }
}

/* Location:
 * Qualified Name:     com.gargoylesoftware.htmlunit.WebClient.BinaryWebResponse
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.gargoylesoftware.htmlunit;

import com.gargoylesoftware.htmlunit.html.BaseFrame;
import com.gargoylesoftware.htmlunit.html.FrameWindow;
import com.gargoylesoftware.htmlunit.html.HtmlElement;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.javascript.host.css.ComputedCSSStyleDeclaration;
import com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement;
import java.io.Serializable;
import java.net.URL;
import java.util.Stack;
import net.sourceforge.htmlunit.corejs.javascript.ScriptableObject;

class WebClient$CurrentWindowTracker
  implements WebWindowListener, Serializable
{
  private static final long serialVersionUID = -987538223249485123L;
  
  WebClient$CurrentWindowTracker(WebClient paramWebClient) {}
  
  public void webWindowClosed(WebWindowEvent event)
  {
    WebWindow window = event.getWebWindow();
    if ((window instanceof TopLevelWindow))
    {
      TopLevelWindow tlw = (TopLevelWindow)event.getWebWindow();
      WebClient.access$100(this$0).remove(tlw);
      if (tlw.equals(this$0.getCurrentWindow())) {
        if (WebClient.access$100(this$0).isEmpty())
        {
          TopLevelWindow newWindow = new TopLevelWindow("", this$0);
          WebClient.access$100(this$0).push(newWindow);
          this$0.setCurrentWindow(newWindow);
        }
        else
        {
          this$0.setCurrentWindow((WebWindow)WebClient.access$100(this$0).peek());
        }
      }
    }
    else if (event.getWebWindow() == this$0.getCurrentWindow())
    {
      this$0.setCurrentWindow((WebWindow)WebClient.access$100(this$0).peek());
    }
  }
  
  public void webWindowContentChanged(WebWindowEvent event)
  {
    WebWindow window = event.getWebWindow();
    boolean use = false;
    if ((window instanceof DialogWindow))
    {
      use = true;
    }
    else if ((window instanceof TopLevelWindow))
    {
      use = event.getOldPage() == null;
    }
    else if ((window instanceof FrameWindow))
    {
      FrameWindow fw = (FrameWindow)window;
      String enclosingPageState = fw.getEnclosingPage().getDocumentElement().getReadyState();
      URL frameUrl = fw.getEnclosedPage().getWebResponse().getRequestSettings().getUrl();
      if ((!"complete".equals(enclosingPageState)) || (frameUrl == WebClient.URL_ABOUT_BLANK)) {
        return;
      }
      BaseFrame frameElement = fw.getFrameElement();
      if (frameElement.isDisplayed())
      {
        ScriptableObject scriptableObject = frameElement.getScriptObject();
        ComputedCSSStyleDeclaration style = ((HTMLElement)scriptableObject).jsxGet_currentStyle();
        use = (style.getCalculatedWidth(false, false) != 0) && (style.getCalculatedHeight(false, false) != 0);
      }
    }
    if (use) {
      this$0.setCurrentWindow(window);
    }
  }
  
  public void webWindowOpened(WebWindowEvent event)
  {
    WebWindow window = event.getWebWindow();
    if ((window instanceof TopLevelWindow))
    {
      TopLevelWindow tlw = (TopLevelWindow)event.getWebWindow();
      WebClient.access$100(this$0).push(tlw);
    }
  }
}

/* Location:
 * Qualified Name:     com.gargoylesoftware.htmlunit.WebClient.CurrentWindowTracker
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.gargoylesoftware.htmlunit;

import java.lang.ref.WeakReference;
import java.net.URL;

class WebClient$LoadJob
{
  private final WebWindow requestingWindow_;
  private final String target_;
  private final WebResponse response_;
  private final URL urlWithOnlyHashChange_;
  private final WeakReference<Page> originalPage_;
  
  WebClient$LoadJob(WebWindow requestingWindow, String target, WebResponse response)
  {
    requestingWindow_ = requestingWindow;
    target_ = target;
    response_ = response;
    urlWithOnlyHashChange_ = null;
    originalPage_ = new WeakReference(requestingWindow.getEnclosedPage());
  }
  
  WebClient$LoadJob(WebWindow requestingWindow, String target, URL urlWithOnlyHashChange)
  {
    requestingWindow_ = requestingWindow;
    target_ = target;
    response_ = null;
    urlWithOnlyHashChange_ = urlWithOnlyHashChange;
    originalPage_ = new WeakReference(requestingWindow.getEnclosedPage());
  }
  
  public boolean isOutdated()
  {
    if ((target_ != null) && (target_.length() != 0)) {
      return false;
    }
    if (requestingWindow_.isClosed()) {
      return true;
    }
    if (requestingWindow_.getEnclosedPage() != originalPage_.get()) {
      return true;
    }
    return false;
  }
}

/* Location:
 * Qualified Name:     com.gargoylesoftware.htmlunit.WebClient.LoadJob
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.gargoylesoftware.htmlunit;

import com.gargoylesoftware.htmlunit.attachment.Attachment;
import com.gargoylesoftware.htmlunit.attachment.AttachmentHandler;
import com.gargoylesoftware.htmlunit.html.BaseFrame;
import com.gargoylesoftware.htmlunit.html.FrameWindow;
import com.gargoylesoftware.htmlunit.html.HTMLParser;
import com.gargoylesoftware.htmlunit.html.HTMLParserListener;
import com.gargoylesoftware.htmlunit.html.HtmlElement;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory;
import com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine;
import com.gargoylesoftware.htmlunit.javascript.ProxyAutoConfig;
import com.gargoylesoftware.htmlunit.javascript.background.JavaScriptJobManager;
import com.gargoylesoftware.htmlunit.javascript.host.Window;
import com.gargoylesoftware.htmlunit.javascript.host.css.ComputedCSSStyleDeclaration;
import com.gargoylesoftware.htmlunit.javascript.host.html.HTMLDocument;
import com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement;
import com.gargoylesoftware.htmlunit.protocol.data.DataUrlDecoder;
import com.gargoylesoftware.htmlunit.ssl.InsecureSSLProtocolSocketFactory;
import com.gargoylesoftware.htmlunit.util.NameValuePair;
import com.gargoylesoftware.htmlunit.util.UrlUtils;
import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.Serializable;
import java.lang.ref.WeakReference;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.security.GeneralSecurityException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.ConcurrentModificationException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.Stack;
import net.sourceforge.htmlunit.corejs.javascript.ScriptableObject;
import org.apache.commons.codec.DecoderException;
import org.apache.commons.httpclient.auth.CredentialsProvider;
import org.apache.commons.httpclient.protocol.Protocol;
import org.apache.commons.httpclient.protocol.ProtocolSocketFactory;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.w3c.css.sac.ErrorHandler;

public c
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2019. Infinite Loop Ltd