<%@ page language="java" contentType="text/html; charset=UTF-8" %> <%@ page import="java.util.*, java.text.*" %> <%@ page import="com.hof.mi.web.service.*" %> <%@ page import="java.net.URLEncoder" %> <% String host = "localhost"; Integer port = 8080; String userid = "admin@yellowfin.com.au"; String password = "test"; String orgid = "1"; String uuid = request.getParameter("uuid"); String fname = request.getParameter("fname"); String ufilter = request.getParameter("filters").replace(",","|"); String path = "/services/ReportService"; String suffix = ""; String format = request.getParameter("format"); String contentType = "application/octet-stream"; if (format == null) format = "PDF"; if (format.equals("CSV")) { contentType = "text/comma-separated-values"; suffix = ".csv"; } else if (format.equals("PDF")) { contentType = "application/pdf"; suffix = ".pdf"; } else if (format.equals("XLS")) contentType = "application/vnd.ms-excel"; else if (format.equals("XLSX")) { contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; suffix = ".xlsx"; } else if (format.equals("RTF")) contentType = "application/rtf"; else if (format.equals("TEXT")) contentType = "text/tab-separated-values"; ReportServiceClient rsc = new ReportServiceClient(host, port, userid, password, path); i4Report report = rsc.loadReportForUser(uuid, userid, password, orgid); ReportSchema[] filters = report.getFilterSchema(); String[] userfilters = ufilter.split("\\--|\\!!"); Map filterMap = new HashMap(); if (filters != null) { String key = null; String val = null; for (int i = 0; i < filters.length; i++) { for (int j = 1; j < userfilters.length; j++) { if (userfilters[j].trim().equals(filters[i].getDisplayName().trim())) { key = "filter-" + filters[i].getFilterId() + "-val" + j; val = userfilters[j + 1]; filterMap.put(key, val); } } report.setFilterById(filters[i].getFilterId(), val); } request.getSession().setAttribute("YFFILTERS", filterMap); } HashMap elementStorage = new HashMap(); report.run(elementStorage, format); response.setContentType(contentType); fname = fname + suffix; String encodedFilename = URLEncoder.encode( fname , "UTF-8"); response.setHeader("Content-Disposition","attachment;" + "filename=\"" + encodedFilename + "\""); java.io.BufferedOutputStream o = new java.io.BufferedOutputStream(response.getOutputStream(), 32000); o.write(report.renderBinary()); o.flush(); %>