javax.servlet.jsp.tagext.SimpleTag Java Examples

The following examples show how to use javax.servlet.jsp.tagext.SimpleTag. 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: JspUtils.java    From velocity-tools with Apache License 2.0 6 votes vote down vote up
/**
 * If necessary, wraps a {@link SimpleTag} into a {@link Tag}.
 *
 * @param tag The tag to (possibly) wrap.
 * @return The wrapped tag, or the tag passed as parameter if it was not necessary.
 */
public static Tag wrapTag(JspTag tag) {
    if (tag == null) {
        return null;
    }
    if (tag instanceof Tag)
    {
        return (Tag) tag;
    }
    if (tag instanceof SimpleTag)
    {
        return new TagAdapter((SimpleTag) tag);
    }
    throw new VelocityToolsJspException(
            "Cannot get tag that is not a Tag nor a SimpleTag, class "
                    + tag.getClass().getCanonicalName());
}
 
Example #2
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#executeSimpleTag(org.apache.velocity.context.InternalContextAdapter, org.apache.velocity.runtime.parser.node.Node, javax.servlet.jsp.PageContext, javax.servlet.jsp.tagext.SimpleTag)}.
 * @throws IOException If something goes wrong.
 * @throws JspException If something goes wrong.
 */
@Test
public void testExecuteSimpleTag() throws JspException, IOException
{
    InternalContextAdapter context = createMock(InternalContextAdapter.class);
    Node node = createMock(Node.class);
    PageContext pageContext = createMock(PageContext.class);
    SimpleTag tag = createMock(SimpleTag.class);
    ASTBlock block = createMock(ASTBlock.class);

    tag.setJspBody(isA(VelocityJspFragment.class));
    expect(node.jjtGetChild(1)).andReturn(block);
    tag.doTag();

    replay(context, node, pageContext, block, tag);
    JspUtils.executeSimpleTag(context, node, pageContext, tag);
    verify(context, node, pageContext, block, tag);
}
 
Example #3
Source File: Node.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
public CustomTag(String qName, String prefix, String localName,
        String uri, Attributes attrs, Attributes nonTaglibXmlnsAttrs,
        Attributes taglibAttrs, Mark start, Node parent,
        TagInfo tagInfo, Class<?> tagHandlerClass) {
    super(qName, localName, attrs, nonTaglibXmlnsAttrs, taglibAttrs,
            start, parent);

    this.uri = uri;
    this.prefix = prefix;
    this.tagInfo = tagInfo;
    this.tagFileInfo = null;
    this.tagHandlerClass = tagHandlerClass;
    this.customNestingLevel = makeCustomNestingLevel();
    this.childInfo = new ChildInfo();

    this.implementsIterationTag = IterationTag.class
            .isAssignableFrom(tagHandlerClass);
    this.implementsBodyTag = BodyTag.class
            .isAssignableFrom(tagHandlerClass);
    this.implementsTryCatchFinally = TryCatchFinally.class
            .isAssignableFrom(tagHandlerClass);
    this.implementsSimpleTag = SimpleTag.class
            .isAssignableFrom(tagHandlerClass);
    this.implementsDynamicAttributes = DynamicAttributes.class
            .isAssignableFrom(tagHandlerClass);
    this.implementsJspIdConsumer = JspIdConsumer.class
            .isAssignableFrom(tagHandlerClass);
}
 
Example #4
Source File: Node.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
public CustomTag(String qName, String prefix, String localName,
        String uri, Attributes attrs, Attributes nonTaglibXmlnsAttrs,
        Attributes taglibAttrs, Mark start, Node parent,
        TagInfo tagInfo, Class<?> tagHandlerClass) {
    super(qName, localName, attrs, nonTaglibXmlnsAttrs, taglibAttrs,
            start, parent);

    this.uri = uri;
    this.prefix = prefix;
    this.tagInfo = tagInfo;
    this.tagHandlerClass = tagHandlerClass;
    this.customNestingLevel = makeCustomNestingLevel();
    this.childInfo = new ChildInfo();

    this.implementsIterationTag = IterationTag.class
            .isAssignableFrom(tagHandlerClass);
    this.implementsBodyTag = BodyTag.class
            .isAssignableFrom(tagHandlerClass);
    this.implementsTryCatchFinally = TryCatchFinally.class
            .isAssignableFrom(tagHandlerClass);
    this.implementsSimpleTag = SimpleTag.class
            .isAssignableFrom(tagHandlerClass);
    this.implementsDynamicAttributes = DynamicAttributes.class
            .isAssignableFrom(tagHandlerClass);
    this.implementsJspIdConsumer = JspIdConsumer.class
            .isAssignableFrom(tagHandlerClass);
}
 
