net.sourceforge.cvsgrab
Class WebBrowser

java.lang.Object
  extended by net.sourceforge.cvsgrab.WebBrowser

public class WebBrowser
extends Object

Emulates a web browser

Version:
$Revision: 1.19 $ $Date: 2005/06/25 19:51:33 $
Author:
Ludovic Claude
Created:
on 11 oct. 2003

Constructor Summary
WebBrowser()
          Constructor for WebBrowser
 
Method Summary
static String addQueryParam(String url, String queryParam)
           
static String addQueryParam(String url, String paramName, String paramValue)
           
 org.apache.commons.httpclient.HttpMethod executeMethod(org.apache.commons.httpclient.HttpMethod method, String url)
          Execute a http method
static String forceFinalSlash(String s)
           
 Document getDocument(org.apache.commons.httpclient.HttpMethod method, String url)
          Execute the method and gets the response as a xml document.
 Document getDocument(String url)
          Execute the method and gets the response as a xml document.
 Document getDocumentFromSource(String docSource)
           
static WebBrowser getInstance()
           
static Properties getQueryParams(String urlQuery)
          Extract the query parameters
 String getResponse(org.apache.commons.httpclient.HttpMethod method, String url)
          Gets the response from a method that has been executed
 void loadFile(org.apache.commons.httpclient.HttpMethod method, File destFile, String url)
           
 void loadFile(String url, File destFile)
           
static String removeFinalSlash(String s)
           
static String toQueryParams(Properties queryItems)
          Converts the query items to a single query string
 void useMultithreading()
          Allow simultaneous connections on different threads.
 void useProxy(String proxyHost, int proxyPort, String ntDomain, String userName, String password)
          Use a proxy to bypass the firewall
 void useWebAuthentification(String userName, String password)
          Use authentification for the web server
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WebBrowser

public WebBrowser()
Constructor for WebBrowser

Method Detail

getInstance

public static WebBrowser getInstance()
Returns:
the singleton instance

forceFinalSlash

public static String forceFinalSlash(String s)

removeFinalSlash

public static String removeFinalSlash(String s)

addQueryParam

public static String addQueryParam(String url,
                                   String queryParam)

addQueryParam

public static String addQueryParam(String url,
                                   String paramName,
                                   String paramValue)

getQueryParams

public static Properties getQueryParams(String urlQuery)
Extract the query parameters

Parameters:
urlQuery - The query section of the url. Must be of the form ? (optional) key1=value1&key2=value2
Returns:
the parameters extracted as properties

toQueryParams

public static String toQueryParams(Properties queryItems)
Converts the query items to a single query string

Parameters:
queryItems - The set of (key,value) for the query
Returns:
a query string compatible with the format of url queries

useProxy

public void useProxy(String proxyHost,
                     int proxyPort,
                     String ntDomain,
                     String userName,
                     String password)
Use a proxy to bypass the firewall

Parameters:
proxyHost - Host of the proxy
proxyPort - Port of the proxy
proxyNTDomain - NT domain for authentification on a MS proxy
userName - Username (if authentification is required), or null
password - Password (if authentification is required), or null

useWebAuthentification

public void useWebAuthentification(String userName,
                                   String password)
Use authentification for the web server

Parameters:
userName - The username to use on the web server
password - The password to use on the web server

useMultithreading

public void useMultithreading()
Allow simultaneous connections on different threads.


executeMethod

public org.apache.commons.httpclient.HttpMethod executeMethod(org.apache.commons.httpclient.HttpMethod method,
                                                              String url)
Execute a http method

Parameters:
method - The method
url - The url called by the method, only useful for error reporting
Returns:
the last http method executed (after following redirects)

getResponse

public String getResponse(org.apache.commons.httpclient.HttpMethod method,
                          String url)
Gets the response from a method that has been executed

Parameters:
method - The method
url - The url called by the method, only useful for error reporting

getDocument

public Document getDocument(String url)
                     throws Exception
Execute the method and gets the response as a xml document.

Parameters:
method - The method
url - The url called by the method, only useful for error reporting
Throws:
Exception

getDocument

public Document getDocument(org.apache.commons.httpclient.HttpMethod method,
                            String url)
                     throws Exception
Execute the method and gets the response as a xml document.

Parameters:
method - The method
url - The url called by the method, only useful for error reporting
Throws:
Exception

getDocumentFromSource

public Document getDocumentFromSource(String docSource)
                               throws Exception
Throws:
Exception

loadFile

public void loadFile(String url,
                     File destFile)
              throws Exception
Throws:
Exception

loadFile

public void loadFile(org.apache.commons.httpclient.HttpMethod method,
                     File destFile,
                     String url)
              throws Exception
Throws:
Exception


Copyright © 2002-2005 Ludovic Claude. All Rights Reserved.