use of com.day.cq.wcm.api.Page in project acs-aem-commons by Adobe-Consulting-Services.
the class LastModifiedOperationImpl method withParams.
@Override
protected List<Result> withParams(final SlingHttpServletRequest request, final SlingHttpServletResponse response, final Command cmd) {
final long start = System.currentTimeMillis();
final List<Result> results = new ArrayList<Result>();
final ResourceResolver resourceResolver = request.getResourceResolver();
final PageManager pageManager = resourceResolver.adaptTo(PageManager.class);
final List<Resource> pages = this.getLastModifiedPages(resourceResolver, cmd);
log.debug("LastModified pages -- [ {} ] results", pages.size());
for (final Resource resource : pages) {
final Page page = pageManager.getContainingPage(resource);
if (page == null) {
continue;
}
final String title = TextUtil.getFirstNonEmpty(page.getTitle(), page.getPageTitle(), page.getNavigationTitle(), page.getName());
final String description = page.getPath() + " by " + page.getLastModifiedBy() + " at " + DATE_FORMAT.format(page.getLastModified().getTime());
results.add(new Result.Builder(title).path(page.getPath()).description(description).resultType(OpenResultSerializerImpl.TYPE).build());
}
log.debug("Lastmod - Execution time: {} ms", System.currentTimeMillis() - start);
return results;
}
use of com.day.cq.wcm.api.Page in project acs-aem-commons by Adobe-Consulting-Services.
the class GenericListAdapterFactoryTest method test_that_adapting_page_with_null_template_returns_null.
@Test
public void test_that_adapting_page_with_null_template_returns_null() {
Page wrongPage = mock(Page.class);
when(wrongPage.getProperties()).thenAnswer(new Answer<ValueMap>() {
public ValueMap answer(InvocationOnMock invocation) throws Throwable {
return new ValueMapDecorator(new HashMap<String, Object>());
}
});
GenericList section = adaptToGenericList(wrongPage);
assertNull(section);
}
use of com.day.cq.wcm.api.Page in project acs-aem-commons by Adobe-Consulting-Services.
the class GenericListAdapterFactoryTest method test_that_adapting_page_with_wrong_resourceType_returns_null.
@Test
public void test_that_adapting_page_with_wrong_resourceType_returns_null() {
Page wrongPage = mock(Page.class);
Resource wrongContentResource = mock(Resource.class);
when(wrongPage.getContentResource()).thenReturn(wrongContentResource);
when(wrongContentResource.isResourceType(GenericListImpl.RT_GENERIC_LIST)).thenReturn(false);
GenericList section = adaptToGenericList(wrongPage);
assertNull(section);
}
use of com.day.cq.wcm.api.Page in project acs-aem-commons by Adobe-Consulting-Services.
the class NamedTransformImageServlet method resolveImage.
/**
* Intelligently determines how to find the Image based on the associated SlingRequest.
*
* @param request the SlingRequest Obj
* @return the Image object configured w the info of where the image to render is stored in CRX
*/
protected final Image resolveImage(final SlingHttpServletRequest request) {
final Resource resource = request.getResource();
final ResourceResolver resourceResolver = request.getResourceResolver();
final PageManager pageManager = resourceResolver.adaptTo(PageManager.class);
final Page page = pageManager.getContainingPage(resource);
if (DamUtil.isAsset(resource)) {
// For assets, pick the configured rendition if it exists
// If rendition does not exist, use original
final Asset asset = DamUtil.resolveToAsset(resource);
Rendition rendition = asset.getRendition(renditionPatternPicker);
if (rendition == null) {
log.warn("Could not find rendition [ {} ] for [ {} ]", renditionPatternPicker.toString(), resource.getPath());
rendition = asset.getOriginal();
}
final Resource renditionResource = request.getResourceResolver().getResource(rendition.getPath());
final Image image = new Image(resource);
image.set(Image.PN_REFERENCE, renditionResource.getPath());
return image;
} else if (DamUtil.isRendition(resource) || resourceResolver.isResourceType(resource, JcrConstants.NT_FILE) || resourceResolver.isResourceType(resource, JcrConstants.NT_RESOURCE)) {
// For renditions; use the requested rendition
final Image image = new Image(resource);
image.set(Image.PN_REFERENCE, resource.getPath());
return image;
} else if (page != null) {
if (resourceResolver.isResourceType(resource, NameConstants.NT_PAGE) || StringUtils.equals(resource.getPath(), page.getContentResource().getPath())) {
// Is a Page or Page's Content Resource; use the Page's image resource
return new Image(page.getContentResource(), NAME_IMAGE);
} else {
return new Image(resource);
}
} else {
if (resourceResolver.isResourceType(resource, RT_LOCAL_SOCIAL_IMAGE) && resource.getValueMap().get("mimetype", StringUtils.EMPTY).startsWith("image/")) {
// Is a UGC image
return new SocialImageImpl(resource, NAME_IMAGE);
} else if (resourceResolver.isResourceType(resource, RT_REMOTE_SOCIAL_IMAGE)) {
// Is a UGC image
return new SocialRemoteImageImpl(resource, NAME_IMAGE);
}
}
return new Image(resource);
}
use of com.day.cq.wcm.api.Page in project acs-aem-commons by Adobe-Consulting-Services.
the class TemplateUtilTest method test_that_correct_template_returns_false.
@Test
public void test_that_correct_template_returns_false() {
Page page = mock(Page.class);
ValueMap properties = createTemplateValueMap(TMPL_FAKE2);
when(page.getProperties()).thenReturn(properties);
assertThat(TemplateUtil.hasTemplate(page, TMPL_FAKE), is(false));
}
Aggregations