下面列出了javax.servlet.jsp.tagext.DynamicAttributes#javax.servlet.jsp.tagext.SimpleTag 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* 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());
}
/**
* 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);
}
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);
}
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);
}
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);
}
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);
}
/**
* 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);
}
/**
* 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();
}