javax.servlet.jsp.tagext.Tag类的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(10.1k)|赞(0)|评价(0)|浏览(207)

本文整理了Java中javax.servlet.jsp.tagext.Tag类的一些代码示例,展示了Tag类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Tag类的具体详情如下:
包路径:javax.servlet.jsp.tagext.Tag
类名称:Tag

Tag介绍

[英]The interface of a classic tag handler that does not want to manipulate its body. The Tag interface defines the basic protocol between a Tag handler and JSP page implementation class. It defines the life cycle and the methods to be invoked at start and end tag.

Properties

The Tag interface specifies the setter and getter methods for the core pageContext and parent properties.

The JSP page implementation object invokes setPageContext and setParent, in that order, before invoking doStartTag() or doEndTag().

Methods

There are two main actions: doStartTag and doEndTag. Once all appropriate properties have been initialized, the doStartTag and doEndTag methods can be invoked on the tag handler. Between these invocations, the tag handler is assumed to hold a state that must be preserved. After the doEndTag invocation, the tag handler is available for further invocations (and it is expected to have retained its properties).

Lifecycle

Lifecycle details are described by the transition diagram below, with the following comments:

  • [1] This transition is intended to be for releasing long-term data. no guarantees are assumed on whether any properties have been retained or not.
  • [2] This transition happens if and only if the tag ends normally without raising an exception
  • [3] Some setters may be called again before a tag handler is reused. For instance, setParent() is called if it's reused within the same page but at a different level, setPageContext() is called if it's used in another page, and attribute setters are called if the values differ or are expressed as request-time attribute values.
  • Check the TryCatchFinally interface for additional details related to exception handling and resource management.

Once all invocations on the tag handler are completed, the release method is invoked on it. Once a release method is invoked all properties, including parent and pageContext, are assumed to have been reset to an unspecified value. The page compiler guarantees that release() will be invoked on the Tag handler before the handler is released to the GC.

Empty and Non-Empty Action

If the TagLibraryDescriptor file indicates that the action must always have an empty action, by an <body-content> entry of "empty", then the doStartTag() method must return SKIP_BODY.

Otherwise, the doStartTag() method may return SKIP_BODY or EVAL_BODY_INCLUDE.

If SKIP_BODY is returned the body, if present, is not evaluated.

If EVAL_BODY_INCLUDE is returned, the body is evaluated and "passed through" to the current out.
[中]经典标记处理程序的接口,不希望操纵其主体。标记接口定义了标记处理程序和JSP页面实现类之间的基本协议。它定义了生命周期以及在开始和结束标记时要调用的方法。
属性
标记接口为核心pageContext和父属性指定setter和getter方法。
JSP页面实现对象在调用doStartTag()或doEndTag()之前,按顺序调用setPageContext和setParent。
方法
有两个主要操作:doStartTag和doEndTag。初始化所有适当的属性后,可以在标记处理程序上调用doStartTag和doEndTag方法。在这些调用之间,假设标记处理程序持有必须保留的状态。在doEndTag调用之后,标记处理程序可用于进一步的调用(预计它会保留其属性)。
生命周期
下面的转换图描述了生命周期的详细信息,并附有以下注释:
*[1]此转换旨在发布长期数据。不保证是否保留任何财产。
*[2]当且仅当标记正常结束而不引发异常时,才会发生此转换
*[3]在重用标记处理程序之前,可能会再次调用一些setter。例如,setParent()如果在同一个页面中被重用,但在不同的级别上被调用,setPageContext()如果在另一个页面中被使用,则被调用;如果值不同或表示为请求时间属性值,则调用属性设置器。
查看TryCatchFinally界面,了解有关异常处理和资源管理的更多详细信息。
一旦完成了对标记处理程序的所有调用,就会对其调用release方法。调用发布方法后,所有
属性(包括父级和pageContext)都假定已重置为未指定的值。页面编译器保证在将标记处理程序释放到GC之前,会在标记处理程序上调用release()。
空与非空动作
如果TagLibraryDescriptor文件通过“empty”的<body content>条目指示操作必须始终具有空操作,则doStartTag()方法必须返回SKIP_body。
否则,doStartTag()方法可能会返回SKIP_BODY或EVAL_BODY_INCLUDE。
如果返回SKIP_BODY,则不计算BODY(如果存在)。
如果返回EVAL_BODY_INCLUDE,则会对BODY进行评估并“传递”到当前输出。

