
package edu.wustl.catissuecore.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import edu.wustl.catissuecore.bizlogic.ExportCollectionProtocolBizLogic;
import edu.wustl.common.action.SecureAction;
import edu.wustl.common.util.logger.Logger;

/**
 * This action class receives and forwards all the bulk operations
 * request done from UI.
 * @author sagar_baldwa
 *
 */
public class ExportCollectionProtocolAction extends SecureAction
{

	/**
	 * logger.
	 */
	private transient final Logger logger = Logger.getCommonLogger(ExportCollectionProtocolAction.class);

	@Override
	/**
	 * Execute Secure Action.
	 */
	protected ActionForward executeSecureAction(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) throws Exception
	{
		String mappingForward = null;
		try 
		{
			
			ExportCollectionProtocolBizLogic exportCP=new ExportCollectionProtocolBizLogic();
			StringBuffer downloadFile = exportCP.getCPXMLFile(request.getParameter("title"));
			response.getWriter().append(downloadFile);

			response.setContentType("application/download");
            response.setHeader("Content-Disposition", "attachment;filename=\""+request.getParameter("title")+".csv\"");
            
            
		} catch (Exception exp) {
			logger.error(exp.getMessage(), exp);
		}
		return mapping.findForward(mappingForward);
	}
}
@@ -441,16 +441,62 @@
 Logger;%0D
+%0Aimport edu.wustl.common.xml2excel.CSVWriter;%0D
 %0A%0D%0A/**%0D%0A
@@ -1276,182 +1276,89 @@
 %0A%09%09%09
-response.getWriter().append(downloadFile
+CSVWriter writer = new CSVWriter(
 );%0D%0A
-%0D%0A
 %09%09%09
-response.setContentType(%22application/download%22);%0D%0A            response.setHeader(%22Content-Disposition%22, %22attachment;filename=
+writer.generate(downloadFile.toString(),%22
 %5C%22%22+
@@ -1395,16 +1395,26 @@
 %22.csv%5C%22%22
+, response
 );%0D%0A    

Fix for #169.