//# 0 errors, 89 messages
//#
package net.sourceforge.pebble.util;
    //#urlrewriter.java:1:1: class: net.sourceforge.pebble.util.UrlRewriter$TheRewriter
    //#urlrewriter.java:1:1: method: net.sourceforge.pebble.util.UrlRewriter$TheRewriter.net.sourceforge.pebble.util.UrlRewriter$TheRewriter__static_init
    //#urlrewriter.java:1:1: class: net.sourceforge.pebble.util.UrlRewriter
    //#urlrewriter.java:1: method: Object net.sourceforge.pebble.util.UrlRewriter$TheRewriter.initialValue()
    //#input(Object initialValue()): Param_0
    //#input(Object initialValue()): Param_0.__Tag
    //#input(Object initialValue()): __Descendant_Table[net/sourceforge/pebble/util/UrlRewriter$TheRewriter]
    //#input(Object initialValue()): __Descendant_Table[others]
    //#input(Object initialValue()): __Dispatch_Table.initialValue()Lnet/sourceforge/pebble/util/UrlRewriter;
    //#input(Object initialValue()): net/sourceforge/pebble/util/NullUrlRewriter.instance
    //#output(Object initialValue()): return_value
    //#pre[2] (Object initialValue()): Param_0.__Tag == net/sourceforge/pebble/util/UrlRewriter$TheRewriter
    //#post(Object initialValue()): return_value == &net.sourceforge.pebble.util.NullUrlRewriter__static_init.new NullUrlRewriter(NullUrlRewriter__static_init#1)
    //#urlrewriter.java:1: end of method: Object net.sourceforge.pebble.util.UrlRewriter$TheRewriter.initialValue()

/**
 * This class is used to keep track of a thread local instance 
 * for rewriting URLs - ultimately for deciding if a link should
 * be decorated 'secure' (as in config value secureUrl) or plain.
 * 
 * The initialization (and clean up) is meant to be done in a 
 * servlet filter, so that the thread local rewriter is available 
 * to each request. This is done because a blog itself serves its
 * Url to anybody and doesn't know how to determine if it should be
 * talked to 'secure' or not.
 * 
 * In the current scenario, secureUrl may be used for logging in 
 * and performing administrative work. Be aware though that mixing
 * http and https access to an application may itself impose severe
 * risk while the user feels comfortably safe. Best and most secure 
 * mode for operation would be to go https exclusively. If you 
 * can't, the current solution (this class is participating in)
 * will help you the best it can.
 * 
 * @author Olaf Kock
 *
 */

public abstract class UrlRewriter {
    //#urlrewriter.java:26: method: void net.sourceforge.pebble.util.UrlRewriter.net.sourceforge.pebble.util.UrlRewriter()
    //#urlrewriter.java:26: end of method: void net.sourceforge.pebble.util.UrlRewriter.net.sourceforge.pebble.util.UrlRewriter()
	private static TheRewriter x = new TheRewriter(); 
    //#urlrewriter.java:27: method: net.sourceforge.pebble.util.UrlRewriter.net.sourceforge.pebble.util.UrlRewriter__static_init
    //#output(net.sourceforge.pebble.util.UrlRewriter__static_init): __Descendant_Table[net/sourceforge/pebble/util/UrlRewriter]
    //#output(net.sourceforge.pebble.util.UrlRewriter__static_init): __Dispatch_Table.rewrite(Ljava/lang/String;)Ljava/lang/String;
    //#output(net.sourceforge.pebble.util.UrlRewriter__static_init): new UrlRewriter$TheRewriter(UrlRewriter__static_init#1) num objects
    //#output(net.sourceforge.pebble.util.UrlRewriter__static_init): x.__Tag
    //#output(net.sourceforge.pebble.util.UrlRewriter__static_init): x
    //#new obj(net.sourceforge.pebble.util.UrlRewriter__static_init): new UrlRewriter$TheRewriter(UrlRewriter__static_init#1)
    //#post(net.sourceforge.pebble.util.UrlRewriter__static_init): __Descendant_Table[net/sourceforge/pebble/util/UrlRewriter] == &__Dispatch_Table
    //#post(net.sourceforge.pebble.util.UrlRewriter__static_init): __Dispatch_Table.rewrite(Ljava/lang/String;)Ljava/lang/String; == &rewrite
    //#post(net.sourceforge.pebble.util.UrlRewriter__static_init): x == &new UrlRewriter$TheRewriter(UrlRewriter__static_init#1)
    //#post(net.sourceforge.pebble.util.UrlRewriter__static_init): new UrlRewriter$TheRewriter(UrlRewriter__static_init#1) num objects == 1
    //#post(net.sourceforge.pebble.util.UrlRewriter__static_init): x.__Tag == net/sourceforge/pebble/util/UrlRewriter$TheRewriter
    //#unanalyzed(net.sourceforge.pebble.util.UrlRewriter__static_init): Effects-of-calling:java.lang.ThreadLocal
    //#urlrewriter.java:27: end of method: net.sourceforge.pebble.util.UrlRewriter.net.sourceforge.pebble.util.UrlRewriter__static_init
	
