Search in sources :

Example 1 with Tag

use of javax.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 (Constants.USE_INSTANCE_MANAGER_FOR_TAGS) {
            return (Tag) instanceManager.newInstance(handlerClass.getName(), handlerClass.getClassLoader());
        } else {
            Tag instance = handlerClass.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(javax.servlet.jsp.JspException) Tag(javax.servlet.jsp.tagext.Tag) JspException(javax.servlet.jsp.JspException)

Example 2 with Tag

use of javax.servlet.jsp.tagext.Tag in project sonarqube by SonarSource.

the class NestedPropertyHelper method getCurrentName.

/**
     * <p>Returns the bean name from the request object that the properties
     * are nesting against.</p>
     *
     * <p>The requirement of the tag itself could be removed in the future,
     * but is required if support for the <html:form> tag is maintained.</p>
     *
     * @param request object to fetch the bean reference from
     * @param nested  tag from which to start the search from
     * @return the string of the bean name to be nesting against
     */
public static final String getCurrentName(HttpServletRequest request, NestedNameSupport nested) {
    // get the old one if any
    NestedReference nr = (NestedReference) request.getAttribute(NESTED_INCLUDES_KEY);
    // return null or the property
    if (nr != null) {
        return nr.getBeanName();
    } else {
        // need to look for a form tag...
        Tag tag = (Tag) nested;
        Tag formTag = null;
        // loop all parent tags until we get one that can be nested against
        do {
            tag = tag.getParent();
            if ((tag != null) && tag instanceof FormTag) {
                formTag = tag;
            }
        } while ((formTag == null) && (tag != null));
        if (formTag == null) {
            return "";
        }
        // return the form's name
        return ((FormTag) formTag).getBeanName();
    }
}
Also used : FormTag(org.apache.struts.taglib.html.FormTag) FormTag(org.apache.struts.taglib.html.FormTag) Tag(javax.servlet.jsp.tagext.Tag)

Example 3 with Tag

use of javax.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(javax.servlet.jsp.tagext.Tag) Test(org.junit.Test)

Example 4 with Tag

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

the class TagUtilsTests method assertHasAncestorOfTypeThrowsExceptionOnFail.

@Test(expected = IllegalStateException.class)
public void assertHasAncestorOfTypeThrowsExceptionOnFail() throws Exception {
    Tag a = new TagA();
    Tag b = new TagB();
    Tag anotherB = new TagB();
    a.setParent(b);
    b.setParent(anotherB);
    TagUtils.assertHasAncestorOfType(a, TagC.class, "a", "c");
}
Also used : Tag(javax.servlet.jsp.tagext.Tag) Test(org.junit.Test)

Example 5 with Tag

use of javax.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);
    assertTrue(TagUtils.hasAncestorOfType(a, TagC.class));
}
Also used : Tag(javax.servlet.jsp.tagext.Tag) Test(org.junit.Test)

Aggregations

Tag (javax.servlet.jsp.tagext.Tag)8 Test (org.junit.Test)4 JspException (javax.servlet.jsp.JspException)2 FormTag (org.apache.struts.taglib.html.FormTag)1