代码示例

代码示例来源:origin: spring-projects/spring-framework

/**
 * Determine whether the supplied {@link Tag} has any ancestor tag
 * of the supplied type.
 * @param tag the tag whose ancestors are to be checked
 * @param ancestorTagClass the ancestor {@link Class} being searched for
 * @return {@code true} if the supplied {@link Tag} has any ancestor tag
 * of the supplied type
 * @throws IllegalArgumentException if either of the supplied arguments is {@code null};
 * or if the supplied {@code ancestorTagClass} is not type-assignable to
 * the {@link Tag} class
 */
public static boolean hasAncestorOfType(Tag tag, Class<?> ancestorTagClass) {
  Assert.notNull(tag, "Tag cannot be null");
  Assert.notNull(ancestorTagClass, "Ancestor tag class cannot be null");
  if (!Tag.class.isAssignableFrom(ancestorTagClass)) {
    throw new IllegalArgumentException(
        "Class '" + ancestorTagClass.getName() + "' is not a valid Tag type");
  }
  Tag ancestor = tag.getParent();
  while (ancestor != null) {
    if (ancestorTagClass.isAssignableFrom(ancestor.getClass())) {
      return true;
    }
    ancestor = ancestor.getParent();
  }
  return false;
}

代码示例来源:origin: org.freemarker/freemarker

@Override
public void close() {
  if (closed) {
    return;
  }
  closed = true;
  
  if (needPop) {
    pageContext.popWriter();
  }
  pageContext.popTopTag();
  try {
    if (isTryCatchFinally) {
      ((TryCatchFinally) tag).doFinally();
    }
    // No pooling yet
    tag.release();
  } finally {
    if (needDoublePop) {
      pageContext.popWriter();
    }
  }
}

代码示例来源:origin: org.freemarker/freemarker

private void endEvaluation() throws JspException {
  if (needPop) {
    pageContext.popWriter();
    needPop = false;
  }
  if (tag.doEndTag() == Tag.SKIP_PAGE) {
    LOG.warn("Tag.SKIP_PAGE was ignored from a " + tag.getClass().getName() + " tag.");
  }
}

代码示例来源:origin: org.freemarker/freemarker

FreeMarkerPageContext pageContext = PageContextFactory.getCurrentPageContext();
Tag parentTag = (Tag) pageContext.peekTopTag(Tag.class);
tag.setParent(parentTag);
tag.setPageContext(pageContext);
setupTag(tag, args, pageContext.getObjectWrapper());

代码示例来源:origin: org.metawidget.modules/metawidget-all

private static void writeTagInternal( PageContext context, Tag tag, Tag parentTag )
  throws JspException {
  tag.setPageContext( context );
  tag.setParent( parentTag );
    int returnCode = tag.doStartTag();
    tag.doEndTag();
  } finally {
    tag.release();

代码示例来源:origin: com.mockrunner/mockrunner-jdk1.3-j2ee1.3

try
  int result = tag.doStartTag();
  if(Tag.EVAL_BODY_INCLUDE == result)
  returnValue = tag.doEndTag();
if(doRelease) tag.release();
return returnValue;

代码示例来源:origin: spring-projects/spring-framework

@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");
}

代码示例来源:origin: com.pojosontheweb/ttt-stripes

@Override
  protected void doRender(TttWriter tw) throws Exception {
//        try {
      tag.doStartTag();
      tag.doEndTag();
//        } finally {
//            tag.release();
//        }
  }
}

代码示例来源:origin: com.liferay.faces/liferay-faces-portal

tag.setPageContext(stringPageContext);
tag.doStartTag();
tag.doEndTag();

代码示例来源:origin: org.freemarker/freemarker

