SitecatalystUtil.java
5.46 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.cq.wcm.webservicesupport.Configuration
* javax.jcr.Node
* org.apache.sling.api.SlingHttpServletRequest
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.settings.SlingSettingsService
*/
package com.day.cq.analytics.sitecatalyst;
import com.day.cq.wcm.webservicesupport.Configuration;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.jcr.Node;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.settings.SlingSettingsService;
public class SitecatalystUtil {
private SitecatalystUtil() {
}
public static String getServer(SlingHttpServletRequest request, Configuration config) {
String server = "";
server = request.getScheme().equals("http") ? "http://" + (String)config.getInherited("cq:trackingServer", (Object)"") : "https://" + (String)config.getInherited("cq:trackingServerSecure", (Object)"");
return server;
}
public static String getReportSuites(SlingSettingsService settingsService, Configuration configuration) {
String[] accounts = (String[])configuration.getInherited("reportsuites", (Object)new String[0]);
Set runModes = settingsService != null ? settingsService.getRunModes() : new HashSet();
String s_account = "";
boolean first = true;
for (int i = 0; i < accounts.length; ++i) {
String runMode;
String rsid;
if (accounts[i].indexOf(";") != -1) {
rsid = accounts[i].substring(0, accounts[i].indexOf(";"));
runMode = accounts[i].substring(accounts[i].indexOf(";") + 1);
} else {
rsid = accounts[i];
runMode = "";
}
if (!runMode.equals("") && !runModes.contains(runMode)) continue;
s_account = s_account + (first ? "" : ",") + rsid;
first = false;
}
return s_account;
}
public static Integer getCookieDomainNamePeriod(SlingHttpServletRequest request, String server) {
Integer cookieDomainNamePeriod = 0;
cookieDomainNamePeriod = server.contains("2o7.net") || server.contains("omtrdc.net") ? Integer.valueOf(request.getServerName().split("\\.").length - 1) : Integer.valueOf(server.split("\\.").length - 1);
cookieDomainNamePeriod = cookieDomainNamePeriod < 0 ? 0 : cookieDomainNamePeriod;
return cookieDomainNamePeriod;
}
public static String getFormattedPagePath(Resource pageResource, Configuration configuration) {
String fmtPath = pageResource.getPath();
String cfgPath = configuration.getPath();
if (cfgPath != null && fmtPath.startsWith(cfgPath)) {
fmtPath = fmtPath.replaceFirst(cfgPath, "");
}
if (fmtPath.startsWith("/")) {
fmtPath = fmtPath.replaceFirst("/", "");
}
fmtPath = fmtPath.replaceAll("/", ":");
return fmtPath;
}
public static Resource findAnalyticsResource(ResourceResolver resolver, Resource resource) {
try {
String resourcePath = resource.getPath();
while (resourcePath.lastIndexOf("/") > 0) {
Resource res;
resource = resolver.getResource(resourcePath);
if (resource != null && (res = resource.getChild("jcr:content/analytics")) != null) {
Node jcrContent = (Node)resource.getChild("jcr:content").adaptTo(Node.class);
Node node = (Node)res.adaptTo(Node.class);
if (node.hasProperty("cq:services") || jcrContent.hasProperty("cq:cloudserviceconfigs")) {
return res;
}
}
resourcePath = resourcePath.substring(0, resourcePath.lastIndexOf("/"));
}
}
catch (Exception resourcePath) {
// empty catch block
}
return null;
}
public static String getPublishPreferredReportSuite(Configuration config) {
String[] reportSuites = (String[])config.getInherited("reportsuites", (Object)new String[0]);
HashMap<String, ArrayList<String>> reportingSuitesPerRunMode = new HashMap<String, ArrayList<String>>();
for (String reportSuite : reportSuites) {
ArrayList<String> suites;
String runMode = "all";
String[] tmp = reportSuite.split(";");
if (tmp.length == 2) {
runMode = tmp[1];
}
if ((suites = (ArrayList<String>)reportingSuitesPerRunMode.get(runMode)) == null) {
suites = new ArrayList<String>();
}
suites.add(tmp[0]);
reportingSuitesPerRunMode.put(runMode, suites);
}
String reportSuite2 = null;
if (reportingSuitesPerRunMode.get("publish") != null) {
reportSuite2 = (String)((List)reportingSuitesPerRunMode.get("publish")).get(0);
} else if (reportingSuitesPerRunMode.get("all") != null) {
reportSuite2 = (String)((List)reportingSuitesPerRunMode.get("all")).get(0);
} else if (reportingSuitesPerRunMode.get("author") != null) {
reportSuite2 = (String)((List)reportingSuitesPerRunMode.get("author")).get(0);
}
return reportSuite2;
}
}