cz.vity.freerapid.plugins.webclient
Class AbstractRunner

java.lang.Object
  extended by cz.vity.freerapid.plugins.webclient.AbstractRunner
All Implemented Interfaces:
PluginRunner

public abstract class AbstractRunner
extends Object
implements PluginRunner

Parent class for all "Runners" - implementation of plugins.

Author:
Ladislav Vitasek

Field Summary
protected  HttpDownloadClient client
          Field client - to access internet
protected  HttpFileDownloadTask downloadTask
          Task that manages download
protected  String fileURL
          Field fileURL
protected  HttpFile httpFile
          file that is being downloaded
 
Constructor Summary
AbstractRunner()
          Constructs a new AbstractRunner.
 
Method Summary
protected  void addCookie(org.apache.commons.httpclient.Cookie cookie)
          Sets a cookie to the current session.
protected  String getBaseURL()
          Returns base url for the site
protected  CaptchaSupport getCaptchaSupport()
          Access to class that help to manage loading and showing CAPTCHA to the user
protected  String getContentAsString()
          Returns last response from server as string
protected  DialogSupport getDialogSupport()
          Help method to get support for showing simple dialogs to user during downloading or for user options
protected  org.apache.commons.httpclient.methods.GetMethod getGetMethod(String uri)
          Help method for easier calling client.getGetMethod in Runner
protected  Matcher getMatcherAgainstContent(String regexp)
          Method returns Matcher for given regular expression and content of the web page that was get from the last request
protected  MethodBuilder getMethodBuilder()
          Returns new instance of MethodBuilder, which is used to create GET and POST method.
protected  MethodBuilder getMethodBuilder(String content)
          Returns new instance of MethodBuilder, which is used to create GET and POST method.
 ShareDownloadService getPluginService()
          Getter for property 'pluginService'.
protected  org.apache.commons.httpclient.methods.PostMethod getPostMethod(String uri)
          Help method for easier calling client.getPostMethod in Runner
 void init(ShareDownloadService service, HttpFileDownloadTask downloadTask)
          Initialization of runner - this method is called as first before methods run() and runCheck()
protected  boolean makeRedirectedRequest(org.apache.commons.httpclient.HttpMethod method)
          Method makeRequest does simple request to server via given HTTP method.
protected  boolean makeRequest(org.apache.commons.httpclient.HttpMethod method)
          Method makeRequest does simple request to server via given HTTP method
Autoredirect is off.
 void run()
          Main "bussiness logic" of the plugin - process of file downloading from service If no exception is thrown, everything is being considered to be OK - file download state is set to COMPLETED automatically
 void runCheck()
          Main "bussiness logic" of the plugin - process of downloading If no exception is thrown, everything is being considered to be OK - file state is set to FileState.EXISTING_AND_CHECKED automatically
protected  void setClientParameter(String parameterName, Object parameterValue)
          Sets client parameter for handling requests
protected  void setPageEncoding(String encoding)
          Sets encoding for the web page - encoding must be sets manually, it's not determined automatically
UTF-8 encoding is set by default
protected  boolean tryDownloadAndSaveFile(org.apache.commons.httpclient.HttpMethod method)
          Method uses given method parameter to connect to the server and tries to download.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

client

protected HttpDownloadClient client
Field client - to access internet


downloadTask

protected HttpFileDownloadTask downloadTask
Task that manages download


httpFile

protected HttpFile httpFile
file that is being downloaded


fileURL

protected String fileURL
Field fileURL

Constructor Detail

AbstractRunner

public AbstractRunner()
Constructs a new AbstractRunner.

Method Detail

init

public void init(ShareDownloadService service,
                 HttpFileDownloadTask downloadTask)
Initialization of runner - this method is called as first before methods run() and runCheck()

Specified by:
init in interface PluginRunner
Parameters:
service - download service that is associated to this runner
downloadTask - file downloader

run

public void run()
         throws Exception
Main "bussiness logic" of the plugin - process of file downloading from service If no exception is thrown, everything is being considered to be OK - file download state is set to COMPLETED automatically

Specified by:
run in interface PluginRunner
Throws:
Exception - if anything went wrong
See Also:
DownloadState, FileState

runCheck

public void runCheck()
              throws Exception
Main "bussiness logic" of the plugin - process of downloading If no exception is thrown, everything is being considered to be OK - file state is set to FileState.EXISTING_AND_CHECKED automatically

