htmlunit-2.7

page_;
  }
  
  public String getSuggestedFilename()
  {
    WebResponse response = page_.getWebResponse();
    String disp = response.getResponseHeaderValue("Content-Disposition");
    int start = disp.indexOf("filename=");
    if (start == -1) {
      return null;
    }
    start += "filename=".length();
    int end = disp.indexOf(";", start);
    if (end == -1) {
      end = disp.length();
    }
    if ((disp.charAt(start) == '"') && (disp.charAt(end - 1) == '"'))
    {
      start++;
      end--;
    }
    return disp.substring(start, end);
  }
  
  public static boolean isAttachment(WebResponse response)
  {
    String disp = response.getResponseHeaderValue("Content-Disposition");
    if (disp == null) {
      return false;
    }
    return disp.startsWith("attachment");
  }
}

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

import com.gargoylesoftware.htmlunit.Page;

public abstract interface AttachmentHandler
{
  public abstract void handleAttachment(Page paramPage);
}

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

import com.gargoylesoftware.htmlunit.Page;
import com.gargoylesoftware.htmlunit.WebAssert;
import java.util.ArrayList;
import java.util.List;

public class CollectingAttachmentHandler
  implements AttachmentHandler
{
  private final List<Attachment> collectedAttachments_;
  
  public CollectingAttachmentHandler()
  {
    this(new ArrayList());
  }
  
  public CollectingAttachmentHandler(List<Attachment> list)
  {
    WebAssert.notNull("list", list);
    collectedAttachments_ = list;
  }
  
  public void handleAttachment(Page page)
  {
    collectedAttachments_.add(new Attachment(page));
  }
  
  public List<Attachment> getCollectedAttachments()
  {
    return collectedAttachments_;
  }
}

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

import com.gargoylesoftware.htmlunit.util.NameValuePair;
import com.gargoylesoftware.htmlunit.util.UrlUtils;
import java.io.Serializable;
import java.net.URL;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.httpclient.auth.CredentialsProvider;
import org.apache.commons.lang.ClassUtils;

