Java Code Examples for org.apache.sling.api.resource.ValueMap#containsKey()

The following examples show how to use org.apache.sling.api.resource.ValueMap#containsKey() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CatalogSearchSupport.java    From commerce-cif-connector with Apache License 2.0 7 votes vote down vote up
/**
 * Searches for the {@link #PN_CATALOG_PATH} property at the specified path or its parent pages.
 *
 * @param path a path in the content repository
 * @return the value of the {@link #PN_CATALOG_PATH} property or {@code null} if not found
 */
public String findCatalogPath(String path) {
    if (StringUtils.isBlank(path)) {
        return null;
    }
    Page parentPage = resolver.adaptTo(PageManager.class).getContainingPage(path);
    if (parentPage == null) {
        return null;
    }

    ConfigurationBuilder configBuilder = parentPage.getContentResource().adaptTo(ConfigurationBuilder.class);
    if (configBuilder != null) {
        ValueMap properties = configBuilder.name(CLOUDCONFIGS_BUCKET_NAME + "/" + COMMERCE_CONFIG_NAME).asValueMap();
        if (properties.containsKey(PN_CATALOG_PATH)) {
            return properties.get(PN_CATALOG_PATH, String.class);
        }
    }

    InheritanceValueMap inheritedProperties = new HierarchyNodeInheritanceValueMap(parentPage.getContentResource());
    return inheritedProperties.getInherited(PN_CATALOG_PATH, String.class);
}
 
Example 2
Source File: NPEfix19_nineteen_s.java    From coming with MIT License 6 votes vote down vote up
private boolean isJcrData(Resource resource){
    boolean jcrData = false;
    if (resource!= null) {
        ValueMap props = resource.adaptTo(ValueMap.class);
        if (props.containsKey(PROP_JCR_DATA) ) {
            jcrData = true;
        } else {
            Resource jcrContent = resource.getChild(JCR_CONTENT_LEAF);
            if (jcrContent!= null) {
                props = jcrContent.adaptTo(ValueMap.class);
                if (props.containsKey(PROP_JCR_DATA) ) {
                    jcrData = true;
                }
            }
        }
    }
    return jcrData;
}
 
Example 3
Source File: NPEfix19_nineteen_t.java    From coming with MIT License 6 votes vote down vote up
private boolean isJcrData(Resource resource){
    boolean jcrData = false;
    if (resource!= null) {
        ValueMap props = resource.adaptTo(ValueMap.class);
        if (props != null && props.containsKey(PROP_JCR_DATA) ) {
            jcrData = true;
        } else {
            Resource jcrContent = resource.getChild(JCR_CONTENT_LEAF);
            if (jcrContent!= null) {
                props = jcrContent.adaptTo(ValueMap.class);
                if (props != null && props.containsKey(PROP_JCR_DATA) ) {
                    jcrData = true;
                }
            }
        }
    }
    return jcrData;
}
 
Example 4
Source File: ChildrenDataSourceServlet.java    From commerce-cif-connector with Apache License 2.0 5 votes vote down vote up
private static Predicate createProductPredicate(String commerceType) {
    return object -> {
        final Resource resource = (Resource) object;
        ValueMap valueMap = resource.getValueMap();

        return valueMap.containsKey("sling:resourceType") &&
            resource.isResourceType("commerce/components/product") &&
            valueMap.containsKey("cq:commerceType") &&
            commerceType.equals(valueMap.get("cq:commerceType", String.class));
    };
}
 
Example 5
Source File: CIFCategoryFieldHelper.java    From commerce-cif-connector with Apache License 2.0 5 votes vote down vote up
public boolean hasChildren() {
    Resource resource = getResource();
    ValueMap valueMap = resource.getValueMap();
    if (valueMap != null && valueMap.containsKey("isLeaf") && valueMap.get("isLeaf").equals(true)) {
        return false;
    }
    return true;
}
 
Example 6
Source File: children.java    From commerce-cif-connector with Apache License 2.0 5 votes vote down vote up
@Override
public boolean evaluate(Resource resource) {
    ValueMap valueMap = resource.getValueMap();

    if (!valueMap.containsKey("sling:resourceType") || !valueMap.containsKey("cq:commerceType"))
        return false;

    final boolean ret = resource.isResourceType("sling:Folder") &&
            "category".equals(valueMap.get("cq:commerceType", String.class));

    return ret;
}
 
