File Source: urlrewriter.java

         /* 
    P/P   *  Method: Object initialValue()
          * 
          *  Postconditions:
          *    return_value == &net.sourceforge.pebble.util.NullUrlRewriter__static_init.new NullUrlRewriter(NullUrlRewriter__static_init#1)
          */
     1  package net.sourceforge.pebble.util;
     2  
     3  /**
     4   * This class is used to keep track of a thread local instance 
     5   * for rewriting URLs - ultimately for deciding if a link should
     6   * be decorated 'secure' (as in config value secureUrl) or plain.
     7   * 
     8   * The initialization (and clean up) is meant to be done in a 
     9   * servlet filter, so that the thread local rewriter is available 
    10   * to each request. This is done because a blog itself serves its
    11   * Url to anybody and doesn't know how to determine if it should be
    12   * talked to 'secure' or not.
    13   * 
    14   * In the current scenario, secureUrl may be used for logging in 
    15   * and performing administrative work. Be aware though that mixing
    16   * http and https access to an application may itself impose severe
    17   * risk while the user feels comfortably safe. Best and most secure 
    18   * mode for operation would be to go https exclusively. If you 
    19   * can't, the current solution (this class is participating in)
    20   * will help you the best it can.
    21   * 
    22   * @author Olaf Kock
    23   *
    24   */
    25  
         /* 
    P/P   *  Method: void net.sourceforge.pebble.util.UrlRewriter()
          */
    26  public abstract class UrlRewriter {
        	 /* 
    P/P 	  *  Method: net.sourceforge.pebble.util.UrlRewriter__static_init
        	  * 
        	  *  Postconditions:
        	  *    x == &new UrlRewriter$TheRewriter(UrlRewriter__static_init#1)
        	  *    new UrlRewriter$TheRewriter(UrlRewriter__static_init#1) num objects == 1
        	  */
    27  	private static TheRewriter x = new TheRewriter(); 
    28  	
    29  	/**
    30  	 * Initialize the threadlocal urlRewriter. The given rewriter 
    31  	 * will be used until this method is called again (or clear()
    32  	 * is called) 
    33  	 * @param urlRewriter
    34  	 */
    35  	public static void useThisRewriter(UrlRewriter urlRewriter) {
        		 /* 
    P/P 		  *  Method: void useThisRewriter(UrlRewriter)
        		  * 
        		  *  Preconditions:
        		  *    x != null
        		  */
    36  		x.set(urlRewriter);
    37  	}
    38  	
    39  	/**
    40  	 * Urls will not be rewritten after this call - this clears 
    41  	 * the threadlocal UrlRewriter.
    42  	 */
    43  	public static void clear() {
        		 /* 
    P/P 		  *  Method: void clear()
        		  * 
        		  *  Preconditions:
        		  *    x != null
        		  */
    44  		x.remove();
    45  	}
    46  
    47  	/**
    48  	 * Delegate url rewriting to the current threadlocal rewriter.
    49  	 * @param url
    50  	 * @return
    51  	 */
    52  	public static String doRewrite(String url) {
        		 /* 
    P/P 		  *  Method: String doRewrite(String)
        		  * 
        		  *  Preconditions:
        		  *    x != null
        		  * 
        		  *  Presumptions:
        		  *    net.sourceforge.pebble.util.UrlRewriter_TheRewriter:get(...)@53 != null
        		  * 
        		  *  Postconditions:
        		  *    init'ed(return_value)
        		  */
    53  		return x.get().rewrite(url);
    54  	}
    55  
    56  	/**
    57  	 * This class serves as its own interface for the implementing 
    58  	 * UrlRewriters. Might be seen as a bit unclean, but keeps the 
    59  	 * implementation tightly together without introducing another
    60  	 * one-method-interface.
    61  	 * @param url
    62  	 * @return
    63  	 */
    64  	abstract public String rewrite(String url);
    65  	
        	 /* 
    P/P 	  *  Method: void net.sourceforge.pebble.util.UrlRewriter$TheRewriter(UrlRewriter$TheRewriter)
        	  */
    66  	private static class TheRewriter extends ThreadLocal<UrlRewriter> {
    67  		@Override
    68  		protected UrlRewriter initialValue() {
        			 /* 
    P/P 			  *  Method: UrlRewriter initialValue()
        			  * 
        			  *  Postconditions:
        			  *    return_value == &net.sourceforge.pebble.util.NullUrlRewriter__static_init.new NullUrlRewriter(NullUrlRewriter__static_init#1)
        			  */
    69  			return NullUrlRewriter.instance;
    70  		}
    71  	}
    72  }








SofCheck Inspector Build Version : 2.22510
urlrewriter.java 2010-Jun-25 19:40:32
urlrewriter.class 2010-Jul-19 20:23:38
urlrewriter$therewriter.class 2010-Jul-19 20:23:38