String idStr = (String)request.getAttribute("biobjectId");
Integer id = new Integer (idStr);
BIObject obj = DAOFactory.getBIObjectDAO().loadBIObjectById(id);
ObjTemplate templ1 = obj.getActiveTemplate();
byte[] jcrContent1 = templ1.getContent();
String templateFileName = templ1.getName();
ZipEntry entry = new ZipEntry(templateFileName);
String label = obj.getLabel();
zipOut.putNextEntry(entry);
zipOut.write(jcrContent1);
List subReports = DAOFactory.getSubreportDAO().loadSubreportsByMasterRptId(id);
Iterator subReportsIt = subReports.iterator();
while (subReportsIt.hasNext()) {
Subreport subRpt = (Subreport) subReportsIt.next();
BIObject aSubRptObj = DAOFactory.getBIObjectDAO().loadBIObjectById(subRpt.getSub_rpt_id());
// load the subreport template
ObjTemplate templ = aSubRptObj.getActiveTemplate();
byte[] jcrContent = templ.getContent();
templateFileName = templ.getName();
label = aSubRptObj.getLabel();
// put the subreport template in a folder which name is the subreport label
entry = new ZipEntry(label + "/" + templateFileName);
zipOut.putNextEntry(entry);
zipOut.write(jcrContent);
}
String templateFileZIP = (String)request.getAttribute("fileName");
if (templateFileName == null){
templateFileName = "template.zip";
}
httpResp.setHeader("Content-Disposition","attachment; filename=\"" + templateFileZIP + "\";");
zipOut.flush();
zipOut.close();
out.flush();
}else{
freezeHttpResponse();
HttpServletResponse httpResp = getHttpResponse();
String idTemplateStr = (String)request.getAttribute("TEMP_ID");
Integer idTemplate = new Integer(idTemplateStr);
IObjTemplateDAO objtempdao = DAOFactory.getObjTemplateDAO();
ObjTemplate objTemp = objtempdao.loadBIObjectTemplate(idTemplate);
byte[] content = objTemp.getContent();
httpResp.setHeader("Content-Disposition","attachment; filename=\"" + objTemp.getName() + "\";");
httpResp.setContentLength(content.length);
httpResp.getOutputStream().write(content);
httpResp.getOutputStream().flush();
}
}