/*
* Copyright (c) 2001 - 2005 ivata limited.
* All rights reserved.
* -----------------------------------------------------------------------------
* ivata masks may be redistributed under the GNU General Public
* License as published by the Free Software Foundation;
* version 2 of the License.
*
* These programs are free software; you can redistribute them and/or
* modify them under the terms of the GNU General Public License
* as published by the Free Software Foundation; version 2 of the License.
*
* These programs are distributed in the hope that they will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* See the GNU General Public License in the file LICENSE.txt for more
* details.
*
* If you would like a copy of the GNU General Public License write to
*
* Free Software Foundation, Inc.
* 59 Temple Place - Suite 330
* Boston, MA 02111-1307, USA.
*
*
* To arrange commercial support and licensing, contact ivata at
* http://www.ivata.com/contact.jsp
* -----------------------------------------------------------------------------
* $Log: BufferAppendTag.java,v $
* Revision 1.5 2005/10/11 18:54:06 colinmacleod
* Fixed some checkstyle and javadoc issues.
*
* Revision 1.4 2005/10/03 10:17:25 colinmacleod
* Fixed some style and javadoc issues.
*
* Revision 1.3 2005/10/02 14:06:34 colinmacleod
* Added/improved log4j logging.
*
* Revision 1.2 2005/09/14 13:23:58 colinmacleod
* Added serialVersionUID.
*
* Revision 1.1 2005/04/26 15:05:32 colinmacleod
* Added string buffer append tag.
*
* -----------------------------------------------------------------------------
*/
package com.ivata.mask.web.tag.util;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.BodyTagSupport;
import org.apache.log4j.Logger;
/**
* Appends the JSP contents to a <code>StringBuffer</code>.
*
* @since ivata masks 0.6 (2005-04-26)
* @author Colin MacLeod
* <a href='mailto:colin.macleod@ivata.com'>colin.macleod@ivata.com</a>
* @version $Revision: 1.5 $
*/
public class BufferAppendTag extends BodyTagSupport {
/**
* Serialization version (for <code>Serializable</code> interface).
*/
private static final long serialVersionUID = 1L;
/**
* Logger for this class.
*/
private static final Logger logger = Logger
.getLogger(BufferAppendTag.class);
/**
* <copyDoc>Refer to {@link #getBufferName}.</copyDoc>
*/
private String bufferName = null;
/**
* Stores the value of the current page.
*/
private String value = null;
/**
* <p>This method is called after the JSP engine processes the body
* content of the tag.</p>
* @exception JspException encapsulates any exception when calling
* {@link #writeTagBodyContent writeTagBodyContent}.
* @return <code>SKIP_BODY</code> since we only ever want to evaluate
* this tag once.
* @see #writeTagBodyContent
* )
*
*/
public int doAfterBody() throws JspException {
if (logger.isDebugEnabled()) {
logger.debug("doAfterBody() - start");
}
if (getBodyContent() != null) {
value = getBodyContent().getString();
} else {
value = null;
}
if (logger.isDebugEnabled()) {
logger.debug("doAfterBody() - end - return value = " + SKIP_BODY);
}
return SKIP_BODY;
}
/**
* <p>This method is called after the JSP engine finished processing
* the tag.</p>
*
* @exception JspException encapsulates any exception when calling
* <code>out.println</code>
* @return <code>EVAL_PAGE</code> since we always want to evaluate
* the page after this tag.
*/
public int doEndTag() throws JspException {
if (logger.isDebugEnabled()) {
logger.debug("doEndTag() - start");
}
StringBuffer buffer = (StringBuffer) pageContext
.findAttribute(bufferName);
if (buffer == null) {
throw new JspException("Cannot find buffer called '"
+ bufferName
+ "' at any scope.");
}
if (value != null) {
buffer.append(value);
}
if (logger.isDebugEnabled()) {
logger.debug("doEndTag() - end - return value = " + EVAL_PAGE);
}
return EVAL_PAGE;
}
/**
* <p>
* Use this attribute to specify a <code>java.lang.StringBuffer</code>
* instance in the current page context.
* </p>
*
* @return the current value of mapName.
*/
public final String getBufferName() {
if (logger.isDebugEnabled()) {
logger.debug("getBufferName() - start");
}
if (logger.isDebugEnabled()) {
logger
.debug("getBufferName() - end - return value = "
+ bufferName);
}
return bufferName;
}
/**
* <copyDoc>Refer to {@link #getBufferName}.</copyDoc>
* @param bufferNameParam
* <copyDoc>Refer to {@link #getBufferName}.</copyDoc>
*/
public void setBufferName(final String bufferNameParam) {
if (logger.isDebugEnabled()) {
logger.debug("Setting bufferName. Before '" + bufferName
+ "', after '" + bufferNameParam + "'");
}
bufferName = bufferNameParam;
if (logger.isDebugEnabled()) {
logger.debug("setBufferName(String) - end");
}
}
}
|