use of org.apache.sling.api.resource.Resource in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class ListImpl method populateTagListItems.
private void populateTagListItems() {
listItems = new ArrayList<>();
String[] tags = properties.get(PN_TAGS, new String[0]);
boolean matchAny = properties.get(PN_TAGS_MATCH, TAGS_MATCH_ANY_VALUE).equals(TAGS_MATCH_ANY_VALUE);
if (ArrayUtils.isNotEmpty(tags)) {
Page rootPage = getRootPage(PN_TAGS_PARENT_PAGE);
if (rootPage != null) {
TagManager tagManager = resourceResolver.adaptTo(TagManager.class);
if (tagManager != null) {
RangeIterator<Resource> resourceRangeIterator = tagManager.find(rootPage.getPath(), tags, matchAny);
if (resourceRangeIterator != null) {
while (resourceRangeIterator.hasNext()) {
Page containingPage = pageManager.getContainingPage(resourceRangeIterator.next());
if (containingPage != null) {
listItems.add(containingPage);
}
}
}
}
}
}
}
use of org.apache.sling.api.resource.Resource in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class AdaptiveImageServletTest method prepareRequestResponsePair.
private Pair<MockSlingHttpServletRequest, MockSlingHttpServletResponse> prepareRequestResponsePair(String resourcePath, String selectorString, String extension) {
final MockSlingHttpServletRequest request = new MockSlingHttpServletRequest(aemContext.resourceResolver(), aemContext.bundleContext());
final MockSlingHttpServletResponse response = new MockSlingHttpServletResponse();
Resource resource = resourceResolver.getResource(resourcePath);
request.setResource(resource);
MockRequestPathInfo requestPathInfo = (MockRequestPathInfo) request.getRequestPathInfo();
requestPathInfo.setSelectorString(selectorString);
requestPathInfo.setExtension(extension);
SlingBindings bindings = new SlingBindings();
bindings.put(SlingBindings.REQUEST, request);
bindings.put(SlingBindings.RESPONSE, response);
bindings.put(SlingBindings.SLING, aemContext.slingScriptHelper());
bindings.put(SlingBindings.RESOLVER, resourceResolver);
request.setAttribute(SlingBindings.class.getName(), bindings);
return new Pair<MockSlingHttpServletRequest, MockSlingHttpServletResponse>() {
@Override
public MockSlingHttpServletRequest getLeft() {
return request;
}
@Override
public MockSlingHttpServletResponse getRight() {
return response;
}
@Override
public MockSlingHttpServletResponse setValue(MockSlingHttpServletResponse value) {
throw new UnsupportedOperationException();
}
};
}
use of org.apache.sling.api.resource.Resource in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class MockCommerceFactory method getProduct.
public static Product getProduct(Resource resource) {
Product product = mock(Product.class);
when(product.getPath()).thenReturn(resource.getPath());
Resource image = resource.getChild("image");
if (image != null) {
ImageResource imageResource = new ImageResource(image);
when(product.getImage()).thenReturn(imageResource);
}
return product;
}
use of org.apache.sling.api.resource.Resource in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class MockXFFactory method getExperienceFragmentSocialVariation.
public static ExperienceFragmentSocialVariation getExperienceFragmentSocialVariation(Page page) {
ExperienceFragmentSocialVariation socialVariation = mock(ExperienceFragmentSocialVariation.class);
StringBuilder stringBuilder = new StringBuilder();
String image = null;
for (Resource resource : page.getContentResource().getChild("root").getChildren()) {
if (resource.isResourceType(IMAGE_RT) && StringUtils.isEmpty(image)) {
image = resource.getValueMap().get("fileReference", String.class);
}
String text = resource.getValueMap().get("text", String.class);
if (StringUtils.isNotEmpty(text)) {
stringBuilder.append(text);
}
}
when(socialVariation.getText()).thenReturn(stringBuilder.toString());
when(socialVariation.getImagePath()).thenReturn(image);
return socialVariation;
}
use of org.apache.sling.api.resource.Resource in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class FormStructureHelperImplTest method testGetFormElements.
@Test
public void testGetFormElements() {
Resource resource = resourceResolver.getResource(CONTAINING_PAGE + "/jcr:content/root/responsivegrid");
Iterator<Resource> formFields = formStructureHelper.getFormElements(resource).iterator();
assertFalse(formFields.hasNext());
Set<String> allowedFields = new HashSet<>(4);
allowedFields.add("text");
allowedFields.add("hidden");
allowedFields.add("button_button");
allowedFields.add("text_inside_non_form_node");
allowedFields.add("button_button_inherited");
Set<String> returnedFormFields = new HashSet<>();
resource = resourceResolver.getResource(CONTAINING_PAGE + "/jcr:content/root/responsivegrid/container");
formFields = formStructureHelper.getFormElements(resource).iterator();
//test only the allowed fields should be returned
while (formFields.hasNext()) {
Resource field = formFields.next();
assertTrue(allowedFields.contains(field.getName()));
returnedFormFields.add(field.getName());
}
//test all the fields preset in allowedFields should be returned
for (String field : allowedFields) {
assertTrue(returnedFormFields.contains(field));
}
}
Aggregations