CvsStreamInfo streamInfo = new CvsStreamInfo();
if(stack.isEmpty() || stack.peek().getAttribute(DynamicListAction.TABLE_KEY) == null) {
throw new IllegalArgumentException("no panel or table found");
} else {
Table table = (Table)stack.peek().getAttribute(DynamicListAction.TABLE_KEY);
table.query(true);
ArrayList<String> header = new ArrayList<String>();
for(Column column : table.getColumns()) {
header.add(removeHTML(MessageUtil.message(request, column.getMessageKey())));
}
streamInfo.addLine(header);
for(Row row : table.getRows()) {
ArrayList<String> values = new ArrayList<String>();
for(int i=0; i<row.getColumns().length; i++) {
Object cell = row.getColumns()[i];
if(cell == null) {
values.add("");
} else {
String value = table.getColumns()[i].getFormatter().format(
(MessageResources)request.getSession().getServletContext().getAttribute(Globals.MESSAGES_KEY),
(Locale)request.getSession().getAttribute(Globals.LOCALE_KEY),
cell);
values.add(removeHTML(value));
}
}
streamInfo.addLine(values);
}
String fileName = sdf.format(new Date())+" ";
if(ListConfigurationVO.Type.PERSON.getName().equals(table.getName())) {
fileName += MessageUtil.message(request, "entity.system.listConfiguration.type.persons");
} else if(ListConfigurationVO.Type.COMPANY.getName().equals(table.getName())) {
fileName += MessageUtil.message(request, "entity.system.listConfiguration.type.companies");
} else {
fileName += "download";
}
fileName += ".csv";