public class WebRequestSettings
  implements Serializable
{
  private static final long serialVersionUID = -7405507885099274031L;
  private String url_;
  private String proxyHost_;
  private int proxyPort_;
  private HttpMethod httpMethod_ = HttpMethod.GET;
  private FormEncodingType encodingType_ = FormEncodingType.URL_ENCODED;
  private Map<String, String> additionalHeaders_ = new HashMap();
  private CredentialsProvider credentialsProvider_;
  private String charset_ = "ISO-8859-1";
  private List<NameValuePair> requestParameters_ = Collections.emptyList();
  private String requestBody_;
  
  public WebRequestSettings(URL url)
  {
    setUrl(url);
    setAdditionalHeader("Accept", "*/*");
  }
  
  public WebRequestSettings(WebRequestSettings originalRequest, URL url)
  {
    this(url);
    setProxyHost(originalRequest.getProxyHost());
    setProxyPort(originalRequest.getProxyPort());
  }
  
  public WebRequestSettings(URL url, HttpMethod submitMethod)
  {
    this(url);
    setHttpMethod(submitMethod);
  }
  
  public URL getUrl()
  {
    return UrlUtils.toUrlSafe(url_);
  }
  
  public void setUrl(URL url)
  {
    if (url != null)
    {
      String path = url.getPath();
      if (path.length() == 0)
      {
        url = buildUrlWithNewFile(url, "/" + url.getFile());
      }
      else if (path.contains("./"))
      {
        String query = url.getQuery() != null ? "?" + url.getQuery() : "";
        url = buildUrlWithNewFile(url, removeDots(path) + query);
      }
      url_ = url.toExternalForm();
    }
    else
    {
      url_ = null;
    }
  }
  
  private String removeDots(String path)
  {
    String newPath = path;
    
    newPath = newPath.replaceAll("^/(\\.\\.?/)*", "/");
    
    Pattern dotPattern = Pattern.compile("/\\./");
    while (dotPattern.matcher(newPath).find()) {
      newPath = dotPattern.matcher(newPath).replaceAll("/");
    }
    Pattern dotDotPattern = Pattern.compile("/(?!\\.\\.)[^/]*/\\.\\./");
    while (dotDotPattern.matcher(newPath).find()) {
      newPath = dotDotPattern.matcher(newPath).replaceAll("/");
    }
    return newPath;
  }
  
  private URL buildUrlWithNewFile(URL url, String newFile)
  {
    try
    {
      if (url.getRef() != null) {
        newFile = newFile + '#' + url.getRef();
      }
      url = new URL(url.getProtocol(), url.getHost(), url.getPort(), newFile);
    }
    catch (Exception e)
    {
      throw new RuntimeException("Cannot set URL: " + url.toExternalForm(), e);
    }
    return url;
  }
  
  public String getProxyHost()
  {
    return proxyHost_;
  }
  
  public void setProxyHost(String proxyHost)
  {
    proxyHost_ = proxyHost;
  }
  
  public int getProxyPort()
  {
    return proxyPort_;
  }
  
  public void setProxyPort(int proxyPort)
  {
    proxyPort_ = proxyPort;
  }
  
  public FormEncodingType getEncodingType()
  {
    return encodingType_;
  }
  
  public void setEncodingType(FormEncodingType encodingType)
  {
    encodingType_ = encodingType;
  }
  
  public List<NameValuePair> getRequestParameters()
  {
    return requestParameters_;
  }
  
  public void setRequestParameters(List<NameValuePair> requestParameters)
    throws RuntimeException
  {
    if (requestBody_ != null)
    {
      String msg = "Trying to set the request parameters, but the request body has already been specified;the two are mutually exclusive!";
      
      throw new RuntimeException("Trying to set the request parameters, but the request body has already been specified;the two are mutually exclusive!");
    }
    requestParameters_ = requestParameters;
  }
  
  public String getRequestBody()
  {
    return requestBody_;
  }
  
  public void setRequestBody(String requestBody)
    throws RuntimeException
  {
    if ((requestParameters_ != null) && (!requestParameters_.isEmpty()))
    {
      String msg = "Trying to set the request body, but the request parameters have already been specified;the two are mutually exclusive!";
      
      throw new RuntimeException("Trying to set the request body, but the request parameters have already been specified;the two are mutually exclusive!");
    }
    if ((httpMethod_ != HttpMethod.POST) && (httpMethod_ != HttpMethod.PUT))
    {
      String msg = "The request body may only be set for POST or PUT requests!";
      throw new RuntimeException("The request body may only be set for POST or PUT requests!");
    }
    requestBody_ = requestBody;
  }
  
  public HttpMethod getHttpMethod()
  {
    return httpMethod_;
  }
  
  public void setHttpMethod(HttpMethod submitMethod)
  {
    httpMethod_ = submitMethod;
  }
  
  public Map<String, String> getAdditionalHeaders()
  {
    return additionalHeaders_;
  }
  
  public void setAdditionalHeaders(Map<String, String> additionalHeaders)
  {
    additionalHeaders_ = additionalHeaders;
  }
  
  public boolean isAdditionalHeader(String name)
  {
    for (String key : additionalHeaders_.keySet()) {
      if (name.equalsIgnoreCase(key)) {
        return true;
      }
    }
    return false;
  }
  
  public void setAdditionalHeader(String name, String value)
  {
    for (String key : additionalHeaders_.keySet()) {
      if (name.equalsIgnoreCase(key))
      {
        name = key;
        break;
      }
    }
    additionalHeaders_.put(name, value);
  }
  
  @Deprecated
  public void addAdditionalHeader(String name, String value)
  {
    setAdditionalHeader(name, value);
  }
  
  public void removeAdditionalHeader(String name)
  {
    for (String key : additionalHeaders_.keySet()) {
      if (name.equalsIgnoreCase(key))
      {
        name = key;
        break;
      }
    }
    additionalHeaders_.remove(name);
  }
  
  public CredentialsProvider getCredentialsProvider()
  {
    return credentialsProvider_;
  }
  
  public void setCredentialsProvider(CredentialsProvider credentialsProvider)
  {
    credentialsProvider_ = credentialsProvider;
  }
  
  public String getCharset()
  {
    return charset_;
  }
  
  public void setCharset(String charset)
  {
    charset_ = charset;
  }
  
  public String toString()
  {
    StringBuilder buffer = new StringBuilder();
    buffer.append(ClassUtils.getShortClassName(getClass()));
    buffer.append("[<");
    buffer.append("url=\"" + url_ + '"');
    buffer.append(", " + httpMethod_);
    buffer.append(", " + encodingType_);
    buffer.append(", " + requestParameters_);
    buffer.append(", " + additionalHeaders_);
    buffer.append(", " + credentialsProvider_);
    buffer.append(">]");
    return buffer.toString();
  }
}

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

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Properties;
import java.util.Set;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;

