@Override
public void service(HttpServletRequest req, HttpServletResponse resp)
throws IOException, ServletException {
UserService userService = UserServiceFactory.getUserService();
User user = userService.getCurrentUser();
// logEnvironment();
String knowledgeBaseFile = req.getParameter(PARAM_KNOWLEDGE_BASE);
String excelFile = req.getParameter(PARAM_EXCEL_DATA_FILE);
//Identify where the rules are stored
RuleSource ruleSource = new RuleSource();
ruleSource.setKnowledgeBaseLocation(knowledgeBaseFile);
log.info("Using knowledgeBaseFile"+knowledgeBaseFile);
if ((user != null)&&(knowledgeBaseFile!=null)&&!knowledgeBaseFile.equals("")&&(excelFile!=null)&&!excelFile.equals("")) {
resp.setContentType("application/vnd.ms-excel");
resp.setHeader("Content-Disposition",
"attachment; filename=result.xls");
//Check the RUL
RedSecurityManager.checkUrl(knowledgeBaseFile);
RedSecurityManager.checkUrl(excelFile);
log.info("Using Excel File"+excelFile);
URL url = new URL(excelFile);
HSSFWorkbook wb;
try {
wb = commonSpreadsheetUtils.callRules(url,ruleSource, RedConstants.EXCEL_LOG_WORKSHEET_NAME);
SpreadSheetOutputter.outputToStream(wb, resp.getOutputStream());
} catch (Exception e) {
log.warning(e.getMessage());
throw new ServletException(e);
}
} else {
resp.sendRedirect(userService.createLoginURL(req.getRequestURI()));
}
}