	/**
	 * Initialize the threadlocal urlRewriter. The given rewriter 
	 * will be used until this method is called again (or clear()
	 * is called) 
	 * @param urlRewriter
	 */
	public static void useThisRewriter(UrlRewriter urlRewriter) {
		x.set(urlRewriter);
    //#urlrewriter.java:36: method: void net.sourceforge.pebble.util.UrlRewriter.useThisRewriter(UrlRewriter)
    //#urlrewriter.java:36: Warning: method not available
    //#    -- call on void net.sourceforge.pebble.util.UrlRewriter$TheRewriter:set(Object)
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.util.UrlRewriter
    //#    method: void useThisRewriter(UrlRewriter)
    //#    unanalyzed callee: void net.sourceforge.pebble.util.UrlRewriter$TheRewriter:set(Object)
    //#input(void useThisRewriter(UrlRewriter)): urlRewriter
    //#input(void useThisRewriter(UrlRewriter)): x
    //#pre[2] (void useThisRewriter(UrlRewriter)): x != null
	}
    //#urlrewriter.java:37: end of method: void net.sourceforge.pebble.util.UrlRewriter.useThisRewriter(UrlRewriter)
	
	/**
	 * Urls will not be rewritten after this call - this clears 
	 * the threadlocal UrlRewriter.
	 */
	public static void clear() {
		x.remove();
    //#urlrewriter.java:44: method: void net.sourceforge.pebble.util.UrlRewriter.clear()
    //#urlrewriter.java:44: Warning: method not available
    //#    -- call on void net.sourceforge.pebble.util.UrlRewriter$TheRewriter:remove()
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.util.UrlRewriter
    //#    method: void clear()
    //#    unanalyzed callee: void net.sourceforge.pebble.util.UrlRewriter$TheRewriter:remove()
    //#input(void clear()): x
    //#pre[1] (void clear()): x != null
	}
    //#urlrewriter.java:45: end of method: void net.sourceforge.pebble.util.UrlRewriter.clear()

	/**
	 * Delegate url rewriting to the current threadlocal rewriter.
	 * @param url
	 * @return
	 */
	public static String doRewrite(String url) {
		return x.get().rewrite(url);
    //#urlrewriter.java:53: method: String net.sourceforge.pebble.util.UrlRewriter.doRewrite(String)
    //#urlrewriter.java:53: Warning: method not available
    //#    -- call on Object net.sourceforge.pebble.util.UrlRewriter$TheRewriter:get()
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.util.UrlRewriter
    //#    method: String doRewrite(String)
    //#    unanalyzed callee: Object net.sourceforge.pebble.util.UrlRewriter$TheRewriter:get()
    //#urlrewriter.java:53: Warning: method not available
    //#    -- call on String rewrite(String)
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.util.UrlRewriter
    //#    method: String doRewrite(String)
    //#    unanalyzed callee: String rewrite(String)
    //#input(String doRewrite(String)): __Descendant_Table[net/sourceforge/pebble/util/HttpsURLRewriter]
    //#input(String doRewrite(String)): __Descendant_Table[net/sourceforge/pebble/util/NullUrlRewriter]
    //#input(String doRewrite(String)): __Descendant_Table[net/sourceforge/pebble/util/UrlRewriter]
    //#input(String doRewrite(String)): __Descendant_Table[others]
    //#input(String doRewrite(String)): __Dispatch_Table.rewrite(Ljava/lang/String;)Ljava/lang/String;
    //#input(String doRewrite(String)): net.sourceforge.pebble.PebbleContext__static_init.new PebbleContext(PebbleContext__static_init#1).__Tag
    //#input(String doRewrite(String)): net/sourceforge/pebble/PebbleContext.__Descendant_Table[net/sourceforge/pebble/PebbleContext]
    //#input(String doRewrite(String)): net/sourceforge/pebble/PebbleContext.__Dispatch_Table.getConfiguration()Lnet/sourceforge/pebble/Configuration;
    //#input(String doRewrite(String)): net/sourceforge/pebble/PebbleContext.instance
    //#input(String doRewrite(String)): net/sourceforge/pebble/util/HttpsURLRewriter.__Dispatch_Table.rewrite(Ljava/lang/String;)Ljava/lang/String;
    //#input(String doRewrite(String)): net/sourceforge/pebble/util/NullUrlRewriter.__Dispatch_Table.rewrite(Ljava/lang/String;)Ljava/lang/String;
    //#input(String doRewrite(String)): url
    //#input(String doRewrite(String)): x
    //#output(String doRewrite(String)): return_value
    //#pre[3] (String doRewrite(String)): x != null
    //#presumption(String doRewrite(String)): net.sourceforge.pebble.util.UrlRewriter$TheRewriter:get(...).__Tag@53 in {net/sourceforge/pebble/util/HttpsURLRewriter, net/sourceforge/pebble/util/NullUrlRewriter, net/sourceforge/pebble/util/UrlRewriter}
    //#presumption(String doRewrite(String)): net.sourceforge.pebble.util.UrlRewriter_TheRewriter:get(...)@53 != null
    //#post(String doRewrite(String)): init'ed(return_value)
    //#unanalyzed(String doRewrite(String)): Effects-of-calling:java.lang.String:startsWith
    //#unanalyzed(String doRewrite(String)): Effects-of-calling:java.lang.String:equals
    //#unanalyzed(String doRewrite(String)): Effects-of-calling:net.sourceforge.pebble.Configuration:getSecureUrl
    //#unanalyzed(String doRewrite(String)): Effects-of-calling:net.sourceforge.pebble.Configuration:getUrl
    //#unanalyzed(String doRewrite(String)): Effects-of-calling:java.lang.String:replace
    //#urlrewriter.java:53: end of method: String net.sourceforge.pebble.util.UrlRewriter.doRewrite(String)
	}

