/**
 * <p>Title: ShoppingCartHDAO Class>
 * <p>Description:	ShoppingCartBizLogic provides the shopping cart functionality.</p>
 * Copyright:    Copyright (c) year
 * Company: Washington University, School of Medicine, St. Louis.
 * @author Aniruddha Phadnis
 * @version 1.00
 * Created on Jul 21, 2005
 */

package edu.wustl.catissuecore.bizlogic;

import java.io.File;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.List;

import edu.wustl.catissuecore.domain.Specimen;
import edu.wustl.catissuecore.query.ShoppingCart;
import edu.wustl.catissuecore.util.global.Variables;
import edu.wustl.common.util.dbManager.DAOException;
import edu.wustl.common.util.logger.Logger;

/**
 * ShoppingCartBizLogic provides the shopping cart functionality.
 * @author aniruddha_phadnis
 */
public class ShoppingCartBizLogic extends DefaultBizLogic
{
	public void add(ShoppingCart cart,Object obj[]) throws DAOException
    {
		if(cart!=null && obj!=null)
		{
			for(int i=0;i<obj.length;i++)
			{
				List list = retrieve(Specimen.class.getName(),"systemIdentifier",obj[i].toString());
				
				if (list!=null && list.size()!= 0)
				{
					Specimen specimen = (Specimen)list.get(0);
					cart.add(specimen);
				}
			}
		}
    }
    
	public ShoppingCart delete(ShoppingCart cart,Object obj[])
    {
		if(cart!=null && obj!=null)
		{
			for(int i=0;i<obj.length;i++)
			{
	        	String str = obj[i].toString();
	        	int index = str.indexOf(":") + 1;
	        	
	        	cart.remove(str.substring(index));
			}
		}
		
		return cart;
    }
    
	public void deleteCartFile(String fileName)
    {
		try
		{
			fileName = fileName + ".txt";
			File f = new File(Variables.catissueHome,fileName);
			f.delete();
		}
		catch(Exception e)
		{
			 Logger.out.error(e.getMessage(), e);
		}
	}
	
	public List export(ShoppingCart cart,String fileName)
    {
		List shoppingCartList = null;
		
		if(cart != null)
		{
			Hashtable table = cart.getCart();
			
			if(table != null && table.size() != 0)
			{
				Enumeration enum = table.keys();
				
				shoppingCartList = new ArrayList();
				
				List rowList = new ArrayList();
				
				rowList.add("Identifier");
				rowList.add("Type");
				rowList.add("Subtype");
				rowList.add("Tissue Site");
				rowList.add("Tissue Side");
				rowList.add("Pathological Status");
				
				shoppingCartList.add(rowList);
				
				while(enum.hasMoreElements())
				{
					rowList = new ArrayList();
					
					String key = (String)enum.nextElement();
					Specimen specimen = (Specimen)table.get(key);
					
					rowList.add(String.valueOf(specimen.getSystemIdentifier()));
					rowList.add(specimen.getClassName());
					
					if(specimen.getType() != null)
						rowList.add(specimen.getType());
					else
						rowList.add("");
					
					rowList.add(specimen.getSpecimenCharacteristics().getTissueSite());
					rowList.add(specimen.getSpecimenCharacteristics().getTissueSide());
					rowList.add(specimen.getSpecimenCharacteristics().getPathologicalStatus());
					
					shoppingCartList.add(rowList);
				}
			}
		}
		
		return shoppingCartList;
	}
}
@@ -1538,17 +1538,17 @@
 ndexOf(%22
-:
+_
 %22) + 1;%0D

Change in export()