View Javadoc

1   package net.sf.statcvs.pages;
2   
3   
4   public abstract class AbstractMarkup {
5       protected void addTwitterScript(final StringBuffer b) {
6   //        if ("xdoc".equalsIgnoreCase(ConfigurationOptions.getOutputFormat())) {
7   //            b.append("<![CDATA[").append("\n");
8   //        }
9           b.append("<script type=\"text/javascript\" charset=\"utf-8\" src=\"");
10          b.append("http://bit.ly/javascript-api.js?version=latest&#38;login=statsvn&#38;apiKey=R_2c362b417d0517c27876cbaca1bb68cc");
11          b.append("\"></script>\n");
12  //        if ("xdoc".equalsIgnoreCase(ConfigurationOptions.getOutputFormat())) {
13  //            b.append("]]>");
14  //        }
15          b.append("<script type=\"text/javascript\" charset=\"utf-8\">").append("\n");
16          b.append("   // wait until page is loaded to call API").append("\n");
17          b.append("   var redir_url;").append("\n");
18          b.append("   var short_url;").append("\n");
19          b.append("   BitlyCB.myShortenCallback = function(data) {").append("\n");
20          b.append("      // this is how to get a result of shortening a single url").append("\n");
21          b.append("      var result;").append("\n");
22          b.append("      short_url=null;").append("\n");
23          b.append("      for (var r in data.results) {").append("\n");
24          b.append("         result = data.results[r];").append("\n");
25          b.append("         result['longUrl'] = r;").append("\n");
26          b.append("         short_url = result['shortUrl'];").append("\n");
27          b.append("         break;").append("\n");
28          b.append("      }").append("\n");
29          b.append("      if (short_url==null) // bit.ly failed").append("\n");
30          b.append("      document.location=redir_url;").append("\n");
31          b.append("      else").append("\n");
32          b.append("      redirToTwitter();").append("\n");
33          b.append("   };").append("\n");
34          b.append("   function shortenTweet(url) {").append("\n");
35          b.append("      if (short_url == null || redir_url!=url) {").append("\n");
36          b.append("      redir_url = url;").append("\n");
37          b.append("      BitlyClient.shorten(document.location, 'BitlyCB.myShortenCallback');").append("\n");
38          b.append("      }").append("\n");
39          b.append("      else").append("\n");
40          b.append("      redirToTwitter();").append("\n");
41          b.append("      return false;").append("\n");
42          b.append("   }").append("\n");
43          b.append("   function redirToTwitter() { ").append("\n");
44          b.append("      // replace {0} which is visible as %7B0} in the link").append("\n");
45          b.append("      document.location = redir_url.replace('%7B0}', short_url);").append("\n");
46          b.append("   }").append("\n");
47          b.append("</script>").append("\n");
48  
49          /*
50          b.append("var redir_url;").append("\n");
51          b.append("BitlyCB.myShortenCallback = function(data) {").append("\n");
52          b.append("var result;").append("\n");
53          b.append("for (var r in data.results) {").append("\n");
54          b.append("result = data.results[r];").append("\n");
55          b.append("result['longUrl'] = r;").append("\n");
56          b.append("break;").append("\n");
57          b.append("}").append("\n");
58          b.append("document.location = redir_url.replace('{0}', result['shortUrl']);").append("\n");
59          b.append("};").append("\n");
60          b.append("function shortenTweet(url) {").append("\n");
61          b.append("redir_url = url;").append("\n");
62          b.append("BitlyClient.shorten(url, 'BitlyCB.myShortenCallback');").append("\n");
63          b.append("return false;").append("\n");
64          b.append("}").append("\n");
65          b.append("</script>").append("\n");
66          */
67      }
68  }