Java Code Examples for org.apache.sling.api.resource.Resource#isResourceType()

The following examples show how to use org.apache.sling.api.resource.Resource#isResourceType() . 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: IsProductDetailPageServlet.java    From commerce-cif-connector with Apache License 2.0 6 votes vote down vote up
static boolean containsComponent(String resourceType, Resource resource) {
    if (resource == null)
        return false;

    if (resource.isResourceType(resourceType)) {
        return true;
    }

    for (Resource child : resource.getChildren()) {
        boolean val = containsComponent(resourceType, child);
        if (val) {
            return true;
        }
    }

    return false;
}
 
Example 2
Source File: ChildrenDataSourceServlet.java    From commerce-cif-connector with Apache License 2.0 5 votes vote down vote up
private static Predicate createFolderPredicate() {
    return object -> {
        Resource resource = (Resource) object;
        return resource.isResourceType("sling:Folder")
            || resource.isResourceType("sling:OrderedFolder")
            || resource.isResourceType(JcrConstants.NT_FOLDER);
    };
}
 
Example 3
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 4
Source File: CIFCategoryFieldHelper.java    From commerce-cif-connector with Apache License 2.0 5 votes vote down vote up
public boolean isCloudFolder() {
    Resource resource = getResource();

    return (isVirtual(resource) || isCloudBoundFolder(resource)) && (resource.isResourceType("sling:Folder")
            || resource.isResourceType("sling:OrderedFolder")
            || resource.isResourceType(JcrConstants.NT_FOLDER));
}
 
Example 5
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 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) {
    if (resource.isResourceType("sling:Folder")
            || resource.isResourceType("sling:OrderedFolder")
            || resource.isResourceType(JcrConstants.NT_FOLDER))
        return true;

    return categoryPredicate.evaluate(resource);
}
 
Example 7
Source File: ViewHelper.java    From commerce-cif-connector with Apache License 2.0 5 votes vote down vote up
public boolean isFolder() {
    Resource resource = getResource();

    return resource.isResourceType("sling:Folder")
            || resource.isResourceType("sling:OrderedFolder")
            || resource.isResourceType(JcrConstants.NT_FOLDER);
}
 
Example 8
Source File: CIFProductFieldHelper.java    From commerce-cif-connector with Apache License 2.0 5 votes vote down vote up
public boolean isCloudFolder() {
    Resource resource = getResource();

    return (isVirtual(resource) || isCloudBoundFolder(resource)) && (resource.isResourceType("sling:Folder")
            || resource.isResourceType("sling:OrderedFolder")
            || resource.isResourceType(JcrConstants.NT_FOLDER));
}
 
Example 9
Source File: NavigationImpl.java    From aem-core-cif-components with Apache License 2.0 5 votes vote down vote up
private boolean isCatalogPage(Page page) {
    if (page == null) {
        return false;
    }

    Resource contentResource = page.getContentResource();
    if (contentResource == null) {
        return false;
    }

    return contentResource.isResourceType(RT_CATALOG_PAGE);
}
 
Example 10
Source File: StreamEntry.java    From sling-samples with Apache License 2.0 5 votes vote down vote up
public Stream getStream() {
    if ( this.stream == null ) {
        if ( resource == null ) {
            stream = new Stream(null);
        } else {
            Resource rsrc = this.resource.getParent();
            while (rsrc != null && !rsrc.isResourceType(Stream.RESOURCETYPE) ) {
                rsrc = rsrc.getParent();
            }
            stream = new Stream(rsrc);
        }
    }
    return stream;
}
 
Example 11
Source File: StreamInfo.java    From sling-samples with Apache License 2.0 5 votes vote down vote up
public long getEntryCount() {
    if ( entryCount == -1 ) {
        entryCount = 0;
        if ( this.resource != null ) {
            for(final Resource rsrc : this.resource.getParent().getChildren()) {
                if ( rsrc.isResourceType(StreamEntry.RESOURCETYPE) ) {
                    entryCount++;
                }
            }
        }
    }
    return entryCount;
}
 
Example 12
Source File: ConfigurationColumnViewItem.java    From commerce-cif-connector with Apache License 2.0 4 votes vote down vote up
private boolean isFolder(Resource resource) {
    return resource.isResourceType(JcrConstants.NT_FOLDER) || isSlingFolder(resource);
}
 
Example 13
Source File: ConfigurationColumnViewItem.java    From commerce-cif-connector with Apache License 2.0 4 votes vote down vote up
private boolean isSlingFolder(Resource resource) {
    return resource.isResourceType(JcrResourceConstants.NT_SLING_FOLDER) ||
        resource.isResourceType(JcrResourceConstants.NT_SLING_ORDERED_FOLDER);
}
 
Example 14
Source File: CIFCategoryFieldHelper.java    From commerce-cif-connector with Apache License 2.0 4 votes vote down vote up
private boolean isFolder(Resource resource ) {
    return resource.isResourceType("sling:Folder")
            || resource.isResourceType("sling:OrderedFolder")
            || resource.isResourceType(JcrConstants.NT_FOLDER);
}
 
Example 15
Source File: ResourceResolverImpl.java    From jackalope with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isResourceType(Resource resource, String resourceType) {
    return resource.isResourceType(resourceType);
}
 
Example 16
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;
}