public class BrowserVersion
  implements Serializable
{
  private static final long serialVersionUID = 594005988985654117L;
  private String applicationCodeName_ = "Mozilla";
  private String applicationMinorVersion_ = "0";
  private String applicationName_;
  private String applicationVersion_;
  private String browserLanguage_ = "en-us";
  private String cpuClass_ = "x86";
  private boolean onLine_ = true;
  private String platform_ = "Win32";
  private String systemLanguage_ = "en-us";
  private String userAgent_;
  private String userLanguage_ = "en-us";
  private float browserVersionNumeric_;
  private Set<PluginConfiguration> plugins_ = new HashSet();
  private final List<BrowserVersionFeatures> features_ = new ArrayList();
  private final String nickname_;
  public static final String APP_CODE_NAME = "Mozilla";
  public static final String INTERNET_EXPLORER = "Microsoft Internet Explorer";
  public static final String NETSCAPE = "Netscape";
  public static final String LANGUAGE_ENGLISH_US = "en-us";
  public static final String CPU_CLASS_X86 = "x86";
  public static final String PLATFORM_WIN32 = "Win32";
  @Deprecated
  public static final BrowserVersion FIREFOX_2 = new BrowserVersion("Netscape", "5.0 (Windows; en-US)", "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4", 2.0F, "FF2", null);
  public static final BrowserVersion FIREFOX_3 = new BrowserVersion("Netscape", "5.0 (Windows; en-US)", "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1", 3.0F, "FF3", null);
  public static final BrowserVersion INTERNET_EXPLORER_6 = new BrowserVersion("Microsoft Internet Explorer", "4.0 (compatible; MSIE 6.0b; Windows 98)", "Mozilla/4.0 (compatible; MSIE 6.0; Windows 98)", 6.0F, "IE6", null);
  public static final BrowserVersion INTERNET_EXPLORER_7 = new BrowserVersion("Microsoft Internet Explorer", "4.0 (compatible; MSIE 7.0; Windows NT 5.1)", "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)", 7.0F, "IE7", null);
  public static final BrowserVersion INTERNET_EXPLORER_8 = new BrowserVersion("Microsoft Internet Explorer", "4.0 (compatible; MSIE 8.0; Windows NT 6.0)", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0)", 8.0F, "IE8", null);
  private static BrowserVersion DefaultBrowserVersion_ = INTERNET_EXPLORER_7;
  
  static
  {
    INTERNET_EXPLORER_6.initDefaultFeatures();
    INTERNET_EXPLORER_7.initDefaultFeatures();
    INTERNET_EXPLORER_8.initDefaultFeatures();
    FIREFOX_2.initDefaultFeatures();
    FIREFOX_3.initDefaultFeatures();
    PluginConfiguration flash = new PluginConfiguration("Shockwave Flash", "Shockwave Flash 9.0 r31", "libflashplayer.so");
    
    flash.getMimeTypes().add(new PluginConfiguration.MimeType("application/x-shockwave-flash", "Shockwave Flash", "swf"));
    
    FIREFOX_2.getPlugins().add(flash);
    FIREFOX_3.getPlugins().add(flash);
  }
  
  public BrowserVersion(String applicationName, String applicationVersion, String userAgent, float browserVersionNumeric)
  {
    this(applicationName, applicationVersion, userAgent, browserVersionNumeric, applicationName + browserVersionNumeric, null);
  }
  
  public BrowserVersion(String applicationName, String applicationVersion, String userAgent, float browserVersionNumeric, BrowserVersionFeatures[] features)
  {
    this(applicationName, applicationVersion, userAgent, browserVersionNumeric, applicationName + browserVersionNumeric, features);
  }
  
  private BrowserVersion(String applicationName, String applicationVersion, String userAgent, float browserVersionNumeric, String nickname, BrowserVersionFeatures[] features)
  {
    applicationName_ = applicationName;
    setApplicationVersion(applicationVersion);
    userAgent_ = userAgent;
    browserVersionNumeric_ = browserVersionNumeric;
    nickname_ = nickname;
    if (features != null) {
      features_.addAll(Arrays.asList(features));
    }
  }
  
  private void initDefaultFeatures()
  {
    try
    {
      Properties props = new Properties();
      props.load(getClass().getResourceAsStream("/com/gargoylesoftware/htmlunit/javascript/configuration/" + nickname_ + ".properties"));
      for (Object key : props.keySet()) {
        features_.add(BrowserVersionFeatures.valueOf(key.toString()));
      }
    }
    catch (IllegalArgumentException iae)
    {
      throw new RuntimeException("Invalid entry found in configuration file for BrowserVersion: " + nickname_);
    }
    catch (Exception e)
    {
      throw new RuntimeException("Configuration file not found for BrowserVersion: " + nickname_);
    }
  }
  
  public static BrowserVersion getDefault()
  {
    return DefaultBrowserVersion_;
  }
  
  public static void setDefault(BrowserVersion newBrowserVersion)
  {
    WebAssert.notNull("newBrowserVersion", newBrowserVersion);
    DefaultBrowserVersion_ = newBrowserVersion;
  }
  
  public final boolean isIE()
  {
    return "Microsoft Internet Explorer".equals(getApplicationName());
  }
  
  public final boolean isFirefox()
  {
    return "Netscape".equals(getApplicationName());
  }
  
  public String getApplicationCodeName()
  {
    return applicationCodeName_;
  }
  
  public String getApplicationMinorVersion()
  {
    return applicationMinorVersion_;
  }
  
  public String getApplicationName()
  {
    return applicationName_;
  }
  
  public String getApplicationVersion()
  {
    return applicationVersion_;
  }
  
  public String getBrowserLanguage()
  {
    return browserLanguage_;
  }
  
  public String getCpuClass()
  {
    return cpuClass_;
  }
  
  public boolean isOnLine()
  {
    return onLine_;
  }
  
  public String getPlatform()
  {
    return platform_;
  }
  
  public String getSystemLanguage()
  {
    return systemLanguage_;
  }
  
  public String getUserAgent()
  {
    return userAgent_;
  }
  
  public String getUserLanguage()
  {
    return userLanguage_;
  }
  
  public void setApplicationCodeName(String applicationCodeName)
  {
    applicationCodeName_ = applicationCodeName;
  }
  
  public void setApplicationMinorVersion(String applicationMinorVersion)
  {
    applicationMinorVersion_ = applicationMinorVersion;
  }
  
  public void setApplicationName(String applicationName)
  {
    applicationName_ = applicationName;
  }
  
  public void setApplicationVersion(String applicationVersion)
  {
    applicationVersion_ = applicationVersion;
  }
  
  public void setBrowserLanguage(String browserLanguage)
  {
    browserLanguage_ = browserLanguage;
  }
  
  public void setCpuClass(String cpuClass)
  {
    cpuClass_ = cpuClass;
  }
  
  public void setOnLine(boolean onLine)
  {
    onLine_ = onLine;
  }
  
  public void setPlatform(String platform)
  {
    platform_ = platform;
  }
  
  public void setSystemLanguage(String systemLanguage)
  {
    systemLanguage_ = systemLanguage;
  }
  
  public void setUserAgent(String userAgent)
  {
    userAgent_ = userAgent;
  }
  
  public void setUserLanguage(String userLanguage)
  {
    userLanguage_ = userLanguage;
  }
  
  public void setBrowserVersion(float browserVersion)
  {
    browserVersionNumeric_ = browserVersion;
  }
  
  public float getBrowserVersionNumeric()
  {
    return browserVersionNumeric_;
  }
  
  public boolean equals(Object o)
  {
    return EqualsBuilder.reflectionEquals(this, o);
  }
  
  public int hashCode()
  {
    return HashCodeBuilder.reflectionHashCode(this);
  }
  
  public Set<PluginConfiguration> getPlugins()
  {
    return plugins_;
  }
  
  public boolean hasFeature(BrowserVersionFeatures property)
  {
    return features_.contains(property);
  }
  
  public String getNickname()
  {
    return nickname_;
  }
}

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