Specified by:
runCheck in interface PluginRunner
Throws:
Exception
See Also:
DownloadState, FileState

getCaptchaSupport

protected CaptchaSupport getCaptchaSupport()
Access to class that help to manage loading and showing CAPTCHA to the user

Returns:
instance of CaptchaSupport
See Also:
CaptchaSupport

getDialogSupport

protected DialogSupport getDialogSupport()
Help method to get support for showing simple dialogs to user during downloading or for user options

Returns:
instance to DialogSupport
See Also:
DialogSupport

tryDownloadAndSaveFile

protected boolean tryDownloadAndSaveFile(org.apache.commons.httpclient.HttpMethod method)
                                  throws Exception
Method uses given method parameter to connect to the server and tries to download.
Method updates download state of HttpFile automatically - sets DownloadState.GETTING and then DownloadState.DOWNLOADING

Parameters:
method - HttpMethod - its URL should be a link to the file
Returns:
true if file was sucessfuly downloaded, false otherwise - file was not found, only string content is available
Throws:
Exception - when connection/writing to file failed

getPluginService

public ShareDownloadService getPluginService()
Getter for property 'pluginService'.

Returns:
Value for property 'pluginService'.

makeRequest

protected boolean makeRequest(org.apache.commons.httpclient.HttpMethod method)
                       throws IOException
Method makeRequest does simple request to server via given HTTP method
Autoredirect is off.

Parameters:
method - HTTP method
Returns:
boolean true if request finished with HTTP status code 200
Throws:
IOException - when there was error during getting response from server
See Also:
HttpStatus.SC_OK

makeRedirectedRequest

protected boolean makeRedirectedRequest(org.apache.commons.httpclient.HttpMethod method)
                                 throws IOException
Method makeRequest does simple request to server via given HTTP method.
Autoredirect is on.

Parameters:
method - HTTP method
Returns:
boolean true if request finished with HTTP status code 200
Throws:
IOException - when there was error during getting response from server
See Also:
HttpStatus.SC_OK

getPostMethod

protected org.apache.commons.httpclient.methods.PostMethod getPostMethod(String uri)
Help method for easier calling client.getPostMethod in Runner

Parameters:
uri - URI for connecting via this POST method
Returns:
new instance of Http PostMethod
See Also:
HttpDownloadClient.getPostMethod(String)

getGetMethod

protected org.apache.commons.httpclient.methods.GetMethod getGetMethod(String uri)
Help method for easier calling client.getGetMethod in Runner

Parameters:
uri - URI for connecting via this GET method
Returns:
new instance of Http GetMethod
See Also:
HttpDownloadClient.getGetMethod(String)

getContentAsString

protected String getContentAsString()
Returns last response from server as string

Returns:
text response from server

getMatcherAgainstContent

protected Matcher getMatcherAgainstContent(String regexp)
Method returns Matcher for given regular expression and content of the web page that was get from the last request

Parameters:
regexp - regular expression that is used for parsing content
Returns:
Matcher new instance of Matcher

getMethodBuilder

protected MethodBuilder getMethodBuilder()
                                  throws BuildMethodException
Returns new instance of MethodBuilder, which is used to create GET and POST method.
The default content for parsing is taken from the last HTTP response.
If you need to use your own content for creating method, make your own instance of MethodBuilder.

Returns:
new instance of MethodBuilder
Throws:
BuildMethodException
Since:
0.82

getMethodBuilder

protected MethodBuilder getMethodBuilder(String content)
                                  throws BuildMethodException
Returns new instance of MethodBuilder, which is used to create GET and POST method.
The default content for parsing is taken from the last HTTP response.
If you need to use your own content for creating method, make your own instance of MethodBuilder.

Parameters:
content - specific content
Returns:
new instance of MethodBuilder
Throws:
BuildMethodException
Since:
0.82

addCookie

protected void addCookie(org.apache.commons.httpclient.Cookie cookie)
Sets a cookie to the current session.

Since:
0.82

getBaseURL

protected String getBaseURL()
Returns base url for the site

Returns:
base url - null by default

setClientParameter

protected void setClientParameter(String parameterName,
                                  Object parameterValue)
Sets client parameter for handling requests

Parameters:
parameterName - name of parameter
parameterValue - parameter's value

setPageEncoding

protected void setPageEncoding(String encoding)
Sets encoding for the web page - encoding must be sets manually, it's not determined automatically
UTF-8 encoding is set by default

Parameters:
encoding - encoding name - like Windows-1250, ISO-8859-1