Search in sources :

Example 1 with Tag

use of jakarta.servlet.jsp.tagext.Tag in project spring-framework by spring-projects.

the class TagUtilsTests method testAssertHasAncestorOfTypeDoesNotThrowExceptionOnPass.

@Test
public void testAssertHasAncestorOfTypeDoesNotThrowExceptionOnPass() throws Exception {
    Tag a = new TagA();
    Tag b = new TagB();
    Tag c = new TagC();
    a.setParent(b);
    b.setParent(c);
    TagUtils.assertHasAncestorOfType(a, TagC.class, "a", "c");
}
Also used : Tag(jakarta.servlet.jsp.tagext.Tag) Test(org.junit.jupiter.api.Test)

Example 2 with Tag

use of jakarta.servlet.jsp.tagext.Tag in project spring-framework by spring-projects.

the class TagUtilsTests method assertHasAncestorOfTypeThrowsExceptionOnFail.

@Test
public void assertHasAncestorOfTypeThrowsExceptionOnFail() throws Exception {
    Tag a = new TagA();
    Tag b = new TagB();
    Tag anotherB = new TagB();
    a.setParent(b);
    b.setParent(anotherB);
    assertThatIllegalStateException().isThrownBy(() -> TagUtils.assertHasAncestorOfType(a, TagC.class, "a", "c"));
}
Also used : Tag(jakarta.servlet.jsp.tagext.Tag) Test(org.junit.jupiter.api.Test)

Example 3 with Tag

use of jakarta.servlet.jsp.tagext.Tag in project spring-framework by spring-projects.

the class TagUtilsTests method hasAncestorOfTypeTrueScenario.

@Test
public void hasAncestorOfTypeTrueScenario() throws Exception {
    Tag a = new TagA();
    Tag b = new TagB();
    Tag c = new TagC();
    a.setParent(b);
    b.setParent(c);
    assertThat(TagUtils.hasAncestorOfType(a, TagC.class)).isTrue();
}
Also used : Tag(jakarta.servlet.jsp.tagext.Tag) Test(org.junit.jupiter.api.Test)

Example 4 with Tag

use of jakarta.servlet.jsp.tagext.Tag in project tomcat by apache.

the class TagHandlerPool method get.

/**
 * Gets the next available tag handler from this tag handler pool,
 * instantiating one if this tag handler pool is empty.
 *
 * @param handlerClass
 *            Tag handler class
 * @return Reused or newly instantiated tag handler
 * @throws JspException
 *             if a tag handler cannot be instantiated
 */
public Tag get(Class<? extends Tag> handlerClass) throws JspException {
    Tag handler;
    synchronized (this) {
        if (current >= 0) {
            handler = handlers[current--];
            return handler;
        }
    }
    // wait for us to construct a tag for this thread.
    try {
        if (useInstanceManagerForTags) {
            return (Tag) instanceManager.newInstance(handlerClass.getName(), handlerClass.getClassLoader());
        } else {
            Tag instance = handlerClass.getConstructor().newInstance();
            instanceManager.newInstance(instance);
            return instance;
        }
    } catch (Exception e) {
        Throwable t = ExceptionUtils.unwrapInvocationTargetException(e);
        ExceptionUtils.handleThrowable(t);
        throw new JspException(e.getMessage(), t);
    }
}
Also used : JspException(jakarta.servlet.jsp.JspException) Tag(jakarta.servlet.jsp.tagext.Tag) JspException(jakarta.servlet.jsp.JspException)

Example 5 with Tag

use of jakarta.servlet.jsp.tagext.Tag in project spring-framework by spring-projects.

the class TagUtilsTests method hasAncestorOfTypeFalseScenario.

@Test
public void hasAncestorOfTypeFalseScenario() throws Exception {
    Tag a = new TagA();
    Tag b = new TagB();
    Tag anotherB = new TagB();
    a.setParent(b);
    b.setParent(anotherB);
    assertThat(TagUtils.hasAncestorOfType(a, TagC.class)).isFalse();
}
Also used : Tag(jakarta.servlet.jsp.tagext.Tag) Test(org.junit.jupiter.api.Test)

Aggregations

Tag (jakarta.servlet.jsp.tagext.Tag)6 Test (org.junit.jupiter.api.Test)4 JspException (jakarta.servlet.jsp.JspException)1