| java.lang.Object websphinx.HTMLTransformer websphinx.LinkTransformer
All known Subclasses: websphinx.RewritableLinkTransformer, websphinx.Mirror,
LinkTransformer | public class LinkTransformer extends HTMLTransformer (Code) | | 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.
|
Method Summary | |
public URL | getBase() Get the base URL used by the LinkTransformer.
A transformed link's URL is written out relative
to this URL. | public boolean | getEmitBaseElement() Test whether the LinkTransformer should emit a
<BASE> element pointing to the base URL. | protected void | handleBase(Element elem) Handle the BASE element. | protected void | handleElement(Element elem) Handle an element written through the transformer. | protected void | handleLink(Link link) Handle a Link's transformation. | public boolean | isMapped(URL url) Test whether a URL is mapped. | public String | lookup(URL base, URL url) Look up the href for a URL, taking any mapping
into account. | public synchronized void | map(URL url, String href) Map a URL to an href. | public synchronized void | map(URL url, URL newURL) Map a URL to a new URL. | 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. | public synchronized void | setEmitBaseElement(boolean emitBase) Set whether the LinkTransformer should emit a
<BASE> element pointing to the base URL. | public synchronized void | writePage(Page page) Write a page through the transformer. |
emitBaseElement | boolean emitBaseElement(Code) | | |
needToEmitBase | boolean needToEmitBase(Code) | | |
LinkTransformer | public LinkTransformer(String filename) throws IOException(Code) | | Make a LinkTransformer writing to a file.
Parameters: filename - Filename to write to |
LinkTransformer | public LinkTransformer(String filename, boolean seekable) throws IOException(Code) | | Make a LinkTransformer that writes pages to a
file.
Parameters: filename - Name of file to receive HTML output Parameters: seekable - True if file should be opened for random access |
LinkTransformer | public LinkTransformer(OutputStream out)(Code) | | Make a LinkTransformer writing to a stream.
Parameters: out - stream to write to |
LinkTransformer | public LinkTransformer(HTMLTransformer next)(Code) | | Make a LinkTransformer writing to another HTMLTransformer
Parameters: next - next transformer in filter chain |
getBase | public URL getBase()(Code) | | 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/.
base URL, or null if no base URL is set. Default is null. |
getEmitBaseElement | public boolean getEmitBaseElement()(Code) | | Test whether the LinkTransformer should emit a
<BASE> element pointing to the base URL.
true if a <BASE> element should beemitted with each page. |
handleBase | protected void handleBase(Element elem) throws IOException(Code) | | 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 |
handleElement | protected void handleElement(Element elem) throws IOException(Code) | | Handle an element written through the transformer.
Remaps attributes that contain URLs.
Parameters: elem - Element to transform |
handleLink | protected void handleLink(Link link) throws IOException(Code) | | Handle a Link's transformation.
Default implementation replaces the link's URL
with lookup(URL).
Parameters: link - Link to transform |
isMapped | public boolean isMapped(URL url)(Code) | | Test whether a URL is mapped.
Parameters: url - URL of interest true if map () was called to remap url |
lookup | public String lookup(URL base, URL url)(Code) | | Look up the href for a URL, taking any mapping
into account.
Parameters: base - base URL (or null if an absolute URL is desired) Parameters: url - URL of interest relative href for url from base |
map | public synchronized void map(URL url, String href)(Code) | | 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 Parameters: href - href which should be returned by lookup (null, url) |
map | public synchronized void map(URL url, URL newURL)(Code) | | 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 Parameters: newURL - URL which should be returned by lookup (null, url) |
setBase | public synchronized void setBase(URL base)(Code) | | 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. |
setEmitBaseElement | public synchronized void setEmitBaseElement(boolean emitBase)(Code) | | Set whether the LinkTransformer should emit a
<BASE> element pointing to the base URL.
Parameters: emitBase - true if a <BASE> element should beemitted with each page. |
writePage | public synchronized void writePage(Page page) throws IOException(Code) | | 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 |
|
|