Example 7
Source File: DefaultPageDataElement.java    From AEM-DataLayer with Apache License 2.0 4 votes vote down vote up
@Override
public void updateDataLayer(DataLayer dataLayer) {
	EventInfo event = new EventInfo();
	event.setEventAction("pageLoad");
	event.setEventName("Page Load");
	dataLayer.getEvents().add(event);

	Page page = dataLayer.getPage();

	PageInfo pageInfo = new PageInfo();
	if (dataLayer.getConfig().getSetAuthor() == true) {
		pageInfo.setAuthor(dataLayer.getAEMPage().getLastModifiedBy());
	}

	List<String> breadcrumbs = new ArrayList<String>();
	com.day.cq.wcm.api.Page currentPage = dataLayer.getAEMPage();
	while (currentPage != null && currentPage.getDepth() > dataLayer.getConfig().getSiteRootLevel()) {
		breadcrumbs.add(currentPage.getTitle());
		currentPage = currentPage.getParent();
	}

	Collections.reverse(breadcrumbs);
	pageInfo.setBreadcrumbs(breadcrumbs.toArray(new String[breadcrumbs.size()]));

	currentPage = dataLayer.getAEMPage();
	ValueMap properties = currentPage.getContentResource().getValueMap();
	String path = DataLayerUtil.getSiteSubpath(currentPage, dataLayer.getConfig());

	pageInfo.setDestinationUrl(DataLayerUtil.getSiteUrl(currentPage, dataLayer.getConfig()));
	if (currentPage.getOnTime() != null) {
		pageInfo.setEffectiveDate(currentPage.getOnTime().getTime());
	} else if (properties.containsKey(JcrConstants.JCR_CREATED)) {
		pageInfo.setEffectiveDate(properties.get(JcrConstants.JCR_CREATED, Date.class));
	}
	if (currentPage.getOffTime() != null) {
		pageInfo.setExpiryDate(currentPage.getOffTime().getTime());
	}
	if (properties.containsKey(JcrConstants.JCR_CREATED)) {
		pageInfo.setIssueDate(properties.get(JcrConstants.JCR_CREATED, Date.class));
	}
	pageInfo.setLanguage(currentPage.getLanguage(false).toString());
	pageInfo.setPageId(path);
	pageInfo.setPageName(currentPage.getTitle());
	if (StringUtils.isNotEmpty(dataLayer.getConfig().getPublisher())) {
		pageInfo.setPublisher(dataLayer.getConfig().getPublisher());
	}
	pageInfo.setSysEnv(dataLayer.getConfig().getEnvironment());

	page.setPageInfo(pageInfo);

	String templateName = StringUtils.substringAfterLast(properties.get(NameConstants.NN_TEMPLATE, String.class),
			"/");
	List<String> tags = new ArrayList<String>();

	Category category = new Category();
	category.setPrimaryCategory(templateName);
	for (int i = 0; i < currentPage.getTags().length; i++) {
		category.put("tag" + i, currentPage.getTags()[i].getTitle());
		tags.add(currentPage.getTags()[i].getTitle());
	}
	page.setCategory(category);

	Map<String, Object> attributes = new HashMap<String, Object>();
	attributes.put("tags", tags.toArray(new String[tags.size()]));
	attributes.put("template", templateName);
	page.setAttributes(attributes);

}
 
Example 8
Source File: PageImpl.java    From jackalope with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isHideInNav() {
    ValueMap props = getProperties();
    return props.containsKey("hideInNav") ? props.get("hideInNav", Boolean.class) : false;
}
 
Example 9
Source File: CIFCategoryFieldHelper.java    From commerce-cif-connector with Apache License 2.0 3 votes vote down vote up
private boolean isCategory(Resource resource) {
    ValueMap valueMap = resource.getValueMap();

    if (!valueMap.containsKey("sling:resourceType") || !valueMap.containsKey("cq:commerceType"))
        return false;


    final boolean ret = resource.isResourceType("sling:Folder") &&
            "category".equals(valueMap.get("cq:commerceType", String.class));

    return ret;
}