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:
- To make all links relative to a base URL, use
setBase() to set a base URL.
- To replace certain URLs with different ones,
use map() to set up the mappings.
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.
-
base
-
-
map
-
-
LinkTransformer(HTMLTransformer)
- Make a LinkTransformer writing to another HTMLTransformer
-
LinkTransformer(OutputStream)
- Make a LinkTransformer writing to a stream.
-
LinkTransformer(String)
- Make a LinkTransformer writing to a file.
-
LinkTransformer(String, boolean)
- Make a LinkTransformer that writes pages to a
file.
-
LinkTransformer(Writer)
-
-
getBase()
- Get the base URL used by the LinkTransformer.
-
getEmitBaseElement()
- Test whether the LinkTransformer should emit a
<BASE> element pointing to the base URL.
-
handleBase(Element)
- Handle the BASE element.
-
handleElement(Element)
- Handle an element written through the transformer.
-
handleLink(Link)
- Handle a Link's transformation.
-
isMapped(URL)
- Test whether a URL is mapped.
-
lookup(URL, URL)
- Look up the href for a URL, taking any mapping
into account.
-
map(URL, String)
- Map a URL to an href.
-
map(URL, URL)
- Map a URL to a new URL.
-
setBase(URL)
- Set the base URL used by the LinkTransformer.
-
setEmitBaseElement(boolean)
- Set whether the LinkTransformer should emit a
<BASE> element pointing to the base URL.
-
writePage(Page)
- Write a page through the transformer.
map
protected Hashtable map
base
protected URL base
LinkTransformer
public LinkTransformer(String filename) throws IOException
- Make a LinkTransformer writing to a file.
- Parameters:
- filename - Filename to write to
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
LinkTransformer
public LinkTransformer(OutputStream out)
- Make a LinkTransformer writing to a stream.
- Parameters:
- out - stream to write to
LinkTransformer
public LinkTransformer(Writer writer)
LinkTransformer
public LinkTransformer(HTMLTransformer next)
- Make a LinkTransformer writing to another HTMLTransformer
- Parameters:
- next - next transformer in filter chain
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.
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.
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.
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.
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
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)
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)
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
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
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
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
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