All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.day.cq.commons.predicates.IsTemplateNodePredicate Maven / Gradle / Ivy

There is a newer version: 2024.11.18751.20241128T090041Z-241100
Show newest version
/*************************************************************************
 *
 * ADOBE CONFIDENTIAL
 * ___________________
 * 
 * Copyright 2024 Adobe
 * All Rights Reserved.
 * 
 * NOTICE: All information contained herein is, and remains
 * the property of Adobe and its suppliers, if any. The intellectual
 * and technical concepts contained herein are proprietary to Adobe
 * and its suppliers and are protected by all applicable intellectual
 * property laws, including trade secret and copyright laws.
 * Dissemination of this information or reproduction of this material
 * is strictly forbidden unless prior written permission is obtained
 * from Adobe.
 **************************************************************************/

package com.day.cq.commons.predicates;

import com.day.cq.commons.jcr.JcrConstants;
import java.util.function.Predicate;

import org.osgi.service.component.annotations.Component;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.jcr.Node;
import javax.jcr.RepositoryException;

/**
 * Predicate used to filter Template nodes.
 */
@Component(
        service = Predicate.class,
        property = {
                "service.vendor=Adobe Systems Incorporated",
                "predicate.name=template"
        })
public class IsTemplateNodePredicate implements NodePredicate {

    /**
     * default logger
     */
    private final Logger log = LoggerFactory.getLogger(IsTemplateNodePredicate.class);
    /**
     * {@inheritDoc}
     *
     * @return true if node is an nt:folder containing templates or cq:Template node.
     */
    @Override
    public boolean test(Node node) {
        try {
            if (node.getPrimaryNodeType().getName().equals("cq:Template")) {
                return true;
            }
            if (node.getPrimaryNodeType().getName().equals(JcrConstants.NT_FOLDER)) {
                return node.hasNodes();
            }
        } catch (RepositoryException e) {
            log.warn("RepositoryException in evaluate()", e);
        }
        return false;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy