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
35   152   16   17,5
12   111   0,46   2
2     8  
1    
This report was generated with an evaluation server license. Purchase Clover or configure your license.
 
  SocialBookmarksDecorator       Line # 17 35 0% 16 3 93,9% 0.93877554
 
  (2)
 
1    package net.sourceforge.pebble.decorator;
2   
3    import java.io.UnsupportedEncodingException;
4    import java.net.URLEncoder;
5    import java.util.ResourceBundle;
6   
7    import net.sourceforge.pebble.api.decorator.ContentDecoratorContext;
8    import net.sourceforge.pebble.domain.Blog;
9    import net.sourceforge.pebble.domain.BlogEntry;
10    import net.sourceforge.pebble.util.I18n;
11   
12    /**
13    * Adds links to the social bookmarking sites to add current blog entry
14    *
15    * @author Alexander Zagniotov
16    */
 
17    public class SocialBookmarksDecorator extends ContentDecoratorSupport {
18   
19    private static final String TITLE = "&title=";
20    private static final String TITLE_FURL_YAHOO = "&t=";
21   
22    private static final String SLASHDOT_URL = "http://slashdot.org/bookmark.pl?url=";
23    private static final String DIGG_URL = "http://digg.com/submit?url=";
24    private static final String REDDIT_URL = "http://reddit.com/submit?url=";
25    private static final String DELICIOUS_URL = "http://del.icio.us/post?url=";
26    private static final String STUMBLEUPON_URL = "http://www.stumbleupon.com/submit?url=";
27    private static final String GOOGLE_URL = "http://www.google.com/bookmarks/mark?op=edit&bkmk=";
28    private static final String TECHNORATI_URL = "http://technorati.com/faves?add=";
29    private static final String BLOGLINES_URL = "http://www.bloglines.com/sub/";
30    private static final String FACEBOOK_URL = "http://www.facebook.com/share.php?u=";
31    private static final String FURL_URL = "http://www.furl.net/storeIt.jsp?u=";
32    private static final String WINDOWSLIVE_URL = "https://favorites.live.com/quickadd.aspx?mkt=en-us&url=";
33    private static final String YAHOO_URL = "http://bookmarks.yahoo.com/toolbar/savebm?opener=tb&u=";
34   
35    private static final String SLASHDOT_IMG = "<img src=\"common/images/slashdot.png\" alt=\"Add this post to Slashdot\" border=\"0\" />";
36    private static final String DIGG_IMG = "<img src=\"common/images/digg.png\" alt=\"Add this post to Digg\" border=\"0\" />";
37    private static final String REDDIT_IMG = "<img src=\"common/images/reddit.png\" alt=\"Add this post to Reddit\" border=\"0\" />";
38    private static final String DELICIOUS_IMG = "<img src=\"common/images/delicious.png\" alt=\"Add this post to Delicious\" border=\"0\" />";
39    private static final String STUMBLEUPON_IMG = "<img src=\"common/images/stumbleupon.png\" alt=\"Add this post to Stumble it\" border=\"0\" />";
40    private static final String GOOGLE_IMG = "<img src=\"common/images/google.png\" alt=\"Add this post to Google\" border=\"0\" />";
41    private static final String TECHNORATI_IMG = "<img src=\"common/images/technorati.png\" alt=\"Add this post to Technorati\" border=\"0\" />";
42    private static final String BLOGLINES_IMG = "<img src=\"common/images/bloglines.png\" alt=\"Add this post to Bloglines\" border=\"0\" />";
43    private static final String FACEBOOK_IMG = "<img src=\"common/images/facebook.png\" alt=\"Add this post to Facebook\" border=\"0\" />";
44    private static final String FURL_IMG = "<img src=\"common/images/furl.png\" alt=\"Add this post to Furl\" border=\"0\" />";
45    private static final String WINDOWSLIVE_IMG = "<img src=\"common/images/windowslive.png\" alt=\"Add this post to Windows Live\" border=\"0\" />";
46    private static final String YAHOO_IMG = "<img src=\"common/images/yahoo.png\" alt=\"Add this post to Yahoo!\" border=\"0\" />";
47   
48    private static final String SLASHDOT_ALT = "socialbookmark.addToSlashdot";
49    private static final String DIGG_ALT = "socialbookmark.addToDigg";
50    private static final String REDDIT_ALT = "socialbookmark.addToReddit";
51    private static final String DELICIOUS_ALT = "socialbookmark.addToDelicious";
52    private static final String STUMBLEUPON_ALT = "socialbookmark.addToStumbleupon";
53    private static final String GOOGLE_ALT = "socialbookmark.addToGoogle";
54    private static final String TECHNORATI_ALT = "socialbookmark.addToTechnorati";
55    private static final String BLOGLINES_ALT = "socialbookmark.addToBloglines";
56    private static final String FACEBOOK_ALT = "socialbookmark.addToFacebook";
57    private static final String FURL_ALT = "socialbookmark.addToFurl";
58    private static final String WINDOWSLIVE_ALT = "socialbookmark.addToWindowsLive";
59    private static final String YAHOO_ALT = "socialbookmark.addToYahoo";
60   
61    private static final String[] bookmarkingSites = { SLASHDOT_URL, DIGG_URL,
62    REDDIT_URL, DELICIOUS_URL, STUMBLEUPON_URL, GOOGLE_URL, TECHNORATI_URL, BLOGLINES_URL, FACEBOOK_URL,
63    FURL_URL, WINDOWSLIVE_URL, YAHOO_URL};
64   
65    private static final String[] bookmarkingNames = { SLASHDOT_IMG, DIGG_IMG,
66    REDDIT_IMG, DELICIOUS_IMG, STUMBLEUPON_IMG, GOOGLE_IMG, TECHNORATI_IMG, BLOGLINES_IMG, FACEBOOK_IMG,
67    FURL_IMG, WINDOWSLIVE_IMG, YAHOO_IMG};
68   
69    private static final String[] bookmarkingAltText = { SLASHDOT_ALT, DIGG_ALT,
70    REDDIT_ALT, DELICIOUS_ALT, STUMBLEUPON_ALT, GOOGLE_ALT, TECHNORATI_ALT, BLOGLINES_ALT, FACEBOOK_ALT,
71    FURL_ALT, WINDOWSLIVE_ALT, YAHOO_ALT};
72   
73    /**
74    * Decorates the specified blog entry.
75    *
76    * @param context
77    * the context in which the decoration is running
78    * @param blogEntry
79    * the blog entry to be decorated
80    */
 
81  2 toggle public void decorate(ContentDecoratorContext context, BlogEntry blogEntry) {
82  2 Blog blog = blogEntry.getBlog();
83  2 ResourceBundle bundle = I18n.getBundle(blog.getLocale());
84   
85  2 String body = blogEntry.getBody();
86  2 if (body != null && body.trim().length() > 0) {
87   
88  2 String html = generateDecorationHtml(bundle, blogEntry);
89  2 blogEntry.setBody(body + html);
90    }
91   
92  2 String excerpt = blogEntry.getExcerpt();
93  2 if (excerpt != null && excerpt.trim().length() > 0) {
94   
95  2 String html = generateDecorationHtml(bundle, blogEntry);
96  2 blogEntry.setExcerpt(excerpt + html);
97    }
98    }
99   
100   
101   
 
102  4 toggle private String generateDecorationHtml(ResourceBundle bundle,
103    BlogEntry blogEntry) {
104  4 StringBuffer buf = new StringBuffer();
105  4 String permLink = blogEntry.getPermalink();
106  4 String title = "";
107  4 try {
108  4 title = URLEncoder.encode(blogEntry.getTitle(), "UTF-8");
109    }
110    catch(UnsupportedEncodingException e) {
111  0 title = blogEntry.getTitle();
112    }
113  4 buf.append("<div class=\"tags\"><span>");
114  4 buf.append(bundle.getString("common.bookmarks"));
115  4 buf.append(" : </span>&nbsp;");
116   
117  52 for (int i = 0; i < bookmarkingSites.length; i++) {
118  48 buf.append("<a href=\"");
119  48 buf.append(bookmarkingSites[i] + permLink);
120   
121   
122  48 if (bookmarkingSites[i] != TECHNORATI_URL &&
123    bookmarkingSites[i] != BLOGLINES_URL &&
124    bookmarkingSites[i] != FACEBOOK_URL &&
125    bookmarkingSites[i] != FURL_URL &&
126    bookmarkingSites[i] != YAHOO_URL) {
127  28 buf.append(TITLE + title + "\"");
128    }
129   
130  20 else if (bookmarkingSites[i] == FURL_URL || bookmarkingSites[i] == YAHOO_URL) {
131  8 buf.append(TITLE_FURL_YAHOO + title + "\"");
132    }
133   
134    else {
135  12 buf.append("\"");
136    }
137   
138  48 buf.append(" target=\"_blank\"");
139  48 buf.append(" title=\"" + bundle.getString(bookmarkingAltText[i]) + "\">");
140  48 buf.append(bookmarkingNames[i]);
141  48 buf.append("</a>");
142   
143  48 if (i < bookmarkingSites.length - 1) {
144  44 buf.append("&nbsp;&nbsp;&nbsp;&nbsp;");
145    }
146    }
147   
148  4 buf.append("</div>");
149  4 return buf.toString();
150    }
151   
152    }