%@ 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 = 8922;
String userid = "admin@yellowfin.com.au";
String password = "test";
String orgid = "1";
String uuid = request.getParameter("uuid");
String fname = request.getParameter("fname");
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";
HashMap filters = new HashMap();
boolean cleared = filters.size() == 0;
Iterator f = request.getParameterMap().keySet().iterator();
while (f.hasNext()) {
String key = (String) f.next();
if (key.startsWith("filter")) {
if (!cleared) {
filters.clear();
cleared = true;
}
String value = request.getParameter(key);
int pipeIndex = value.indexOf("|");
if (pipeIndex == -1) continue;
key = value.substring(0, pipeIndex);
value = value.substring(pipeIndex + 1);
filters.put(key, value);
}
}
ReportServiceClient rsc = new ReportServiceClient(host, port, userid, password, path);
i4Report report = rsc.loadReportForUser(uuid, userid, password, orgid);
f = filters.keySet().iterator();
while (f.hasNext()) {
String key = (String) f.next();
String value = (String) filters.get(key);
report.setFilter(key, value);
}
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();
%>