📄 arbitraryiteratorbodytag.java
字号:
/**
*
* $Header: /raid1/wide/cvsroot/wide/dev/struts/struts-metadata/templates/new-app/nitroX-tour/site/WEB-INF/src/java/com/hp/mw/samples/struts/storefront/taglibs/ArbitraryIteratorBodyTag.java,v 1.1 2005/10/10 20:12:04 sami Exp $
*
* Copyright (c) 2002 by M7 Corporation
* All rights reserved.
*
* The information contained herein is confidential and proprietary
* to M7 Corporation, and considered a trade secret as defined under
* civil and criminal statutes. M7 Corporation shall pursue its
* civil and criminal remedies in the event of unauthorized use or
* misappropriation of its trade secrets. Use of this information
* by anyone other than authorized employees of M7 Corporation is
* granted only under a written non-disclosure agreement, expressly
* prescribing the scope and manner of such use.
*
*/
package com.hp.mw.samples.struts.storefront.taglibs;
import java.util.*;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
/**
*
* @author <a href="mailto:zcollier@m7.com">Zaitrarrio Collier</a>
* @version $ Revision: $
*/
public abstract class ArbitraryIteratorBodyTag
extends AbstractBodyTag
{
//~ Instance fields --------------------------------------------------------
protected String id;
protected String indexId;
protected Iterator iterator = null;
protected String emptyText = "";
protected int index = 0;
protected Object currentObject;
//~ Methods ----------------------------------------------------------------
/**
* Set's the id of the scripting variable that should contain the current object during iteration
*
* @param the id of the scripting variable that should contain the current object during iteration
*/
public void setId( String value )
{
this.id = value;
}
/**
* Set's the id of the scripting variable that should be used to contain the current index during iteration
*
* @param the id of the scripting variable that should be used to contain the current index during iteration
*/
public void setIndexId( String value )
{
this.indexId = value;
}
public void setEmptyText( String value )
{
this.emptyText = value;
}
protected abstract Iterator getIterator( )
throws Exception;
protected Object getCurrentObject( )
{
return currentObject;
}
/**
* Sets the attributes which are output to the jsp page
*/
protected Object setOutputAttributes( )
{
if ( id != null )
{
pageContext.setAttribute( id, currentObject = iterator.next( ), PageContext.PAGE_SCOPE );
}
if ( indexId != null )
{
pageContext.setAttribute( indexId, new Integer( index++ ), PageContext.PAGE_SCOPE );
}
return currentObject;
}
/**
* @see javax.servlet.jsp.tagext.BodyTag
*/
public int doStartTag( )
throws JspException
{
try
{
// get the objects
iterator = getIterator( );
if ( ( iterator == null ) || !iterator.hasNext( ) )
{
JspWriter out = pageContext.getOut( );
out.print( emptyText );
return ( SKIP_BODY );
}
// evaluate the body
return ( EVAL_BODY_BUFFERED );
}
catch ( Exception e )
{
handlePageException( e );
return ( SKIP_BODY );
}
}
/**
* @see javax.servlet.jsp.tagext.BodyTag
*/
public void doInitBody( )
{
setOutputAttributes( );
}
/**
* @see javax.servlet.jsp.tagext.BodyTag
*/
public int doAfterBody( )
throws JspException
{
try
{
if ( iterator.hasNext( ) )
{
setOutputAttributes( );
return EVAL_BODY_BUFFERED;
}
else
{
BodyContent body = getBodyContent( );
body.writeOut( getPreviousOut( ) );
}
}
catch ( Exception e )
{
handlePageException( e );
}
return ( SKIP_BODY );
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -