AnalyticsComponent.java
5.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.cq.wcm.api.components.Component
* com.day.cq.wcm.api.components.ComponentManager
* javax.jcr.Node
* javax.jcr.Property
* javax.jcr.Session
* javax.jcr.Value
* org.apache.commons.lang.StringUtils
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.api.resource.ResourceUtil
* org.apache.sling.api.resource.ValueMap
* org.apache.sling.api.wrappers.ValueMapDecorator
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.day.cq.analytics.impl;
import com.day.cq.analytics.impl.AnalyticsComponentQueryCache;
import com.day.cq.wcm.api.components.Component;
import com.day.cq.wcm.api.components.ComponentManager;
import java.util.HashMap;
import java.util.Map;
import javax.jcr.Node;
import javax.jcr.Property;
import javax.jcr.Session;
import javax.jcr.Value;
import org.apache.commons.lang.StringUtils;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceUtil;
import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.api.wrappers.ValueMapDecorator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class AnalyticsComponent {
public static final String PN_MAPPING_COMPONENT = "cq:mappingComponent";
public static final String PN_DEFAULT_STORE = "cq:defaultStore";
public static final String DEFAULT_STORE = "eventdata";
public static final String PN_DEFAULT_EVENT_STORE = "cq:defaultEventStore";
public static final String DEFAULT_EVENT_STORE = "eventdata.events";
public static final String PN_TRACKVARS = "cq:trackvars";
public static final String PN_TRACKEVENTS = "cq:trackevents";
private final Logger logger;
private String path;
private String mappingComponent;
private String defaultStore;
private String defaultEventStore;
private String[] trackedVars;
private String[] trackedEvents;
private ValueMap analyticsProps;
public AnalyticsComponent(Resource component, AnalyticsComponentQueryCache analyticsComponentQueryCache) {
Component comp;
this.logger = LoggerFactory.getLogger(this.getClass());
this.mappingComponent = "";
if (component == null) {
throw new IllegalArgumentException("component may not be null");
}
Node node = (Node)component.adaptTo(Node.class);
if (node == null) {
throw new IllegalArgumentException("Resource at " + component.getPath() + " can't be adapted to a " + Node.class.getName());
}
this.analyticsProps = (ValueMap)component.adaptTo(ValueMap.class);
this.path = ResourceUtil.getParent((String)component.getPath());
ComponentManager componentManager = (ComponentManager)component.getResourceResolver().adaptTo(ComponentManager.class);
if (componentManager != null && (comp = componentManager.getComponent(this.path)) != null) {
this.mappingComponent = (String)comp.getProperties().get("cq:mappingComponent", (Object)"");
}
this.defaultStore = (String)this.analyticsProps.get("cq:defaultStore", (Object)"eventdata");
this.defaultEventStore = (String)this.analyticsProps.get("cq:defaultEventStore", (Object)"eventdata.events");
this.trackedVars = this.getListProperty(node, "cq:trackvars", analyticsComponentQueryCache);
this.trackedEvents = this.getListProperty(node, "cq:trackevents", analyticsComponentQueryCache);
this.analyticsProps = new ValueMapDecorator(new HashMap(this.analyticsProps));
}
public String getPath() {
return this.path;
}
public String getDefaultStore() {
return this.defaultStore;
}
public String getDefaultEventStore() {
return this.defaultEventStore;
}
public String[] getTrackedVars() {
return this.trackedVars;
}
public String[] getTrackedEvents() {
return this.trackedEvents;
}
public ValueMap getAnalyticsProps() {
return this.analyticsProps;
}
public String getMappingComponent() {
return this.mappingComponent;
}
protected String[] getListProperty(Node node, String propertyName, AnalyticsComponentQueryCache analyticsComponentQueryCache) {
String[] list = new String[]{};
try {
if (!node.hasProperty(propertyName)) {
this.logger.warn(node.getPath() + "/" + propertyName + " does not exist");
} else {
Property property = node.getProperty(propertyName);
while (property.getType() == 8) {
property = property.getProperty();
}
if (property.isMultiple()) {
Value[] values = property.getValues();
list = new String[values.length];
for (int i = 0; i < values.length; ++i) {
list[i] = values[i].getString();
}
} else {
String value = property.getValue().getString().trim();
if (value != null && value.startsWith("SELECT ")) {
Session session = node.getSession();
list = analyticsComponentQueryCache.getQueryListProperty(value, session);
} else if (!StringUtils.isEmpty((String)value)) {
list = value.split("\\s*[,\\s]\\s*");
}
}
}
}
catch (Exception ignore) {
this.logger.error(ignore.getMessage(), (Throwable)ignore);
}
return list;
}
}