Example #5
Source File: Node.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
public CustomTag(String qName, String prefix, String localName,
        String uri, Attributes attrs, Attributes nonTaglibXmlnsAttrs,
        Attributes taglibAttrs, Mark start, Node parent,
        TagInfo tagInfo, Class<?> tagHandlerClass) {
    super(qName, localName, attrs, nonTaglibXmlnsAttrs, taglibAttrs,
            start, parent);

    this.uri = uri;
    this.prefix = prefix;
    this.tagInfo = tagInfo;
    this.tagHandlerClass = tagHandlerClass;
    this.customNestingLevel = makeCustomNestingLevel();
    this.childInfo = new ChildInfo();

    this.implementsIterationTag = IterationTag.class
            .isAssignableFrom(tagHandlerClass);
    this.implementsBodyTag = BodyTag.class
            .isAssignableFrom(tagHandlerClass);
    this.implementsTryCatchFinally = TryCatchFinally.class
            .isAssignableFrom(tagHandlerClass);
    this.implementsSimpleTag = SimpleTag.class
            .isAssignableFrom(tagHandlerClass);
    this.implementsDynamicAttributes = DynamicAttributes.class
            .isAssignableFrom(tagHandlerClass);
    this.implementsJspIdConsumer = JspIdConsumer.class
            .isAssignableFrom(tagHandlerClass);
}
 
Example #6
Source File: Node.java    From packagedrone with Eclipse Public License 1.0 5 votes vote down vote up
public CustomTag(String jspVersion, String qName, String prefix,
                        String localName,
		 String uri, Attributes attrs,
		 Attributes nonTaglibXmlnsAttrs,
		 Attributes taglibAttrs,
		 Mark start, Node parent, TagInfo tagInfo,
		 Class tagHandlerClass) {
           super(qName, localName, attrs, nonTaglibXmlnsAttrs, taglibAttrs,
                 start, parent);

           this.jspVersion = Double.valueOf(jspVersion).doubleValue();
    this.uri = uri;
    this.prefix = prefix;
    this.tagInfo = tagInfo;
    this.tagHandlerClass = tagHandlerClass;
    this.customNestingLevel = makeCustomNestingLevel();
           this.childInfo = new ChildInfo();

    this.implementsIterationTag = 
	IterationTag.class.isAssignableFrom(tagHandlerClass);
    this.implementsBodyTag =
	BodyTag.class.isAssignableFrom(tagHandlerClass);
    this.implementsTryCatchFinally = 
	TryCatchFinally.class.isAssignableFrom(tagHandlerClass);
    this.implementsSimpleTag = 
	SimpleTag.class.isAssignableFrom(tagHandlerClass);
    this.implementsDynamicAttributes = 
	DynamicAttributes.class.isAssignableFrom(tagHandlerClass);
}
 
Example #7
Source File: JspUtilsTest.java    From velocity-tools with Apache License 2.0 5 votes vote down vote up
/**
 * Test method for {@link org.apache.velocity.tools.view.jsp.jspimpl.JspUtils#wrapTag(javax.servlet.jsp.tagext.JspTag)}.
 */
@Test
public void testWrapTag()
{
    Tag tag = createMock(Tag.class);
    SimpleTag simpleTag = createMock(SimpleTag.class);

    replay(tag, simpleTag);
    assertSame(tag, JspUtils.wrapTag(tag));
    assertSame(simpleTag, ((TagAdapter) JspUtils.wrapTag(simpleTag)).getAdaptee());
    verify(tag, simpleTag);
}
 
Example #8
Source File: JspUtils.java    From velocity-tools with Apache License 2.0 3 votes vote down vote up
/**
 * Executes a {@link SimpleTag}.
 *
 * @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.
 * @throws IOException If something goes wrong.
 */
public static void executeSimpleTag(InternalContextAdapter context,
        Node node, PageContext pageContext, SimpleTag tag)
        throws JspException, IOException
{
    tag.setJspBody(new VelocityJspFragment(pageContext, (ASTBlock) node
            .jjtGetChild(1), context));
    tag.doTag();
}