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
13   58   5   4,33
4   27   0,38   3
3     1,67  
1    
This report was generated with an evaluation server license. Purchase Clover or configure your license.
 
  RelativeUriDecorator       Line # 13 13 0% 5 0 100% 1.0
 
  (30)
 
1    package net.sourceforge.pebble.decorator;
2   
3    import net.sourceforge.pebble.domain.Attachment;
4    import net.sourceforge.pebble.domain.BlogEntry;
5    import net.sourceforge.pebble.domain.StaticPage;
6    import net.sourceforge.pebble.api.decorator.ContentDecoratorContext;
7   
8    /**
9    * Translates relative URIs in blog entries and static pages into absolute URLs.
10    *
11    * @author Simon Brown
12    */
 
13    public class RelativeUriDecorator extends ContentDecoratorSupport {
14   
15    /**
16    * Decorates the specified blog entry.
17    *
18    * @param context the context in which the decoration is running
19    * @param blogEntry the blog entry to be decorated
20    */
 
21  28 toggle public void decorate(ContentDecoratorContext context, BlogEntry blogEntry) {
22  28 blogEntry.setBody(replaceCommonUris(blogEntry.getBody()));
23  28 blogEntry.setExcerpt(replaceCommonUris(blogEntry.getExcerpt()));
24   
25  28 Attachment attachment = blogEntry.getAttachment();
26  28 if (attachment != null) {
27  4 String attachmentUrl = attachment.getUrl();
28  4 if (attachmentUrl.startsWith("./")) {
29  2 attachment.setUrl(getBlog().getUrl() + attachmentUrl.substring(2));
30    }
31    }
32    }
33   
34    /**
35    * Decorates the specified static page.
36    *
37    * @param context the context in which the decoration is running
38    * @param staticPage the static page to be decorated
39    */
 
40  4 toggle public void decorate(ContentDecoratorContext context, StaticPage staticPage) {
41  4 staticPage.setBody(replaceCommonUris(staticPage.getBody()));
42    }
43   
44    /**
45    * Helper method to replace common relative URIs with their absolute values.
46    *
47    * @param s the String containing relative URIs
48    * @return a new String containing absolute URLs
49    */
 
50  60 toggle private String replaceCommonUris(String s) {
51  60 s = s.replaceAll("href=\"\\./", "href=\"" + getBlog().getUrl());
52  60 s = s.replaceAll("href='\\./", "href='" + getBlog().getUrl());
53  60 s = s.replaceAll("src=\"\\./", "src=\"" + getBlog().getUrl());
54  60 s = s.replaceAll("src='\\./", "src='" + getBlog().getUrl());
55  60 return s;
56    }
57   
58    }