View Javadoc

1   /**
2    * 
3    */
4   package net.sf.statcvs.pages;
5   
6   import java.text.NumberFormat;
7   
8   import net.sf.statcvs.Messages;
9   import net.sf.statcvs.model.Author;
10  import net.sf.statcvs.model.Repository;
11  import net.sf.statcvs.model.Revision;
12  import net.sf.statcvs.output.ReportConfig;
13  import net.sf.statcvs.reports.TopDevelopersTableReport;
14  import net.sf.statcvs.util.StringUtils;
15  
16  /**
17   * @author Benoit
18   *
19   */
20  public final class TwitterHelp {
21      private TwitterHelp() {
22      }
23  
24      public static String buildOverviewLink(final TopDevelopersTableReport topDevelopers, final Repository repository, final ReportConfig config) {
25          final StringBuffer buf = new StringBuffer();
26          startLink(buf);
27          buf.append("http://twitter.com/home?status=Project");
28  
29          final StringBuffer url = new StringBuffer();
30          url.append(" ");
31          url.append(config.getProjectName());
32          url.append(" {0} on ");
33          url.append(HTML.OUTPUT_DATE_FORMAT.format(repository.getLastDate()));
34          url.append(" has ");
35          url.append(NumberFormat.getNumberInstance().format(repository.getCurrentLOC()));
36          url.append(" Lines of Code and ");
37          url.append(topDevelopers.getDeveloperCount());
38          url.append(" Developers: stats by ");
39          url.append(Messages.getString("PROJECT_SHORTNAME"));
40          url.append(" ").append(Messages.getString("PROJECT_SMALL_URL"));
41          
42          buf.append(HTML.escapeUrlParameters(url.toString()));
43  
44          endLinkAndIcon(buf, ReportSuiteMaker.TWEET_THIS_ICON);
45          return buf.toString();
46      }
47  
48      private static void endLinkAndIcon(final StringBuffer buf, final String iconName) {
49          buf.append("\"><img style=\"border:0px\" alt=\"Tweet this\" src=\"").append(iconName).append("\"/></a>");
50      }
51  
52      private static void startLink(final StringBuffer buf) {
53          buf.append("<a onclick=\"return shortenTweet(this.href);\" href=\"");
54      }
55  
56      public static String buildDeveloperLink(final Author developer, final String loc, final Repository repository, final ReportConfig config) {
57          final StringBuffer buf = new StringBuffer();
58          startLink(buf);
59          buf.append("http://twitter.com/home?status=");
60          final StringBuffer url = new StringBuffer();
61          if (StringUtils.isNotEmpty(developer.getTwitterUserName())) {
62              url.append("@").append(developer.getTwitterUserName());
63          } else if (StringUtils.isNotEmpty(developer.getRealName())) {
64              url.append(developer.getRealName());
65          } else {
66              url.append(developer.getName());
67          }
68          url.append(" contributed ");
69          url.append(loc);
70          url.append(" lines to ");
71          url.append(config.getProjectName());
72          url.append(" {0} most recent commit ");
73          url.append(HTML.OUTPUT_DATE_FORMAT.format(((Revision) developer.getRevisions().last()).getDate()));
74          url.append(" stats by ");
75          url.append(Messages.getString("PROJECT_SHORTNAME"));
76          url.append(" ").append(Messages.getString("PROJECT_SMALL_URL"));
77  
78          //        System.out.println("Raw:"+url.toString());
79  
80          String escapeUrl = HTML.escapeUrlParameters(url.toString());
81          //        System.out.println("url:"+escapeUrl);
82          buf.append(escapeUrl);
83          endLinkAndIcon(buf, ReportSuiteMaker.TWEET_THIS_ICON);
84          return buf.toString();
85      }
86  
87      public static String buildDeveloperOfMonthLink(final Author developer, final int loc, final Repository repository, final String month_year,
88              ReportConfig config) {
89          final StringBuffer buf = new StringBuffer();
90          startLink(buf);
91          final StringBuffer url = new StringBuffer();
92          buf.append("http://twitter.com/home?status=");
93          if (StringUtils.isNotEmpty(developer.getTwitterUserName())) {
94              url.append("@").append(developer.getTwitterUserName());
95          } else if (StringUtils.isNotEmpty(developer.getRealName())) {
96              url.append(developer.getRealName());
97          } else {
98              url.append(developer.getName());
99          }
100         url.append(" is Developer of The Month for ");
101         url.append(month_year);
102         url.append(" for ");
103         url.append(config.getProjectName());
104 
105         url.append(" {0} with ");
106         url.append(NumberFormat.getNumberInstance().format(loc));
107         url.append(" lines. Stats by ");
108         url.append(Messages.getString("PROJECT_SHORTNAME"));
109         url.append(" ").append(Messages.getString("PROJECT_SMALL_URL"));
110 
111         buf.append(HTML.escapeUrlParameters(url.toString()));
112 
113         endLinkAndIcon(buf, ReportSuiteMaker.TWEET_THIS_SMALL);
114         return buf.toString();
115     }
116 }