public enum HttpMethod
{
  OPTIONS,  GET,  HEAD,  POST,  PUT,  DELETE,  TRACE;
  
  private HttpMethod() {}
}

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

import com.gargoylesoftware.htmlunit.util.UrlUtils;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.Serializable;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

public class History
  implements Serializable
{
  private static final long serialVersionUID = 2913698177338034112L;
  private final WebWindow window_;
  private final List<String> urls_ = new ArrayList();
  private transient ThreadLocal<Boolean> ignoreNewPages_;
  private int index_ = -1;
  
  public History(WebWindow window)
  {
    window_ = window;
    initTransientFields();
  }
  
  private void initTransientFields()
  {
    ignoreNewPages_ = new ThreadLocal();
  }
  
  public int getLength()
  {
    return urls_.size();
  }
  
  public int getIndex()
  {
    return index_;
  }
  
  public URL getUrl(int index)
  {
    if ((index >= 0) && (index < urls_.size())) {
      return UrlUtils.toUrlSafe((String)urls_.get(index));
    }
    return null;
  }
  
  public History back()
    throws IOException
  {
    if (index_ > 0)
    {
      index_ -= 1;
      goToUrlAtCurrentIndex();
    }
    return this;
  }
  
  public History forward()
    throws IOException
  {
    if (index_ < urls_.size() - 1)
    {
      index_ += 1;
      goToUrlAtCurrentIndex();
    }
    return this;
  }
  
  public History go(int relativeIndex)
    throws IOException
  {
    int i = index_ + relativeIndex;
    if ((i < urls_.size()) && (i >= 0)) {
      index_ = i;
    }
    goToUrlAtCurrentIndex();
    return this;
  }
  
  public String toString()
  {
    return urls_.toString();
  }
  
  protected void addPage(Page page)
  {
    Boolean ignoreNewPages = (Boolean)ignoreNewPages_.get();
    if ((ignoreNewPages != null) && (ignoreNewPages.booleanValue())) {
      return;
    }
    index_ += 1;
    while (urls_.size() > index_) {
      urls_.remove(index_);
    }
    urls_.add(page.getWebResponse().getRequestSettings().getUrl().toExternalForm());
  }
  
  private void goToUrlAtCurrentIndex()
    throws IOException
  {
    URL url = UrlUtils.toUrlSafe((String)urls_.get(index_));
    WebRequestSettings wrs = new WebRequestSettings(url);
    Boolean old = (Boolean)ignoreNewPages_.get();
    try
    {
      ignoreNewPages_.set(Boolean.valueOf(true));
      window_.getWebClient().getPage(window_, wrs);
    }
    finally
    {
      ignoreNewPages_.set(old);
    }
  }
  
  private void readObject(ObjectInputStream in)
    throws IOException, ClassNotFoundException
  {
    in.defaultReadObject();
    initTransientFields();
  }
}

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