public int onStart()
throws TemplateModelException {
  try {
    int dst = tag.doStartTag();
    switch(dst) {
      case Tag.SKIP_BODY:

代码示例来源:origin: com.mockrunner/mockrunner-jdk1.3-j2ee1.3

/**
 * Constructor for a tag with the specified attribute map.
 * If the specified tag is not an instance of <code>TagSupport</code>,
 * the methods that delegate to <code>TagSupport</code> specific methods
 * throw an exception.
 * @param tag the tag
 * @param pageContext the corresponding <code>PageContext</code>
 * @param attributes the attribute map
 */
public NestedStandardTag(Tag tag, PageContext pageContext, Map attributes)
{
  this.tag = tag;
  this.pageContext = pageContext;
  tag.setPageContext(pageContext);
  childs = new ArrayList();
  this.attributes = attributes;
  doRelease = false;
}

代码示例来源:origin: mockobjects/mockobjects-jdk1.4-j2ee1.3

/**
 * Assert that the return value of doStartTag is equal to an expectedValue
 * @param expectedValue value to check against doStartTag
 */
public void assertDoStartTag(final int expectedValue) throws JspException {
  testSubject.setPageContext(pageContext);
  checkReturnValue("doStartTag", expectedValue, testSubject.doStartTag());
}

代码示例来源:origin: com.mockrunner/mockrunner-jdk1.4-j2ee1.3

try
  int result = tag.doStartTag();
  if(Tag.EVAL_BODY_INCLUDE == result)
  returnValue = tag.doEndTag();
if(doRelease) tag.release();
return returnValue;

代码示例来源:origin: com.pojosontheweb/ttt-stripes

public TagTemplate(PageContext pageContext, T tag, B parent) {
  this.tag = tag;
  tag.setPageContext(pageContext);
  if (parent != null) {
    tag.setParent(parent);
  }
}

代码示例来源:origin: spring-projects/spring-framework

@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");
}

代码示例来源:origin: org.seasar.teeda/teeda-extension

protected void processTag(final PageContext pageContext, final Tag tag)
    throws JspException {
  if (Tag.SKIP_BODY != tag.doStartTag()) {
    processChildren(pageContext, tag);
    tag.doEndTag();
  }
}

代码示例来源:origin: com.mockrunner/mockrunner-tag

/**
 * Delegates to wrapped tag.
 */
public int doStartTag() throws JspException
{
  return tag.doStartTag();
}

代码示例来源:origin: com.mockrunner/mockrunner-jdk1.4-j2ee1.3

/**
 * Constructor for a tag with the specified attribute map.
 * If the specified tag is not an instance of <code>TagSupport</code>,
 * the methods that delegate to <code>TagSupport</code> specific methods
 * throw an exception.
 * @param tag the tag
 * @param pageContext the corresponding <code>PageContext</code>
 * @param attributes the attribute map
 */
public NestedStandardTag(Tag tag, PageContext pageContext, Map attributes)
{
  this.tag = tag;
  this.pageContext = pageContext;
  tag.setPageContext(pageContext);
  childs = new ArrayList();
  this.attributes = attributes;
  doRelease = false;
}

代码示例来源:origin: org.springframework/spring-web

/**
 * Determine whether the supplied {@link Tag} has any ancestor tag
 * of the supplied type.
 * @param tag the tag whose ancestors are to be checked
 * @param ancestorTagClass the ancestor {@link Class} being searched for
 * @return {@code true} if the supplied {@link Tag} has any ancestor tag
 * of the supplied type
 * @throws IllegalArgumentException if either of the supplied arguments is {@code null};
 * or if the supplied {@code ancestorTagClass} is not type-assignable to
 * the {@link Tag} class
 */
public static boolean hasAncestorOfType(Tag tag, Class<?> ancestorTagClass) {
  Assert.notNull(tag, "Tag cannot be null");
  Assert.notNull(ancestorTagClass, "Ancestor tag class cannot be null");
  if (!Tag.class.isAssignableFrom(ancestorTagClass)) {
    throw new IllegalArgumentException(
        "Class '" + ancestorTagClass.getName() + "' is not a valid Tag type");
  }
  Tag ancestor = tag.getParent();
  while (ancestor != null) {
    if (ancestorTagClass.isAssignableFrom(ancestor.getClass())) {
      return true;
    }
    ancestor = ancestor.getParent();
  }
  return false;
}

代码示例来源:origin: org.bluestemsoftware.open.maven.tparty/jsp-2.1

/**
 * Calls the release() method of all available tag handlers in this tag
 * handler pool.
 */
public synchronized void release() {
for (int i=current; i>=0; i--) {
  handlers[i].release();
}
}

相关文章