/** {@inheritDoc} */ public MediaType fromString(String header) { if (header == null) throw new IllegalArgumentException(); try { int p = header.indexOf('/'); int col = header.indexOf(';'); String type = null; String subType = null; if (p < 0 && col < 0) // no '/' and ';' return new MediaType(header, null); else if (p > 0 && col < 0) // there is no ';' so no parameters return new MediaType( HeaderHelper.removeWhitespaces(header.substring(0, p)), HeaderHelper.removeWhitespaces(header.substring(p + 1))); else if (p < 0 && col > 0) { // there is no '/' but present ';' type = HeaderHelper.removeWhitespaces(header.substring(0, col)); // sub-type is null } else { // presents '/' and ';' type = HeaderHelper.removeWhitespaces(header.substring(0, p)); subType = header.substring(p + 1, col); } Map<String, String> m = new HeaderParameterParser().parse(header); return new MediaType(type, subType, m); } catch (ParseException e) { throw new IllegalArgumentException(e); } }
@Override public void export( MolgenisRequest request, String fileName, TupleTable tupleTable, int totalPages, int currentPage) throws TableException, IOException { try { final File tempDir = new File(System.getProperty("java.io.tmpdir")); final File spssFile = File.createTempFile("spssExport", ".sps", tempDir); final File spssCsvFile = File.createTempFile("csvSpssExport", ".csv", tempDir); // TODO: instruction .txt file. final File zipExport = File.createTempFile("spssExport", ".zip", tempDir); final FileOutputStream spssFileStream = new FileOutputStream(spssFile); final FileOutputStream spssCsvFileStream = new FileOutputStream(spssCsvFile); final SPSSExporter spssExporter = new SPSSExporter(tupleTable); spssExporter.export(spssCsvFileStream, spssFileStream, spssCsvFile.getName()); spssCsvFileStream.close(); spssFileStream.close(); ZipUtils.compress( Arrays.asList(spssFile, spssCsvFile), zipExport, DirectoryStructure.EXCLUDE_DIR); HeaderHelper.setHeader( request.getResponse(), "application/octet-stream", fileName + ".zip"); exportFile(zipExport, request.getResponse()); } catch (Exception e) { throw new TableException(e); } }
/** {@inheritDoc} */ public String toString(MediaType mime) { StringBuffer sb = new StringBuffer(); sb.append(mime.getType()).append('/').append(mime.getSubtype()); for (Entry<String, String> entry : mime.getParameters().entrySet()) { sb.append(';').append(entry.getKey()).append('='); HeaderHelper.appendWithQuote(sb, entry.getValue()); } return sb.toString(); }
@Override public void export( MolgenisRequest request, String fileName, TupleTable tupleTable, int totalPages, int currentPage) throws TableException, IOException { HeaderHelper.setHeader(request.getResponse(), "application/ms-excel", fileName + ".csv"); final CsvExporter csvExporter = new CsvExporter(tupleTable); csvExporter.export(request.getResponse().getOutputStream()); }