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
26   88   10   8,67
12   48   0,38   3
3     3,33  
1    
This report was generated with an evaluation server license. Purchase Clover or configure your license.
 
  AbstractTagsDecorator       Line # 16 26 0% 10 2 95,1% 0.9512195
 
  (42)
 
1    package net.sourceforge.pebble.decorator;
2   
3    import java.util.Iterator;
4   
5    import net.sourceforge.pebble.api.decorator.ContentDecoratorContext;
6    import net.sourceforge.pebble.domain.PageBasedContent;
7    import net.sourceforge.pebble.domain.Tag;
8    import net.sourceforge.pebble.util.I18n;
9   
10    /**
11    * Generates tag links for inclusion in the body of blog entries,
12    * when rendered as HTML.
13    *
14    * @author Simon Brown
15    */
 
16    public abstract class AbstractTagsDecorator extends ContentDecoratorSupport {
17    private final String resourceKey;
18    private final String target;
19   
20    /**
21    * Extended Parameters for generating Links to different Tagging sites - like Technorati.
22    * @param resourceKey is used to determine the label for the tags from pebbles resource files
23    * @param openLinkInNewWindow set to true to generate links with 'target="_blank"'
24    */
25   
 
26  6 toggle public AbstractTagsDecorator(String resourceKey, boolean openLinkInNewWindow) {
27  6 this.resourceKey = resourceKey;
28  6 target=openLinkInNewWindow ? " target=\"_blank\"":"";
29    }
30   
31    /**
32    * Default constructors makes Tags use the standard label (key tag.tags) and open links
33    * in the same browser window.
34    */
35   
 
36  1340 toggle public AbstractTagsDecorator() {
37  1340 this.resourceKey = "tag.tags";
38  1340 target="";
39    }
40   
 
41  26 toggle protected String generateDecorationHtml(ContentDecoratorContext context, PageBasedContent content) {
42  26 StringBuffer buf = new StringBuffer();
43   
44  26 if (context.getMedia() == ContentDecoratorContext.HTML_PAGE) {
45  8 Iterator<Tag> tags = content.getAllTags().iterator();
46   
47  8 String baseUrl = getBaseUrl(content);
48   
49  8 if (tags.hasNext()) {
50  4 buf.append("<div class=\"tags\"><span>");
51  4 buf.append(I18n.getMessage(content.getBlog(), resourceKey));
52  4 buf.append(" : </span>");
53   
54  16 while (tags.hasNext()) {
55   
56  12 Tag tag = tags.next();
57   
58  12 if (tag.getName() != null && !tag.getName().equals("")) {
59   
60  12 buf.append("<a href=\"");
61  12 buf.append(baseUrl);
62  12 buf.append(tag.getName() + "\"");
63  12 buf.append(target);
64  12 buf.append(" rel=\"tag\">");
65  12 buf.append(tag.getName());
66  12 buf.append("</a>");
67   
68  12 if (tags.hasNext()) {
69  8 buf.append(", ");
70    }
71    }
72    }
73  4 buf.append("</div>");
74   
75    }
76    }
77   
78  26 return buf.toString();
79    }
80   
81    /**
82    * Gets the base URL for tag links, complete with trailing slash.
83    *
84    * @param content the owning content
85    * @return a URL as a String
86    */
87    public abstract String getBaseUrl(PageBasedContent content);
88    }