Class MapPage


  • public class MapPage
    extends java.lang.Object
    Utility class to rewrite links inside of web pages so they appear to come from a different site.

    Note: This only works for "http", not "https".

    Version:
    Author:
    Stephen Uhler
    • Field Summary

      Fields 
      Modifier and Type Field Description
      int count  
      static boolean log  
      java.util.Vector patternMap  
      java.lang.String prefix  
      java.util.Hashtable tagMap
      Initialized to all tag/attribute pairs whose attribute values are considered for rewriting.
      java.util.Hashtable urlMap  
    • Constructor Summary

      Constructors 
      Constructor Description
      MapPage​(java.lang.String prefix)
      Create a site mapper.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addMapEntry​(java.lang.String name, java.lang.String value)
      Add or remove an item to the map table
      void addPatternEntry​(java.lang.String pattern, java.lang.String replacement)
      Add or remove an item to the pattern table
      void addTag​(java.lang.String name, java.lang.String attribute)
      add a tag/attribute pair to the rewrite list.
      void clearPatterns()
      Clear the pattern map.
      java.lang.String convertHtml​(java.lang.String content)
      Rewrite all the url's in this document.
      java.lang.String convertString​(java.lang.String fix)
      Rewrite a url inside a tag parameter.
      void log​(java.lang.String message)
      diagnostic output
      int mapCount()
      How many tags have been mapped?
      void setMap​(java.util.Hashtable map)
      Set the map table for cross-linked sites.
      void setPrefix​(java.lang.String prefix)
      Change the prefix that will replace the leading "/" in a URL.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • tagMap

        public java.util.Hashtable tagMap
        Initialized to all tag/attribute pairs whose attribute values are considered for rewriting.
      • urlMap

        public java.util.Hashtable urlMap
      • patternMap

        public java.util.Vector patternMap
      • prefix

        public java.lang.String prefix
      • log

        public static boolean log
      • count

        public int count
    • Constructor Detail

      • MapPage

        public MapPage​(java.lang.String prefix)
        Create a site mapper. The following table maps all the entity/attribute combinations that are (or could be) URL's to (possibly) rewrite.
        Parameters:
        prefix - Every link starting with "/" has the leading slash replaced by prefix. If prefix is null, then only fully qualified url's are considered for rewriting.
    • Method Detail

      • setPrefix

        public void setPrefix​(java.lang.String prefix)
        Change the prefix that will replace the leading "/" in a URL.
      • addTag

        public void addTag​(java.lang.String name,
                           java.lang.String attribute)
        add a tag/attribute pair to the rewrite list. If the attribute is null, remove the tag.
      • setMap

        public void setMap​(java.util.Hashtable map)
        Set the map table for cross-linked sites. Foreach key in the table that matches a URL, replace the key portion of the url with the key's value.
      • addMapEntry

        public void addMapEntry​(java.lang.String name,
                                java.lang.String value)
        Add or remove an item to the map table
        Parameters:
        name - The prefix of the url to match
        value - The prefix to replace it with. If null, remove the prefix
      • addPatternEntry

        public void addPatternEntry​(java.lang.String pattern,
                                    java.lang.String replacement)
        Add or remove an item to the pattern table
        Parameters:
        pattern - The prefix pattern of the url to match Full tcl8.0-style regexps are supported
        replacement - The prefix to replace it with. If null, remove the prefix. \n's are replaced by the corrosponding sub-matches in the name

        Patterns are stored in a vector, with each pattern taking 3 concecutive elements: the pattern, the replacement rule, and the compiled expression. This way they are searched in order. Sample usage: http://www.([^.]*).com/ /site/\1/ will replace the url: http://www.foo.com/a/b.html with /site/foo/a/b.html

      • clearPatterns

        public void clearPatterns()
        Clear the pattern map.
      • mapCount

        public int mapCount()
        How many tags have been mapped?
      • convertHtml

        public java.lang.String convertHtml​(java.lang.String content)
        Rewrite all the url's in this document. This is accomplished via repeated calls to convertString(java.lang.String).
        Parameters:
        content - The HTML to be processed.
        Returns:
        The smae HTML, will all URL's rewritten. URL's starting with "/" have the "/" replaced with the prefix. All others are re-written based on the supplied mapping tables.
      • convertString

        public java.lang.String convertString​(java.lang.String fix)
        Rewrite a url inside a tag parameter.
        Parameters:
        fix - The value of the tag to be rewritten (fixed)
        Returns:
        null of the existing value is OK, otherwise the new value is returned
      • log

        public void log​(java.lang.String message)
        diagnostic output