websphinx
Class Mirror

java.lang.Object
  |
  +--websphinx.HTMLTransformer
        |
        +--websphinx.LinkTransformer
              |
              +--websphinx.Mirror

public class Mirror
extends LinkTransformer

Offline mirror of a Web site. Web pages written to a mirror are stored as files on the local disk in a directory structure mirroring their URLs.


Field Summary
 
Fields inherited from class websphinx.LinkTransformer
base, map
 
Constructor Summary
Mirror(java.lang.String directory)
          Make a new Mirror.
 
Method Summary
 void close()
          Close the mirror.
 java.lang.String getDefaultFilename()
          Get the filename used for directory URLs.
 int getPageCount()
          Get number of pages written to this mirror.
 java.lang.String lookupDir(java.net.URL base, java.net.URL url)
          Lookup the local directory to which a remote directory URL maps.
static void main(java.lang.String[] args)
           
 void mapDir(java.net.URL url, java.lang.String dir)
          Map a directory URL (of the form http://host/path/) to a local directory.
 void rewrite()
          Rewrite the mirror to make local links consistent.
 void setDefaultFilename(java.lang.String filename)
          Set the filename used for directory URLs.
 void write(Region region)
          Writes a chunk of HTML through the HTML transformer.
 void write(java.lang.String string)
          Writes a literal string through the HTML transformer (without parsing it or transforming it).
 void writePage(Page page)
          Write a page to the mirror.
 
Methods inherited from class websphinx.LinkTransformer
getBase, getEmitBaseElement, handleBase, handleElement, handleLink, isMapped, lookup, map, map, setBase, setEmitBaseElement
 
Methods inherited from class websphinx.HTMLTransformer
emit, emit, finalize, flush, getFilePointer, getOutputStream, getOutputWriter, getRandomAccessFile, seek, setOutput, setRandomAccessFile, transformContents, transformElement
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Mirror

public Mirror(java.lang.String directory)
       throws java.io.IOException
Make a new Mirror.

Parameters:
directory - Root directory (on local disk relative to which the mirror pages are stored)
Method Detail

getDefaultFilename

public java.lang.String getDefaultFilename()
Get the filename used for directory URLs. For example, if the default filename is "index.html", then the remote URL "http://www.xxx.com/path/" would map to the local pathname "www.xxx.com/path/index.html".

Returns:
default filename. Default is "index.html".

setDefaultFilename

public void setDefaultFilename(java.lang.String filename)
Set the filename used for directory URLs. For example, if the default filename is "index.html", then the remote URL "http://www.xxx.com/path/" would map to the local pathname "www.xxx.com/path/index.html".

Parameters:
filename - Default filename.

getPageCount

public int getPageCount()
Get number of pages written to this mirror.

Returns:
number of calls to writePage() on this mirror

write

public void write(Region region)
           throws java.io.IOException
Description copied from class: HTMLTransformer
Writes a chunk of HTML through the HTML transformer.

Overrides:
write in class HTMLTransformer
Following copied from class: websphinx.HTMLTransformer
Parameters:
region - Region to write

write

public void write(java.lang.String string)
           throws java.io.IOException
Description copied from class: HTMLTransformer
Writes a literal string through the HTML transformer (without parsing it or transforming it).

Overrides:
write in class HTMLTransformer
Following copied from class: websphinx.HTMLTransformer
Parameters:
string - String to write

writePage

public void writePage(Page page)
               throws java.io.IOException
Write a page to the mirror. Stores the page on the local disk, fixing up its links to point to the local copies of any pages already stored to this mirror.

Overrides:
writePage in class LinkTransformer
Parameters:
page - Page to write

close

public void close()
           throws java.io.IOException
Close the mirror. Makes sure that links point to local versions of pages wherever possible.

Overrides:
close in class HTMLTransformer

rewrite

public void rewrite()
             throws java.io.IOException
Rewrite the mirror to make local links consistent.


mapDir

public void mapDir(java.net.URL url,
                   java.lang.String dir)
            throws java.net.MalformedURLException
Map a directory URL (of the form http://host/path/) to a local directory.

Parameters:
url - Directory URL. Must end with a slash.
dir - Local directory relative to which descendents of url should be saved.

lookupDir

public java.lang.String lookupDir(java.net.URL base,
                                  java.net.URL url)
Lookup the local directory to which a remote directory URL maps.

Parameters:
base - local file URL to use as a base. If non-null, then the returned pathname is relative to this URL. If null, the returned pathname is an absolute URL (file:/path/).
url - remote directory URL to look up. Must end in slash.

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception