Example usage for org.apache.solr.internal.csv CSVStrategy EXCEL_STRATEGY

List of usage examples for org.apache.solr.internal.csv CSVStrategy EXCEL_STRATEGY

Introduction

In this page you can find the example usage for org.apache.solr.internal.csv CSVStrategy EXCEL_STRATEGY.

Prototype

CSVStrategy EXCEL_STRATEGY

To view the source code for org.apache.solr.internal.csv CSVStrategy EXCEL_STRATEGY.

Click Source Link

Usage

From source file:com.searchbox.framework.web.FavoriteController.java

License:Apache License

@RequestMapping(value = "/favorite/downloadCSV")
public void downloadCSV(@RequestParam String sort, @Qualifier("favoriteTable") Pageable page,
        HttpServletResponse response, HttpServletRequest request) throws IOException {
    String csvFileName = "favorites.csv";
    response.setContentType("text/csv");
    // creates mock data
    String headerKey = "Content-Disposition";
    String headerValue = String.format("attachment; filename=\"%s\"", csvFileName);
    response.setHeader(headerKey, headerValue);
    List<Favorite> list = service.findAllCount(sort, new PageRequest(0, Integer.MAX_VALUE));
    String result = "Id, Title, Url, Time \n";
    for (Favorite f : list) {
        String[] row = new String[4];
        row[0] = f.getFavoriteId();//from  w  w  w.  j a  v a  2s  .c om
        row[1] = f.getTitle();
        URL url = new URL(request.getRequestURL().toString());
        row[2] = url.getHost() + "/oppfin/all/view/?ff=" + f.getIdField() + "[" + f.getFavoriteId() + "]";
        row[3] = f.getTime().toString();
        result = result + CSVUtils.printLine(row, CSVStrategy.EXCEL_STRATEGY) + "\n";
    }
    response.getWriter().print(result);
}