<%@page  contentType="text/html; charset=UTF-8" pageEncoding="ISO-8859-1" session="true"
%><%@page errorPage="Exception.jsp"
%><%@page import="com.fujitsu.iflow.model.bpm.BPMSession"
%><%@page import="com.fujitsu.iflow.model.bpmcore.BPMSessionImpl"
%><%@page import="com.fujitsu.iflow.model.workflow.DMS"
%><%@page import="com.fujitsu.iflow.model.workflow.WFObjectFactory"
%><%@page import="com.fujitsu.iflow.model.workflow.WFSession"
%><%@page import="com.fujitsu.iflow.model.workflow.WorkItem"
%><%@page import="com.fujitsu.iflow.model.workflow.AttachmentRef"
%><%@page import="com.fujitsu.iflow.model.workflow.ProcessInstance"
%><%@page import="com.fujitsu.iflow.model.wfadapter.DocRepository"
%><%@page import="java.util.ArrayList"
%><%@page import="java.io.*"
%>
<% //checks the session is valid or not
   request.setCharacterEncoding("UTF-8");
   BPMSession bps = (BPMSession) session.getAttribute("BPMSession");
    if (bps == null) { 
		throw new Exception("You are not logged in, or your log-in session has expired.  Go back to the previous page, refresh the page, and log in before trying this function again.");
    }
%>
	<%@ include file="dtmCommon.jsp"%>
	<%

		//out.println("File Name received to export;"+fileName);
		
		String exportFile = fileName.substring(fileName.lastIndexOf("/")+1, fileName.length());
		if(exportFile==null)exportFile="dtm.dat";
		
		OutputStream os = response.getOutputStream();

		response.setContentType("application/octet-stream");
        response.setHeader("Content-Disposition",
                           "attachment; filename=\"" + exportFile + "\"");
		
		if (out.getBufferSize() != 0)
       	out.clear();
       
       	ArrayList decisionTables = (ArrayList)(dtm.getDecisionTables());
	//Added for the new Dms Adapter		
	ByteArrayOutputStream bos = new ByteArrayOutputStream();
	ObjectOutputStream oos = new ObjectOutputStream( bos);
	oos.writeObject(decisionTables);
	oos.flush();
	byte buffer [] = bos.toByteArray();   
      os.write(buffer);
      os.close();
	%>
	
	