git clone of logicmail with some fixes/features added
1/*-
2 * Copyright (c) 2011, Derek Konigsberg
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. Neither the name of the project nor the names of its
15 * contributors may be used to endorse or promote products derived
16 * from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
29 * OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31package org.logicprobe.LogicMail;
32
33import java.util.Hashtable;
34
35import com.webtrends.mobile.analytics.IllegalWebtrendsParameterValueException;
36import com.webtrends.mobile.analytics.rim.WebtrendsConfigurator;
37import com.webtrends.mobile.analytics.rim.WebtrendsDataCollector;
38import com.webtrends.mobile.analytics.rim.WebtrendsLogger;
39
40public class LogicMailWebtrendsDataCollector extends AnalyticsDataCollector {
41 private static String STARTUP_CLASS = "org.logicprobe.LogicMail.LogicMailStartup";
42 private static String ANALYTICS_CONFIG_FILE = "webtrends.xml";
43
44 private static boolean initialized;
45 private final WebtrendsDataCollector dataCollector;
46 private final WebtrendsLogger collectorLogger;
47
48 public LogicMailWebtrendsDataCollector() {
49 if(!initialized) {
50 WebtrendsConfigurator.LoadConfigFile(STARTUP_CLASS, ANALYTICS_CONFIG_FILE);
51 WebtrendsDataCollector.getInstance().Initialize();
52 initialized = true;
53 }
54
55 dataCollector = WebtrendsDataCollector.getInstance();
56 collectorLogger = WebtrendsDataCollector.getLog();
57 }
58
59 protected void setConfigured(boolean configured) {
60 WebtrendsDataCollector.setConfigured(configured);
61 }
62
63 public void onApplicationStart() {
64 try {
65 dataCollector.onApplicationForeground(AppInfo.getName(), null);
66 } catch (IllegalWebtrendsParameterValueException err) {
67 collectorLogger.e(err.getMessage());
68 }
69 }
70
71 public void onApplicationTerminate() {
72 try {
73 dataCollector.onApplicationTerminate(AppInfo.getName(), null);
74 } catch (IllegalWebtrendsParameterValueException err) {
75 collectorLogger.e(err.getMessage());
76 }
77 }
78
79 public void onApplicationForeground() {
80 try {
81 dataCollector.onApplicationForeground(AppInfo.getName(), null);
82 }
83 catch (IllegalWebtrendsParameterValueException err) {
84 collectorLogger.e(err.getMessage());
85 }
86 }
87
88 public void onApplicationBackground() {
89 try {
90 dataCollector.onApplicationBackground(AppInfo.getName(), null);
91 }
92 catch (IllegalWebtrendsParameterValueException err) {
93 collectorLogger.e(err.getMessage());
94 }
95 }
96
97 public void onApplicationError(String errorMessage) {
98 Hashtable customParams = new Hashtable();
99 customParams.put("WT.er", errorMessage);
100 try {
101 dataCollector.onApplicationError(AppInfo.getName(), customParams);
102 }
103 catch (IllegalWebtrendsParameterValueException err) {
104 collectorLogger.e(err.getMessage());
105 }
106 }
107
108 public void onButtonClick(
109 String eventPath,
110 String eventDesc,
111 String eventType) {
112 Hashtable customParams = new Hashtable();
113 customParams.put("WT.dl", "0");
114 try {
115 dataCollector.onButtonClick(eventPath, eventDesc, eventType, customParams);
116 }
117 catch (IllegalWebtrendsParameterValueException err) {
118 collectorLogger.e(err.getMessage());
119 }
120 }
121
122 public void onScreenView(
123 String eventPath,
124 String eventDesc,
125 String eventType,
126 String contentGroup) {
127 try {
128 dataCollector.onScreenView(eventPath, eventDesc, eventType, null, contentGroup);
129 }
130 catch (IllegalWebtrendsParameterValueException err) {
131 collectorLogger.e(err.getMessage());
132 }
133 }
134
135 public void onMediaEvent(
136 String eventPath,
137 String eventDesc,
138 String eventType,
139 String contentGroup,
140 String mediaName,
141 String mediaType,
142 String mediaEventType) {
143 Hashtable customParams = new Hashtable();
144 customParams.put("WT.dl", "0");
145 try {
146 dataCollector.onMediaEvent(eventPath, eventDesc, eventType, customParams,
147 contentGroup, mediaName, mediaType, mediaEventType);
148 }
149 catch (IllegalWebtrendsParameterValueException err) {
150 collectorLogger.e(err.getMessage());
151 }
152 }
153
154 public void onCustomEvent(
155 String eventPath,
156 String eventDesc,
157 Hashtable customData) {
158 try {
159 dataCollector.onCustomEvent(eventPath, eventDesc, customData);
160 }
161 catch (IllegalWebtrendsParameterValueException err) {
162 collectorLogger.e(err.getMessage());
163 }
164 }
165}