All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class websphinx.LinkTransformer

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

public class LinkTransformer
extends HTMLTransformer
Transformer that remaps URLs in links.

The default LinkTransformer simply converts all links to absolute URLs. Other common effects are easy to achieve:

The default LinkTransformer strips out <BASE> elements. Instead, it can output a <BASE> element with a user-specified URL. Use setBase() to set the URL and setEmitBaseElement() to indicate that it should be emitted.


Variable Index

 o base
 o map

Constructor Index

 o LinkTransformer(HTMLTransformer)
Make a LinkTransformer writing to another HTMLTransformer
 o LinkTransformer(OutputStream)
Make a LinkTransformer writing to a stream.
 o LinkTransformer(String)
Make a LinkTransformer writing to a file.
 o LinkTransformer(String, boolean)
Make a LinkTransformer that writes pages to a file.
 o LinkTransformer(Writer)

Method Index

 o getBase()
Get the base URL used by the LinkTransformer.
 o getEmitBaseElement()
Test whether the LinkTransformer should emit a <BASE> element pointing to the base URL.
 o handleBase(Element)
Handle the BASE element.
 o handleElement(Element)
Handle an element written through the transformer.
 o handleLink(Link)
Handle a Link's transformation.
 o isMapped(URL)
Test whether a URL is mapped.
 o lookup(URL, URL)
Look up the href for a URL, taking any mapping into account.
 o map(URL, String)
Map a URL to an href.
 o map(URL, URL)
Map a URL to a new URL.
 o setBase(URL)
Set the base URL used by the LinkTransformer.
 o setEmitBaseElement(boolean)
Set whether the LinkTransformer should emit a <BASE> element pointing to the base URL.
 o writePage(Page)
Write a page through the transformer.

Variables

 o map
 protected Hashtable map
 o base
 protected URL base

Constructors

 o LinkTransformer
 public LinkTransformer(String filename) throws IOException
Make a LinkTransformer writing to a file.

Parameters:
filename - Filename to write to
 o LinkTransformer
 public LinkTransformer(String filename,
                        boolean seekable) throws IOException
Make a LinkTransformer that writes pages to a file.

Parameters:
filename - Name of file to receive HTML output
seekable - True if file should be opened for random access
 o LinkTransformer
 public LinkTransformer(OutputStream out)
Make a LinkTransformer writing to a stream.

Parameters:
out - stream to write to
 o LinkTransformer
 public LinkTransformer(Writer writer)
 o LinkTransformer
 public LinkTransformer(HTMLTransformer next)
Make a LinkTransformer writing to another HTMLTransformer

Parameters:
next - next transformer in filter chain

Methods

 o getBase
 public URL getBase()
Get the base URL used by the LinkTransformer. A transformed link's URL is written out relative to this URL. For instance, if the base URL is http://www.yahoo.com/Entertainment/, then a link URL http://www.yahoo.com/News/Current/ would be written out as ../News/Current/.

Returns:
base URL, or null if no base URL is set. Default is null.
 o setBase
 public synchronized void setBase(URL base)
Set the base URL used by the LinkTransformer. A transformed link's URL is written out relative to this URL. For instance, if the base URL is http://www.yahoo.com/Entertainment/, then a link URL http://www.yahoo.com/News/Current/ would be written out as ../News/Current/.

Parameters:
base - base URL, or null if no base URL should be used.
 o getEmitBaseElement
 public boolean getEmitBaseElement()
Test whether the LinkTransformer should emit a <BASE> element pointing to the base URL.

Returns:
true if a <BASE> element should be emitted with each page.
 o setEmitBaseElement
 public synchronized void setEmitBaseElement(boolean emitBase)
Set whether the LinkTransformer should emit a <BASE> element pointing to the base URL.

Parameters:
emitBase - true if a <BASE> element should be emitted with each page.
 o lookup
 public String lookup(URL base,
                      URL url)
Look up the href for a URL, taking any mapping into account.

Parameters:
base - base URL (or null if an absolute URL is desired)
url - URL of interest
Returns:
relative href for url from base
 o map
 public synchronized void map(URL url,
                              String href)
Map a URL to an href. For example, Concatenator uses this call to map page URLs to their corresponding anchors in the concatenation.

Parameters:
url - URL of interest
href - href which should be returned by lookup (null, url)
 o map
 public synchronized void map(URL url,
                              URL newURL)
Map a URL to a new URL. For example, Mirror uses this call to map remote URLs to their corresponding local URLs.

Parameters:
url - URL of interest
newURL - URL which should be returned by lookup (null, url)
 o isMapped
 public boolean isMapped(URL url)
Test whether a URL is mapped.

Parameters:
url - URL of interest
Returns:
true if map () was called to remap url
 o writePage
 public synchronized void writePage(Page page) throws IOException
Write a page through the transformer. If getEmitBaseElement() is true and getBase() is non-null, then the transformer outputs a <BASE> element either inside the page's <HEAD> element (if present) or before the first tag that belongs in <BODY>.

Parameters:
page - Page to write
Overrides:
writePage in class HTMLTransformer
 o handleElement
 protected void handleElement(Element elem) throws IOException
Handle an element written through the transformer. Remaps attributes that contain URLs.

Parameters:
elem - Element to transform
Overrides:
handleElement in class HTMLTransformer
 o handleLink
 protected void handleLink(Link link) throws IOException
Handle a Link's transformation. Default implementation replaces the link's URL with lookup(URL).

Parameters:
link - Link to transform
 o handleBase
 protected void handleBase(Element elem) throws IOException
Handle the BASE element. Default implementation removes if if EmitBaseElement is false, or changes its URL to Base if EmitBaseElement is true.

Parameters:
elem - BASE element to transform

All Packages  Class Hierarchy  This Package  Previous  Next  Index