Java Code Examples for javax.servlet.jsp.tagext.BodyTag#doInitBody()

The following examples show how to use javax.servlet.jsp.tagext.BodyTag#doInitBody() . 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: JspUtilsTest.java    From velocity-tools with Apache License 2.0 6 votes vote down vote up
/**
 * Test method for {@link org.apache.velocity.tools.view.jsp.jspimpl.JspUtils#executeTag(org.apache.velocity.context.InternalContextAdapter, org.apache.velocity.runtime.parser.node.Node, javax.servlet.jsp.PageContext, javax.servlet.jsp.tagext.Tag)}.
 * @throws JspException If something goes wrong.
 * @throws IOException If something goes wrong.
 * @throws ParseErrorException If something goes wrong.
 * @throws ResourceNotFoundException If something goes wrong.
 * @throws MethodInvocationException If something goes wrong.
 */
@Test
public void testExecuteTag() throws JspException, MethodInvocationException, ResourceNotFoundException, ParseErrorException, IOException
{
    InternalContextAdapter context = createMock(InternalContextAdapter.class);
    Node node = createMock(Node.class);
    PageContext pageContext = createMock(PageContext.class);
    BodyTag tag = createMock(BodyTag.class);
    ASTBlock block = createMock(ASTBlock.class);
    JspWriter writer = createMock(JspWriter.class);

    expect(tag.doStartTag()).andReturn(BodyTag.EVAL_BODY_BUFFERED);
    tag.setBodyContent(isA(VelocityBodyContent.class));
    tag.doInitBody();
    expect(node.jjtGetChild(1)).andReturn(block);
    expect(tag.doAfterBody()).andReturn(BodyTag.SKIP_BODY);
    expect(tag.doEndTag()).andReturn(BodyTag.EVAL_PAGE);
    expect(pageContext.getOut()).andReturn(writer);
    expect(block.render(eq(context), isA(StringWriter.class))).andReturn(true);

    replay(context, node, pageContext, block, tag, writer);
    JspUtils.executeTag(context, node, pageContext, tag);
    verify(context, node, pageContext, block, tag, writer);
}
 
Example 2
Source File: JspRuntimeLibrary.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
public static JspWriter startBufferedBody(PageContext pageContext, BodyTag tag)
        throws JspException {
    BodyContent out = pageContext.pushBody();
    tag.setBodyContent(out);
    tag.doInitBody();
    return out;
}
 
Example 3
Source File: JspUtils.java    From velocity-tools with Apache License 2.0 5 votes vote down vote up
/**
 * Executes a {@link Tag}.
 *
 * @param context The directive context.
 * @param node The main node of the directive.
 * @param pageContext The page context.
 * @param tag The tag to execute.
 * @throws JspException If something goes wrong.
 */
public static void executeTag(InternalContextAdapter context, Node node,
        PageContext pageContext, Tag tag) throws JspException
{
    int result = tag.doStartTag();
    if (tag instanceof BodyTag)
    {
        BodyTag bodyTag = (BodyTag) tag;
        BodyContent bodyContent = new VelocityBodyContent(
                pageContext.getOut(), (ASTBlock) node.jjtGetChild(1),
                context);
        switch (result)
        {
        case BodyTag.EVAL_BODY_BUFFERED:
            bodyTag.setBodyContent(bodyContent);
            bodyTag.doInitBody();
        case BodyTag.EVAL_BODY_INCLUDE:
            bodyContent.getString();
        default:
            break;
        }
        while (bodyTag.doAfterBody() == BodyTag.EVAL_BODY_AGAIN) {
            bodyContent.getString();
        }
    }
    tag.doEndTag();
}