Example usage for org.apache.solr.internal.csv CSVUtils printLine

List of usage examples for org.apache.solr.internal.csv CSVUtils printLine

Introduction

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

Prototype

public static String printLine(String[] values, CSVStrategy strategy) 

Source Link

Document

Converts an array of string values into a single CSV line.

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  av  a  2  s .  c  o  m*/
        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);
}