@Override public Resource apply(Page page) { return page.adaptTo(Resource.class); } });
/** * Puts a relative path of a page into the suffix. * @param page the page * @param suffixBasePage the base page used to construct the relative path * @return this */ public @NotNull SuffixBuilder page(@NotNull Page page, @NotNull Page suffixBasePage) { return resource(page.adaptTo(Resource.class), suffixBasePage.adaptTo(Resource.class)); }
/** * Gets site root level path of a site. * @param page CQ Page of site * @return Site root path for the site. The path is not checked for validness. */ public String getRootPath(Page page) { if (page == null) { return null; } return getRootPath(page.adaptTo(Resource.class)); }
/** * Get URL configuration for target page. If this is invalid or not available, get it from adaptable. * @param adaptable Adaptable (request or resource) * @param targetPage Target page (may be null) * @return Url config (never null) */ @SuppressWarnings("null") protected UrlConfig getUrlConfigForTarget(Adaptable adaptable, Page targetPage) { Resource targetResource = null; if (targetPage != null) { targetResource = targetPage.adaptTo(Resource.class); } return getUrlConfigForTarget(adaptable, targetResource); }
/** * Created the URL to the failure page with re-population info and error * info. * * @param form * @param page * @return * * @throws java.io.UnsupportedEncodingException * */ protected final String getRedirectPath(final Form form, final Page page, final String formSelector) throws UnsupportedEncodingException { return getRedirectPath(form, page.adaptTo(Resource.class), formSelector); }
/** * Created the URL to the failure page with re-population info and error info. * * @param form * @param page * @return * @throws org.apache.sling.commons.json.JSONException * * @throws java.io.UnsupportedEncodingException * */ protected final String getRedirectPath(final Form form, final Page page, final String formSelector) throws JSONException, UnsupportedEncodingException { return getRedirectPath(form, page.adaptTo(Resource.class), formSelector); }
/** * Constructs a suffix that contains multiple key-value pairs and address pages. Depending on the * {@link SuffixStateKeepingStrategy}, the suffix contains * further parts from the current request that should be kept when constructing new links. * @param pages pages to address * @param suffixBasePage the base page used to construct the relative path * @return this */ @SuppressWarnings("null") public @NotNull SuffixBuilder pages(@NotNull List<Page> pages, @NotNull Page suffixBasePage) { List<Resource> resources = Lists.transform(pages, new Function<Page, Resource>() { @Override public Resource apply(Page page) { return page.adaptTo(Resource.class); } }); return resources(resources, suffixBasePage.adaptTo(Resource.class)); }
@Override @SuppressWarnings("null") public String buildExternalResourceUrl(@Nullable Resource targetResource) { Resource targetResourceToUse = targetResource; if (targetResourceToUse == null) { targetResourceToUse = resource; } if (targetResourceToUse == null && page != null) { targetResourceToUse = page.adaptTo(Resource.class); } String url = build(); return urlHandler.externalizeResourceUrl(url, targetResourceToUse, urlMode); }
@SuppressWarnings({ "null", "unused" }) @Override public List<EmulatorGroup> getEmulatorGroups(Resource resource) { // convert device groups defined in page props to emulator groups Page page = resource.adaptTo(Page.class); if (page != null) { DeviceGroupList deviceGroups = page.adaptTo(DeviceGroupList.class); if (deviceGroups != null) { List<EmulatorGroup> emulatorGroups = new ArrayList<>(); for (DeviceGroup deviceGroup : deviceGroups) { emulatorGroups.add(new EmulatorGroupImpl(deviceGroup)); } return emulatorGroups; } } return ImmutableList.of(); }
@Override @SuppressWarnings({ "null", "unused" }) public String rewritePathToContext(@NotNull final Resource resource) { if (resource == null) { return null; } if (currentPage != null) { return rewritePathToContext(resource, currentPage.adaptTo(Resource.class)); } else { return resource.getPath(); } }
private ExperienceFragmentSocialVariation findExperienceFragmentSocialVariation() { Page variantPage = currentPage.getPageManager().getPage(variantPath); if (variantPage == null) return null; ExperienceFragmentSocialVariation socialVariant = variantPage.adaptTo(ExperienceFragmentSocialVariation.class); return socialVariant; }
@Override public void addBindings(Bindings bindings) { log.info("In CustomBindingProvider.."); if ( bindings.containsKey(WCMBindings.CURRENT_PAGE)) { log.info("Currentpage does exist.."); // there is the currentPage bindings from Sightly Page current = (Page) bindings.get(WCMBindings.CURRENT_PAGE); // adapt this to MyCustomPage, and add this to the bindings bindings.put("pageName", current.getName()); bindings.put("myPage", current.adaptTo(MyCustomPage.class)); // you can now refer to pageName and myPage in every HTML file // example ${pageName} ${myPage.title} } else { log.info("Currentpage does not exist"); } } }
return null; } else { GenericList list = listPage.adaptTo(GenericList.class); if (list == null) { return null;
return null; } else { GenericList list = listPage.adaptTo(GenericList.class); if (list == null) { return null;
private static String getPagePath(final Page page, final boolean mapped) { final String redirect = page.getProperties().get(REDIRECT_TARGET, ""); final String path = redirect.isEmpty() ? page.getPath() : redirect; final String result; if (mapped) { result = page.adaptTo(Resource.class).getResourceResolver().map(path); } else { result = path; } return result; } }
private com.day.cq.wcm.api.reference.Reference toReference(Resource resource, Page configPage, Map<String, ConfigurationMetadata> configurationMetadatas, Set<String> configurationBuckets) { log.trace("Found configuration reference {} for resource {}", configPage.getPath(), resource.getPath()); return new com.day.cq.wcm.api.reference.Reference(getType(), getReferenceName(configPage, configurationMetadatas, configurationBuckets), configPage.adaptTo(Resource.class), getLastModifiedOf(configPage)); }
/** * Generate JSON objects for pages. * @param pages Child page iterator * @param depth Depth * @param pageFilter Page filter * @return Page array * @throws JSONException JSON exception */ protected final JSONArray getPages(Iterator<Page> pages, int depth, PageFilter pageFilter) throws JSONException { JSONArray pagesArray = new JSONArray(); while (pages.hasNext()) { Page page = pages.next(); // map page attributes to JSON object JSONObject pageObject = getPage(page); if (pageObject != null) { // write children Iterator<Page> children = listChildren(page.adaptTo(Resource.class), pageFilter); if (!children.hasNext()) { pageObject.put("leaf", true); } else if (depth < getMaxDepth() - 1) { pageObject.put("children", getPages(children, depth + 1, pageFilter)); } pagesArray.put(pageObject); } } return pagesArray; }
/** * @{inheritDoc} **/ @Override public final Resource getPageOrAssetResource(ResourceResolver resourceResolver, String path) { Resource payloadResource = resourceResolver.getResource(path); if (payloadResource == null) { return null; } Asset asset = DamUtil.resolveToAsset(payloadResource); if (asset != null) { return asset.adaptTo(Resource.class); } PageManager pageManager = resourceResolver.adaptTo(PageManager.class); Page page = pageManager.getContainingPage(payloadResource); if (page != null) { return page.adaptTo(Resource.class); } return null; }
/** * Checks if the target resource is located outsite the current site, and if for this other * resource context a valid url configuration with a specific hostname exists. * @param adaptable Adaptable * @param currentPage Current page (may be null) * @param targetResource Target resource (may be null) * @return true if the target resources is located in another site/context with separate url configuration */ @SuppressWarnings("null") private boolean linksToOtherDomain(Adaptable adaptable, Page currentPage, Resource targetResource) { if (currentPage == null || targetResource == null) { return false; } UrlHandlerConfig urlHandlerConfig = AdaptTo.notNull(adaptable, UrlHandlerConfig.class); Resource currentResource = currentPage.adaptTo(Resource.class); String currentSiteRoot = getRootPath(currentPage.getPath(), urlHandlerConfig.getSiteRootLevel(currentResource)); String pathSiteRoot = getRootPath(targetResource.getPath(), urlHandlerConfig.getSiteRootLevel(targetResource)); boolean notInCurrentSite = !StringUtils.equals(currentSiteRoot, pathSiteRoot); if (notInCurrentSite) { UrlConfig targetUrlConfig = new UrlConfig(targetResource); return targetUrlConfig.isValid(); } else { return false; } }
/** * Generate JSON object for page * @param page Page * @return JSON object * @throws JSONException JSON exception */ protected final JSONObject getPage(Page page) throws JSONException { Resource resource = page.adaptTo(Resource.class); JSONObject pageObject = new JSONObject(); // node name pageObject.put("name", page.getName()); // node title text String title = page.getTitle(); if (StringUtils.isEmpty(title)) { title = page.getName(); } pageObject.put("text", title); // resource type pageObject.put("type", resource.getResourceType()); // template String template = page.getProperties().get(NameConstants.PN_TEMPLATE, String.class); if (StringUtils.isNotEmpty(template)) { pageObject.put("template", template); } // css class for icon pageObject.put("cls", "page"); return pageObject; }