svn commit: r1221128 - in /ofbiz/trunk: applications/content/src/org/ofbiz/content/cms/ applications/content/src/org/ofbiz/content/content/ applications/content/src/org/ofbiz/content/data/ specialpurpose/ecommerce/webapp/ecommerce/error/

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r1221128 - in /ofbiz/trunk: applications/content/src/org/ofbiz/content/cms/ applications/content/src/org/ofbiz/content/content/ applications/content/src/org/ofbiz/content/data/ specialpurpose/ecommerce/webapp/ecommerce/error/

hansbak-2
Author: hansbak
Date: Tue Dec 20 07:36:45 2011
New Revision: 1221128

URL: http://svn.apache.org/viewvc?rev=1221128&view=rev
Log:
implement 404 page tracking in google analytics also for the pages coming from the content component. more info at: http://support.google.com/googleanalytics/bin/answer.py?hl=en&answer=86927 

Modified:
    ofbiz/trunk/applications/content/src/org/ofbiz/content/cms/CmsEvents.java
    ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentWorker.java
    ofbiz/trunk/applications/content/src/org/ofbiz/content/data/DataResourceWorker.java
    ofbiz/trunk/specialpurpose/ecommerce/webapp/ecommerce/error/404.jsp

Modified: ofbiz/trunk/applications/content/src/org/ofbiz/content/cms/CmsEvents.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/src/org/ofbiz/content/cms/CmsEvents.java?rev=1221128&r1=1221127&r2=1221128&view=diff
==============================================================================
--- ofbiz/trunk/applications/content/src/org/ofbiz/content/cms/CmsEvents.java (original)
+++ ofbiz/trunk/applications/content/src/org/ofbiz/content/cms/CmsEvents.java Tue Dec 20 07:36:45 2011
@@ -284,8 +284,14 @@ public class CmsEvents {
                     templateMap.put("formStringRenderer", formStringRenderer);
                     //include DOCTYPE for cms screens
                     writer.append("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">");
+                    
+                    // if use web analytics
+                    List<GenericValue> webAnalytics = delegator.findByAnd("WebAnalyticsConfig", UtilMisc.toMap("webSiteId", webSiteId));
+                    
                     // render
-                    if (UtilValidate.isEmpty(mapKey)) {
+                    if (UtilValidate.isNotEmpty(webAnalytics) && hasErrorPage) {
+                        ContentWorker.renderContentAsText(dispatcher, delegator, contentId, writer, templateMap, locale, "text/html", null, null, true, webAnalytics);
+                    } else if (UtilValidate.isEmpty(mapKey)) {
                         ContentWorker.renderContentAsText(dispatcher, delegator, contentId, writer, templateMap, locale, "text/html", null, null, true);
                     } else {
                         ContentWorker.renderSubContentAsText(dispatcher, delegator, contentId, writer, mapKey, templateMap, locale, "text/html", true);

Modified: ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentWorker.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentWorker.java?rev=1221128&r1=1221127&r2=1221128&view=diff
==============================================================================
--- ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentWorker.java (original)
+++ ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentWorker.java Tue Dec 20 07:36:45 2011
@@ -180,7 +180,7 @@ public class ContentWorker implements or
     }
 
     public static void renderContentAsText(LocalDispatcher dispatcher, Delegator delegator, GenericValue content, Appendable out,
-            Map<String,Object>templateContext, Locale locale, String mimeTypeId, boolean cache) throws GeneralException, IOException {
+            Map<String,Object>templateContext, Locale locale, String mimeTypeId, boolean cache, List<GenericValue> webAnalytics) throws GeneralException, IOException {
         // if the content has a service attached run the service
 
         String serviceName = content.getString("serviceName");
@@ -266,7 +266,12 @@ public class ContentWorker implements or
                     Debug.logError("No content ID found.", module);
                     return;
                 }
-                DataResourceWorker.renderDataResourceAsText(delegator, dataResourceId, out, templateContext, locale, mimeTypeId, cache);
+                
+                if (UtilValidate.isNotEmpty(webAnalytics)) {
+                    DataResourceWorker.renderDataResourceAsText(delegator, dataResourceId, out, templateContext, locale, mimeTypeId, cache, webAnalytics);
+                } else {
+                    DataResourceWorker.renderDataResourceAsText(delegator, dataResourceId, out, templateContext, locale, mimeTypeId, cache);
+                }
 
             // there is a template; render the data and then the template
             } else {
@@ -325,10 +330,17 @@ public class ContentWorker implements or
         return writer.toString();
     }
 
+    public static String renderContentAsText(LocalDispatcher dispatcher, Delegator delegator, String contentId, Appendable out,
+            Map<String, Object> templateContext, Locale locale, String mimeTypeId, String partyId, String roleTypeId, boolean cache, List<GenericValue> webAnalytics) throws GeneralException, IOException {
+        GenericValue content = ContentWorker.findContentForRendering(delegator, contentId, locale, partyId, roleTypeId, cache);
+        ContentWorker.renderContentAsText(dispatcher, delegator, content, out, templateContext, locale, mimeTypeId, cache, webAnalytics);
+        return out.toString();
+    }
+
     public static void renderContentAsText(LocalDispatcher dispatcher, Delegator delegator, String contentId, Appendable out,
             Map<String, Object> templateContext, Locale locale, String mimeTypeId, String partyId, String roleTypeId, boolean cache) throws GeneralException, IOException {
         GenericValue content = ContentWorker.findContentForRendering(delegator, contentId, locale, partyId, roleTypeId, cache);
-        ContentWorker.renderContentAsText(dispatcher, delegator, content, out, templateContext, locale, mimeTypeId, cache);
+        ContentWorker.renderContentAsText(dispatcher, delegator, content, out, templateContext, locale, mimeTypeId, cache, null);
     }
 
     public static String renderSubContentAsText(LocalDispatcher dispatcher, Delegator delegator, String contentId, String mapKey, Map<String, Object> templateContext,

Modified: ofbiz/trunk/applications/content/src/org/ofbiz/content/data/DataResourceWorker.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/src/org/ofbiz/content/data/DataResourceWorker.java?rev=1221128&r1=1221127&r2=1221128&view=diff
==============================================================================
--- ofbiz/trunk/applications/content/src/org/ofbiz/content/data/DataResourceWorker.java (original)
+++ ofbiz/trunk/applications/content/src/org/ofbiz/content/data/DataResourceWorker.java Tue Dec 20 07:36:45 2011
@@ -55,6 +55,7 @@ import org.ofbiz.base.location.FlexibleL
 import org.ofbiz.base.util.Debug;
 import org.ofbiz.base.util.FileUtil;
 import org.ofbiz.base.util.GeneralException;
+import org.ofbiz.base.util.StringUtil;
 import org.ofbiz.base.util.UtilGenerics;
 import org.ofbiz.base.util.UtilHttp;
 import org.ofbiz.base.util.UtilIO;
@@ -62,6 +63,7 @@ import org.ofbiz.base.util.UtilMisc;
 import org.ofbiz.base.util.UtilProperties;
 import org.ofbiz.base.util.UtilValidate;
 import org.ofbiz.base.util.UtilXml;
+import org.ofbiz.base.util.StringUtil.StringWrapper;
 import org.ofbiz.base.util.collections.MapStack;
 import org.ofbiz.base.util.template.FreeMarkerWorker;
 import org.ofbiz.base.util.template.XslTransform;
@@ -585,12 +587,18 @@ public class DataResourceWorker  impleme
     public static String renderDataResourceAsText(Delegator delegator, String dataResourceId, Map<String, Object> templateContext,
              Locale locale, String targetMimeTypeId, boolean cache) throws GeneralException, IOException {
         Writer writer = new StringWriter();
-        renderDataResourceAsText(delegator, dataResourceId, writer, templateContext, locale, targetMimeTypeId, cache);
+        renderDataResourceAsText(delegator, dataResourceId, writer, templateContext, locale, targetMimeTypeId, cache, null);
         return writer.toString();
     }
 
-    public static void renderDataResourceAsText(Delegator delegator, String dataResourceId, Appendable out,
+    public static String renderDataResourceAsText(Delegator delegator, String dataResourceId, Appendable out,
             Map<String, Object> templateContext, Locale locale, String targetMimeTypeId, boolean cache) throws GeneralException, IOException {
+       renderDataResourceAsText(delegator, dataResourceId, out, templateContext, locale, targetMimeTypeId, cache, null);
+       return out.toString();
+   }
+
+    public static void renderDataResourceAsText(Delegator delegator, String dataResourceId, Appendable out,
+            Map<String, Object> templateContext, Locale locale, String targetMimeTypeId, boolean cache, List<GenericValue> webAnalytics) throws GeneralException, IOException {
         if (dataResourceId == null) {
             throw new GeneralException("Cannot lookup data resource with for a null dataResourceId");
         }
@@ -655,6 +663,19 @@ public class DataResourceWorker  impleme
                     // get the template data for rendering
                     String templateText = getDataResourceText(dataResource, targetMimeTypeId, locale, templateContext, delegator, cache);
 
+                    // if use web analytics.
+                    if (UtilValidate.isNotEmpty(webAnalytics)) {
+                        StringBuffer newTemplateText = new StringBuffer(templateText);
+                        String webAnalyticsCode = "<script language=\"JavaScript\" type=\"text/javascript\">";
+                        for (GenericValue webAnalytic : webAnalytics) {
+                            StringWrapper wrapString = StringUtil.wrapString((String) webAnalytic.get("webAnalyticsCode"));
+                            webAnalyticsCode += wrapString.toString();
+                        }
+                        webAnalyticsCode += "</script>";
+                        newTemplateText.insert(templateText.lastIndexOf("</head>"), webAnalyticsCode);
+                        templateText = newTemplateText.toString();
+                    }
+
                     // render the FTL template
                     FreeMarkerWorker.renderTemplate("DataResource:" + dataResourceId, templateText, templateContext, out);
                 } catch (TemplateException e) {

Modified: ofbiz/trunk/specialpurpose/ecommerce/webapp/ecommerce/error/404.jsp
URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/ecommerce/webapp/ecommerce/error/404.jsp?rev=1221128&r1=1221127&r2=1221128&view=diff
==============================================================================
--- ofbiz/trunk/specialpurpose/ecommerce/webapp/ecommerce/error/404.jsp (original)
+++ ofbiz/trunk/specialpurpose/ecommerce/webapp/ecommerce/error/404.jsp Tue Dec 20 07:36:45 2011
@@ -16,9 +16,27 @@ KIND, either express or implied.  See th
 specific language governing permissions and limitations
 under the License.
 --%>
+<%@ page import="java.util.*" %>
+<%@ page import="org.ofbiz.base.util.*" %>
+<%@ page import="org.ofbiz.entity.*" %>
+<%@ page import="org.ofbiz.entity.util.*" %>
+<jsp:useBean id="delegator" type="org.ofbiz.entity.GenericDelegator" scope="request" />
+<%
+ServletContext context = pageContext.getServletContext();
+String webSiteId = (String) context.getAttribute("webSiteId");
+List<GenericValue> webAnalytics = delegator.findByAnd("WebAnalyticsConfig", UtilMisc.toMap("webSiteId", webSiteId));
+%>
 <html>
 <head>
 <title>Error 404</title>
+<%if (webAnalytics != null) {%>
+<script language="JavaScript" type="text/javascript">
+<%for (GenericValue webAnalytic : webAnalytics) {%>
+    <%=StringUtil.wrapString((String) webAnalytic.get("webAnalyticsCode"))%>
+<%}%>
+</script>
+<%}%>
+</head>
 <body>
 <p>
 <b>404.</b>