import java.io.IOException;

public abstract interface WebConnection
{
  public abstract WebResponse getResponse(WebRequestSettings paramWebRequestSettings)
    throws IOException;
}

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

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class ProxyConfig
  implements Serializable
{
  private static final long serialVersionUID = -9164636437071690421L;
  private String proxyHost_;
  private int proxyPort_;
  private final Map<String, Pattern> proxyBypassHosts_;
  private String proxyAutoConfigUrl_;
  private String proxyAutoConfigContent_;
  
  public ProxyConfig()
  {
    this(null, 0);
  }
  
  public ProxyConfig(String proxyHost, int proxyPort)
  {
    proxyHost_ = proxyHost;
    proxyPort_ = proxyPort;
    proxyBypassHosts_ = new HashMap();
  }
  
  public String getProxyHost()
  {
    return proxyHost_;
  }
  
  public void setProxyHost(String proxyHost)
  {
    proxyHost_ = proxyHost;
  }
  
  public int getProxyPort()
  {
    return proxyPort_;
  }
  
  public void setProxyPort(int proxyPort)
  {
    proxyPort_ = proxyPort;
  }
  
  public void addHostsToProxyBypass(String pattern)
  {
    proxyBypassHosts_.put(pattern, Pattern.compile(pattern));
  }
  
  public void removeHostsFromProxyBypass(String pattern)
  {
    proxyBypassHosts_.remove(pattern);
  }
  
  protected boolean shouldBypassProxy(String hostname)
  {
    boolean bypass = false;
    for (Pattern p : proxyBypassHosts_.values()) {
      if (p.matcher(hostname).find())
      {
        bypass = true;
        break;
      }
    }
    return bypass;
  }
  
  public String getProxyAutoConfigUrl()
  {
    return proxyAutoConfigUrl_;
  }
  
  public void setProxyAutoConfigUrl(String proxyAutoConfigUrl)
  {
    proxyAutoConfigUrl_ = proxyAutoConfigUrl;
    setProxyAutoConfigContent(null);
  }
  
  protected String getProxyAutoConfigContent()
  {
    return proxyAutoConfigContent_;
  }
  
  protected void setProxyAutoConfigContent(String proxyAutoConfigContent)
  {
    proxyAutoConfigContent_ = proxyAutoConfigContent;
  }
}

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

import java.io.Serializable;
import java.net.URL;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Set;
import org.apache.commons.httpclient.HttpState;
import org.apache.commons.httpclient.cookie.CookiePolicy;
import org.apache.commons.httpclient.cookie.CookieSpec;
import org.apache.commons.lang.StringUtils;

