Last active
December 25, 2015 21:39
-
-
Save jdorrance/7044218 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% | |
Boolean isMicroSite = false; | |
List<Site> sites = sling.getService(SiteHostService.class).getSiteMappings(); | |
for(Site site : sites){ | |
if(currentPage.getPath().contains("/content/" + site.getKey()) | |
|| currentPage.getPath().contains("/content/dam" + site.getKey())){ | |
isMicroSite = true; | |
} | |
} | |
if(isMicroSite){ | |
sling.include(resource.getPath() + "content", "replaceSelectors= microsite"); | |
}else{ | |
//ORIGINAL LOGIC GOES HERE | |
} | |
%> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%--********************************************************************** | |
* | |
* ADOBE CONFIDENTIAL | |
* __________________ | |
* | |
* Copyright 2011 Adobe Systems Incorporated | |
* All Rights Reserved. | |
* | |
* NOTICE: All information contained herein is, and remains | |
* the property of Adobe Systems Incorporated and its suppliers, | |
* if any. The intellectual and technical concepts contained | |
* herein are proprietary to Adobe Systems Incorporated and its | |
* suppliers and are protected by trade secret or copyright law. | |
* Dissemination of this information or reproduction of this material | |
* is strictly forbidden unless prior written permission is obtained | |
* from Adobe Systems Incorporated. | |
**********************************************************************--%><%! | |
%><%@ page import="com.day.cq.commons.TidyJSONWriter, | |
org.acs.cq.utils.Site, | |
org.acs.cq.utils.SiteHostService, | |
org.apache.sling.api.scripting.SlingScriptHelper, | |
org.apache.sling.commons.json.io.JSONWriter, | |
com.day.cq.wcm.api.WCMException, | |
com.day.cq.tagging.Tag, | |
com.day.cq.wcm.core.stats.PageViewStatistics, | |
java.io.StringWriter, | |
java.util.Date, | |
java.text.DecimalFormat, | |
java.util.Date, | |
java.util.List, | |
java.util.Random" | |
contentType="text/javascript"%><%! | |
%><%@ include file="/apps/acs/components/shared/global.jsp" %><% | |
StringWriter buf = new StringWriter(); | |
TidyJSONWriter writer = new TidyJSONWriter(buf); | |
writer.setTidy(true); | |
try { | |
Page cPage = null; | |
if (request.getParameter("path") != null) { | |
Resource r = resourceResolver.getResource(request.getParameter("path")); | |
cPage = (r != null ? r.adaptTo(Page.class) : null); | |
} else { | |
cPage = currentPage; | |
} | |
setPageInitialData(writer, sling, cPage); | |
} catch (Exception e) { | |
log.error("Error while generating JSON pagedata initial data", e); | |
} | |
%>if( CQ_Analytics && CQ_Analytics.PageDataMgr) { | |
CQ_Analytics.PageDataMgr.loadInitProperties(<%=buf%>, true); | |
}<%! | |
void setPageInitialData(JSONWriter writer, | |
SlingScriptHelper sling, | |
Page currentPage) throws Exception { | |
writer.object(); | |
if (currentPage != null) { | |
long monthlyHits = 0; | |
try { | |
final PageViewStatistics pwSvc = sling.getService(PageViewStatistics.class); | |
Object[] hits = pwSvc.report(currentPage); | |
if (hits != null && hits.length > 2) { | |
monthlyHits = (Long) hits[2]; | |
} | |
} catch (WCMException ex) { | |
monthlyHits = -1; | |
} | |
writer.key("hits").value(monthlyHits); | |
writer.key("title").value(currentPage.getTitle()); | |
writer.key("path").value(currentPage.getPath()); | |
//EY TESTING | |
String channel = ""; | |
String subSection = ""; | |
String subSection2 = ""; | |
String subSection3 = ""; | |
String pageName = ""; | |
String hier = ""; | |
String domain = "ACS.org"; | |
//Channel | |
Page channelPage = currentPage.getAbsoluteParent(3); | |
if(channelPage != null){ | |
if(StringUtils.isNotBlank(channelPage.getNavigationTitle())){ | |
channel = hier = channelPage.getNavigationTitle(); | |
} | |
else{ | |
channel = hier = "No Value"; | |
} | |
Page subSectionPage = currentPage.getAbsoluteParent(4); | |
//Sub Section 1 | |
if(subSectionPage != null){ | |
if(StringUtils.isNotBlank(subSectionPage.getNavigationTitle())){ | |
subSection = hier = channel + ":" + subSectionPage.getNavigationTitle(); | |
} | |
else{ | |
subSection = hier = channel + ":No Value"; | |
} | |
//Sub Section 2 | |
Page subSectionPage2 = currentPage.getAbsoluteParent(5); | |
if(subSectionPage2 != null){ | |
if(StringUtils.isNotBlank(subSectionPage2.getNavigationTitle())){ | |
subSection2 = hier = subSection + ":" + subSectionPage2.getNavigationTitle(); | |
} | |
else{ | |
subSection2 = hier = subSection + ":No Value"; | |
} | |
//Sub Section 3 | |
Page subSectionPage3 = currentPage.getAbsoluteParent(6); | |
if(subSectionPage3 != null){ | |
if(StringUtils.isNotBlank(subSectionPage3.getNavigationTitle())){ | |
subSection3 = hier = subSection2 + ":" + subSectionPage3.getNavigationTitle(); | |
} | |
else{ | |
subSection3 = hier = subSection2 + ":No Value"; | |
} | |
} | |
} | |
} | |
} | |
//Page Name | |
String choppedPath = currentPage.getPath(); | |
choppedPath = choppedPath.substring( choppedPath.indexOf("en/")+3, choppedPath.length()); | |
pageName = channel + ":" + choppedPath; | |
String contentId = currentPage.getProperties().get("content_id", ""); | |
writer.key("omniContentId").value(contentId); | |
writer.key("test").value("test"); | |
//Home page | |
Page homePage = currentPage.getAbsoluteParent(2); | |
if(currentPage.getPath().equals(homePage.getPath())){ | |
pageName = "Home:index.htm"; | |
channel = "Home"; | |
} | |
//Domain overwrite (John Dorrance 10 18 2013) | |
List<Site> sites = sling.getService(SiteHostService.class).getSiteMappings(); | |
for(Site site : sites){ | |
if(currentPage.getPath().contains("/content/" + site.getKey()) | |
|| currentPage.getPath().contains("/content/dam" + site.getKey())){ | |
domain = site.getHost(); | |
} | |
} | |
writer.key("omniPageName").value(pageName); | |
writer.key("omniChannel").value(channel); | |
writer.key("omniSubSection1").value(subSection); | |
writer.key("omniSubSection2").value(subSection2); | |
writer.key("omniSubSection3").value(subSection3); | |
writer.key("omniHier1").value(hier); | |
writer.key("omniDomain").value(domain); | |
//END EY TESTING | |
String navTitle = currentPage.getNavigationTitle(); | |
writer.key("navTitle").value(navTitle); | |
if(currentPage.getTemplate() != null) { | |
writer.key("template").value(currentPage.getTemplate().getPath()); | |
writer.key("thumbnail").value(currentPage.getTemplate().getThumbnailPath()); | |
} | |
Tag[] tags = currentPage.getTags(); | |
String tagsStr = ""; | |
for(Tag tag: tags) { | |
tagsStr += tag.getTitle() + " "; | |
} | |
writer.key("tags").value(tagsStr); | |
String descr = currentPage.getDescription(); | |
writer.key("description").value(descr != null ? descr : ""); | |
Page siteLevelPage = currentPage.getAbsoluteParent(2); | |
if ( siteLevelPage != null ){ | |
writer.key("sitesection").value(siteLevelPage.getName()); | |
} | |
Page topLevelPage = currentPage.getAbsoluteParent(3); | |
if ( topLevelPage!= null ){ | |
writer.key("subsection").value(topLevelPage.getName()); | |
} | |
} | |
Random rand = new Random(new Date().getTime()); | |
DecimalFormat df = new DecimalFormat("0.00"); | |
double r = rand.nextDouble(); | |
writer.key("random").value(df.format(r)); | |
writer.endObject(); | |
} | |
%> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment