use of jakarta.servlet.jsp.tagext.Tag in project spring-framework by spring-projects.
the class TagUtils method hasAncestorOfType.
/**
* Determine whether the supplied {@link Tag} has any ancestor tag
* of the supplied type.
* @param tag the tag whose ancestors are to be checked
* @param ancestorTagClass the ancestor {@link Class} being searched for
* @return {@code true} if the supplied {@link Tag} has any ancestor tag
* of the supplied type
* @throws IllegalArgumentException if either of the supplied arguments is {@code null};
* or if the supplied {@code ancestorTagClass} is not type-assignable to
* the {@link Tag} class
*/
public static boolean hasAncestorOfType(Tag tag, Class<?> ancestorTagClass) {
Assert.notNull(tag, "Tag cannot be null");
Assert.notNull(ancestorTagClass, "Ancestor tag class cannot be null");
if (!Tag.class.isAssignableFrom(ancestorTagClass)) {
throw new IllegalArgumentException("Class '" + ancestorTagClass.getName() + "' is not a valid Tag type");
}
Tag ancestor = tag.getParent();
while (ancestor != null) {
if (ancestorTagClass.isAssignableFrom(ancestor.getClass())) {
return true;
}
ancestor = ancestor.getParent();
}
return false;
}
Aggregations