public class CookieManager
  implements Serializable
{
  private static final long serialVersionUID = 4145377365165079425L;
  public static final String HTMLUNIT_COOKIE_POLICY = "compatibility";
  private boolean cookiesEnabled_;
  private final Set<com.gargoylesoftware.htmlunit.util.Cookie> cookies_;
  
  public CookieManager()
  {
    cookiesEnabled_ = true;
    cookies_ = new LinkedHashSet();
  }
  
  public synchronized void setCookiesEnabled(boolean enabled)
  {
    cookiesEnabled_ = enabled;
  }
  
  public synchronized boolean isCookiesEnabled()
  {
    return cookiesEnabled_;
  }
  
  public synchronized Set<com.gargoylesoftware.htmlunit.util.Cookie> getCookies()
  {
    return Collections.unmodifiableSet(cookies_);
  }
  
  public synchronized Set<com.gargoylesoftware.htmlunit.util.Cookie> getCookies(URL url)
  {
    String host = url.getHost();
    String path = url.getPath();
    boolean secure = "https".equals(url.getProtocol());
    int port;
    int port;
    if (url.getPort() != -1) {
      port = url.getPort();
    } else {
      port = url.getDefaultPort();
    }
    CookieSpec spec = CookiePolicy.getCookieSpec("compatibility");
    org.apache.commons.httpclient.Cookie[] all = com.gargoylesoftware.htmlunit.util.Cookie.toHttpClient(cookies_);
    org.apache.commons.httpclient.Cookie[] matches = spec.match(host, port, path, secure, all);
    
    Set<com.gargoylesoftware.htmlunit.util.Cookie> cookies = new LinkedHashSet();
    cookies.addAll(com.gargoylesoftware.htmlunit.util.Cookie.fromHttpClient(matches));
    return Collections.unmodifiableSet(cookies);
  }
  
  public synchronized com.gargoylesoftware.htmlunit.util.Cookie getCookie(String name)
  {
    for (com.gargoylesoftware.htmlunit.util.Cookie cookie : cookies_) {
      if (StringUtils.equals(cookie.getName(), name)) {
        return cookie;
      }
    }
    return null;
  }
  
  public synchronized void addCookie(com.gargoylesoftware.htmlunit.util.Cookie cookie)
  {
    cookies_.remove(cookie);
    cookies_.add(cookie);
  }
  
  public synchronized void removeCookie(com.gargoylesoftware.htmlunit.util.Cookie cookie)
  {
    cookies_.remove(cookie);
  }
  
  public synchronized void clearCookies()
  {
    cookies_.clear();
  }
  
  protected synchronized void updateState(HttpState state)
  {
    if (!cookiesEnabled_) {
      return;
    }
    state.clearCookies();
    for (com.gargoylesoftware.htmlunit.util.Cookie cookie : cookies_) {
      state.addCookie(cookie.toHttpClient());
    }
  }
  
  protected synchronized void updateFromState(HttpState state)
  {
    if (!cookiesEnabled_) {
      return;
    }
    cookies_.clear();
    cookies_.addAll(com.gargoylesoftware.htmlunit.util.Cookie.fromHttpClient(state.getCookies()));
  }
}

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

public abstract interface IncorrectnessListener
{
  public abstract void notify(String paramString, Object paramObject);
}

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

public abstract interface AlertHandler
{
  public abstract void handleAlert(Page paramPage, String paramString);
}

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

public abstract interface ConfirmHandler
{
  public abstract boolean handleConfirm(Page paramPage, String paramString);
}

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

public abstract interface PromptHandler
{
  public abstract String handlePrompt(Page paramPage, String paramString);
}

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

public abstract interface StatusHandler
{
  public abstract void statusMessageChanged(Page paramPage, String paramString);
}

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

import com.gargoylesoftware.htmlunit.html.HtmlPage;
import java.io.Serializable;

public class AjaxController
  implements Serializable
{
  private static final long serialVersionUID = 2170842485774504546L;
  
  public boolean processSynchron(HtmlPage page, WebRequestSettings settings, boolean async)
  {
    return !async;
  }
}

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

import java.io.IOException;

public abstract interface PageCreator
{
  public abstract Page createPage(WebResponse paramWebResponse, WebWindow paramWebWindow)
    throws IOException;
}

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

public abstract interface WebWindowListener
{
  public abstract void webWindowOpened(WebWindowEvent paramWebWindowEvent);
  
  public abstract void webWindowContentChanged(WebWindowEvent paramWebWindowEvent);
  
  public abstract void webWindowClosed(WebWindowEvent paramWebWindowEvent);
}

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

