use of com.day.cq.wcm.api.PageManager in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class LanguageNavigationImpl method getItems.
@Override
public List<NavigationItem> getItems() {
if (items == null) {
PageManager pageManager = currentPage.getPageManager();
rootPage = pageManager.getPage(navigationRoot);
if (rootPage != null) {
int rootPageLevel = rootPage.getDepth();
startLevel = rootPageLevel + 1;
structureDepth += rootPageLevel;
items = getItems(rootPage);
} else {
items = Collections.emptyList();
}
}
return Collections.unmodifiableList(items);
}
use of com.day.cq.wcm.api.PageManager in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class LanguageNavigationImpl method getLocalizedPage.
private Page getLocalizedPage(Page page, Page languageRoot) {
Page localizedPage;
String path = languageRoot.getPath();
String relativePath = page.getPath();
if (relativePath.startsWith(path)) {
localizedPage = page;
} else {
String separator = "/";
int i = relativePath.indexOf(separator);
int occurrence = StringUtils.countMatches(path, separator) + 1;
while (--occurrence > 0 && i != -1) {
i = relativePath.indexOf(separator, i + 1);
}
relativePath = (i > 0) ? relativePath.substring(i) : "";
path = path.concat(relativePath);
PageManager pageManager = page.getPageManager();
localizedPage = pageManager.getPage(path);
}
return localizedPage;
}
use of com.day.cq.wcm.api.PageManager in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class RedirectItemImpl method getRedirectPage.
private Page getRedirectPage(@NotNull SlingHttpServletRequest request) {
Page page = null;
ResourceResolver resourceResolver = request.getResourceResolver();
Resource targetResource = resourceResolver.getResource(redirectTarget);
PageManager pageManager = resourceResolver.adaptTo(PageManager.class);
if (pageManager != null && targetResource != null) {
page = pageManager.getContainingPage(targetResource);
}
return page;
}
use of com.day.cq.wcm.api.PageManager in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class ComponentUtils method generateId.
/**
* Returns an auto generated component ID.
*
* The ID is the first {@value ComponentUtils#ID_HASH_LENGTH} characters of an SHA-1 hexadecimal hash of the component path,
* prefixed with the component name. Example: title-810f3af321
*
* If the component is referenced, the path is taken to be a concatenation of the component path,
* with the path of the first parent context resource that exists on the page or in the template.
* This ensures the ID is unique if the same component is referenced multiple times on the same page or template.
*
* Collision
* ---------
* c = expected collisions
* c ~= (i^2)/(2m) - where i is the number of items and m is the number of possibilities for each item.
* m = 16^n - for a hexadecimal string, where n is the number of characters.
*
* For i = 1000 components with the same name, and n = 10 characters:
*
* c ~= (1000^2)/(2*(16^10))
* c ~= 0.00000045
*
* @return the auto generated component ID
*/
@NotNull
private static String generateId(@NotNull final Resource resource, @Nullable final Page currentPage, @Nullable final String resourceCallerPath, @Nullable final ComponentContext componentContext) {
String resourceType = resource.getResourceType();
String prefix = StringUtils.substringAfterLast(resourceType, "/");
String path = resource.getPath();
if (currentPage != null && componentContext != null) {
PageManager pageManager = currentPage.getPageManager();
Page resourcePage = pageManager.getContainingPage(resource);
Template template = currentPage.getTemplate();
boolean inCurrentPage = (resourcePage != null && StringUtils.equals(resourcePage.getPath(), currentPage.getPath()));
boolean inTemplate = (template != null && path.startsWith(template.getPath()));
if (resourceCallerPath != null) {
path = resourceCallerPath.concat(resource.getPath());
} else if (!inCurrentPage && !inTemplate) {
ComponentContext parentContext = componentContext.getParent();
while (parentContext != null) {
Resource parentContextResource = parentContext.getResource();
if (parentContextResource != null) {
Page parentContextPage = pageManager.getContainingPage(parentContextResource);
inCurrentPage = (parentContextPage != null && StringUtils.equals(parentContextPage.getPath(), currentPage.getPath()));
inTemplate = (template != null && parentContextResource.getPath().startsWith(template.getPath()));
if (inCurrentPage || inTemplate) {
path = parentContextResource.getPath().concat(resource.getPath());
break;
}
}
parentContext = parentContext.getParent();
}
}
}
return ComponentUtils.generateId(prefix, path);
}
use of com.day.cq.wcm.api.PageManager in project APM by Cognifide.
the class HistoryImpl method getOrCreateLogDir.
private Page getOrCreateLogDir(ResourceResolver resolver) throws WCMException {
PageManager pageManager = resolver.adaptTo(PageManager.class);
Page historyPage = pageManager.getPage(HISTORY_PATH);
if (historyPage == null) {
boolean autoCommit = true;
historyPage = pageManager.create("/etc/cqsm", "history", "/apps/cqsm/core/templates/historyTemplate", "History", autoCommit);
}
return historyPage;
}
Aggregations