Clover Coverage Report - Pebble 2.5-SNAPSHOT
Coverage timestamp: Sat Jun 12 2010 09:39:29 EST
../../../../img/srcFileCovDistChart10.png 0% of files have more coverage
4   72   4   1
0   20   1   2
4     1  
2    
This report was generated with an evaluation server license. Purchase Clover or configure your license.
 
  UrlRewriter       Line # 26 3 0% 3 0 100% 1.0
  UrlRewriter.TheRewriter       Line # 66 1 0% 1 0 100% 1.0
 
  (6)
 
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   
 
26    public abstract class UrlRewriter {
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  8 toggle public static void useThisRewriter(UrlRewriter urlRewriter) {
36  8 x.set(urlRewriter);
37    }
38   
39    /**
40    * Urls will not be rewritten after this call - this clears
41    * the threadlocal UrlRewriter.
42    */
 
43  2 toggle public static void clear() {
44  2 x.remove();
45    }
46   
47    /**
48    * Delegate url rewriting to the current threadlocal rewriter.
49    * @param url
50    * @return
51    */
 
52  12 toggle public static String doRewrite(String url) {
53  12 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   
 
66    private static class TheRewriter extends ThreadLocal<UrlRewriter> {
 
67  4 toggle @Override
68    protected UrlRewriter initialValue() {
69  4 return NullUrlRewriter.instance;
70    }
71    }
72    }