Commits

Anonymous committed 6b47a76

Comments (0)

Files changed (7)

encuestame-business/src/main/resources/org/encuestame/business/config/encuestame-config.properties

 social.facebook=http://www.facebook.com/permalink.php?story_fbid={A}&id={B}
 social.linkedin=http://www.linkedin.com/updates?view=all&trk=tab-nus-all
 social.identica=http://identi.ca/notice/{id}
+
+#-----------------------------------------------------------------------------
+# Google Analytics
+#-----------------------------------------------------------------------------
+google.analytic.code =

encuestame-mvc/src/main/java/org/encuestame/mvc/util/WidgetUtil.java

  */
 package org.encuestame.mvc.util;
 
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+
 import javax.servlet.http.HttpServletRequest;
 
+import org.apache.commons.lang.StringUtils;
+import org.encuestame.core.config.EnMePlaceHolderConfigurer;
 import org.encuestame.core.files.PathUtil;
+import org.encuestame.persistence.exception.EnMeExpcetion;
 import org.encuestame.utils.MD5Utils;
 import org.encuestame.utils.PictureUtils;
 import org.jfree.util.Log;
+import org.springframework.core.io.ClassPathResource;
 
 /**
  * Dojo Widget Utils.
         gravatarUl.append(size);
         return gravatarUl.toString();
     }
+
+    /**
+     * Get Analytics google code.
+     * @param path
+     * @return
+     */
+    public static final String getAnalytics(final String path){
+        final String analyticCode = EnMePlaceHolderConfigurer.getProperty("google.analytic.code");
+        final String scriptFilePath = path;
+        final StringBuffer stb = new StringBuffer("");
+        BufferedReader reader;
+        String analyticBlock;
+        try {
+            if (analyticCode.isEmpty()) {
+                throw new EnMeExpcetion("analytics code is emtpy");
+            }
+            reader = new BufferedReader(
+                     new InputStreamReader(new ClassPathResource(scriptFilePath).getInputStream()));
+            String aux;
+            while(true) { aux = reader.readLine();
+            if (aux == null) break;
+            stb.append(aux);
+            }
+            reader.close();
+            analyticBlock = stb.toString();
+            analyticBlock = StringUtils.replace(analyticBlock, "$analyticCode", analyticCode);
+        } catch (IOException e) {
+            analyticBlock = "";
+        } catch (EnMeExpcetion e) {
+            analyticBlock = "";
+        }
+        return analyticBlock;
+    }
 }

encuestame-mvc/src/main/resources/properties-test/test-analytics.inc

+<script type="text/javascript">
+
+var _gaq = _gaq || [];
+_gaq.push(['_setAccount', '$analyticCode']);
+_gaq.push(['_trackPageview']);
+
+(function() {
+var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
+ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
+var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
+})();
+
+</script>

encuestame-mvc/src/test/java/org/encuestame/mvc/test/widget/TestWidgetUtils.java

+/*
+ ************************************************************************************
+ * Copyright (C) 2001-2011 encuestame: system online surveys Copyright (C) 2009
+ * encuestame Development Team.
+ * Licensed under the Apache Software License version 2.0
+ * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to  in writing,  software  distributed
+ * under the License is distributed  on  an  "AS IS"  BASIS,  WITHOUT  WARRANTIES  OR
+ * CONDITIONS OF ANY KIND, either  express  or  implied.  See  the  License  for  the
+ * specific language governing permissions and limitations under the License.
+ ************************************************************************************
+ */
+package org.encuestame.mvc.test.widget;
+
+import org.encuestame.mvc.test.config.AbstractMvcUnitBeans;
+import org.encuestame.mvc.util.WidgetUtil;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Test Widget Utils.
+ * @author Morales, Diana Paola paolaATencuestame.org
+ * @since July 05, 2011
+ * @version $Id:$
+ */
+public class TestWidgetUtils extends AbstractMvcUnitBeans {
+
+    /**
+     * Test Get analytic google file.
+     */
+    @Test
+    public void testGetAnalyticFile(){
+        String file = WidgetUtil.getAnalytics("properties-test/test-analytics.inc");
+        //System.out.println("file data --->"+file);
+        Assert.assertNotNull(file);
+    }
+
+}

encuestame-persistence/src/main/resources/properties-test/encuestame-test-config.properties

 # real path of indexes domain (hibernate search)
 dir.data.index.hibernate.search.store.path = ${user.home}/encuestame-test/indexes/domain/
 
+google.analytic.code = UA-XXXXX-X

encuestame-war/src/main/resources/analytics.inc

+<script type="text/javascript">
+
+var _gaq = _gaq || [];
+_gaq.push(['_setAccount', '$analyticCode']);
+_gaq.push(['_trackPageview']);
+
+(function() {
+var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
+ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
+var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
+})();
+
+</script>

encuestame-war/src/main/webapp/WEB-INF/jsp/includes/javascript.jsp

+<%@page import="org.encuestame.mvc.util.WidgetUtil"%>
 <script src="<%=request.getContextPath()%>/resources/js/dojo/dojo.js"
         djConfig="parseOnLoad: true, useCommentedJson:true, isDebug: false"></script>
 <script type="text/javascript">
             tp : {a : 2, hr : false, minsoa : 1 }
         };
 </script>
-<script src="<%=request.getContextPath()%>/resources/js/dojo/encuestame-commons.js"></script>
+<script src="<%=request.getContextPath()%>/resources/js/dojo/encuestame-commons.js"></script>
+<%=WidgetUtil.getAnalytics("analytics.inc")%>