import com.gargoylesoftware.htmlunit.html.FrameWindow;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.javascript.background.JavaScriptJobManager;
import com.gargoylesoftware.htmlunit.javascript.background.JavaScriptJobManagerImpl;
import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public abstract class WebWindowImpl
  implements WebWindow
{
  private static final long serialVersionUID = -8407026088913790772L;
  private static final Log LOG = LogFactory.getLog(WebWindowImpl.class);
  private WebClient webClient_;
  private Page enclosedPage_;
  private Object scriptObject_;
  private JavaScriptJobManager jobManager_;
  private List<WebWindowImpl> childWindows_ = new ArrayList();
  private String name_ = "";
  private History history_ = new History(this);
  private boolean closed_;
  
  @Deprecated
  protected WebWindowImpl() {}
  
  public WebWindowImpl(WebClient webClient)
  {
    WebAssert.notNull("webClient", webClient);
    webClient_ = webClient;
    jobManager_ = new JavaScriptJobManagerImpl(this);
    performRegistration();
  }
  
  protected void performRegistration()
  {
    webClient_.registerWebWindow(this);
  }
  
  public WebClient getWebClient()
  {
    return webClient_;
  }
  
  public Page getEnclosedPage()
  {
    return enclosedPage_;
  }
  
  public void setEnclosedPage(Page page)
  {
    LOG.debug("setEnclosedPage: " + page);
    if (page == enclosedPage_) {
      return;
    }
    destroyChildren();
    enclosedPage_ = page;
    history_.addPage(page);
    if (isJavaScriptInitializationNeeded()) {
      webClient_.initialize(this);
    }
    webClient_.initialize(page);
  }
  
  protected abstract boolean isJavaScriptInitializationNeeded();
  
  public void setScriptObject(Object scriptObject)
  {
    scriptObject_ = scriptObject;
  }
  
  public Object getScriptObject()
  {
    return scriptObject_;
  }
  
  public JavaScriptJobManager getJobManager()
  {
    return jobManager_;
  }
  
  public void setJobManager(JavaScriptJobManager jobManager)
  {
    jobManager_ = jobManager;
  }
  
  public void addChildWindow(FrameWindow child)
  {
    childWindows_.add(child);
  }
  
  void destroyChildren()
  {
    LOG.debug("destroyChildren");
    getJobManager().removeAllJobs();
    for (ListIterator<WebWindowImpl> iter = childWindows_.listIterator(); iter.hasNext();)
    {
      WebWindowImpl window = (WebWindowImpl)iter.next();
      LOG.debug("closing child window: " + window);
      window.setClosed();
      window.getJobManager().shutdown();
      Page page = window.getEnclosedPage();
      if ((page instanceof HtmlPage)) {
        ((HtmlPage)page).cleanUp();
      }
      window.destroyChildren();
      iter.remove();
    }
  }
  
  public String getName()
  {
    return name_;
  }
  
  public void setName(String name)
  {
    name_ = name;
  }
  
  public History getHistory()
  {
    return history_;
  }
  
  public boolean isClosed()
  {
    return closed_;
  }
  
  protected void setClosed()
  {
    closed_ = true;
  }
}

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

public abstract interface OnbeforeunloadHandler
{
  public abstract boolean handleEvent(Page paramPage, String paramString);
}

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

import java.io.Serializable;
import org.apache.commons.lang.math.NumberUtils;

class Cache$Entry
  implements Comparable<Entry>, Serializable
{
  private static final long serialVersionUID = 588400350259242484L;
  private final String key_;
  private final Object value_;
  private long lastAccess_;
  
  Cache$Entry(Cache paramCache, String key, Object value)
  {
    key_ = key;
    value_ = value;
    lastAccess_ = System.currentTimeMillis();
  }
  
  public int compareTo(Entry other)
  {
    return NumberUtils.compare((float)lastAccess_, (float)lastAccess_);
  }
  
  public void touch()
  {
    lastAccess_ = System.currentTimeMillis();
  }
}

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

import com.gargoylesoftware.htmlunit.util.StringUtils;
import java.io.Serializable;
import java.net.URL;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.lang.math.NumberUtils;
import org.w3c.dom.css.CSSStyleSheet;

