org.erowid.sperowider
Class AHandler

java.lang.Object
  extended byorg.erowid.sperowider.AHandler
Direct Known Subclasses:
GenericHandler, PatternMatchingHandler, TextCssHandler, TextHtmlHandler

public abstract class AHandler
extends Object

Interface that all download handlers must implement

Version:
: $Header: /cvsroot/sperowider/SPEROWIDER_MODULE/javasource/org/erowid/sperowider/AHandler.java,v 1.21 2005/03/14 02:48:51 gurustu Exp $
Author:
: $Author: gurustu $

Constructor Summary
AHandler()
           
 
Method Summary
 void addURLToModel(String sourceURL, URL foundURL)
          All requests to add URLs to the queue come through here, so we do the filtering and logging at this point.
abstract  void download(HttpURLConnection connection, String fileName, String originalURL)
          This method is responsible for downloading the data at the passed in connection, and processing as appropriate (including, for example, spidering, adding it to the rectification queue, etc.)
 FileOutputStream getFileOutputStream(String fileName)
          Returns an OutputStream to allow extending classes to write to the named file.
 String[] getReplaceableFilenameSuffixes()
          This works with getRequiredFilenameSuffix() by providing a list of suffixes that could simply be replaced with the value returned by getRequiredFilenameSuffix().
 String getRequiredFilenamePrefix()
          Implementing classes can override this method to force files downloaded by this handler to start with a guaranteed prefix.
 String getRequiredFilenameSuffix()
          Implementing classes can override this method to force files downloaded by this handler to end with a guaranteed suffix.
 SperowiderContext getSperowiderContext()
           
abstract  void rectify(String filename)
          This method is responsible for parsing the local file, and rewriting it as appropriate, typically replacing all URLs with relative local file references
 void setSperowiderContext(SperowiderContext sperowiderContext)
           
 void stampFile(Writer writer, URL url)
          Writes an "originally found at" stamp into the passed in writer, which typically points to the downloaded file.
 String urlFoundInRectify(String sourceFileName, String foundURL)
          Called by descendant classes when they find a URL during rectifying.
 String urlFoundInSpider(URL sourceURL, String foundURL)
          Called by descendant classes when they find a URL during spidering.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AHandler

public AHandler()
Method Detail

download

public abstract void download(HttpURLConnection connection,
                              String fileName,
                              String originalURL)
                       throws IOException
This method is responsible for downloading the data at the passed in connection, and processing as appropriate (including, for example, spidering, adding it to the rectification queue, etc.)

Throws:
IOException

rectify

public abstract void rectify(String filename)
                      throws IOException
This method is responsible for parsing the local file, and rewriting it as appropriate, typically replacing all URLs with relative local file references

Throws:
IOException

addURLToModel

public void addURLToModel(String sourceURL,
                          URL foundURL)
All requests to add URLs to the queue come through here, so we do the filtering and logging at this point.


getFileOutputStream

public FileOutputStream getFileOutputStream(String fileName)
                                     throws IOException
Returns an OutputStream to allow extending classes to write to the named file.

Throws:
IOException

getSperowiderContext

public SperowiderContext getSperowiderContext()
Returns:
Returns the sperowiderContext.

setSperowiderContext

public void setSperowiderContext(SperowiderContext sperowiderContext)
Parameters:
sperowiderContext - The sperowiderContext to set.

getRequiredFilenamePrefix

public String getRequiredFilenamePrefix()
Implementing classes can override this method to force files downloaded by this handler to start with a guaranteed prefix.


getRequiredFilenameSuffix

public String getRequiredFilenameSuffix()
Implementing classes can override this method to force files downloaded by this handler to end with a guaranteed suffix. For example, you might want to force all downloaded HTML files to end with ".html".


getReplaceableFilenameSuffixes

public String[] getReplaceableFilenameSuffixes()
This works with getRequiredFilenameSuffix() by providing a list of suffixes that could simply be replaced with the value returned by getRequiredFilenameSuffix(). So, for example, instead of simply having ".html" always get appended, you could say "in the case of .shtml, .php, .jsp, .asp, replace those with .html", for a more attractive file name.


urlFoundInSpider

public String urlFoundInSpider(URL sourceURL,
                               String foundURL)
Called by descendant classes when they find a URL during spidering. It returns an absolute form of the URL. Look at TextHtmlHandler for an example of how to use this.


urlFoundInRectify

public String urlFoundInRectify(String sourceFileName,
                                String foundURL)
Called by descendant classes when they find a URL during rectifying. It returns an relative path from the sourceFile to the file that the found URL maps to.


stampFile

public void stampFile(Writer writer,
                      URL url)
               throws IOException
Writes an "originally found at" stamp into the passed in writer, which typically points to the downloaded file.

Throws:
IOException

spero logo small Sperowider is
© 2005 Erowid.org