/*
* 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: CollectionAddTag.java,v $
* Revision 1.4 2005/10/02 14:06:34 colinmacleod
* Added/improved log4j logging.
*
* Revision 1.3 2005/09/14 13:23:58 colinmacleod
* Added serialVersionUID.
*
* Revision 1.2 2005/04/09 18:04:20 colinmacleod
* Changed copyright text to GPL v2 explicitly.
*
* Revision 1.1 2005/01/19 12:58:20 colinmacleod
* Moved from ivata groupware.
*
* Revision 1.1 2004/09/30 15:16:03 colinmacleod
* Split off addressbook elements into security subproject.
*
* Revision 1.3 2004/03/21 21:16:09 colinmacleod
* Shortened name to ivata op.
*
* Revision 1.2 2004/02/01 22:00:34 colinmacleod
* Added full names to author tags
*
* Revision 1.1.1.1 2004/01/27 20:57:58 colinmacleod
* Moved ivata openportal to SourceForge..
*
* Revision 1.1.1.1 2003/10/13 20:50:11 colin
* Restructured portal into subprojects
*
* Revision 1.1 2003/02/25 08:15:50 colin
* moved to jsp category
*
* Revision 1.3 2003/02/04 17:43:51 colin
* copyright notice
*
* Revision 1.2 2002/09/25 11:40:53 colin
* added checking for null collection at page scope -> session scope
*
* Revision 1.1 2002/07/01 10:38:41 colin
* first version of collection add tag
* -----------------------------------------------------------------------------
*/
package com.ivata.mask.web.tag.util;
import org.apache.log4j.Logger;
import java.util.Collection;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.TagSupport;
/**
* <p>This class is a wrapper tag to <code>Collection.add</code>.</p>
*
* <p><b>Tag attributes:</b><br/>
* <table cellpadding='2' cellspacing='5' border='0' align='center'
* width='85%'>
* <tr class='TableHeadingColor'>
* <th>attribute</th>
* <th>reqd.</th>
* <th>param. class</th>
* <th width='100%'>description</th>
* </tr>
* <tr class='TableRowColor'>
* <td>name</td>
* <td>true</td>
* <td><code>String</code></td>
* <td>The name of the <code>Collection</code> you .want
* to add an element to. This should have been instantiated with
* page scope using the <code>useBean</code> tag.</td>
* </tr>
* <tr class='TableRowColor'>
* <td>value</td>
* <td>true</td>
* <td><code>Object</code></td>
* <td>The value of the object you want to add.</td>
* </tr>
* </table>
* </p>
*
* @since ivata masks 0.5 (2002-06-29)
* @author Colin MacLeod
* <a href='mailto:colin.macleod@ivata.com'>colin.macleod@ivata.com</a>
* @version $Revision: 1.4 $
*/
public class CollectionAddTag extends TagSupport {
/**
* Logger for this class.
*/
private static final Logger logger = Logger
.getLogger(CollectionAddTag.class);
/**
* Serialization version (for <code>Serializable</code> interface).
*/
private static final long serialVersionUID = 1L;
/**
* <p>Stores the name of the colleciton to add a new value to.</p>
*/
private String name;
/**
* <p>Stores the value of the object to be added to the
* <code>Colleciton</code>.</p>
*/
private Object value;
/**
* <p>Default constructor.</p>
*/
public CollectionAddTag() {
super();
}
/**
* <p>Performs the action of adding the value supplied to the
* <code>Collection</code>.</p>
*
* <p>This method is called when the JSP engine encounters the start tag,
* after the attributes are processed.<p>
*
* <p>Scripting variables (if any) have their values set here.</p>
*
* @exception JspException if the <code>Collection</code> with
* the name specified does not exist at page scope.
* @return <code>SKIP_BODY</code> since this tag has no body.
*/
public int doStartTag() throws JspException {
if (logger.isDebugEnabled()) {
logger.debug("doStartTag() - start");
}
//super.doStartTag();
Collection collection = (Collection)
pageContext.getAttribute(name, PageContext.PAGE_SCOPE);
// if there is nothing at page scope, try session scope
if (collection == null) {
collection = (Collection) pageContext.getAttribute(name,
PageContext.SESSION_SCOPE);
}
// if there is no collection with this name, cry now
if (collection == null) {
throw new JspException("Error in CollectionAddTag: No collection "
+ "found in page or session scope called '"
+ name
+ "'");
}
collection.add(value);
if (logger.isDebugEnabled()) {
logger.debug("doStartTag() - end - return value = " + SKIP_BODY);
}
return SKIP_BODY;
}
/**
* <p>Get the name of the collection to add a new value to.</p>
*
* @return the current value of the <code>Collection</code> name.
*/
public final String getName() {
if (logger.isDebugEnabled()) {
logger.debug("getName() - start");
}
if (logger.isDebugEnabled()) {
logger.debug("getName() - end - return value = " + name);
}
return name;
}
/**
* <p>Get the value of the object to be added to the
* <code>Colleciton</code>.</p>
*
* @return the current value of the object to be added.
*/
public final Object getValue() {
if (logger.isDebugEnabled()) {
logger.debug("getValue() - start");
}
if (logger.isDebugEnabled()) {
logger.debug("getValue() - end - return value = " + value);
}
return value;
}
/**
* <p>Set the name of the colleciton to add a new value to.</p>
*
* @param nameParam the new value of the <code>Collection</code> name.
*/
public final void setName(final String nameParam) {
if (logger.isDebugEnabled()) {
logger.debug("setName(String nameParam = " + nameParam
+ ") - start");
}
this.name = nameParam;
if (logger.isDebugEnabled()) {
logger.debug("setName(String) - end");
}
}
/**
* <p>Set the value of the object to be added to the
* <code>Colleciton</code>.</p>
*
* @param valueParam the new value of object to be added.
*/
public final void setValue(final Object valueParam) {
if (logger.isDebugEnabled()) {
logger.debug("setValue(Object valueParam = " + valueParam
+ ") - start");
}
this.value = valueParam;
if (logger.isDebugEnabled()) {
logger.debug("setValue(Object) - end");
}
}
}
|