public class Cache
  implements Serializable
{
  private static final long serialVersionUID = -3864114727885057419L;
  private int maxSize_;
  private final Map<String, Entry> entries_;
  
  public Cache()
  {
    maxSize_ = 40;
    
    entries_ = Collections.synchronizedMap(new HashMap(maxSize_));
  }
  
  private class Entry
    implements Comparable<Entry>, Serializable
  {
    private static final long serialVersionUID = 588400350259242484L;
    private final String key_;
    private final Object value_;
    private long lastAccess_;
    
    Entry(String key, Object value)
    {
      key_ = key;
      value_ = value;
      lastAccess_ = System.currentTimeMillis();
    }
    
    public int compareTo(Entry other)
    {
      return NumberUtils.compare((float)lastAccess_, (float)lastAccess_);
    }
    
    public void touch()
    {
      lastAccess_ = System.currentTimeMillis();
    }
  }
  
  public void cacheIfPossible(WebRequestSettings request, WebResponse response, Object toCache)
  {
    if (isCacheable(request, response))
    {
      String url = response.getRequestSettings().getUrl().toString();
      Entry entry = new Entry(url, toCache);
      entries_.put(key_, entry);
      deleteOverflow();
    }
  }
  
  public void cache(String css, CSSStyleSheet styleSheet)
  {
    Entry entry = new Entry(css, styleSheet);
    entries_.put(key_, entry);
    deleteOverflow();
  }
  
  protected void deleteOverflow()
  {
    synchronized (entries_)
    {
      while (entries_.size() > maxSize_)
      {
        Entry oldestEntry = (Entry)Collections.min(entries_.values());
        entries_.remove(key_);
      }
    }
  }
  
  protected boolean isCacheable(WebRequestSettings request, WebResponse response)
  {
    return (HttpMethod.GET == response.getRequestSettings().getHttpMethod()) && (!isDynamicContent(response));
  }
  
  protected boolean isDynamicContent(WebResponse response)
  {
    Date lastModified = parseDateHeader(response, "Last-Modified");
    Date expires = parseDateHeader(response, "Expires");
    
    long delay = 600000L;
    long now = System.currentTimeMillis();
    
    boolean cacheableContent = ((expires != null) && (expires.getTime() - now > 600000L)) || ((expires == null) && (lastModified != null) && (now - lastModified.getTime() > 600000L));
    
    return !cacheableContent;
  }
  
  protected Date parseDateHeader(WebResponse response, String headerName)
  {
    String value = response.getResponseHeaderValue(headerName);
    Date date = StringUtils.parseHttpDate(value);
    return date;
  }
  
  protected boolean isJavaScript(WebResponse webResponse)
  {
    String contentType = webResponse.getContentType().toLowerCase();
    return ("text/javascript".equals(contentType)) || ("application/x-javascript".equals(contentType)) || (webResponse.getRequestSettings().getUrl().getPath().endsWith(".js"));
  }
  
  public Object getCachedObject(WebRequestSettings request)
  {
    if (HttpMethod.GET != request.getHttpMethod()) {
      return null;
    }
    Entry cachedEntry = (Entry)entries_.get(request.getUrl().toString());
    if (cachedEntry == null) {
      return null;
    }
    synchronized (entries_)
    {
      cachedEntry.touch();
    }
    return value_;
  }
  
  public CSSStyleSheet getCachedStyleSheet(String css)
  {
    Entry cachedEntry = (Entry)entries_.get(css);
    if (cachedEntry == null) {
      return null;
    }
    synchronized (entries_)
    {
      cachedEntry.touch();
    }
    return (CSSStyleSheet)value_;
  }
  
  public int getMaxSize()
  {
    return maxSize_;
  }
  
  public void setMaxSize(int maxSize)
  {
    if (maxSize < 0) {
      throw new IllegalArgumentException("Illegal value for maxSize: " + maxSize);
    }
    maxSize_ = maxSize;
    deleteOverflow();
  }
  
  public int getSize()
  {
    return entries_.size();
  }
  
  public void clear()
  {
    synchronized (entries_)
    {
      entries_.clear();
    }
  }
}

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

import com.gargoylesoftware.htmlunit.html.HtmlElement;
import com.gargoylesoftware.htmlunit.html.HtmlPage;

public abstract interface ScriptPreProcessor
{
  public abstract String preProcess(HtmlPage paramHtmlPage, String paramString1, String paramString2, HtmlElement paramHtmlElement);
}

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

import java.io.IOException;
import java.net.URL;

public abstract interface RefreshHandler
{
  public abstract void handleRefresh(Page paramPage, URL paramURL, int paramInt)
    throws IOException;
}

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

import java.net.URL;

public class FailingHttpStatusCodeException
  extends RuntimeException
{
  private static final long serialVersionUID = 4080165207084775250L;
  private final WebResponse response_;
  
  public FailingHttpStatusCodeException(WebResponse failingResponse)
  {
    this(buildMessage(failingResponse), failingResponse);
  }
  
  FailingHttpStatusCodeException(String message, WebResponse failingResponse)
  {
    super(message);
    response_ = failingResponse;
  }
  
  public int getStatusCode()
  {
    return response_.getStatusCode();
  }
  
  public String getStatusMessage()
  {
    return response_.getStatusMessage();
  }
  
  private static String buildMessage(WebResponse failingResponse)
  {
    int code = failingResponse.getStatusCode();
    String msg = failingResponse.getStatusMessage();
    URL url = failingResponse.getRequestSettings().getUrl();
    return code + " " + msg + " for " + url;
  }
  
  public WebResponse getResp
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-2017. Infinite Loop Ltd