View Javadoc

1   /*
2    * Sonar, entreprise quality control tool.
3    * Copyright (C) 2007-2008 Hortis-GRC SA
4    * mailto:be_agile HAT hortis DOT ch
5    *
6    * Sonar is free software; you can redistribute it and/or
7    * modify it under the terms of the GNU Lesser General Public
8    * License as published by the Free Software Foundation; either
9    * version 3 of the License, or (at your option) any later version.
10   *
11   * Sonar is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14   * Lesser General Public License for more details.
15   *
16   * You should have received a copy of the GNU Lesser General Public
17   * License along with Sonar; if not, write to the Free Software
18   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
19   */
20  package org.sonar.plugins.googleanalytics;
21  
22  import org.apache.commons.configuration.Configuration;
23  import org.sonar.plugins.api.web.Footer;
24  
25  public class GoogleAnalyticsWebFooter implements Footer {
26  
27    private Configuration configuration;
28  
29    public GoogleAnalyticsWebFooter(Configuration configuration) {
30      this.configuration = configuration;
31    }
32  
33    protected String getIdAccount() {
34      return configuration.getString(GoogleAnalyticsPlugin.PROP_KEY_ACCOUNT, GoogleAnalyticsPlugin.PROP_DEFAULT_VALUE_ACCOUNT);
35    }
36  
37    public String getKey() {
38      return "webfooter_" + GoogleAnalyticsPlugin.PLUGIN_KEY;
39    }
40  
41    public String getHtml() {
42      String id = getIdAccount();
43      if (id != null && !"".equals(id)) {
44        return "<script type=\"text/javascript\">\n" +
45          "var gaJsHost = ((\"https:\" == document.location.protocol) ? \"https://ssl.\" : \"http://www.\");\n" +
46          "document.write(unescape(\"%3Cscript src='\" + gaJsHost + \"google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E\"));\n" +
47          "</script>\n" +
48          "<script type=\"text/javascript\">\n" +
49          "var pageTracker = _gat._getTracker(\"" + id + "\");\n" +
50          "pageTracker._initData();\n" +
51          "pageTracker._trackPageview();\n" +
52          "</script>";
53      }
54      return null;
55    }
56  
57    public String toString() {
58      return getKey();
59    }
60  
61  }