/** * Get valuemap/papge properties of current page. * @param page Page * @return Value map of current page or empty map if current page is null. */ private static ValueMap getPagePropertiesNullSafe(Page page) { if (page != null) { return page.getProperties(); } else { return ValueMap.EMPTY; } }
private boolean isHidden(final Page page) { return page.getProperties().get(this.excludeFromSiteMapProperty, false); }
private boolean isHidden(final Page page) { return page.getProperties().get(this.excludeFromSiteMapProperty, false); }
@PostConstruct private void initModel() throws Exception { ValueMap pageProperties = currentPage.getProperties(); String[] socialMedia = pageProperties.get(PN_SOCIAL_MEDIA, String[].class); facebookEnabled = ArrayUtils.contains(socialMedia, PV_FACEBOOK); pinterestEnabled = ArrayUtils.contains(socialMedia, PV_PINTEREST); socialMediaEnabled = facebookEnabled || pinterestEnabled; variantPath = pageProperties.get(PN_VARIANT_PATH, String.class); }
/** * Determine if the page is of a particular template type. This method * is null safe and works properly in the publish and author environments. * * @param page the page to check * @param templatePath the path of the template to check * @return true if the page is of the defined template */ @Function public static boolean hasTemplate(@CheckForNull final Page page, @CheckForNull final String templatePath) { if (page == null) { return false; } return hasTemplate(page.getProperties(), templatePath); }
/** * Determine if the page is of a particular template type. This method * is null safe and works properly in the publish and author environments. * * @param page the page to check * @param templatePath the path of the template to check * @return true if the page is of the defined template */ @Function public static boolean hasTemplate(@CheckForNull final Page page, @CheckForNull final String templatePath) { if (page == null) { return false; } return hasTemplate(page.getProperties(), templatePath); }
Iterator<Page> iterator = currentPage.listChildern(); while (iterator.hasNext()) { Page childPage = iterator.next(); ValueMap childProps = childPage.getProperties(); String title = childProps.get("title", ""); String text = childProps.get("text", ""); //output this props values just like you want to }
private String getThumbnailUrl(Page page, int width, int height) { String ck = ""; ValueMap metadata = page.getProperties(PN_IMAGE_FILE_JCR_CONTENT); if (metadata != null) { Calendar imageLastModified = metadata.get(JcrConstants.JCR_LASTMODIFIED, Calendar.class); Calendar pageLastModified = page.getLastModified(); if (pageLastModified != null && pageLastModified.after(imageLastModified)) { ck += pageLastModified.getTimeInMillis() / 1000; } else if (imageLastModified != null) { ck += imageLastModified.getTimeInMillis() / 1000; } else if (pageLastModified != null) { ck += pageLastModified.getTimeInMillis() / 1000; } } return page.getPath() + ".thumb." + width + "." + height + ".png?ck=" + ck; }
@SuppressWarnings("null") @Override public boolean handles(Resource resource) { // check if resource is a page, and if the page uses a configured template Page page = resource.adaptTo(Page.class); if (page != null) { String templatePath = page.getProperties().get(NameConstants.PN_TEMPLATE, String.class); if (StringUtils.isNotEmpty(templatePath)) { for (Pattern pattern : templatePathPatterns) { Matcher matcher = pattern.matcher(templatePath); if (matcher.matches()) { return true; } } } } return false; }
private Collection<Resource> getAssetFolders(Page page, ResourceResolver resolver) { List<Resource> allAssetFolders = new ArrayList<Resource>(); ValueMap properties = page.getProperties(); String[] configuredAssetFolderPaths = properties.get(damAssetProperty, String[].class); if (configuredAssetFolderPaths != null) { // Sort to aid in removal of duplicate paths. Arrays.sort(configuredAssetFolderPaths); String prevPath = "#"; for (String configuredAssetFolderPath : configuredAssetFolderPaths) { // Ensure that this folder is not a child folder of another // configured folder, since it will already be included when // the parent folder is traversed. if (StringUtils.isNotBlank(configuredAssetFolderPath) && !configuredAssetFolderPath.equals(prevPath) && !StringUtils.startsWith(configuredAssetFolderPath, prevPath + "/")) { Resource assetFolder = resolver.getResource(configuredAssetFolderPath); if (assetFolder != null) { prevPath = configuredAssetFolderPath; allAssetFolders.add(assetFolder); } } } } return allAssetFolders; }
@SuppressWarnings("null") private List<String> getContextPathCandidatesMatchAll(Page page, ResourceResolver resourceResolver) { List<String> candidates = new ArrayList<>(); if (page != null) { for (int level = minLevel; level <= maxLevel; level++) { Page rootPage = Path.getAbsoluteParent(page, level, resourceResolver); if (rootPage != null) { String templatePath = rootPage.getProperties().get(NameConstants.PN_TEMPLATE, String.class); if (templatePath != null && templatePaths.contains(templatePath)) { candidates.add(rootPage.getPath()); } } } } return candidates; }
private Page getRedirectTarget(@Nonnull Page page) { Page result = page; String redirectTarget; PageManager pageManager = page.getPageManager(); Set<String> redirectCandidates = new LinkedHashSet<>(); redirectCandidates.add(page.getPath()); while (result != null && StringUtils.isNotEmpty((redirectTarget = result.getProperties().get(PageImpl.PN_REDIRECT_TARGET, String.class)))) { result = pageManager.getPage(redirectTarget); if (result != null) { if (!redirectCandidates.add(result.getPath())) { LOGGER.warn("Detected redirect loop for the following pages: {}.", redirectCandidates.toString()); break; } } } return result; }
@SuppressWarnings("null") private List<String> getContextPathCandidatesMatchInnermost(Page page, ResourceResolver resourceResolver) { List<String> candidates = new ArrayList<>(); if (page != null) { for (int level = minLevel; level <= maxLevel; level++) { Page rootPage = Path.getAbsoluteParent(page, level, resourceResolver); if (rootPage != null) { String templatePath = rootPage.getProperties().get(NameConstants.PN_TEMPLATE, String.class); if (templatePath != null) { candidates.add(rootPage.getPath()); if (templatePaths.contains(templatePath)) { break; } } } } } return candidates; }
/** * Get the last modified date for a Page. * * @param page * @return */ private static long getLastModified(final Page page) { if (page.getLastModified() != null) { return page.getLastModified().getTimeInMillis(); } else { final ValueMap properties = page.getProperties(); Date lastModified = properties.get(NameConstants.PN_PAGE_LAST_MOD, Date.class); if (lastModified != null) { return lastModified.getTime(); } else { return 0L; } } }
/** * Get the last modified date for a Page. * * @param page * @return */ private static long getLastModified(final Page page) { if (page.getLastModified() != null) { return page.getLastModified().getTimeInMillis(); } else { final ValueMap properties = page.getProperties(); Date lastModified = properties.get(NameConstants.PN_PAGE_LAST_MOD, Date.class); if (lastModified != null) { return lastModified.getTime(); } else { return 0L; } } }
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; } }
@Override public final Iterator<String> findConfigurationIds(Resource resource) { List<String> configurationIds = new ArrayList<>(); PageManager pageManager = AdaptTo.notNull(resource.getResourceResolver(), PageManager.class); Page page = pageManager.getContainingPage(resource); if (page != null) { for (int level = minLevel; level <= maxLevel; level++) { Page rootPage = page.getAbsoluteParent(level); if (rootPage != null) { String templatePath = rootPage.getProperties().get(NameConstants.PN_TEMPLATE, String.class); if (templatePath != null) { configurationIds.add(rootPage.getPath()); if (configRootTemplatePaths.contains(templatePath)) { break; } } } } } return configurationIds.iterator(); }
@SuppressWarnings({ "null", "unused" }) private boolean isResourceBelongingToBlacklistedTemplates(Resource resource, PageManager pageManager) { if (templatePathsBlacklist.isEmpty()) { return false; } Page page = pageManager.getContainingPage(resource); // if no containing page could be determined, we don't blacklist if (page == null) { log.trace("Resource '{}' is not part of page, blacklisted templates are not considered.", resource.getPath()); return false; } String templatePath = page.getProperties().get(NameConstants.PN_TEMPLATE, String.class); if (templatePath != null) { if (templatePathsBlacklist.contains(templatePath)) { return true; } } else { log.trace("Resource '{}' is part of page '{}' which doesn't contain any template property, blacklisted templates are not considered.", resource.getPath(), page.getPath()); return false; } log.trace("Resource '{}' is part of page '{}' but is not based on any of the blacklisted templates.", resource.getPath(), page.getPath()); return false; }
/** * Get a builder instance for a page using the specified title type on the returned builder. * * @param page page * @param mapped if true, link path will be mapped through resource resolver * @param titleType type of page title to set on the builder * @return builder containing the path and title of the given page */ public static LinkBuilder forPage(final Page page, final boolean mapped, final TitleType titleType) { final String title = checkNotNull(page).getProperties().get(titleType.getPropertyName(), page.getTitle()); return new DefaultLinkBuilder(getPagePath(page, mapped)).setTitle(title); }
private void write(Page page, XMLStreamWriter stream, ResourceResolver resolver) throws XMLStreamException { if (isHidden(page)) { return; } stream.writeStartElement(NS, "url"); String loc = externalizer.externalLink(resolver, externalizerDomain, String.format("%s.html", page.getPath())); writeElement(stream, "loc", loc); if (includeLastModified) { Calendar cal = page.getLastModified(); if (cal != null) { writeElement(stream, "lastmod", DATE_FORMAT.format(cal)); } } final ValueMap properties = page.getProperties(); writeFirstPropertyValue(stream, "changefreq", changefreqProperties, properties); writeFirstPropertyValue(stream, "priority", priorityProperties, properties); stream.writeEndElement(); }