<%@page session="false"%><%--********************************************************************** * * 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.wcm.msm.api.LiveRelationshipManager, java.util.Collection, com.day.cq.wcm.msm.api.LiveRelationship, com.day.cq.wcm.msm.api.RolloutConfig, java.util.List, com.day.text.Text, com.day.cq.wcm.api.WCMException, java.io.PrintWriter, com.day.cq.wcm.emulator.EmulatorGroup, org.apache.sling.commons.json.JSONObject, com.day.cq.wcm.emulator.Emulator, com.day.cq.wcm.emulator.EmulatorService, static com.day.cq.wcm.mobile.api.MobileConstants.HTML_ID_CONTENT_CSS, org.apache.sling.commons.json.JSONException, com.day.cq.wcm.mobile.api.device.DeviceGroup, com.day.cq.wcm.mobile.api.device.DeviceGroupList, org.apache.commons.lang3.StringEscapeUtils, java.io.StringWriter" %><%! %><%@include file="/libs/foundation/global.jsp"%><% 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; } if( cPage != null ) { //found corresponding mobile page LiveRelationshipManager relationMgr = sling.getService(LiveRelationshipManager.class); Page mobilePage = getMobilePage(relationMgr, cPage); if( mobilePage == null ) { //try by injecting "_mobile" in the path String path = cPage.getPath(); String computedPath = Text.getAbsoluteParent(path, 1); computedPath = path.replaceAll(computedPath, computedPath + "_mobile"); Resource computed = resourceResolver.resolve(computedPath); if( computed != null ) { mobilePage = computed.adaptTo(Page.class); } } if( mobilePage != null) { EmulatorService emulatorService = sling.getService(EmulatorService.class); List allEmulators = getEmulators(emulatorService, mobilePage); final DeviceGroupList deviceGroups = mobilePage.adaptTo(DeviceGroupList.class); if(deviceGroups != null && !allEmulators.isEmpty()) { %><% } } //case of a mobile page, SurerInfo should be updated when emulator is changed %> <% }%><%! Page getMobilePage(LiveRelationshipManager relationMgr, Page currentPage) throws com.day.cq.wcm.api.WCMException { if (relationMgr != null && currentPage != null) { PageManager pageManager = currentPage.getPageManager(); Collection relations = relationMgr.getLiveRelationships(currentPage, null, null, false); for(LiveRelationship lr: relations) { List configs = lr.getRolloutConfigs(); for(RolloutConfig rc: configs) { if( rc.getPath().toLowerCase().indexOf("mobile") != -1) { Page mobilePage = pageManager.getContainingPage(lr.getTargetPath()); if( mobilePage != null) { return mobilePage; } } } } } return null; } List getEmulatorGroups(EmulatorService emulatorService, Page mobilePage) { return emulatorService.getEmulatorGroups(mobilePage.adaptTo(Resource.class)); } List getEmulators(EmulatorService emulatorService, Page mobilePage) { return emulatorService.getEmulators(mobilePage.adaptTo(Resource.class)); } StringWriter getEmulatorsConfig(DeviceGroupList deviceGroups, String contextPath) { StringWriter res = new StringWriter(); String delim = ""; res.write("{"); for (final DeviceGroup group : deviceGroups) { final List emulators = group.getEmulators(); for (final Emulator emulator : emulators) { res.write(delim); res.write(StringEscapeUtils.escapeEcmaScript(emulator.getName()) + ": {"); res.write("plugins: {"); String pluginDelim = ""; if (emulator.canRotate()) { res.write("rotation: {"); res.write("ptype: CQ.wcm.emulator.plugins.RotationPlugin.NAME,"); res.write("config: {"); res.write("defaultDeviceOrientation: \"vertical\""); res.write("}"); res.write("}"); pluginDelim = ","; } if (emulator.hasTouchScrolling()) { res.write(pluginDelim + "touchscrolling: {"); res.write("ptype: CQ.wcm.emulator.plugins.TouchScrollingPlugin.NAME,"); res.write("config: {}"); res.write("}"); } res.write("},"); res.write("group: \"" + StringEscapeUtils.escapeEcmaScript(group.getName()) + "\","); res.write("title: \"" + StringEscapeUtils.escapeEcmaScript(emulator.getTitle()) + "\","); res.write("description: \"" + StringEscapeUtils.escapeEcmaScript(emulator.getDescription()) + "\","); res.write("contentCssPath: \"" + (null != emulator.getContentCssPath() ? contextPath + emulator.getContentCssPath(): "null") + "\""); res.write("}"); delim = ","; } } res.write("}"); return res; } %>