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
12   58   4   6
2   25   0,33   2
2     2  
1    
This report was generated with an evaluation server license. Purchase Clover or configure your license.
 
  EntryToPdfDecorator       Line # 15 12 0% 4 1 93,8% 0.9375
 
  (2)
 
1    package net.sourceforge.pebble.decorator;
2   
3    import net.sourceforge.pebble.domain.Blog;
4    import net.sourceforge.pebble.domain.BlogEntry;
5    import net.sourceforge.pebble.domain.StaticPage;
6    import net.sourceforge.pebble.api.decorator.ContentDecoratorContext;
7   
8    import java.util.ResourceBundle;
9   
10    /**
11    * Allow to export current blog entry as PDF document
12    *
13    * @author Alexander Zagniotov
14    */
 
15    public class EntryToPdfDecorator extends ContentDecoratorSupport {
16   
17    private static final String PDF_IMG = "<img src=\"common/images/pdf_logo.gif\" alt=\"Export this post as PDF document\" align=\"bottom\" border=\"0\" />";
18   
19    /**
20    * Decorates the specified blog entry.
21    *
22    * @param context
23    * the context in which the decoration is running
24    * @param blogEntry
25    * the blog entry to be decorated
26    */
 
27  2 toggle public void decorate(ContentDecoratorContext context, BlogEntry blogEntry) {
28   
29  2 String body = blogEntry.getBody();
30  2 if (body != null && body.trim().length() > 0) {
31   
32  2 String html = generateDecorationHtml(blogEntry);
33  2 blogEntry.setBody(body + html);
34    }
35   
36    // String excerpt = blogEntry.getExcerpt();
37    //
38    // if (excerpt != null && excerpt.trim().length() > 0) {
39    // String html = generateDecorationHtml(blogEntry);
40    // blogEntry.setExcerpt(excerpt + html);
41    // }
42    }
43   
 
44  2 toggle private String generateDecorationHtml(BlogEntry blogEntry) {
45   
46  2 StringBuffer buf = new StringBuffer();
47  2 String title = blogEntry.getTitle();
48  2 String subtitle = blogEntry.getSubtitle();
49   
50  2 buf.append("<p>");
51  2 buf.append("<a href=\"" + blogEntry.getBlog().getUrl() + "entryToPDF.action?entry=" + blogEntry.getId() + "\" title=\"Export " + title + " - " + subtitle + " as PDF document\">");
52  2 buf.append(PDF_IMG);
53  2 buf.append("</a>&nbsp;&nbsp;Export this post to PDF document</p>");
54   
55  2 return buf.toString();
56    }
57   
58    }