	/**
	 * This class serves as its own interface for the implementing 
	 * UrlRewriters. Might be seen as a bit unclean, but keeps the 
	 * implementation tightly together without introducing another
	 * one-method-interface.
	 * @param url
	 * @return
	 */
	abstract public String rewrite(String url);
	
	private static class TheRewriter extends ThreadLocal<UrlRewriter> {
    //#urlrewriter.java:66: method: void net.sourceforge.pebble.util.UrlRewriter$TheRewriter.net.sourceforge.pebble.util.UrlRewriter$TheRewriter()
    //#input(void net.sourceforge.pebble.util.UrlRewriter$TheRewriter()): this
    //#urlrewriter.java:66: end of method: void net.sourceforge.pebble.util.UrlRewriter$TheRewriter.net.sourceforge.pebble.util.UrlRewriter$TheRewriter()
    //#urlrewriter.java:66: method: void net.sourceforge.pebble.util.UrlRewriter$TheRewriter.net.sourceforge.pebble.util.UrlRewriter$TheRewriter(UrlRewriter$TheRewriter)
    //#input(void net.sourceforge.pebble.util.UrlRewriter$TheRewriter(UrlRewriter$TheRewriter)): Param_0
    //#unanalyzed(void net.sourceforge.pebble.util.UrlRewriter$TheRewriter(UrlRewriter$TheRewriter)): Effects-of-calling:java.lang.ThreadLocal
    //#urlrewriter.java:66: end of method: void net.sourceforge.pebble.util.UrlRewriter$TheRewriter.net.sourceforge.pebble.util.UrlRewriter$TheRewriter(UrlRewriter$TheRewriter)
		@Override
		protected UrlRewriter initialValue() {
			return NullUrlRewriter.instance;
    //#urlrewriter.java:69: method: UrlRewriter net.sourceforge.pebble.util.UrlRewriter$TheRewriter.initialValue()
    //#input(UrlRewriter initialValue()): net/sourceforge/pebble/util/NullUrlRewriter.instance
    //#output(UrlRewriter initialValue()): return_value
    //#post(UrlRewriter initialValue()): return_value == &net.sourceforge.pebble.util.NullUrlRewriter__static_init.new NullUrlRewriter(NullUrlRewriter__static_init#1)
    //#urlrewriter.java:69: end of method: UrlRewriter net.sourceforge.pebble.util.UrlRewriter$TheRewriter.initialValue()
		}
	}
}
    //#output(net.sourceforge.pebble.util.UrlRewriter$TheRewriter__static_init): __Descendant_Table[net/sourceforge/pebble/util/UrlRewriter$TheRewriter]
    //#output(net.sourceforge.pebble.util.UrlRewriter$TheRewriter__static_init): __Dispatch_Table.initialValue()Ljava/lang/Object;
    //#output(net.sourceforge.pebble.util.UrlRewriter$TheRewriter__static_init): __Dispatch_Table.initialValue()Lnet/sourceforge/pebble/util/UrlRewriter;
    //#post(net.sourceforge.pebble.util.UrlRewriter$TheRewriter__static_init): __Descendant_Table[net/sourceforge/pebble/util/UrlRewriter$TheRewriter] == &__Dispatch_Table
    //#post(net.sourceforge.pebble.util.UrlRewriter$TheRewriter__static_init): __Dispatch_Table.initialValue()Ljava/lang/Object; == &initialValue
    //#post(net.sourceforge.pebble.util.UrlRewriter$TheRewriter__static_init): __Dispatch_Table.initialValue()Lnet/sourceforge/pebble/util/UrlRewriter; == &initialValue
    //#urlrewriter.java:: end of method: net.sourceforge.pebble.util.UrlRewriter$TheRewriter.net.sourceforge.pebble.util.UrlRewriter$TheRewriter__static_init
    //#urlrewriter.java:: end of class: net.sourceforge.pebble.util.UrlRewriter$TheRewriter
    //#urlrewriter.java:: end of class: net.sourceforge.pebble.util.UrlRewriter
