sunlabs.brazil.util.http
Class MapHtmlUrl

java.lang.Object
  extended by sunlabs.brazil.util.http.MapHtmlUrl (view source)

public class MapHtmlUrl
extends Object

Utility class to systematically rewrite links inside of html pages and/or stylesheets. The "convertHtml()" method finds all URL's in the supplied HTML document, including embedded stylesheets and style attributes, and calls "mapURL" for each URL, allowing the URL to be rewritten. (This is intended to replace the MapPage class someday).


Nested Class Summary
static interface MapHtmlUrl.Map
          Every URL calls this to map the string.
 
Constructor Summary
MapHtmlUrl(MapHtmlUrl.Map map, boolean doStyle)
          Create a url mapper with the supplied url rewriter.
 
Method Summary
 void addTag(String name, String attr)
          Add a tag/attribute pair to be mapped.
 String convertCSS(String style)
          Rewrite URL's in style sheets.
 String convertHtml(String html)
          Rewrite all the url's in this document.
 void delTag(String name)
          Remove a tag for mapping
 MapHtmlUrl.Map getMap()
          Return our mapper instance
static Hashtable init(Hashtable h)
          Create a hashtable containing all the standard tag/attribute pairs in HTML whose values are URL's.
static void main(String[] argv)
          test this stuff out, sort of.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MapHtmlUrl

public MapHtmlUrl(MapHtmlUrl.Map map,
                  boolean doStyle)
Create a url mapper with the supplied url rewriter.

Parameters:
map - A class that maps URL's to URL's.
style - There can be URL's inside of inline style attributes. It's not common, and potentially expensive to look for them, so you pick.
Method Detail

addTag

public void addTag(String name,
                   String attr)
Add a tag/attribute pair to be mapped.

Parameters:
name - An html tag
attr - The attribute that is a URL.

delTag

public void delTag(String name)
Remove a tag for mapping

Parameters:
name - The html tag that shouldn't be examined

getMap

public MapHtmlUrl.Map getMap()
Return our mapper instance


init

public static Hashtable init(Hashtable h)
Create a hashtable containing all the standard tag/attribute pairs in HTML whose values are URL's.


convertHtml

public String convertHtml(String html)
Rewrite all the url's in this document. This is accomplished by iterating through the document and replacing all URL's with the result of mapUrl() from our Map instance.

Parameters:
content - The HTML to be processed.
Returns:
The same HTML, will all URL's rewritten.

convertCSS

public String convertCSS(String style)
Rewrite URL's in style sheets. This works via repeated calls to mapUrl(). (This implementation is preliminary).

Look for url(href) in a stylesheet value. "href" may be delimited by (") or ('), and surrounding whitespace is ignored.


main

public static void main(String[] argv)
                 throws IOException
test this stuff out, sort of. Usage: MapHtmlUrl markup
- read markup from "markup" file - write markup to stdout - surround all url's with []

Throws:
IOException

Version Kenai-svn-r24, Generated 08/18/09
Copyright (c) 2001-2009, Sun Microsystems.